Quote of the day : "Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders." Alanna

Next quote in 1.1 hours. [suggest a quote]

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

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 :

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 :
GraphEdit screenshot : 1st graph
Remove the video part and the audio renderer (click on the filter and press the delete key), now it looks like :
GraphEdit screenshot : 2nd graph
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 :
GraphEdit screenshot : 3rd graph
Draw arrows like this :
GraphEdit screenshot : 4th graph
Then press the play button (GraphEdit 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 : Then launch this audio2.bat file. BeSweet will then start to compress, looking like this :
BeSweet screenshot : compression
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.
GK screenshot : Bitrate tab

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
GK screenshot : resolution tab

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.
GK screenshot : save .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) : 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.
Gordian Knot screenshot : DivX Encoding Control Panel 1
(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 : Gordian Knot screenshot : DivX Encoding Control Panel 2

Credits

We used the following resources to write this tut : Learn more on :
Comments :
(Sauron76, on Tue, 17 Jun 2008 02:51:41 +0200) Report Reply
Newcomer Where can we change the target size? For example my MPEG file is 5GB & I want to reduce the size to at least 1GB.
Replies :
Show
[Add a comment]