AnimeSuki Forums

Register Forum Rules FAQ Members List Social Groups Search Today's Posts Mark Forums Read

Go Back   AnimeSuki Forum > Support > Tech Support

Notices

Reply
 
Thread Tools
Old 2014-07-16, 14:20   Link #1
jahob000
Junior Member
 
Join Date: Jul 2014
MKVMERGE Batch Scripting Multiple Files

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...&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.

I also came across an old thread on this site but it didn't work for me.

http://forums.animesuki.com/showthread.php?t=106210

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?
jahob000 is offline   Reply With Quote
Old 2014-07-16, 16:35   Link #2
sneaker
Senior Member
 
Join Date: Dec 2008
Create a folder structure that looks like this:

\A\
\B\
\output\
\mux.bat

The "mux.bat" should be a text file with the following content:
Code:
@echo off
setlocal enabledelayedexpansion 
cd /D %~dp0
cd A
set i=0
for %%a in (*.mkv) do set /A i+=1 & set alpha[!i!]=%%a
cd ..
cd B
set i=0
for %%b in (*.mkv) do set /A i+=1 & set beta[!i!]=%%b
cd ..
set n=%i%
for /L %%i in (1,1,%n%) do "C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "output\!alpha[%%i]!" "A\!alpha[%%i]!" --no-video "B\!beta[%%i]!"
1. Move the mkv files you want to keep the video of into folder "A"
2. Move the mkv files you only want the audio + subtitles from into folder "B"
3. run "mux.bat"

Notes:
- Do not extract the audio or subtitle tracks using mkvcleaver. That would only complicate things further.
- Because of difficult filename handling this uses just folder "A" and "B". It relies on the mkv files in both folders being in exactly the same alphabetical order!
sneaker is offline   Reply With Quote
Old 2014-07-16, 17:40   Link #3
jahob000
Junior Member
 
Join Date: Jul 2014
Thanks. I'll give that a try and see what happens. I'll make copies and try it those just in case anything goes wrong.

UPDATE: It didn't work for me. It simply flashed on the screen for a quick second then went away. I tried the regular click and then "Run As Administrator". I even tried running it from the command prompt by putting "C:\Users\Guy\Desktop\Dual Audio\mux.bat" with and without the quotes. With the quotes, nothing happened. Without the quotes it said "is not recognized as an internal or external command". Underneath it is said "operable program or batch file".

Even though you showed the folder structure I wasn't sure how to do it so I tried it different ways. I thought it was suppose to be where I create a folder and put folders A, B, Output and the .bat file in it the root of it. I tried putting the .bat inside of "Output" then "Output" inside of "B" and "B" inside of "A". Then I did the same thing but left the .bat file in the root. I wasn't sure if I was supposed to have MKVMERGE open or not.

I put the videos where you told me and I made sure that I copied the text perfectly.

I'm not sure if I'm doing something wrong or not. Also excuse my simplicity. Like I said, I'm not savvy with these kinds of things. They usually have to be explained to me in baby steps.

Last edited by jahob000; 2014-07-16 at 18:53.
jahob000 is offline   Reply With Quote
Old 2014-07-16, 23:43   Link #4
sneaker
Senior Member
 
Join Date: Dec 2008
Your first assumption about the folders was correct, all folders and the .bat file belong into the same root. Add a new line to the end of the script with the string "pause". This should allow you to view error messages. Make sure that mkvmerge.exe really is in "C:\Program Files (x86)\MKVToolNix\" and that the files you are trying to combine have the ".mkv" file extension.
sneaker is offline   Reply With Quote
Old 2014-07-17, 20:40   Link #5
jahob000
Junior Member
 
Join Date: Jul 2014
I added the new line. I wasn't sure if it was supposed to have quotes or not so I tried both ways. It still appeared and disappeared quickly when I clicked on it normally and as an administrator. So I tried to open it from the Command Prompt, normally and as an administrator also. The same message in my previous post showed up. I double checked to make sure that's where MKVMERGE's executable file was and it's there at the right location. I have my extensions shown and not hidden so I'm sure they are all MKVs. Just to double and triple check, I right clicked and checked the properties as well and they are all MKV files.

I'm not sure what else to try.
jahob000 is offline   Reply With Quote
Old 2014-07-17, 21:16   Link #6
sneaker
Senior Member
 
Join Date: Dec 2008
Quote:
Originally Posted by jahob000 View Post
"is not recognized as an internal or external command". Underneath it is said "operable program or batch file".
What does the error say exactly before the "is not..." part? Screenshot?

Either way I don't really know why this is happening. Sometimes people use the wrong encoding when saving the .bat file (try this one). Maybe it's a problem with your Windows? (Version? Language?)
sneaker is offline   Reply With Quote
Old 2014-07-18, 11:31   Link #7
jahob000
Junior Member
 
Join Date: Jul 2014
This is a screenshot when I do it with the one I made

