table of contents   --> next chapter   <-- previous chapter  last modified on August 23, 2002

4. Transcoding the DVD to an AVI

Here you really have two choices - it's either transcode or MEncoder. Both have pros and cons. Here's a very short list that is true at least for the CVS versions from April 28, 2002:

4.1. Aspect ratios

Before we start let me introduce you to the most common aspect ratios you might encounter. I'm talking about PAL here. Unfortunately I don't have that much knowledge about NTSC, so keep that in mind. DVDs are always encoded at 720x576 (5:4) although the picture will be scaled at playback. Common video formats are 4:3 = 1.33 for TV, 16:9 = 1.78 for normal cinema movies and 2.35:1 for Cinemascope.

Here is a list of common scenarios:

Don't worry if you don't understand all that at once. Take a look at dvd::rip's clipping and scaling options for a more intuitive overview.

If you want to understand what is really happening then you just have to do some math. Let's assume that the DVD is encoded with 720x576 which is 5:4, and its flags indicate that it should be played back at 16:9. This means that the player has to change the picture's aspect ratio from 5:4 to 16:9 by either scaling to 1024x576 or to 720x405. How to I calculate these values? Well I simply multiply the width with (display AR / encoded AR) which is (16:9 / 5:4) = 1.78 / 1.25 = 1.42. It's similar for the latter case. But this includes the black bars that may be present! So if your DVD cover says that the movie has an aspect ratio of 2.35 then you still see black bars on this scaled picture.

4.2. Using dvd::rip

Using dvd::rip is by far the best and easiest method to get your AVI. As stated earlier it relies heavily on transcode to do its job.

After starting dvd::rip you rip the titles you wish to transcode to your hard disk. Refer to chapter 3 for a detailed description.

4.2.1. Clipping and zooming

Now head over to the Clip & Zoom tab. Here's where you set all parameters regarding picture size and cropping (called "clipping" here). First get yourself a picture to work with: simply enter a frame number (like 200) into the Grab Preview Frame input line and press Grab Frame from ripped VOB. After a few seconds the three views below show the frame you requested.

transcode uses three steps to bring the picture to its final size: first it clips the unscaled image, then it does resizing and last it clips again. Each of this steps can be left out by selecting 0 for clipping and the original width and height for resizing. Each window shows the result of those three steps. If you want to see how big the pictures really are then just click onto any of them and a pop-up window will be opened containing the result.

You may have noticed the drop-down listbox below the three preview windows. dvd::rip offers a wide rage of presets for you to work with. Simply select one of those gives you a place to start. You can still change the values manually after selecting such a preset. All presets that are named "autoadjust..." try to guess the correct clipping regions. After selecting a preset hit the Apply Preset Values button. Now adjust the values you got until you're happy.

The big frame, medium frame and small frame parts refer to the final image size that is to be achieved. big keeps almost full DVD resolution, medium is somewhere between 500 to 600 for the width and small is somewhere around 350.

One note about resizing: Use fast resizing has a big impact upon image processing but requires that the target width and height are divisible by 32. Don't worry, dvd::rip will tell you if you can't use fast resizing. Note also that while it is possible to actually enlarge the picture I strongly advise against it. There are several drawbacks: the encoder needs a lot more bits to achieve the same quality you'd get when encoding a smaller picture and then scaling it up while playing it back, and you might even get distorted pictures (Peter Schuller reported such a case to me). Always scale down.

4.2.2. Choosing encoding parameters

We're done with this tab. Open the
Transcode tab. First decide about the video codec you want to use. If you've installed DivX5 for Linux then you can use that, but I would recommend using XviD. If you've downloaded XviD from CVS then the option to chose is xvidcvs (obviously). If transcode later aborts with some obscure error then you can try xvid.

Do you remember that I asked you to check if the video was interlaced? Now we need it. If your video is not interlaced then simply leave deinterlacing to and antialias off. Otherwise select 3 - Zoom To Full Frame. This is the slowest but best looking deinterlacer. Again here's the interlaced sample from Ally McBeal. You can see the result from 3 - Zoom To Full Frame in the first deinterlaced picture.

