Converting MPEG 2 to MKV (or OGM or AVI)
Introduction
This tutorial will guide you, step by step, through the convertion of an
MPEG2 video to a Matroska (
MKV) file with an XviD compression for the video stream and an Ogg Vorbis compression for the audio stream. However, it will be easy for you to slightly modify the options we choose in order to use an
AVI or
OGM container, a DivX or x264 video compression and/or an
MP3 audio compression.
For this tutorial, we used an
Athlon 64 X2 4200+ with 2GiB of
RAM running Windows XP Pro
SP2.
Note : this tutorial is heavily based on our
DVD to MKV tutorial. It was made especially for converting an MPEG2 file produced by the
TV card Hauppauge WinTV PVR
USB2, but should work as well (with very few modifications) with any MPEG or MPEG2 file.
Summary
- Introduction
- Material
- Installation
- Converting the audio
- Converting the video
- Credits
Short explanation : container, video, audio
See in our
DVD to MKV tutorial.
Material
You need (mandatory for creating the MKV file with XviD and Ogg) :
We also advise you to get the latest
Ogg Vorbis dlls, but we won't explain how to use them here.
If you want to use other codecs, you'll need to download them. Here is the DivX one :
- DivX (DivX encoder is not free). Warning : we strongly advise you against DivX. This codec is becoming less and less free. Use XviD instead, it's approximately as powerful and it's open source (so it can be used on any OS - Linux, Mac, Windows, BSD)... Don't tell me I didn't warn you :)
Installation
Install the stuff... just a few remarks :
Gordian Knot Rip Pack : install everything except if you know what you're doing (we installed everything except VobSub).
GraphEdit : unzip the installation zip (for us it was
graphedit011008.zip) in a folder of your choice. Then launch register.bat (double-click on it).
Converting the audio
Extract the audio data
Launch GraphEdit.
In the menu, go to File → Open Graph. In the box that appear, choose
All Files (*.*) in the field
Files of type. Then find and open the MPEG file that you want to convert. Here is what you should get :

Remove the video part and the audio renderer (click on the filter and press the delete key), now it looks like :

In the menu, go to Graph → Insert Filters... Then go to
DirectShow Filters, click on
File writer then on
Insert Filter (then choose a name for your audio file - we chose
I:\audio2.wav).
Click on
WAV Dest then on
Insert Filter. Then click
Close. Now you have :

Draw arrows like this :

Then press the play button (

) - the audio file gets created. It may take a few minutes.
Then you can close GraphEdit.
Compress the audio data
Go to the folder where you installed Gordian Knot and search for a folder named BeSweet. Now write down the path to BeSweet.exe. For us it's
F:\MEDIA\GordianKnot\BeSweet\BeSweet.exe.
We are going to compress your audio file in Ogg. To do this, create a batch file with notepad (we named it
audio2.bat) with the following content :
"F:\MEDIA\GordianKnot\BeSweet\BeSweet.exe" -core( -input "i:\audio2.wav" -output "i:\audio2.ogg" -logfilea "i:\audio2.log" ) -ogg( -q 0.200 )
Replace :
- F:\MEDIA\GordianKnot\BeSweet\BeSweet.exe with your path to BeSweet.exe
- i:\audio2.wav with the name of your audio file
- i:\audio2.ogg with the name you want for your compressed audio file
- i:\audio2.log with the name you want for your log file
- 0.200 with the quality you want. It can range from -0.100 (? - not sure) to 1.000. 0.400 is enough for any music (approx CD quality, takes as much space as 128kbps MP3), 0.000 (64kbps) is enough for voice only like documentaries but remains decent for music, I often use 0.200 (96kbps) for movies and even music.
Then launch this
audio2.bat file. BeSweet will then start to compress, looking like this :

