Update Jul 16, 2011: I finally did a much-needed upgrade of my website, but in the process have broken images on almost all of my old posts. The images are still around; I'll try to get to restoring them on this post when I get some time to do so.
Note as of Jan 16, 2010: It's been several years since I've had to convert video using the methods in this article. A couple years ago, I had purchased a Popcorn Hour A-110 set top box which can play MKV files with H.264 video and any of a large number of audio codecs (and with 720p or 1080p resolution, too). Asking for help from me on any aspects of this guide will be pretty fruitless as I haven't had to deal with converting video files in such a long time.
Really, I won't be providing support for this guide, though I'll leave it up as it still seems useful to people. You'll be much better off going to an audio/video codec and conversion tools site.
As I promised earlier, I will post about how to convert an MKV container file with an H.264 encoded video and AC-3 encoded audio to an AVI container file with an XviD encoded video and, optionally, 2-channel MP3 encoded audio.
The MKV format makes a very good distibuting format, with the ability to have multiple audio streams and multiple subtitling streams, combined with the H.264 codec for high quality video. Unfortuntely, if you're like me, you have a DVD player that isn't able to play such files but can play XviD or DivX encoded video in AVI files (like my OPPO OPDV971H Player ) hooked up to a big-screen and an home theater audio system, but would wish to watch (or invite others to watch) that greatest and latest video that you've found on the internet, that's only available as an MKV file!
(I may have some errors in here. Feel free to comment to help with details or ask questions)
I was recently made aware the AllToAvi project. I haven't checked it out yet, but if it works like I think it does, then much of the following steps aren't necessary... ;). Still, I'll keep all of it up until I am able to confirm this.
These were installed and run on a Windows XP Home system. Yes, I am a Linux freak, but I am too used to windows for this process. There's also several commercial programs that seem able to do this, like Stoik Video Converter or All to AVI, but I'm sticking with freeware or open source tools in this guide.
- MKVExtractGUI v. 1.6.4 (If that site is down doesn't work, try downloading it from here)
- avc2avi1. There's a version with a GUI available here (Link comes from here, so check there out if the direct link doesn't work).
- H.264 and XviD VFW Codecs (These should both be usable through the Combined Community Codec Pack but, for some reason, I use the XviD Encoder from this installer instead for encoding XviD. You can also use any Codec Pack that includes the FFDShow VFW Codec)
- AC3ACM (Optional, to decode AC3 in VirtualDubMod)
- LameACM (Optional, to encode to MP3 in VirtualDubMod)
Install and Setup
Though a few of the tools and codecs that I've pointed to above have self-installers that will set everything up for you, the others require that you install them into your operating system.
The first example is VirtualDubMod. When I downloaded the file VirtualDubMod_1_5_10_2_All_inclusive.zip, all you get are the actual files instead of the normal install executable, so I extract all the files in it to "C:\Program Files\VirtualDubMod". When the VobSub_2.23 asks for the VirtualDub location, I give it the same path. I also create a shortcut to "C:\Program Files\VirtualDubMod\VirtualDubMod.exe" on my Desktop.
I also extract MKVExtractGUI and avc2avi into the same directory that the MKVtoolnix installer ("C:\Program Files\MKVtoolnix").
Many codecs either use an executable installer (especially if they are part of a codec pack) or can by installed by extracting the files into a temporary directory, right-clicking on the .inf file, and selecting Install.
FFDShow may need some configuring before it can decode H.264 streams for VirtualDubMod. Open up the FFDShow VFW Codec Configuration (On my system, Start -> All Programs -> Combined Community Codec Pack -> FFDShow VFW Codec Configuration), the click on the Decoder tab. Make sure that "Codecs" is selected in the left select box.
On the row with the H.264 format, change the Decoder to "libavcodec". If you wish to use FFDShow for your encoder, click on the Encoder tab and change the Encoder field to what ever format you wish (XviD is probably a good choice). When you get to the encoding step further down, choose the "ffdshow Video Codec" instead of the "XviD MPEG-4 Codec" that I use. Keep in mind that configuring it will look different.
For my examples, I will be using a video at C:\temp\Global_Astroliner\Global_Astroliner.mkv, for simplicity's sake.
The first step is to run it through MKVextractGUI to separate the video, audio, and subtitle streams to manipulate in VirtualDubMod:
Once you have the Input file setup and all of the Tracks selected, press the Extract button.
When the process is finished, you should end up with at least three files with the following extensions: .h264 (video file), .ac3 (audio file), and .ass (subtitle track. Yes, I do think it's an amusing extension). Close MKVextractGUI
Unfortunately, VirtualDubMod cannot read the .h264 file, so we will have to put it into an AVI container, which is where avc2avi comes in. It is a command-line program, so was have to open up a console window via Start->Run, type in "cmd" at the prompt and press the "OK" button. Navigate to the directory where the .h264 file is at, and run:
avc2avi -i <input file>.h264 -o <output file>.avi
This may take some time, but once it is finished you should have a .avi version of the video track that should be usable by Virtual Dub Mod! You may now close the command line window.
Now we get to the real work. Open up the above .avi file in VirtualDubMod.
Note: On my system, I couldn't move the position slider to the middle of the video and press play (I.E., to check for subtitle/audio syncronization with the video) without getting an error. I always had to start from the beginning of the video to do this. This seems to be an issue of the h.264 decoder I used. Fortunately, this does not affect the actual encoding of the AVI file.
Go into the Video menu and select Compression to choose the desired compression method. Select the codec, and press the Configure button to set it up.
As you may notice, I'm using a pretty high target bitrate for this run, as I wish to maintain as much of the original video quality as possible to be able to run on the big screen TV hooked into the player. I think most distributed video files go for around 800 kbps.
To add the audio stream, go to the Streams menu and select Stream List. When that window pops up, press the Add button and select the .ac3 file that was extracted by MKVextractGUI.
Optional: At this point, you may choose to process the audio into a 2-channel ADPCM or MP3 format. In my case, this was unnecessary as my player will pass through the AC-3 stream from the AVI file to my 6-channel sound system. If you decide to re-encode it, don't forget set the mode to Full Processing Mode and use the Conversion window to convert down to 2-channel Stereo before setting the desired Compression method. I'm not sure if all of the 6-channel AC-3 stream is down converted into 2-channel stereo this way, so you might have to use Filters (select Use advanced filtering to do this), but this is outside of my realm of knowledge.
After you get the the audio stream added and configured like you want, you will have to modify the framerate of the video stream, as that information is lost when you ran avc2avi earlier. Open up the menu option Video, and select Frame Rate....
Simply select Change so video and audio durations match and press the Ok button.
Now, we will add the subtitle track to the AVI file by adding it to the video stream. This step is actually optional, as my player will play the subtitle track if it's offered as a separate file on the disc, but the TextSub filter (which should be a part of the VobSub plugin) for VirtualDubMod does a much better job than my player does (I.E., text placement, colors, and proper line breaks. My DVD player will break to the next line in the middle of a word...).
Go into the Video menu, select Filters..., and press the Add... button. Select the TextSub filter and press the OK button.
Press the Open... button, choose the .ass file. I usually click on the Styles... button and setup the margins to account for overscan on my TV (You'll have to experiment for your own setup for the right values. For a 720x480 image, I'm trying out 30 for all the margins). Close the Subtitle Style Editer by pressing OK, close the TextSub settings by pressing OK, then OK again to close the Filter screen.
At this point, I am ready to create the AVI file with the video at 720x480, as my player will simply stretch the image to full screen on the widescreen TV. For those who wish to set a proper aspect ratio in the video may do so using the resize filter (Video -> Filters... -> Add... -> resize). As a reference, many distributed videos files use a size of 704x396 for a widescreen video, and 640x480 is good for a full screen video. I believe it is okay to use Bilinear for the filter mode. Be aware that your encoding codec may not support any particular screensize (which would give you an error when you try to create the AVI file in the next section), so feel free to experiment.
Creating the AVI file
At this point, you can preview the video by clicking on the "Play" button with the "O" on it. If you get an error, rewind to the beginning of the video and try to play it again. Watch to make sure the video, audio, and subtitling sync up with each other.
This is the simplest step. Go into the File Menu, choose Save As..., Enter in the desired file name and press the Save button. Now you're in for a bit of a wait. Do something else, or simply sit back and watch the pretty graphs...
Please resist the urge to click around on things. On my system, clicking on the Log tab of the VirtualDubMod Status window caused it to crash, causing me to have to start over.
Once the video is finished, watch it. Skip forward in it and pay attention to the video/audio/subtitle synchronization. If something seems off, you may have skipped over a step.
I hope this helps others, as I wasn't able to find any good instructions to convert these MKV files I had to play on my OPPO DVD player. This document is the result of a lot of Googling with quite a bit of time experimenting with programs.