View Full Version : Batch Remuxing with Mkvmerge
tosh9i
27th September 2010, 20:59
I use minicoder to encode videos. Currently, I have about 51 videos that I tried to re-encode, but minicoder just gave me an error message. I remuxed it with mkvmerge and now I don't get an error message.
That leaves me with 50 other videos that I have to add to mkvmerge > click on Start Muxing > wait about 30 seconds > remove file and go on to the next one, over and over again.
I was hoping that I could use the command line to make it so that mkvmerge remuxes all the files in a directory, batch remux.
Bottom line, I don't want to add them one by one, so I was hoping that I could use a script or something and make it so that mkvmerge does it.
Inspector.Gadget
27th September 2010, 21:46
Batchenc can automate this to some degree, provided the muxing options are the same for each file (e.g., all have 1 video and 1 audio stream that you want to tag "English" etc.)
J_Darnley
27th September 2010, 22:07
This is a one-liner:
FOR %A IN (*.mkv) DO mkvmerge -o "remux-%~nA.mkv" "%~A"
tosh9i
27th September 2010, 23:20
This is a one-liner:
FOR %A IN (*.mkv) DO mkvmerge -o "remux-%~nA.mkv" "%~A"
So, do I just copy and paste that into a text file and rename with a bat extension. Then put it in the folder with the rest of the videos I want to re-encode and double click on the batch file because I did that and the only thing that happened was a window popped up for a second then disappeared without providing any results.
I'll look into Batchenc as well, and let you guys know how it goes.
Thanks
J_Darnley
28th September 2010, 14:01
No. You cannot copy that into a batch file. A batch file requires double %. I was suggesting you run it from the command line.
tosh9i
28th September 2010, 19:58
my god...it finally worked. thank you thank you thank you. Now, I don't have to go through 50 files one by one, and I can use that command line again in the future. Even though, I couldn't figure out how to use it from the command line, I did what you said and added another % to the other ones > copied and pasted it to a text document > renamed it with bat extension and ran that, and it worked.
And Inspector.Gadget, thanks but I couldn't quite figure out that batchenc.
If possible J_Darnley, could you please help me out with two more batch command scripts.
1) a script that removes the first 3 seconds of a video. All the videos will be the same. This other fansub adds a clip to the front of the video and that causes sync problems when re-encoded.
2) batch combine a subtitle file (.srt) with the video file
J_Darnley
29th September 2010, 10:47
If you can do 1) with mkvmerge, just lookup the appropriate option and add it. If mkvmerge can't do this then I would suggest ffmpeg with a command like:
ffmpeg -ss 3 -i "%~A" -vcodec copy -acodec copy "remux-%~nA.mkv"
If the files have more than one audio track, or existing subtitles, you will need some more options there.
If the subtitles for 2) have the same name and are in the same folder you can append the following to the mkvmerge command: "%~dpnA.srt"
To do this all with ffmpeg:
ffmpeg -ss 3 -i "%~A" -i "%~dpnA.srt" -vcodec copy -acodec copy -scodec copy "remux-%~nA.mkv"
tosh9i
30th September 2010, 02:16
well, I managed to combine the video and srt using the the command line you provided. Thanks for that
I tried you ffmpeg, but nothing happened. I also tried downloading an updated version of ffmpeg, but still nothing.
But for now, I think I'll stick with mkvmerge.
This is the command line it shows when I split it after 3 seconds:
"C:\Program Files\MKVtoolnix\mkvmerge.exe" -o "F:\\Desktop\\mkvmerge\\Kindaichi Shonen no Jikenbo 01.mkv" "--forced-track" "0:no" "--forced-track" "1:no" "-a" "1" "-d" "0" "-S" "-T" "--no-global-tags" "--no-chapters" "F:\\JDownload\\New folder (2)\\Kindaichi Shonen no Jikenbo 01.avi" "--track-order" "0:0,0:1" "--split" "timecodes:00:00:03"
I tried adding that split timecodes part to the other command line, but nothing happened. Can you please help me one last time and provide me with a command line that will batch split videos after 3 seconds using mkvmerge.
Thanks again, you don' know how much time and effort you saved me.
Update: it worked (the split thing). I guess I was doing something wrong with it earlier.
Thanks for everything.
Stanley_A
9th December 2013, 03:46
So, I was able to add srts to mkvs using
FOR %A IN (*.mkv) DO mkvmerge -o "remux-%~nA.mkv" "%~A" "%~dpnA.srt"
Is there a way for me to put these command in a file I could double clic?
sneaker_ger
9th December 2013, 10:05
Exchange every "%" with "%%", put it into a text file and name it "whatever.bat".
Stanley_A
9th December 2013, 11:54
Thanks a lot!
Stanley_A
11th January 2014, 03:03
What if my original file is an AVI?
So, I have an AVI and a SRT, both with the same name.
And I want to use this script to mux them into an MKV.
How can I do that?
M+AUDIO
11th January 2014, 13:48
What if my original file is an AVI?
So, I have an AVI and a SRT, both with the same name.
And I want to use this script to mux them into an MKV.
How can I do that?
Hello,
Yes, this way:
FOR %%A IN (*.avi) DO mkvmerge -o "remux-%%~nA.mkv" "%%~A" "%%~dpnA.srt"
Stanley_A
14th January 2014, 01:54
Hi, thanks.
I get 5,53 KB files.
And the script when running says:
terminate called after throwing an instance of 'mtx::mm_io : : end_of_file_x'
what<>: end of file error
This aplication has requested the runtime to terminate ir in an unusual way
I'm using MKVToolNix 6.7.0 64bit.
And if I do it manually with mkvmerge gui I get no problems.
M+AUDIO
15th January 2014, 01:35
Agreed, x86 build works well with that command line but 64bit build not (as you saw yourself).
Sounds like there are some bugs in 6.7.0 x64 due to compiler. But no problem. The updated 64bit build (https://trac.bunkus.org/wiki/Troubleshooting) correctly works for me ;)
Stanley_A
16th January 2014, 04:41
That worked!
Thanks a lot!
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.