VideoHelp Forum




+ Reply to Thread
Results 1 to 28 of 28
  1. Hi all,

    I have more than 50 mkvs that I would like to mux with subtitles. It will take a lot of time if I have to do it one by one. I read somewhere that you can do this by creating a batch file. Unfortunately, I have no idea how to do it. I hope somebody can help me. Thank you.
    Quote Quote  
  2. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    How are your video and subtitles files named? It will be easy if they are named same like video.mkv and video.srt.
    Quote Quote  
  3. Originally Posted by Baldrick View Post
    How are your video and subtitles files named? It will be easy if they are named same like video.mkv and video.srt.
    They are name like this:

    Avatar (2009).mkv
    Avatar (2009)_track02.srt


    Thanks for helping
    Quote Quote  
  4. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    Always with _track02.srt?
    Quote Quote  
  5. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    Mkvmerge batch code:
    Code:
    FOR %%f IN (*.mkv) DO (
    mkvmerge -o c:\newfolder\%%~nf-new.mkv %%~nf.mkv %%~nf_track02.srt
    )
    See https://forum.videohelp.com/threads/353334-%5BHelp%5D-Remux-multiple-mkv-with-ssa?p=221...=1#post2219832 for full details.
    Quote Quote  
  6. Originally Posted by Baldrick View Post
    Mkvmerge batch code:
    Code:
    FOR %%f IN (*.mkv) DO (
    mkvmerge -o c:\newfolder\%%~nf-new.mkv %%~nf.mkv %%~nf_track02.srt
    )
    See https://forum.videohelp.com/threads/353334-%5BHelp%5D-Remux-multiple-mkv-with-ssa?p=221...=1#post2219832 for full details.
    Do I need to change anything on your script or just copy paste & follow your instruction here
    "Put the test.bat and mkvmerge.exe in same folder as your mkv files.
    Create a new folder for you new mkv files, the c:\newfolder in this example. It should NOT be same as your current mkv/ssa files.
    Run the test.bat. You can try with a few mkv/ssa files first."


    To answer your question yes all of the subs (srt's) always have "_track02" at the end.


    Question for you.

    1. The script you provided will it also remove all the subtitles in the movie?

    Basically what I would like to do is to remux all mkvs with the new subtitle (with "_track02") but remove all the original subs from the mkv.


    2. Will it leave everything by default for the video,audio,chapters and tags?



    Im totally noob at this I appreciate your help.
    Quote Quote  
  7. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    Just copy everything and try with ONE mkv first.

    I don't think it will remove any subs. I don't know how to do that easy using the batch batch.

    You can also read https://forum.videohelp.com/threads/356314-How-to-batch-convert-multiplex-any-files-with-ffmpeg (how batch script works with ffmpeg but you use mkvmerge instead)
    Quote Quote  
  8. I will check on it once I get home and will update here how it works
    Quote Quote  
  9. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Add -S (note the capital S) between the output file name and the source MKV name to remove the subtitles from the remux.

    Code:
    FOR %%y IN (*.mkv) DO (
    	mkvmerge -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" "%%~dpny_track02.srt"
    )
    Last edited by ndjamena; 5th Dec 2014 at 05:28.
    Quote Quote  
  10. Originally Posted by TeddyBear10 View Post
    To answer your question yes all of the subs (srt's) always have "_track02" at the end.
    Or simple remove in SRT name _track02 with batch rename program like ReNamer
    drag all SRT files to program, add Remove _track02 and click rename
    Players like VLC or XBMC always play video with SRT subtitle first, if name of video and subtitle its same
    even if video contain subtitles
    Quote Quote  
  11. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Originally Posted by roma_turok View Post
    Originally Posted by TeddyBear10 View Post
    To answer your question yes all of the subs (srt's) always have "_track02" at the end.
    Or simple remove in SRT name _track02 with batch rename program like ReNamer
    drag all SRT files to program, add Remove _track02 and click rename
    Players like VLC or XBMC always play video with SRT subtitle first, if name of video and subtitle its same
    even if video contain subtitles
    You don't actually need to remove the _track02 for that to work, they look for anything that STARTS with the original file name, otherwise you wouldn't be able to have multiple srt files for a single video file.
    Quote Quote  
  12. [QUOTE=Baldrick;2360814]Mkvmerge batch code:
    Code:
    FOR %%f IN (*.mkv) DO (
    mkvmerge -o c:\newfolder\%%~nf-new.mkv %%~nf.mkv %%~nf_track02.srt
    )
    Tried it. Didn't work.

    I created a new folder put one mkv and sub. Then copy pasted the code above onto notepad save as *all files* name mux.bat. Also, I copy the mkvmerge icon into the same folder. When I click the .bat file cmd opens for a second then disappear.

    Anything I did wrong?
    Quote Quote  
  13. Originally Posted by ndjamena View Post
    Add -S (note the capital S) between the output file name and the source MKV name to remove the subtitles from the remux.

    Code:
    FOR %%y IN (*.mkv) DO (
    	mkvmerge -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" "%%~dpny_track02.srt"
    )
    Thanks for chiming in. Tried this too with the same result above.
    Quote Quote  
  14. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Then you're doing something wrong. What, if any, error messages are being thrown at you? (open a command prompt, CD /D to the directory, then type in the name of the .bat and the window will stay open once the bat has run).

    -Edit- Oh, you need the actual MKVMerge.exe somewhere the batch can find it, not just a shortcut. The exe is in the Program Files directory (in windows) MKVToolNix, you can move the exe, add the full path name to the bat or add the full MKVTopolNix directory name to the PATH system variable.
    Quote Quote  
  15. Banned
    Join Date
    Oct 2014
    Location
    Northern California
    Search PM
    Originally Posted by TeddyBear10 View Post
    Originally Posted by Baldrick View Post
    Mkvmerge batch code:
    Code:
    FOR %%f IN (*.mkv) DO (
    mkvmerge -o c:\newfolder\%%~nf-new.mkv %%~nf.mkv %%~nf_track02.srt
    )
    Tried it. Didn't work.

    I created a new folder put one mkv and sub. Then copy pasted the code above onto notepad save as *all files* name mux.bat. Also, I copy the mkvmerge icon into the same folder. When I click the .bat file cmd opens for a second then disappear.

    Anything I did wrong?
    Did you run this from a cmd window?
    Last edited by newpball; 6th Dec 2014 at 00:55.
    Quote Quote  
  16. Update--- after hours of playing with the batch it finally work. I put the mkvmerge path instead of just "mkvmerge". The original subs were gone.yey. I also added "--language 0:eng" to set the language of sub to english based on what I read from here https://www.bunkus.org/videotools/mkvtoolnix/doc/mkvmerge.html
    This is what I came up with.

    Code:
    FOR %%y IN (*.mkv) DO (
    	"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" --language 0:eng "%%~dpny_track02.srt"
    )

    Does it look alright? Will it set all the settings for the video,audio,chapters and tags by default like the original mkv?I just dont want to start ripping dvd's again if I messed up
    and is there anything I can add to get like a log in text file from the batch?
    Quote Quote  
  17. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Code:
    FOR %%y IN (*.mkv) DO (
    	"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" --language 0:eng "%%~dpny_track02.srt">"%%~dpny.log"
    )
    Quote Quote  
  18. Originally Posted by ndjamena View Post
    You don't actually need to remove the _track02 for that to work, they look for anything that STARTS with the original file name, otherwise you wouldn't be able to have multiple srt files for a single video file.
    I know that
    but if you have option remove this with single click, why not.
    Quote Quote  
  19. Hi TeddyBear10 ,

    > is there anything I can add to get like a log in text file from the batch?
    YES .

    Code:
    @echo on
    FOR %%y IN (*.mkv) DO (
    	"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" --language 0:eng "%%~dpny_track02.srt">"%%~dpny.log"
    )
    pause
    :end
    The CMD screen will stay open during the process .
    !!! At the end , DON'T strike any key of the keyboard !!!
    Right-click on that page => choose 'Select all' => Click on the 'ENTER' key .

    Open a text editor => paste the clipboard .
    Here , you have what you have selected .

    The properties of the CMD file can be nodified , when a batch file is open ( for example ) .
    Colors , number of lines , Height , width , etc.

    Regards .
    Quote Quote  
  20. Member
    Join Date
    Sep 2012
    Location
    Australia
    Search Comp PM
    Um, you probably should have copy/pasted an earlier batch, mine already outputs to a log.

    Code:
    >"%%~dpny.log"
    I could get it to output to the screen AND a log using a for /f loop...

    Code:
    FOR %%y IN (*.mkv) DO (
    	echo.>"%%~dpny.log"
    	for /f "tokens=* delims=" %%g in ('"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~ny-new.mkv" -S "%%~fy" --language 0:eng "%%~dpny_track02.srt"') DO (
    		echo %%g
    		echo %%g>>"%%~dpny.log"
    	)
    )
    Quote Quote  
  21. Hi ndjamena ,

    Thanks for your's informations about log .
    ( I am a bit old , my mind is tired ) .

    Regards .
    Quote Quote  
  22. Code:
    FOR %%y IN (*.mkv) DO (
    	echo.>"%%~dpny.log"
    	for /f "tokens=* delims=" %%g in ('"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~ny-new.mkv" -S "%%~fy" --language 0:eng "%%~dpny_track02.srt"') DO (
    		echo %%g
    		echo %%g>>"%%~dpny.log"
    	)
    )
    for some reason this doesn't work for me. it only creates a blank log file no muxing took place. I also tried to run it from cmd but it didn't do anything.




    Code:
    @echo on
    FOR %%y IN (*.mkv) DO (
    	"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" --language 0:eng "%%~dpny_track02.srt">"%%~dpny.log"
    )
    pause
    :end
    This one works. just one hiccup it created a log for every single mkv. This will be a little bit of work for me clicking every one of them instead of just one log file. But I guess I can find a simple program to scrape all the logs and put it in one text file.
    Quote Quote  
  23. you can always add a single log to one LOG that holds all of them, echo or type perhaps can return wrong thing while calling from within parentheses so maybe it is a good idea to just call function that always add single log that complete log:
    Code:
    @echo on
    break>all_logs.log
    FOR %%y IN (*.mkv) DO (
    	"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" --language 0:eng "%%~dpny_track02.srt">"%%~dpny.log"
    	call :print_log "%%~dpny.log"
            del "%%~dpny.log"
    )
    pause
    :end
    
    :print_log 
    echo. >>all_logs.log
    echo %~n1.LOG >>all_logs.log
    echo --------------------------------- >>all_logs.log
    type "%~1">>all_logs.log
    goto :eof
    Last edited by _Al_; 8th Dec 2014 at 10:17.
    Quote Quote  
  24. Hi TeddyBear10 ,

    For example : you own 3 files .log in witch you have a text written .

    --- Fichier_1.log
    Fichier_1.mkv

    --- Fichier_2.log
    Fichier_2.mkv

    --- Fichier_3.log
    Fichier_3.mkv

    If you create a batch file like below

    @echo on
    copy /b Fichier_1.log +Fichier_2.log +Fichier_3.log Groupement_1.log
    rem OR
    copy /b Fichier_*.log Groupement_2.log
    pause
    :fin

    You'll get the same result for Groupement_1.log and Groupement_2.log
    ---
    Fichier_1.mkvFichier_2.mkvFichier_3.mkv
    ---

    Cheers .
    Last edited by aazerty; 8th Dec 2014 at 11:58.
    Quote Quote  
  25. yes, copy is a nice example too, it can join txt files
    Quote Quote  
  26. Code:
    @echo on
    break>all_logs.log
    FOR %%y IN (*.mkv) DO (
    	"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" --language 0:eng "%%~dpny_track02.srt">"%%~dpny.log"
    	call :print_log "%%~dpny.log"
            del "%%~dpny.log"
    )
    pause
    :end
    
    :print_log 
    echo. >>all_logs.log
    echo %~n1.LOG >>all_logs.log
    echo --------------------------------- >>all_logs.log
    type "%~1">>all_logs.log
    goto :eof

    It works perfectly. Just one log for all the mkv's. Thank you everyone I really appreciate all your help. this will save me a lot of time!
    Quote Quote  
  27. I hate to bring this old thread back but I just need help to modify the code below to use it for another two different batch process.
    Basically, I would like to do the the following seperately
    (1) remux mkvs without the original subtitles in it (just keep the video & audio file)

    (2) remux mkvs with two new subtitles with name ending in "_track02" & "_track03". Track02 should be labeled forced & track03 is default track and should be next to audio in order of tracks.

    Example:
    Movie\Avatar.mkv (this has two subtitles in it)
    \Avatar_track02.srt
    \Avatar_track03.srt

    Order of tracks after remux
    Video
    Audio
    Track03 (default)
    Track02 (forced)

    Thank you for helping.

    Code:
    @echo on
    break>all_logs.log
    FOR %%y IN (*.mkv) DO (
    	"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" --language 0:eng "%%~dpny_track02.srt">"%%~dpny.log"
    	call :print_log "%%~dpny.log"
            del "%%~dpny.log"
    )
    pause
    :end
    
    :print_log 
    echo. >>all_logs.log
    echo %~n1.LOG >>all_logs.log
    echo --------------------------------- >>all_logs.log
    type "%~1">>all_logs.log
    goto :eof
    Quote Quote  
  28. 1.)
    Code:
    @echo on
    break>all_logs.log
    FOR %%y IN (*.mkv) DO (
    	"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~nxy" -S "%%~fy">"%%~dpny.log"
    	call :print_log "%%~dpny.log"
            del "%%~dpny.log"
    )
    pause
    :end
    
    :print_log 
    echo. >>all_logs.log
    echo %~n1.LOG >>all_logs.log
    echo --------------------------------- >>all_logs.log
    type "%~1">>all_logs.log
    goto :eof
    2.)
    Code:
    @echo on
    break>all_logs.log
    FOR %%y IN (*.mkv) DO (
    	"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "%%~dpyremuxed\%%~nxy" -S "%%~fy" --default-track 0:1 --forced-track 0:0 "%%~dpny_track03.srt" --default-track 0:0 --forced-track 0:1 "%%~dpny_track02.srt">"%%~dpny.log"
    	call :print_log "%%~dpny.log"
            del "%%~dpny.log"
    )
    pause
    :end
    
    :print_log 
    echo. >>all_logs.log
    echo %~n1.LOG >>all_logs.log
    echo --------------------------------- >>all_logs.log
    type "%~1">>all_logs.log
    goto :eof
    Try to learn:
    https://mkvtoolnix.download/doc/mkvmerge.html
    Maybe MKVBatch will interest you as well.
    Quote Quote  
Visit our sponsor! Try DVDFab and backup Blu-rays!