[IMG][/IMG]

This is a screenshot when I do it with the one you sent me

[IMG][/IMG]

When I try yours, as you see in the screenshot, it says press any key and then I do but nothing else happens. It just goes away.

I have Windows 7 Home Edition and It's all in English. I'm in America.
jahob000 is offline   Reply With Quote
Old 2014-07-18, 14:58   Link #8
sneaker
Senior Member
 
Join Date: Dec 2008
1st screenshot: didn't even run the .bat file because you didn't use quotation marks and the path has a space in it
2nd screenshot: Looks like the .bat was started correctly but there were no mkv files in folders A and B
sneaker is offline   Reply With Quote
Old 2014-07-18, 16:29   Link #9
jahob000
Junior Member
 
Join Date: Jul 2014
Ah ok. I knew it had to be something simple and that it was on my end. Ok so this time used the .bat file that I made with the info you gave me. I copied the location from that info (with the quotes around the location) some stuff came up this time

Here's a screenshot
[IMG][/IMG]

Also, that's the A folder with the mkv files in them. Ignore the FLAC in the filename, that was already there but it is a video, I opened it to quadrupal check myself. I also have mkv files in the B folder as well.

Do you think it's because I have them as hidden? I don't think so because all of my other programs recognize my hidden files. But then again you know more than I do XD.

So I'm guessing the stuff in the command prompt is what is supposed to show up?

UPDATE: OH MY GOD I LOVE YOU!!!!! After talking about my files being hidden, I tested it with the one you sent. I put the mux.bat file you sent me in the root of the folder and this time I unhid all the files in Folders A and B. I double clicked on it and it immediately started muxing everything!! I checked the video and it has both audio and all the subtitles!!

I'm super excited!! You don't know how much you helped me out! However, before I become overly excite, I'm going to test it on on a few more different videos just to make sure it's absolutely working. I'll update this message again after that.

UPDATE 2: Ok I've verified that it works completely!!! Wow! I can't believe this! I've been trying to do this for so long! The best part is that I had a 2GB video file and it muxed it completely within 2 minutes!! That means I can have ALL my videos muxed overnight! Though I do have to remember what you said, the order of the episodes or videos in folders A and B have to match up otherwise I might have episodes being muxed to the wrong video.

Also, While I am at it, I have several questions.

Question 1.) I should be able to mux any file so long as I edit it in the .bat file correct?

Question 2.) Does this also mean I can mux files that are of different formats so long as I specify that in the .bat file?? Like an MKV and an AVI or something? Of course I mean the audio and video, not both videos together lol. I'm sure you know what I meant.

Question 3.) Are there certain audio files that won't mux with and MKV file or vise versa?

Question 4.) Speaking of formats, I'm not a wizard on this but are MKV files the only ones that have different audio and subtitle tracks? Like can AVIs, WMVs, RMVBs, FLVs, all have different tracks and stuff too? Because I may have some stuff where I want things put into an FLV or something instead.

Question 5.) Why are you so damn AWESOME?!

Haha. I think that's it.

Last edited by jahob000; 2014-07-18 at 17:25.
jahob000 is offline   Reply With Quote
Old 2014-07-18, 22:17   Link #10
sneaker
Senior Member
 
Join Date: Dec 2008
1., 2., 3.) Here is a revised version. It will work with any input file extension (including mixing different types) and unhide hidden files but ultimately the input files have to be supported by mkvmerge. The WMV container is not supported by mkvmerge iirc.

4.) Other files can have multiple tracks as well but you will find these mostly within mkv. AVIs sometimes have multiple audio tracks but the other types are 99.9% only one video track plus one audio track (subtitles hardcoded into video).

If you want to test for support you can simply open one of the files in mkvmerge GUI. If all tracks are listed and there is no error message it will very likely work.

Code:
@echo off
setlocal enabledelayedexpansion 
cd /D %~dp0
cd A
attrib -h *.*
set i=0
for %%a in (*.*) do set /A i+=1 & set alpha[!i!]=%%a & set gamma[!i!]=%%~na
cd ..
cd B
attrib -h *.*
set i=0
for %%b in (*.*) do set /A i+=1 & set beta[!i!]=%%b
cd ..
set n=%i%

for /L %%i in (1,1,%n%) do "C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "output\!gamma[%%i]!.mkv" "A\!alpha[%%i]!" --no-video "B\!beta[%%i]!"
sneaker is offline   Reply With Quote
Old 2014-07-19, 02:41   Link #11
jahob000
Junior Member
 
Join Date: Jul 2014
I see. Most of the files that I'll be dealing with is MKVs anyway. The other formats were just out of curiosity. Well, once again, thank you for all your help! I'll be sure to take this revised version as well and make a copy of it and put it away for safe keeping.
jahob000 is offline   Reply With Quote
Old 2014-07-29, 08:56   Link #12
sneaker
Senior Member
 