Another filter for deinterlacing is provided by an external plugin (don't worry you've already installed it with transcode itself). Have a look at the lower right. There's a input box labeled transcode options. All options entered here are simply passed along to transcode. We can use this for deinterlacing. Here's the same picture as above deinterlaced with other deinterlacer. This deinterlacer is faster than the 3 - Zoom To Full Frame option. If you want to use this deinterlacer then set deinterlace to off and enter -J dilyuvmmx in the input line.

dvd::rip tries to autodetect your framerate. If it failed you can correct it here. Use YUV internal should always be yes unless the output codec does not support YUV modes. XviD does. Leaving it on gives a huge speed boost. DivX multipass should be yes as well unless you only want to do a preview. For final results always chose two pass encoding. Although this is labeled DivX multipass it works nicely with XviD as well.

The audio options should be self explanatory. You chose either to reencode the audio to MP3 using the specified bitrate or to use the original AC3 sound without reencoding. AC3 audio provides surround sound and all those advantages but is bigger than MP3 sound. It's really your choice. If you use MP3 then make sure that the MP3 Quality setting is at 2. According to lame's documentation (lame is used for MP3 compression) higher quality settings like 1 or 0 - best but slower are at lot slower but do not produce significantly higher quality. The volume rescale allows normalization the audio which does not require a separate (external) program. dvd::rip automagically scans the sound and provides a rescale value.

In the upper right is the bitrate option. You can easily chose the rip size by selecting the count and size of CDs you want to use. Manipulating the Target Size or the Video Bitrate works as well. dvd::rip automatically updates the calculated values below so finding the optimal bitrate is rather easy.

4.2.3. Generating a quick preview

Most of the times you should let dvd::rip generate a small preview. You do that by providing a Frame Range. I usually take a 30 second sample which would be 750 frames at 25fps (<number of seconds> * <fps> = <number of frames to encode>) and start sometime into the movie (like 200, 300 frames). Good values might be 200 - 950. You should also give transcode a high nice level (which results in a low process priority) so it will only use spare time. If you really want your preview right here right now you can also temporarily disable DivX Multipass. Just remember to turn it back on later!

When you're done click Transcode. After a couple of minutes at most your AVI/MPEG will be ready. Now have a look at it (like mplayer my-new-file.avi). This is a good moment to see if deinterlacing works as expected and to check if audio and video perfectly synchronized. If they are, you're set. If they aren't, then read on:

4.2.4. Preventing audio/video desynchronization

If your audio and video are not synchronized in the preview (or when you play back the DVD itself) then you can give transcode a frame offset for the a/v synchronization. You do that by providing the parameter -D nr in the transcode options input line on the Transcodetab. The nr is the number of frames the audio is delayed. This number can be negative. A frame is 40msecs long at 25fps. In general the frame length is (1000 / fps)msecs long. For my Ally McBeal DVD I need a correction of -2 which amounts to -80msecs: -D -2. Now regenerate your preview video (the other parameters should still be the same) and check the audio again. If needed redo this step until you're satisfied.

4.2.5. Doing the whole thing

When the preview is fine you can start your transcode. Make sure that DivX Multipass is turned on again if you disabled it for the preview. Either click on Transcode or on Transcode + Split if you want your files to be split automatically according to the settings under Video Bitrate Calculation.

Now is really a fine time for some socialising :-)

4.2.6. For advanced users: transcode command line arguments

This chapter explains the transcode command line options used by dvd::rip. It is not crucial to the transcoding process so you may as well skip it. I provide it for those who wish to have some deeper insight into what dvd::rip and transcode do.

In dvd::rip press CTRL-t to see what the commands dvd::rip executes look like. For now let's concentrate on the last set of commands, Transcode command. Here's an example for my Star Trek: The Next Generation DVD without all those mkdir and cd commands:

  1. transcode -i /space/tng-biggoodbye/vob/004 -w 4357,250,100 -a 1 -b 128,0,0 -s 3.311 -V -f 25 -B 12,10,8 -R 1 -x vob,null -o /dev/null -y xvidcvs,null
  2. transcode -i /space/tng-biggoodbye/vob/004 -w 4357,250,100 -a 1 -b 128,0,0 -s 3.311 -V -f 25 -B 12,10,8 -R 2 -x vob -o /space/tng-biggoodbye/avi/004/tng-biggoodbye-004.avi -y xvidcvs
