Hi everyone,
I was wondering how I can batch merge many mp4 video files with several subtitles into a single mkv?
For example:
namevideo01.mp4 [This mp4 has 1 video + 1 audio]
namevideo01.en-US.cc.srt
namevideo01.es-419.forced.srt
namevideo01.es-419.srt
namevideo02.mp4 [This mp4 has 1 video + 1 audio]
namevideo02.en-US.cc.srt
namevideo02.es-419.forced.srt
namevideo02.es-419.srt
I could use this:
FOR %%A IN (*.mp4) DO "C:\Program Files\MKVToolNix\mkvmerge.exe" -o "%%~nA.mkv" "%%~A" "%%~nA.en-US.cc.srt" "%%~nA.es-419.forced.srt" "%%~nA.es-419.srt"
but I'd like something more generic, something that will pick up as many subtitles as possible. Also I'd like to get the right name, like English / Spanish (Forced) / Spanish, and make the forced subs activated by default.
Any help would be appreciated. Thanks
+ Reply to Thread
Results 1 to 5 of 5
-
-
"metafox" can do it just by dragging and dropping files, you just have to configure it to group video and subs,
☞ https://codecpack.co/download/MetaFox.html -
metafox doesn't rename the tracks correctly. Only creates track 1 track 2 and track 3, it doesn't pick up the language named in the file name.
-
not sure but check out Losslesscut and videomass as both of these do merging / concatenating files
-
Perhaps you could use a batch script to create the mkvmerge scripts themselves. Not sure how to do it precisely, but I've seen such suggestions in the past (from master “jagabo” if I'm not mistaken — indeed, here).
Something like :
Code:FOR %%A in (*.mp4) DO ( echo FOR %%%%A IN (*.mp4) DO ^"C:^\Program Files^\MKVToolNix^\mkvmerge.exe^" -o ^"%%%%~nA.mkv^" ^"%%%%~A" >"%%~nA.bat" IF EXIST "%%~nA.en-US.srt" echo ^"%%%%~nB.en-US.cc.srt^"" >>"%%~nA.bat" IF EXIST "%%~nA.es-419.forced.srt" echo ^"%%%%~nB.es-419.forced.srt"" >>"%%~nA.bat" IF EXIST "%%~nA.es-419.srt" echo " ^"%%%%~nB.es-419.srt^"" >>"%%~nA.bat" ... )
So I tried this instead :
Code:chcp 1252 setlocal enabledelayedexpansion FOR %%A in (*.mp4) DO ( SET name=%%~nA SET merge=^"C:\Program Files\MKVToolNix\mkvmerge.exe^" -o ^"!name!.mkv^" ^"!name!.mp4^" FOR %%B in ("!name!.*.srt") DO ( set srt=%%B FOR /F "tokens=2 delims=." %%C in ("!srt!") DO set lang=%%C set merge=!merge! ^"!name!.!lang!.srt^" ) echo !merge!>>"%%~nA mkvmerge.bat" ) pause
Disclaimer : My grasp of these scripting things is cursory at best (in this case I had a hard time figuring out how each special character ought to be “escaped” -- this helped), what I came up with may contain egregious mistakes, so test thoroughly before commiting to any of the above.
Note : I put « chcp 1252 » to deal with names containing accentuated characters (as the name of the file I tested the script with), it should not be required with english names.
Note : It would be a bit more streamlined, and more convenient in general, to put a copy of mkvmerge.exe (or better yet a hard link) somewhere in your system's “path”. That way you would only have to type « mkvmerge » instead of « "C:\Program Files\MKVToolNix\mkmerge.exe" ».
Note : You could add all commands to process all MP4 files in a folder to the same script by specifying a single name, with no variable, for instance « echo !merge!>>"mkvmerge.bat" », but then there would be a risk of overwriting a previous script with the same name left in the same folder which you may want to keep for future reference (although the « >> » redirection appends new data to an existing file, as opposed to « > » which does overwrite).
Note : It might be possible to improve the above script to achieve the last of your queries, i.e. set explicit names and have “forced” subtitles activated by default. Enough for today as far as I'm concerned, but someone may chime in.Last edited by abolibibelot; 2nd Oct 2021 at 14:24.
Similar Threads
-
Batch remux mkv to mp4 with Windows PowerShell
By [ss]vegeta in forum Newbie / General discussionsReplies: 0Last Post: 22nd Dec 2020, 14:48 -
MKVToolnix Batch Merge Videos and Subtitles, Different Formats
By pumpysworld in forum Newbie / General discussionsReplies: 2Last Post: 25th Nov 2018, 21:16 -
Assistance needed to change subtitles with MKV Merge
By jarod1005 in forum SubtitleReplies: 12Last Post: 19th Jul 2017, 12:57 -
Batch muxing MP4 subtitles with Vidcoder?
By bizzybody in forum Video ConversionReplies: 5Last Post: 7th Jul 2017, 02:54 -
Windows Software to Merge Multiple Video Inputs Into Single Camera Output?
By pone44 in forum Newbie / General discussionsReplies: 4Last Post: 28th Mar 2017, 15:54