Join Date: Dec 2008
Quote:
Originally Posted by jahob000
Now I just need your help to do the opposite. Instead of adding, I want to take away.

I told you before that I have a program called MKV Clever that can extract audio, subtitles, time codes and anything embedded in an MKV file. However it doesn't truly remove it but makes a copy of what it extracts to whatever folder specified.

There may be times where I don't want the video to have any audio in it or maybe I want to take away an audio track. Needless to say I also want to do this with bulk. I was hoping that for this, maybe I just simply had to tweak the one you made for me already.

Is it the same thing? Is it more complicated?
See the mkvmerge documentation 2.7. Basically you can tell mkvmerge to only copy specific tracks or to not copy specific kind of tracks at all. Like in the batch file I made you can see that I used "--no-video" for the second input file as you didn't want the video of the second file at all (only audio and subtitles).

If it's only one input file each it becomes much more simple than the other batch:
Code:
@echo off
cd /D %~dp0
for %%a in (*.mkv) do "C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "output\%%a" --video-tracks 0 --audio-tracks 1,2 --subtitle-tracks !3,5 "%%a"
Means:
copy video track with id 0
copy audio tracks with id 1 and id 2
copy all subtitle tracks except the ones with id 3 and id 5 ("!" reverses meaning)

By default all tracks are copied so you only need to use the correspondent commands (--video-tracks/--audio-tracks/--subtitle-tracks) if you want to not copy every video/audio/subtitle track.
sneaker is offline   Reply With Quote
Old 2014-07-29, 11:03   Link #13
jahob000
Junior Member
 
Join Date: Jul 2014
Thanks for the Document source page. Maybe now I can try to learn how to make this stuff myself.

EDIT: I'm trying find different track IDs by using the Identify command but I'm having issues how to use it. I tried Googling but no one addresses it directly.

EDIT 2: Actually nevermind about that. I forgot that I had MKVMerge GUI to where I can just drag and drop a file to get the regular track IDs and the track IDs used when extracting. I got what I needed.

Last edited by jahob000; 2014-07-29 at 21:19.
jahob000 is offline   Reply With Quote
Old 2014-10-19, 08:57   Link #14
redpeppery
Junior Member
 
Join Date: Oct 2014
how to add subtitile to all .mkv in folder

Hello,

I need a batch file that will add subtitle in mkv container for all .mkv files in a folder that not contained allready a subtitle with a certain language. Subs name are the same with the .mkv.

The usual mkv merge command is bellow.

Do you think is posible to do something like this?

Thanks

"C:\Program Files\MKVToolNix\mkvmerge.exe" -o "G:\\Seinfeld.Complete.720p.HDTV..x264-TvT\\Seinfeld.S06.720p.HDTV.x264.DD5.1-Mixed\\Seinfeld.S06E06.720p.x264.DD5.1-iLL (1).mkv" "--language" "0:eng" "--default-track" "0:no" "--forced-track" "0:no" "--display-dimensions" "0:1280x720" "--default-track" "1:yes" "--forced-track" "1:no" "-a" "1" "-d" "0" "-S" "-T" "--no-global-tags" "--no-chapters" "(" "G:\\Seinfeld.Complete.720p.HDTV..x264-TvT\\Seinfeld.S06.720p.HDTV.x264.DD5.1-Mixed\\Seinfeld.S06E06.720p.x264.DD5.1-iLL.mkv" ")" "--language" "0:rum" "--forced-track" "0:no" "-s" "0" "-D" "-A" "-T" "--no-global-tags" "--no-chapters" "(" "G:\\Seinfeld.Complete.720p.HDTV..x264-TvT\\Seinfeld.S06.720p.HDTV.x264.DD5.1-Mixed\\Seinfeld.S06E06.720p.x264.DD5.1-iLL.srt" ")" "--track-order" "0:0,0:1,1:0"
redpeppery is offline   Reply With Quote
Old 2015-02-04, 22:58   Link #15
TSimpsons
Junior Member
 
Join Date: Feb 2015
Hi, first of all i want to say that im not read and speak very well english.. im spanish >.<
, i also where searching how to do this, i have like 300 episodes and i want to add a subititle track for all.. but it takes a lot of time 1 by 1 with mkvmerge, i dont know anything about comand promp and how to use it for muxing files could some one brind me a video or snatshots explaining how do this? i wathced this video https://www.youtube.com/watch?featur...&v=bHTlQ61AaIE
and understanded this part that he translate
for %%a in (*.mkv) do "C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o "output\%%a" --video-tracks 0 --audio-tracks 1,2 --subtitle-tracks !3,5 "%%a"
but where i have to put all this??? What is the bat.file in this snapshot?
http://s16.postimg.org/uf1n85nhx/Com...pt_message.png

Thanks !!
TSimpsons is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 22:35.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2015, vBulletin Solutions, Inc.
We use Silk.