Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- rem -----------------------------------------------------------
- rem FILEMENUTOOLS SCRIPT
- rem Script author : AYUKAWAA (ayukawaa-at-gmail-dot-com)
- rem Release : 1.3a [2021]
- rem Description : Remux a bunch of .m2ts files to .mkv using mkvmerge
- rem Comments : The program ask for destination folder
- rem REQUIREMENTS
- rem FileMenuTools : https://www.lopesoft.com/index.php/en/filemenutools
- rem MKVToolnix [mkvmerge] : https://mkvtoolnix.download
- rem Parameters that must be changed in FileMenuTools config
- rem USE AS: 'Add command':
- rem SECTION GENERAL
- rem Action : Run programm
- rem Sort files : By file name asc
- rem Menu text : Mkvmerge M2TS -> MKV
- rem Icon : [full path to mkvmerge] C:\Program Files\MKVToolNix\mkvmerge.exe
- rem Element type
- rem Files : Yes
- rem Extensions : m2ts
- rem Number of elements : >=1
- rem SECTION PROGRAM PROPERTIES
- rem Program : [full path to this file] C:\_UTILS\m2ts2mkv.cmd
- rem Arguments : @FOLDER:Destination directory:@ %FILENAMES%
- rem Working folder : %FOLDERPATH%
- rem CHANGELOG
- rem 1.3: some fixes over wrong chars, & and . in directories/filenames
- rem TODO
- rem - check number of parameters
- rem - check free space on destination drive
- rem - before starting look for all destination files and ask for deleting if needed
- rem - check for different exit codes: 0=ok,1=warning but continue,2=fatal error
- rem -----------------------------------------------------------
- rem CONSOLE COLORS
- rem
- rem For Windows versions greater than 1511
- rem Remove everything AFTER the = if it doesnt work for you
- rem
- rem r=RESET color
- rem d=DISPLAY color
- rem v=VALUES color
- rem c=COMMAND color
- rem o=OK color
- rem e=ERROR color
- rem p=PAUSE color
- rem
- rem https://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line
- set r=[0m
- set d=[1;92m
- set v=[93m
- set c=[37m
- set o=[92m
- set e=[101;93m
- set p=[91m
- rem change console to UTF8 for problems with chars//not needed if only english
- @chcp 65001 > nul
- rem global parameters
- set window_text="M2TS->MKV"
- set mkvmerge="C:\Program Files\MKVToolNix\mkvmerge.exe"
- rem beware of & and . in directory names
- set "source_directory=%~dp2"
- set "destination_directory=%~dpn1"
- SetLocal EnableDelayedExpansion
- rem calculate number of arguments
- set count=0
- set total_count=0
- for %%a in (%*) do set /a total_count+=1
- rem rem remove 1st parameter: destination directory
- set /a total_count-=1
- rem set destination_directory=%1
- shift
- rem loop through all parameters
- :tag_loop
- if [%1]==[] goto tag_endofloop
- set /a count+=1
- rem change source filename extension from .m2ts to .mkv
- set original_file="%~snx1"
- set destination_file=%original_file:~0,-5%mkv"
- rem ".
- set full_destination_file="%destination_directory%\%destination_file:~1%
- rem ".
- rem always delete first if destination exists
- set "destination_file_exists=NO"
- if exist %full_destination_file% set "destination_file_exists=YES / DELETING"
- if exist %full_destination_file% ECHO Y | del /Q %full_destination_file%
- echo.
- echo %d% ______________________________________________________________________ %r%
- echo.
- echo %d% SOURCE FILE : %v% %original_file% %r%
- echo %d% DESTINATION FILE : %v% %destination_file% %r%
- echo %d% DEST. FILE EXISTS : %v% %destination_file_exists% %r%
- echo %d% SOURCE DIRECTORY : %v% "%source_directory%" %r%
- echo %d% FULL DESTINATION FILE : %v% %full_destination_file% %r%
- echo %d% ______________________________________________________________________ %r%
- echo.%r%
- rem do command line and check for errors
- title %window_text% [%count%/%total_count%]
- echo.%c%
- @echo on
- %mkvmerge% -o %full_destination_file% %original_file%
- @echo off
- echo.%r%
- if %ERRORLEVEL% NEQ 0 goto tag_errorlevel
- shift
- goto tag_loop
- rem work done!
- :tag_endofloop
- echo.
- echo %d% ____________________________________________ %r%
- echo.
- echo %d% %window_text% // %v% %total_count% FILES PROCESED %r%
- echo %d% ____________________________________________ %r%
- echo.
- title %window_text% [Ok]
- goto tag_endofprogram
- rem check for exit code not ok
- :tag_errorlevel
- echo.%e%
- echo _____________________________________________
- echo.
- echo.
- echo W A R N I N G : ERRORS FOUND !!!
- echo.
- echo.
- echo Check this window log before closing ...
- echo _____________________________________________
- echo.
- echo.%r%
- title %window_text% [ WARNING!!! ERRORS found ]
- goto tag_endofprogram
- rem you guess... end of program!
- :tag_endofprogram
- EndLocal
- pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement