Advertisement
ayukawaa

Batch BDRemux using command line

Feb 24th, 2021
1,784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.21 KB | None | 0 0
  1. @echo off
  2. rem -----------------------------------------------------------
  3. rem FILEMENUTOOLS SCRIPT
  4. rem    Script author                    : AYUKAWAA (ayukawaa-at-gmail-dot-com)
  5. rem    Release                          : 1.3a [2021]
  6. rem    Description                      : Remux a bunch of .m2ts files to .mkv using mkvmerge
  7. rem    Comments                         : The program ask for destination folder
  8. rem REQUIREMENTS
  9. rem    FileMenuTools                    : https://www.lopesoft.com/index.php/en/filemenutools
  10. rem    MKVToolnix [mkvmerge]            : https://mkvtoolnix.download
  11. rem Parameters that must be changed in FileMenuTools config
  12. rem    USE AS:                           'Add command':
  13. rem    SECTION GENERAL
  14. rem         Action                      : Run programm
  15. rem         Sort files                  : By file name asc
  16. rem         Menu text                   : Mkvmerge M2TS -> MKV
  17. rem         Icon                        : [full path to mkvmerge] C:\Program Files\MKVToolNix\mkvmerge.exe
  18. rem         Element type
  19. rem             Files                   : Yes
  20. rem             Extensions              : m2ts
  21. rem             Number of elements      : >=1
  22. rem    SECTION PROGRAM PROPERTIES
  23. rem         Program                     : [full path to this file] C:\_UTILS\m2ts2mkv.cmd
  24. rem         Arguments                   : @FOLDER:Destination directory:@ %FILENAMES%
  25. rem         Working folder              : %FOLDERPATH%
  26. rem CHANGELOG
  27. rem    1.3: some fixes over wrong chars, & and . in directories/filenames
  28. rem TODO
  29. rem    - check number of parameters
  30. rem    - check free space on destination drive
  31. rem    - before starting look for all destination files and ask for deleting if needed
  32. rem    - check for different exit codes: 0=ok,1=warning but continue,2=fatal error
  33. rem -----------------------------------------------------------
  34.  
  35. rem CONSOLE COLORS
  36. rem
  37. rem    For Windows versions greater than 1511
  38. rem    Remove everything AFTER the = if it doesnt work for you
  39. rem
  40. rem       r=RESET color
  41. rem       d=DISPLAY color
  42. rem       v=VALUES color
  43. rem       c=COMMAND color
  44. rem       o=OK color
  45. rem       e=ERROR color
  46. rem       p=PAUSE color
  47. rem
  48. rem       https://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line
  49. set r=
  50. set d=
  51. set v=
  52. set c=
  53. set o=
  54. set e=
  55. set p=
  56.  
  57.  
  58.  
  59. rem change console to UTF8 for problems with chars//not needed if only english
  60. @chcp 65001 > nul
  61.  
  62.  
  63.  
  64. rem global parameters
  65. set window_text="M2TS->MKV"
  66. set mkvmerge="C:\Program Files\MKVToolNix\mkvmerge.exe"
  67.  
  68.  
  69.  
  70. rem beware of & and . in directory names
  71. set "source_directory=%~dp2"
  72. set "destination_directory=%~dpn1"
  73. SetLocal EnableDelayedExpansion
  74.  
  75.  
  76.  
  77. rem calculate number of arguments
  78. set count=0
  79. set total_count=0
  80. for %%a in (%*) do set /a total_count+=1
  81.  
  82.  
  83.  
  84. rem rem remove 1st parameter: destination directory
  85. set /a total_count-=1
  86. rem set destination_directory=%1
  87. shift
  88.  
  89. rem loop through all parameters
  90. :tag_loop
  91. if [%1]==[] goto tag_endofloop
  92. set /a count+=1
  93. rem change source filename extension from .m2ts to .mkv
  94. set original_file="%~snx1"
  95. set destination_file=%original_file:~0,-5%mkv"
  96. rem ".
  97. set full_destination_file="%destination_directory%\%destination_file:~1%
  98. rem ".
  99.  
  100.  
  101.  
  102. rem always delete first if destination exists
  103. set "destination_file_exists=NO"
  104. if exist %full_destination_file% set "destination_file_exists=YES / DELETING"
  105. if exist %full_destination_file% ECHO Y | del /Q %full_destination_file%
  106.  
  107.  
  108. echo.
  109. echo %d% ______________________________________________________________________ %r%
  110. echo.
  111. echo %d% SOURCE FILE           : %v% %original_file% %r%
  112. echo %d% DESTINATION FILE      : %v% %destination_file% %r%
  113. echo %d% DEST. FILE EXISTS     : %v% %destination_file_exists% %r%
  114. echo %d% SOURCE DIRECTORY      : %v% "%source_directory%" %r%
  115. echo %d% FULL DESTINATION FILE : %v% %full_destination_file% %r%
  116. echo %d% ______________________________________________________________________ %r%
  117. echo.%r%
  118.  
  119. rem do command line and check for errors
  120. title %window_text% [%count%/%total_count%]
  121. echo.%c%
  122. @echo on
  123. %mkvmerge% -o %full_destination_file% %original_file%
  124. @echo off
  125. echo.%r%
  126. if %ERRORLEVEL% NEQ 0 goto tag_errorlevel
  127. shift
  128. goto tag_loop
  129.  
  130.  
  131.  
  132. rem work done!
  133. :tag_endofloop
  134. echo.
  135. echo %d% ____________________________________________ %r%
  136. echo.
  137. echo %d% %window_text% // %v% %total_count% FILES PROCESED %r%
  138. echo %d% ____________________________________________ %r%
  139. echo.
  140. title %window_text% [Ok]
  141. goto tag_endofprogram
  142.  
  143.  
  144.  
  145. rem check for exit code not ok
  146. :tag_errorlevel
  147. echo.%e%
  148. echo _____________________________________________
  149. echo.                                            
  150. echo.                                            
  151. echo     W A R N I N G  :  ERRORS FOUND !!!      
  152. echo.                                            
  153. echo.                                            
  154. echo  Check this window log before closing ...    
  155. echo _____________________________________________
  156. echo.                                            
  157. echo.%r%
  158. title %window_text% [ WARNING!!! ERRORS found ]
  159. goto tag_endofprogram
  160.  
  161.  
  162.  
  163. rem you guess... end of program!
  164. :tag_endofprogram
  165. EndLocal
  166. pause
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement