# Batch re-mux .mkv to DiVX w subs

1. Hello,

I have got quite a number of .mkv-files of the same format. Like this:
Code:
Format                           : Matroska
File size                        : 343 MiB
Duration                         : 49mn 9s
Overall bit rate                 : 975 Kbps
Writing application              : mkvmerge v2.0.0 ('After The Rain Has Fallen') built on Feb  7 2007 18:53:57
Writing library                  : libebml v0.7.7 + libmatroska v0.8.0

Video
Format                           : MPEG-4 Visual
Format profile                   : Streaming Video@L1
Format settings, BVOP            : Yes
Format settings, QPel            : No
Format settings, GMC             : No warppoints
Format settings, Matrix          : Default
Codec ID                         : XVID
Codec ID/Hint                    : XviD
Duration                         : 49mn 6s
Bit rate                         : 798 Kbps
Width                            : 704 pixels
Height                           : 480 pixels
Display aspect ratio             : 4/3
Frame rate                       : 23.976 fps
Resolution                       : 24 bits
Colorimetry                      : 4:2:0
Scan type                        : Progressive
Writing library                  : XviD 1.1.2 (UTC 2006-11-01)

Audio
Format                           : MPEG Audio
Format version                   : Version 1
Format profile                   : Layer 3
Codec ID                         : A_MPEG/L3
Codec ID/Hint                    : MP3
Duration                         : 49mn 9s
Bit rate mode                    : Constant
Bit rate                         : 128 Kbps
Minimum bit rate                 : 128 Kbps
Channel(s)                       : 2 channels
Sampling rate                    : 48.0 KHz
Resolution                       : 16 bits
Writing library                  : LAME3.96r
Encoding settings                : CBR
Language                         : English

Text
Format                           : VobSub
Codec ID                         : S_VOBSUB
Codec ID/Info                    : The same subtitle format used on DVDs
Language                         : English
So it's obvious I don't need re-encoding, 'just' re-muxing, to DiVX w/ Subs. Is there a simple way?
If not, would someone advise me on how to create a batch file using avidemux/VirtualDubMod/mkvextract (one of these is sufficient, whatever is easier to do... ) and AVIAddXSubs?
I'm a newbie on those .bat-files, know the basics though.

Would be great, thanks!
2. I believe you can use the job list in AVIdemux to simply remux the videos into .avi (using 'copy' for both video and audio). I don't think it'll handle the subs that way, though.

I'm not sure AVIAddXSubs can be used in a batchfile, but I could be wrong.
3. That's right.

The downside is that I cannot access the subs included in the .mkv-files with avidemux. So I would have to de-mux those (or all streams) first and then re-mux. That's the question: how to do it with a batch file, if simple remuxing with one app in one step is not possible.

Other apps for muxing into .divx with subs are there, like avisub, divxmux.exe (and the GUI of course) and Txt2VobSub. But - I need help on a possible batch file.
Especially the opening and loading of apps and files by .bat-file, when to use the Windows commands in the .bat-file, when to use the apps' own commmands and how to differentiate between them on the respective lines of the .bat.

Perhabs someone already did something similar and could post a sample .bat-file? Would possibly be all I need! Not necessarily this routine (mkv2divx...), just something with two or more applications used and those with their respective parameters, etc.

4. Well,

I solved my own problem partly this way. For batch demuxing .mkv-files - assuming they're in the same directory! - put the following into any txt_editor (Windows Editor will do as well as any other) and be careful to replace the path to mkvextract.exe with the correct one on your system (keep quotation-marks!), then: save as a .bat-file.
Code:
for %%F in (*.mkv) do "C:\path to...\mkvextract.exe" tracks "%%F" "1:%%F_Track1.mp3" "2:%%F_Track2.idx" "3:%%F_Track3.avi"
pause
Note: the track ID's are crucial, you have to find out what they are first, they differ for any given .mkv. Then replace the corresponding numbers in this example with your own.
You may use mkvinfo this way (from mkvextract's helpfile), just open Windows' commandline editor in mkvmerge's directory, then enter the following:
Code:
mkvmerge -i "path\to\one\of\the\movie.mkv"
I presume (as in my case) that the files all contain the same streams in a respectively given order for the batch to work properly.
So of course for e.g. an ac3-stream you would change the extension in the batch from this "1:%%F_Track1.mp3" to this: "X:%%F_Track1.ac3" where "X" represents the track-ID you found out before.

When you have prepared and saved the .bat-file, you put in into the same directory as the .mkv-files, then double-click the .bat-file - and perhabs have a cup of coffee...
5. Well, here I am back.
Believe it or not, but I still have not solved the problem of batch-muxing the extracted streams. For now I have given up to try muxing the .divx /w vobsub. Although possible in theory of course, in practice mkvextract (or mkvmerge?) damages the vobsub-files and they cannot be used in any divx-muxing app. Neither does OCR work, 'cause they're damaged...

But I would like at least to batch re-mux the extraxted video-only avi's and the mp3's into working avi-files. And I have found a number of instructions, but not how to do a working batch-file!
I would gladly use mencoder, ffmpeg or AviMux GUI, but cannot for the life of me figure out how to do the batch properly.

My mencoder batch for example looked something like this,
Code:
 for %%F in (*.avi,*.mp3) do "path\to\mencoder" -oac copy -ovc copy  -o "%%F_New.avi" -audiofile "%%F" "%%F"
I also tried this:
Code:
 for %%F in (*.avi,*.mp3) do "path\to\mencoder" -oac copy -ovc copy  -o "%%F_New.avi" -audiofile "%%F.mp3" "%%F.avi"
but both ways mencoder didn't find the correct streams, although with single files and their respective names instead of variables it works like a charm...!
So basically I need to know, what variables I would have to use... Is it possible at all?

With ffmpeg I haven't succeeded so far in creating an .avi that my DVD-standalone will seek through properly (apart from the batch problem).

for %%F in (*.avi) do "x:\path\to\mencoder" "%%~F" -ovc copy -oac copy -mc 0 -noskip -noodml -audiofile "%%~nF.mp3" -o "%%~nF_new.avi"