The compression takes around 20 times shorter than the sound we are compressing on our computer (like 3 minutes per hour of sound).
Converting the video
With notepad, create a .avs file (for instance
source.avs), with the following content :
DirectShowSource("i:\My Video.mpg")
Replace
i:\My Video.mpg with the path to your MPEG2 file.
Configure video bitrate
Open Gordian Knot.
In the
Bitrate tab, press the
Open button at the bottom left, and open the .avs file you've just created.
This opens a window with the movie you are ripping, minimize it but don't close it.
Click on the
Bitrate tab.
We'll now set the video compression options. The following are only choices we made for this tut, of course you can make other choices, but we won't explain them.
(1) In the
Container field, choose
MKV.
(2) In the
Mode field, choose
Calculate Avi File Size (you can choose the other option if you want to target a specific filesize, but this is not what we chose for this tut. If you choose
Calculate Average Bitrate, you'll have to set other options on your own, in a way different way from what we did, but it's still easy).
(3) In the
Codec field, choose
XviD.
(4) In the
Total Size field, make sure
Split final file into CDs is not checked.
(5) In the
Video field, specify the
Average Bitrate. We chose 1000 kBit/s.
Set the resolution
Click on the
Resolution tab.
(1) In the
Input Resolution field, check the right format... for us it's PAL... if you don't know, follow the same method as described in our
DVD to MKV tutorial.
(2) In the
Input Pixel Aspect Ratio field, check
1:1.
(3) In the
Crop field, press
Auto Crop and then adjust manually to crop the picture (see it in the window that you minimized when you opened the avs file with Gordian Knot) as you want. If there is no need to crop, just check
disable.
(4) In the
Output Resolution field, set W-Modul and H-Modul to 1 then increase or decrease the Width and Height so that they are the same as the Width and Height from the
Crop field
Save & Encode
Open the window that you minimized when you opened the avs file with Gordian Knot.
In this window, click on
Save & Encode. A
Save .avs window appears.
(1) In the
Resizing field, choose
Selected Output Resolution.
(2) In the
Resize Filter field, choose
Neutral Bicubic.
(3) In the
Noise Filter field, choose
None, except if your video is very noisy, because it will lower quality (like any noise filter in fact).
(4) In the
File Operation field, choose
None.
(5) Make sure the
Subtitles field isn't checked (except if you want subtitles).
(6) In the
Extras field, don't check anything.
(7) In the
Compressibility Check field, check Off.
(8) Click on
Save - this will create another avs file. We called ours
i:\source2.avs.
AVS again...
Close the video file in Gordian Knot but let Gordian Knot open (or close it and re-open it).
With notepad, open
i:\source2.avs (or whatever you named it), and edit it as follow (don't forget to replace all path by yours) :
- replace avisource("I:\source.avs") with DirectShowSource("i:\My Video.mpg")
- find a line that begins with BicubicResize (for instance BicubicResize(696,568,0,0.5)) and remove this line
- find a line that contains Undot() and remove it
Save the file and close it.
Final video compression
In Gordian Knot, click on the
Encoder tab. Then click Add. It opens the DivX Encoding Control Panel.

(1) Make sure that
Multi Passes is checked.
(2) Make sure that
Frame Server is
I:\source2.avs.
(3) Make sure that
AVI Output File is something .
mkv.
(4) In the
Audio 1 tab, select
I:\audio2.ogg as the
Audio Source File. And select
Just Mux.
(5) In the
Audio 2 tab, check that audio processing is disabled.
(6) In the
XviD tab :
- uncheck Re-Calculate Bitrate if needed
- click on First Pass : Profile@Level should be (unrestricted), and Encoding type should be Twopass - 1st pass
- click on Second Pass : Profile@Level should be (unrestricted), and Encoding type should be Twopass - 2nd pass. What's more, Target bitrate (kbps) should be 1000 (or whatever bitrate you chose)
- click on Add Job to Encoding Queue. It asks you if you want to start encoding now... I guess you want so click yes :) Then it will open a few windows... let it do (don't close the windows it opens !).
Note : if the program doesn't ask you if you want to start encoding, click on Start Encoding in the Encoder tab of Gordian Knot.
Credits
We used the following resources to write this tut :
Learn more on :