VideoHelp Forum
+ Reply to Thread
Page 2 of 2
FirstFirst 1 2
Results 31 to 39 of 39
Thread
  1. Originally Posted by drudge View Post
    I've created a Windows Batch (.bat) file to solve a similar scenario, and I hope others find useful.




    PasteBin: http://pastebin.com/Xqu2ZA7m

    Code:
    @ECHO OFF
    REM // =======================
    REM || Batch Subtitle Muxing
    REM ||       for MKVmerge
    REM || v0.4-20150511 by drudge
    REM \\ =======================
    REM @@ This batch script will scan the provided directory (or current folder)
    REM @@ for video files, attempt to match them with subtitle files,
    REM @@ and mux them using the MKVmerge command line.
    REM	// ---- ---- ---- ----
    REM || USER CONFIGURATION
    REM // full path to mkvmerge.exe
    	SET "muxpath=C:\Program Files\MKVToolNix\mkvmerge.exe"
    REM \\ -- -- -- -- --
    REM // full path to unrar program, make sure to include switches
    	SET "rarpath=C:\Program Files\7-Zip\7z.exe"
    	SET "rarcmd=e"
    REM \\ -- -- -- -- --
    REM // output path (with trailing slash)
    REM ++ leave blank for working directory
    	SET "outputdir="
    REM @@ default: SET "outputdir="
    REM \\ -- -- -- -- --
    REM // prepend text to output filename
    REM ++ REQUIRED if outputdir is left blank
    	SET "fileprefix=subtitled-"
    REM @@ blank: SET "fileprefix="
    REM \\ -- -- -- -- --
    REM || END USER CONFIG
    REM \\ ---- ---- ---- ----
    REM -- editing below this line should be done precisely. (here thar be dragons)
    REM ===========================================================================
    
    REM @@ simple counters
    SET /A "mc=0"
    SET /A "me=0"
    
    REM @@ default working path
    SET "wp=."
    
    REM @@ optional working path via argument
    IF EXIST "%~1" SET "wp=%~1"
    
    REM @@ ready steady go!
    CLS
    ECHO ===========================================================================
    
    REM @@ attempt to use custom setting for output path
    IF EXIST "%outputdir%" (
    	REM @@ user has provided output path
    	ECHO == User Setting -- Output to: [%outputdir%]
    ) ELSE (
    	REM @@ no custom setting, check for prefix
    	IF [%fileprefix%]==[] (
    		ECHO @@ ERROR: empty [fileprefix] setting requires [outputdir] to be set
    		SET /A me+=1
    		GOTO:done
    	)
    	REM @@ use working path for output
    	SET "outputdir=%wp%\"
    )
    FOR %%H IN ("%wp%") DO (
    	REM @@ because "." doesn't tell us where we are
    	ECHO == Scanning [%%~dpfH\] for video files...
    )
    
    :getfiles
    FOR %%I IN ("%wp%\*.avi",
    REM			"%wp%\*.customVideoExtension",
    			"%wp%\*.mkv",
    			"%wp%\*.mp4") DO (
    	REM @@ found a video file, now check for subtitles
    	CALL:getsubs "%%~I"
    )
    GOTO:done
    
    :getsubs
    FOR %%J IN ("%wp%\%~n1.idx",
    REM			"%wp%\%~n1.customSubtitleExtension",
    			"%wp%\%~n1.srt") DO (
    REM @@ check for paired subtitle files. USF/XML may require this check as well
    	IF %%~xJ==.idx IF EXIST "%wp%\%%~nJ.idx" IF NOT EXIST "%wp%\%%~nJ.sub" (
    		IF EXIST "%wp%\%%~nJ.rar" (
    			ECHO -- [%%~nJ.sub] -- Found potential .rar
    			ECHO | SET /p extdone=">> "
    			"%rarpath%" "%rarcmd%" "%%~dpJ%%~nJ.rar" | FIND "Extracting"
    		) ELSE (
    			ECHO @@ ERROR: [%%~nJ.idx] -- Missing .sub file
    			SET /A me+=1
    			GOTO:eof
    		)
    	)
    REM @@ subtitle found, time to put it all together
    	IF EXIST "%wp%\%%~nJ%%~xJ" CALL:muxit "%%~f1" "%%~xJ"
    )
    GOTO:eof
    
    :muxit
    REM @@ make sure the destination file doesn't exist first
    IF EXIST "%outputdir%%fileprefix%%~n1%~x1" (
    	ECHO @@ ERROR: [%~n1%~x1] -- Existing output file
    	SET /A me+=1
    	GOTO:eof
    )
    
    REM @@ we've made it!
    SET /A mc+=1
    REM @@ now we let mkvmerge work its magic
    ECHO | SET /p muxdone="++ Muxing: (%mc%) [%~n1%~x1]"
    "%muxpath%" -q -o "%outputdir%%fileprefix%%~n1%~x1" "%~1" "%wp%\%~n1%~2"
    ECHO  ..complete
    REM @@ success!
    GOTO:eof
    
    :done
    ECHO == Finished Processing: %mc% completed / %me% errors
    ECHO ===========================================================================
    REM @@ game over, man
    pause
    This is a fantastic batch that works great for me. But I would actually need it to work with subfolders AND erase original video and sub files on completion. I would like it to work on hundreds of my files and I don't have enough space on my HD to keep the old files and the new ones. I don't know anything about coding batch files, could somebody help ?
    Quote Quote  
  2. Member
    Join Date
    Aug 2017
    Location
    Türkiye
    Search PM
    Originally Posted by drudge View Post
    I've created a Windows Batch (.bat) file to solve a similar scenario, and I hope others find useful.




    PasteBin: http://pastebin.com/Xqu2ZA7m

    Code:
    @ECHO OFF
    REM // =======================
    REM || Batch Subtitle Muxing
    REM ||       for MKVmerge
    REM || v0.4-20150511 by drudge
    REM \\ =======================
    REM @@ This batch script will scan the provided directory (or current folder)
    REM @@ for video files, attempt to match them with subtitle files,
    REM @@ and mux them using the MKVmerge command line.
    REM	// ---- ---- ---- ----
    REM || USER CONFIGURATION
    REM // full path to mkvmerge.exe
    	SET "muxpath=C:\Program Files\MKVToolNix\mkvmerge.exe"
    REM \\ -- -- -- -- --
    REM // full path to unrar program, make sure to include switches
    	SET "rarpath=C:\Program Files\7-Zip\7z.exe"
    	SET "rarcmd=e"
    REM \\ -- -- -- -- --
    REM // output path (with trailing slash)
    REM ++ leave blank for working directory
    	SET "outputdir="
    REM @@ default: SET "outputdir="
    REM \\ -- -- -- -- --
    REM // prepend text to output filename
    REM ++ REQUIRED if outputdir is left blank
    	SET "fileprefix=subtitled-"
    REM @@ blank: SET "fileprefix="
    REM \\ -- -- -- -- --
    REM || END USER CONFIG
    REM \\ ---- ---- ---- ----
    REM -- editing below this line should be done precisely. (here thar be dragons)
    REM ===========================================================================
    
    REM @@ simple counters
    SET /A "mc=0"
    SET /A "me=0"
    
    REM @@ default working path
    SET "wp=."
    
    REM @@ optional working path via argument
    IF EXIST "%~1" SET "wp=%~1"
    
    REM @@ ready steady go!
    CLS
    ECHO ===========================================================================
    
    REM @@ attempt to use custom setting for output path
    IF EXIST "%outputdir%" (
    	REM @@ user has provided output path
    	ECHO == User Setting -- Output to: [%outputdir%]
    ) ELSE (
    	REM @@ no custom setting, check for prefix
    	IF [%fileprefix%]==[] (
    		ECHO @@ ERROR: empty [fileprefix] setting requires [outputdir] to be set
    		SET /A me+=1
    		GOTO:done
    	)
    	REM @@ use working path for output
    	SET "outputdir=%wp%\"
    )
    FOR %%H IN ("%wp%") DO (
    	REM @@ because "." doesn't tell us where we are
    	ECHO == Scanning [%%~dpfH\] for video files...
    )
    
    :getfiles
    FOR %%I IN ("%wp%\*.avi",
    REM			"%wp%\*.customVideoExtension",
    			"%wp%\*.mkv",
    			"%wp%\*.mp4") DO (
    	REM @@ found a video file, now check for subtitles
    	CALL:getsubs "%%~I"
    )
    GOTO:done
    
    :getsubs
    FOR %%J IN ("%wp%\%~n1.idx",
    REM			"%wp%\%~n1.customSubtitleExtension",
    			"%wp%\%~n1.srt") DO (
    REM @@ check for paired subtitle files. USF/XML may require this check as well
    	IF %%~xJ==.idx IF EXIST "%wp%\%%~nJ.idx" IF NOT EXIST "%wp%\%%~nJ.sub" (
    		IF EXIST "%wp%\%%~nJ.rar" (
    			ECHO -- [%%~nJ.sub] -- Found potential .rar
    			ECHO | SET /p extdone=">> "
    			"%rarpath%" "%rarcmd%" "%%~dpJ%%~nJ.rar" | FIND "Extracting"
    		) ELSE (
    			ECHO @@ ERROR: [%%~nJ.idx] -- Missing .sub file
    			SET /A me+=1
    			GOTO:eof
    		)
    	)
    REM @@ subtitle found, time to put it all together
    	IF EXIST "%wp%\%%~nJ%%~xJ" CALL:muxit "%%~f1" "%%~xJ"
    )
    GOTO:eof
    
    :muxit
    REM @@ make sure the destination file doesn't exist first
    IF EXIST "%outputdir%%fileprefix%%~n1%~x1" (
    	ECHO @@ ERROR: [%~n1%~x1] -- Existing output file
    	SET /A me+=1
    	GOTO:eof
    )
    
    REM @@ we've made it!
    SET /A mc+=1
    REM @@ now we let mkvmerge work its magic
    ECHO | SET /p muxdone="++ Muxing: (%mc%) [%~n1%~x1]"
    "%muxpath%" -q -o "%outputdir%%fileprefix%%~n1%~x1" "%~1" "%wp%\%~n1%~2"
    ECHO  ..complete
    REM @@ success!
    GOTO:eof
    
    :done
    ECHO == Finished Processing: %mc% completed / %me% errors
    ECHO ===========================================================================
    REM @@ game over, man
    pause
    Hi,
    The script works perfectly. There are already subtitles in my mkvs and I'm adding 2nd subtitles in them. But the added subtitle's language is undefined. What can I do to specify the subtitle language and it's subtitle language track?
    Thanks in advance.
    Quote Quote  
  3. Member
    Join Date
    Sep 2017
    Location
    Asia
    Search Comp PM
    I'm pretty lost with the codes here especially since I dont have much experience with bat files or bat coding.

    But can any1 help me with doing a batch mux? basically I just want to disable subtitles for all of the video files in my 1 folder. The output must be outside the folder (the previous folder) and it must not delete the original file just to be safe.

    Would also appreciate it if you can include a way to reverse the default audio order for the 2nd audio to be the main while the 1st to not be the default audio. Or for the japanese instead of english and vice versa (incase I need this knowledge in the future).
    Quote Quote  
  4. not working is other folder sorry man
    Quote Quote  
  5. Originally Posted by _Al_ View Post
    maybe it could be done easier, not sure, this script goes through those folders in MOVIE folder (or whatever name), finds ts and ac3 and muxes it to mkv, names of those folders or filenames are not important, just those extensions
    Code:
    @echo off
    set "MOVIE_directory=D:\Movies"
    set "mkv_merge=C:\Program Files\MKVtoolnix\mkvmerge.exe"
    
    for /R "%MOVIE_directory%" %%a in (.) do call :mux_TS_and_AC3 "%%a"
    echo DONE muxing
    pause
    
    :mux_TS_and_AC3 <folder name>
    if "%MOVIE_directory%"=="%~dpn1" goto :eof
    echo folder: %~dpn1
    set "ts_name="
    set "ac3_name_ext="
    for /r "%~dpn1" %%i in ("*.ts","*.TS") do set "ts_name=%%~ni" & set "ts_name_ext=%%~nxi"
    for /r "%~dpn1" %%i in ("*.ac3","*.AC3") do set "ac3_name_ext=%%~nxi"
    if not defined ts_name  echo    ts not found in %~n1 folder & goto :eof
    if not defined ac3_name_ext echo    ac3 not found in %~n1 folder & goto :eof
    echo muxing %ts_name%.mkv from %~n1 folder
    pushd "%~dpn1"
    "%mkv_merge%" -o "%~dp1%ts_name%.mkv" "%ts_name_ext%" "%ac3_name_ext%"
    popd
    echo ----------------------------------------
    goto :eof
    Can you help me for the same but MKV + AAC. The added sound should be the default.
    Quote Quote  
  6. Originally Posted by amxcs View Post

    Can you help me for the same but MKV + AAC. The added sound should be the default.
    Change *.ts to *.mkv and *.ac3 to *.aac.
    Quote Quote  
  7. if you want I wrote this C# GUI..
    https://github.com/Bazzu85/MKVmergeBatcher

    try 1.167 version (windows only)
    Quote Quote  
  8. Member Randombit's Avatar
    Join Date
    Dec 2010
    Location
    Acadiana
    Search PM
    I know this is an old thread, but it popped up in search and it did not have the solution for me.
    I found this thread when I needed to mux too many files, HEVC video in mkv container (without audio) and opus in plain audio files. I am new to scripting, thus my script is simple. Please note, subdirectory 'done' is not created automatically, it must exist before executing. You could add 'mkdir -p done' to the script if you wish. Files were named like this:
    Code:
    foo0.mkv
    foo0.opus
    foo1.mkv
    foo1.opus
    ...
    And here is my script.
    Code:
    find -type f -exec basename -s .opus {} \; | {
      while read filename ; do
        mkvmerge -o done/"${filename%}.mkv" "$filename.opus" "$filename.mkv"
      done
    }
    As you can see I get the filename without extension from all opus files and then I use this filename to mux .opus and .mkv files. It shouldn't be hard to modify this script for your needs.
    Quote Quote  
  9. Originally Posted by drudge View Post
    I've created a Windows Batch (.bat) file to solve a similar scenario, and I hope others find useful.
    Hi drudge. Is it possible to modify your script that accepts MP4 and SRT files...but output MKV instead? Unfortunately I don't have the coding dexterity to do this.

    Downloading MP4 files with SRT is quite common, but since the audio may not be MP4 compliant, MKV is best. Thanks!
    Quote Quote  
Visit our sponsor! Try DVDFab and backup Blu-rays!