I have a bunch of anime series in mkv format on my computer where I want to condense the audio and subtitle tracks from multiple videos together and make them have multiple audio and subtitle tracks instead of more separate videos. For example 2 videos, one with English audio and 2 subtitles (one is for titles, signs etc.) and another video with Japanese audio with subtitles that were translated English. Instead of that I want one video with both audio and all subtitle tracks.
The audio, video and subtitles are all compatible with one another, I guess meaning they can be muxed together no problems since I tried one with mkvmerge and it worked. The English versions have the same filenames with the exception of the episode number. The Japanese version has a different filename than the English version but all the Japanese versions have the same filenames with one another. With each anime series they are usually all the same format. It's not like I'll have an anime series with different video qualities such as aspect ratios, video format, etc. They are usually the same.
I already found a program that can batch rip everything from the mkv file such as video, audio and subtitles. If anyone's interested in that program it's called mkvcleaver I think. It was pretty handy. I was looking for program that is similar to that but ADDS extra audio and subtitle tracks in bulk. I don't want to re-encode anything. I couldn't find anything however.
I was using mkvmerger but as I'm sure other people have the same problem, it can only do each video one at a time. In which this program is now very time consuming when you have over 300 videos plus. Not to mention I read that the program creator doesn't ever intend on adding a batch feature due to time constraints.
I googled on how to make a batch script for this program and came across all kinds of things but most of the time it was for a different process and wouldn't work for me. I found one where some said to just copy the command line from mkvmerge and paste it onto a text document then paste it for as many as there are videos or episodes then change them. As I mentioned, not a good solution for the large volume of videos I have.
I know absolutely nothing of coding or anything about the details of mkv files and what not. I only got as far as I did from doing extensive googling. So I'll just post a few things I found and some info from mkvmerge
I came across this a lot
FOR %%A IN (*.mkv) DO mkvmerge -o "remux-%%~nA.mkv" "%%~A"
I guess that's what you use to include in a .bat file but I have no idea what it means, what else goes with it or how to use it.
Also I came across this video
http://www.youtube.com/watch?feature=player_embedded&v=bHTlQ61AaIE
It's not what I want to do but I saw something in there about not having to worry about renaming so I wanted that to be included in the .bat file.
FROM MKVMERGE
"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "C:\\Users\\Guy\\Videos\\Anim\\Anime Newly Combined Audio Video and Subtitles\\[Yousei-raws] Phantom Requiem for the Phantom 01 [BDrip 1920x1080 x264 FLAC] (1).mkv" "--track-name" "0:BDrip by moodperson" "--default-track" "0:yes" "--forced-track" "0:no" "--display-dimensions" "0:1920x1080" "--language" "1:jpn" "--track-name" "1:LPCM -> FLAC" "--default-track" "1:yes" "--forced-track" "1:no" "--language" "2:eng" "--default-track" "2:no" "--forced-track" "2:no" "-a" "1" "-d" "0" "-s" "2" "-T" "--no-global-tags" "--no-chapters" "(" "C:\\Users\\Guy\\Videos\\Anim\\ALREADY WATCHED\\Phantom\\[Yousei-raws] Phantom Requiem for the Phantom [BDrip 1920x1080 x264 FLAC]\\[Yousei-raws] Phantom Requiem for the Phantom 01 [BDrip 1920x1080 x264 FLAC].mkv" ")" "--forced-track" "0:no" "-a" "0" "-D" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "C:\\Users\\Guy\\Videos\\Anim\\Anime Subtitles and Audio Extracts\\[Cman21] Phantom ~Requiem for the Phantom~ Ep 01 'Awakening' [Blu-Ray 1080p][DBAFDE5F]_Track01.flac" ")" "--forced-track" "0:no" "-s" "0" "-D" "-A" "-T" "--no-global-tags" "--no-chapters" "(" "C:\\Users\\Guy\\Videos\\Anim\\Anime Subtitles and Audio Extracts\\[Cman21] Phantom ~Requiem for the Phantom~ Ep 01 'Awakening' [Blu-Ray 1080p][DBAFDE5F]_Track03.ass" ")" "--forced-track" "0:no" "-s" "0" "-D" "-A" "-T" "--no-global-tags" "--no-chapters" "(" "C:\\Users\\Guy\\Videos\\Anim\\Anime Subtitles and Audio Extracts\\[Cman21] Phantom ~Requiem for the Phantom~ Ep 01 'Awakening' [Blu-Ray 1080p][DBAFDE5F]_Track04.ass" ")" "--track-order" "0:0,0:1,0:2,1:0,2:0,3:0"
I'm sorry that this is so long and drawn out but I wasn't sure what else to put or to do. I think this might be too much to ask but can someone help me making a script for all of this? Is it difficult?
+ Reply to Thread
Results 1 to 30 of 39
Thread
-
-
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
-
@drudge
Long time since I seen a batch files.. shame really as they're extremely powerful.
Thanks for that. I added my own default language option. I added this at the top:
Code:REM // Default Language of created 'tracks' REM ++ Leave as is to set English flag SET "lang=eng" REM @@ blank: SET "lang=eng"
Code:"%muxpath%" --default-language "%lang%" -q -o "%outputdir%%fileprefix%%~n1%~x1" "%~1" "%wp%\%~n1%~2"
Hope this helps others!
~Steph -
I have lots of video-only-files and audio-files in subfolders of one folder.
I want to combine the video-stream and the audio-stream to MKV-files in another directory.
Can somebody help me what script I need?Last edited by flashandpan007; 28th Aug 2015 at 12:34.
-
I think I can use the script from drudge. working through the script ...
Do I need unrar? -> 7-Zip for this? -
-
If all files are in one folder the following does work for me:
Code:for %%a in (*.ts) do ("C:\Program Files\MKVtoolnix\mkvmerge.exe" -o "D:\Test\%%a.mkv" "%%a" "%%~na.ac3")
I tried:
Code:for /r "D:\Test\" %%a in (*.ts) do ("C:\Program Files\MKVtoolnix\mkvmerge.exe" -o "D:\Test\%%a.mkv" "%%a" "%%~na.ac3")
Does anybody know how to modify my little script?Last edited by flashandpan007; 30th Aug 2015 at 12:19.
-
because you are running your BAT file from folder with those ts files perhaps and it does not see those ac3 files in other folder, you'd need to include whole path for those ac3 files,
Code:for /r "D:\Test\" %%a in (*.ts) do ("C:\Program Files\MKVtoolnix\mkvmerge.exe" -o "D:\Test\%%~na.mkv" "%%~na.ts" "D:\Test\folder_with_ac3_files\%%~na.ac3")
-
The subfolders are called differently and each subfolder contains one ts-file and one ac3 file. Do I maybe need a variable for the directories?
-
If possible, I need a wildcard for the names of the subfolders (-> all subfolders) but * or ? doesn't work.
-
Movies
├─Movie_abc [...]
│ ├─Movie_abc.ts
│ └─Movie_abc.ac3
│
├─Movie_def [...]
│ ├─Movie_def.ts
│ └─Movie_def.ac3
│
├─Movie_ghi [...]
│ ├─Movie_ghi.ts
│ └─Movie_ghi.ac3
│
├─Movie_jkl [...]
│ ├─Movie_jkl.ts
│ └─Movie_jkl.ac3
│
├─Movie_mno [...]
│ ├─Movie_mno.ts
│ └─Movie_mno.ac3
│
├─Movie_pqr [...]
│ ├─Movie_pqr.ts
│ └─Movie_pqr.ac3
│
├─Movie_stu [...]
│ ├─Movie_stu.ts
│ └─Movie_stu.ac3
│
.
.
. -
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
Last edited by _Al_; 31st Aug 2015 at 18:29.
-
Thank you very much. It works
How to I set it up to put the outputfiles to a specific path. Before I edited the -o but now it doesn't work. What do have to change in this script. -
Ok last request:
Is it possible to make a preference of dts files Over ac3. Same filename in Same Directory of ac3 files of some movies. -
try this:
Code:@echo off set "DESTINATION_directory=D:\Movies" 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 "audio_name_ext=" for /r "%~dpn1" %%i in ("*.ts","*.TS") do set "ts_name=%%~ni" & set "ts_name_ext=%%~nxi" for /r "%~dpn1" %%i in ("*.dts","*.DTS","*.ac3","*.AC3") do set "audio_name_ext=%%~nxi" & goto :mux :mux if not defined ts_name echo ts not found in %~n1 folder & goto :eof if not defined audio_name_ext echo ac3 or DTS not found in %~n1 folder & goto :eof echo muxing %ts_name%.mkv from %~n1 folder pushd "%~dpn1" "%mkv_merge%" -o "%DESTINATION_directory%\%ts_name%.mkv" "%ts_name_ext%" "%audio_name_ext%" popd echo ---------------------------------------- goto :eof
"*.dts","*.DTS","*.ac3","*.AC3"
you can modify that as you want, first extension found is the audio for muxing -
had to change it to
Code:"*.ac3","*.AC3","*.dts","*.DTS"
Very nice. Now I'm happy. Thank you very much _Al_ -
I realise this is an old thread but but it's just come up in the search I did. The batch file works fine but how would I edit it to get to tag the audio as English BUT the subs as French?
EDIT: Ok, I see that it was the subs track that it tags so I was able to work that out; change SET "lang=eng" to SET "lang=fre". So that's all good. But is there a way to get it to tag the audio track as well? As English.Last edited by TomPhillips; 16th Oct 2015 at 12:13.
-
Is it possible to add a counter for the number of muxed files into that script? I tried it and it works but it only works for the file-structure above but _Al_ 's script also works when the movies are in that kind of file structure:
Code:All Movies ├Movies A .. C │ ├─Movie_A [...] │ │ ├─Movie_A.ts │ │ └─Movie_A.ac3 │ │ │ ├─Movie_B [...] │ │ ├─Movie_B.ts │ │ └─Movie_B.ac3 │ │ │ └─Movie_C [...] │ ├─Movie_C.ts │ └─Movie_C.ac3 │ ├Movies D .. F │ ├─Movie_D [...] │ │ ├─Movie_D.ts │ │ └─Movie_D.ac3 │ │ │ ├─Movie_E [...] │ │ ├─Movie_E.ts │ │ └─Movie_E.ac3 │ │ │ └─Movie_F [...] │ ├─Movie_F.ts │ └─Movie_F.ac3 │ ├Movies G .. I │ ├─Movie_G [...] │ │ ├─Movie_G.ts │ │ └─Movie_G.ac3 │ │ │ ├─Movie_H [...] │ │ ├─Movie_H.ts │ │ └─Movie_H.ac3 │ │ │ └─Movie_I [...] │ ├─Movie_I.ts │ └─Movie_I.ac3 │ . . .
Thank youLast edited by flashandpan007; 24th Dec 2015 at 08:01.
-
it was designed for that specific structure, ....,also that counter it can be done in many ways, you can generate a log file with filenames and counter as well, hopefully there is no syntax error in script I modified:
Code:@echo off set "DESTINATION_directory=D:\Movies" set "MOVIE_directory=D:\Movies" set "mkv_merge=C:\Program Files\MKVtoolnix\mkvmerge.exe" set "logfile=%DESTINATION_directory%\logfile.log" rem erasing logfile: break>"%logfile%" rem resetting counters: set "counter=0" set "counter_success=0" for /R "%MOVIE_directory%" %%a in (.) do call :mux_TS_and_AC3 "%%a" echo logfile is in: "%logfile%" echo. >> "%logfile%" echo total of MKV processed: %counter% >> "%logfile%" echo total of MKV created : %counter_success% >> "%logfile%" echo. echo total of MKV processed: %counter% echo total of MKV created : %counter_success% echo DONE muxing pause :mux_TS_and_AC3 <folder name> if "%MOVIE_directory%"=="%~dpn1" goto :eof echo folder: %~dpn1 set "ts_name=" set "audio_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", "*.dts","*.DTS") do set "audio_name_ext=%%~nxi" & goto :mux :mux if not defined ts_name echo ts not found in %~n1 folder & goto :eof if not defined audio_name_ext echo ac3 or DTS not found in %~n1 folder & goto :eof echo muxing %ts_name%.mkv from %~n1 folder pushd "%~dpn1" echo. >> "%logfile%" echo folder name: %~dpn1 >> "%logfile%" set /a counter=%counter% + 1 ver>nul "%mkv_merge%" -o "%DESTINATION_directory%\%ts_name%.mkv" "%ts_name_ext%" "%audio_name_ext%" if not %errorlevel%==0 echo ------------ error returned by mkvmerge ------------- >> "%logfile%" & popd &goto :eof if not exist "%DESTINATION_directory%\%ts_name%.mkv" echo ------------ error, mkv not created ------------- >> "%logfile%" & popd &goto :eof echo new mkv: .... \%ts_name%.mkv >> "%logfile%" set /a counter_success=%counter_success% + 1 popd echo ---------------------------------------- goto :eof
-
OMG! Thank you very much. I tested your script and I'm happy, but I noticed that the total of MKV processed is one per Folder Movie_A [...], Movie_B [...], Movie_C [...] higher than the created MKV Files. That is the similar issue I had with my script. Do you know what is causing this?
-
looks like this is caused by mkvmerge itself.
If a movie has an ampersand in the filename like Fast & Furious then the logfile doesn't contain the line with new mkv in the logfile caused by the ampersand in the filename which causes to take Furious as a command.
I searched but I'm not sure if this can be fixed?
Thank you _Al_Last edited by flashandpan007; 27th Dec 2015 at 15:46.
-
This works great, had to add the .ass subtitle extension but when testing it auto-added perfectly. However it stops at like episode 32 with no errors or anything and doesn't go past that. I took out the ones before it so that it would start with the problematic episode and managed to print screen when the CMD flashed and went away, it says:
Code:.avi] was unexpected at this time
-
Any special characters in the file name where it fails? Often these things happen because of unescaped characters like parentheses.
-
Only the exclamation point, but there were other episodes before that with one. Oh and the parentheses for part one and two.
EDIT, just went by some more with parentheses and no issues. Strange.
EDIT2, also every time the subs are merged either by this script or mkvToolnix I get audio sync issues....Last edited by negativzeroe; 6th Feb 2016 at 16:41.