VideoHelp Forum
+ Reply to Thread
Results 1 to 5 of 5
Thread
  1. 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
    Quote Quote  
  2. "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
    Quote Quote  
  3. 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.
    Quote Quote  
  4. not sure but check out Losslesscut and videomass as both of these do merging / concatenating files
    Quote Quote  
  5. 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"
        ...
    )
    But then you would have to add to such a script every possible language name that could be found, even if the naming scheme does follow a standard as in your example that's not so convenient ; also each subtitle name would be added as a new line, so the .bat file would have to be edited first to remove line breaks.
    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
    ...which seems to do the trick. (Damn, how much time did I spend on this !... O_O With my damn computer crashing midpoint to boot, as it does every f##king day, usually at a very bad moment...)

    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 15:24.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!