7.1. Encoding 2 or 3-pass MPEG-4 ("DivX")
Prev | Chapter 7. Encoding with MEncoder | Next

## 7.1. Encoding 2 or 3-pass MPEG-4 ("DivX")

2-pass encoding. The name comes from the fact that this method encodes the file twice. The first encoding (dubbed pass) creates some temporary files (`*.log`) with a size of few megabytes, do not delete them yet (you can delete the AVI). In the second pass, the 2-pass output file is created, using the bitrate data from the temporary files. The resulting file will have much better image quality. If this is the first time you heard about this, you should consult some guides available on the Net.

This example shows how to encode a DVD to a 2-pass MPEG-4 ("DivX") AVI. Just two commands are needed:

    rm frameno.avi

remove this file, which can come from a previous 3-pass encoding (it interferes with current one)

    mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac copy -o movie.avi
    mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -oac copy -o movie.avi

3-pass encoding. This is an extension of 2-pass encoding, where the audio encoding takes place in a separate pass. This method enables estimation of recommended video bitrate in order to fit on a CD. Also, the audio is encoded only once, unlike in 2-pass mode. The schematics:

1. Remove conflicting temporary file:

       rm frameno.avi

2. First pass:

       mencoder file/DVD -ovc frameno -oac mp3lame -lameopts vbr=3 -o frameno.avi

   An audio-only avi file will be created, containing only the requested audio stream. Don't forget `-lameopts`, if you need to set it. If you were encoding a long movie, MEncoder prints the recommended bitrate values for 650Mb, 700Mb, and 800Mb destination sizes, after this pass finishes.

3. Second pass:

       mencoder file/DVD -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=1:vbitrate=bitrate

   This is the first pass of video encoding. Optionally specify the video bitrate MEncoder printed at the end of the previous pass.

4. Third pass:

       mencoder file/DVD -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vpass=2:vbitrate=bitrate

   This is the second pass of video encoding. Specify the same bitrate as in the previous pass unless you really know what you are doing. In this pass, audio from `frameno.avi` will be inserted into the destination file...and it's all ready!

Example 7.1. Example of 3-pass encoding

    rm frameno.avi

remove this file, which can come from a previous 3-pass encoding (it interferes with current one)

    mencoder dvd://2 -ovc frameno -o frameno.avi -oac mp3lame -lameopts vbr=3
    mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=1 -oac copy -o movie.avi
    mencoder dvd://2 -ovc lavc -lavcopts vcodec=mpeg4:vpass=2 -oac copy -o movie.avi

Prev | Up | Next
Chapter 7. Encoding with MEncoder | Home | 7.2. Encoding to MPEG format