Let's take a look at the first command and its parameters: The second command line is not that different. It just skips all options that would discard output (like -o real-file-name and -y xvidcvs). For a more complete reference have a look at transcode's and lame's man pages.

As a last note you will find that transcode as of version 0.6.0pre6-20020529 contains support for libavcodec via a still experimental export module written by me. You can activate it by using -y ffmpeg4 (remember: libavcodec is part of ffmpeg) instead of your previous codec. dvd::rip does not support it at the moment (read: it is not in the list of selectable codecs).

4.3. Using MEncoder

As mentioned earlier there is no GUI for MEncoder at the moment. Therefore I won't provide screenshots and you have to do everything by hand. This is a process called "three pass encoding".

4.3.1. Encoding the audio

The first step is to encode only the audio. Make sure you know what audio language you want to use - you need either the audio id (which is 128 for the first stream, 129 for the second etc.) or the two-letter country code (like en for English or de for German). You can find out about these codes by running MPlayer in verbose mode: mplayer -dvd 1 -v. It should print a lot of lines. Search these for lines similar to:
[open] audio stream: 0 audio format: ac3 language: en aid: 128
[open] audio stream: 1 audio format: ac3 language: de aid: 129
[open] audio stream: 2 audio format: ac3 language: es aid: 130

Here I have three audio streams: English, German, Spanish and their IDs.

Now call MEncoder to encode the audio for you:
nice -+19 cat /space/*vob | nice-+19 mencoder -ovc frameno -o frameno.avi -oac mp3lame -lameopts abr:br=128 -alang de -
Here's an explanation for the command line arguments used:

Wait some time and you'll have your audio. MEncoder even prints some suggestions for the video bitrate:
Recommended video bitrate for 650MB CD: 1845
Recommended video bitrate for 700MB CD: 1992
Recommended video bitrate for 800MB CD: 2287

As you can see these values are rather high - but that's because an Ally McBeal episode is only 41minutes long. So I'd go for two episodes per CD and give the video a bitrate of about 1000.

4.3.2. Generating a preview (first pass)

Now's the time to decide about the video codec you're going to use. I'm assuming that AVI is the desired result with one of the different DivX encoders. MEncoder has support for DivX 4 or DivX 5 (same under Windows actually, you have either v4 or v5 running) as well as for XviD or lavc. Although most of you won't have heard of libavcodec or the ffmpeg-project before you should be advised that lavc is far superior to DivX 4 or 5 and at least as good as XviD. So I will only provide examples for lavc as you don't even need special codecs for playback: MPlayer plays them just fine (naturally), and for Windows you simply need DivX 5 (free edition is absolutely sufficient). So here we go.

Let's assemble the command line options one by one:

Put together the complete command line looks like this:
nice -+19 mencoder -oac copy -o /dev/null -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:vpass=1 -vop scale=640:480 -npp lb -ss 0:20 -endpos 0:30 /space/first.vob

4.3.3. Generating a preview (second pass)

For this step we can keep most of our previous command line. Of course we change the vpass=1 to vpass=2 to tell the encoder that it's the second pass this time. Of course we should save the final output and replace -o /dev/null with something useful, e.g. -o ally-preview.avi.

Here's the command line:
nice -+19 mencoder -oac copy -o ally-preview.avi -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:vpass=2 -vop scale=640:480 -npp lb -ss 0:20 -endpos 0:30 /space/first.vob
After MEncoder finishes take a look at your preview. Adjust parameters if needed. Redo the preview until you're happy with it.

4.3.4. Generating the final AVI (both passes)

The calls for the final options simply leave out -ss and -endpos. Unfortunately MEncoder can't handle multiple input files on the command line. That's what the cat is for. Just enter:
cat /space/*vob | nice -+19 mencoder -oac copy -o /dev/null -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:vpass=1:vqmin=2:vqmax=31 -vop scale=640:480 -npp lb -
cat /space/*vob | nice -+19 mencoder -oac copy -o ally.avi -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:vpass=2:vqmin=2:vqmax=31 -vop scale=640:480 -npp lb -

Note that -ss does not seem to work with the cat *vob | mencoder... variant. So for the preview just specify the first vob as the last argument on the command line (just look up).

Now go get a beer and a nice book.


table of contents   --> next chapter   <-- previous chapter  this guide was written by Moritz Bunkus