Fix vf_tcdump's compilation
[mplayer/kovensky.git] / DOCS / tech / encoding-guide.txt
blob0393bcbb5f7186486bd0581fedad264f78281965
1 Topics:
4 I. Preparing to encode
5    1. Identifying source material and framerate
6    2. Selecting the quality you want
7    3. Constraints for efficient encoding
8    4. Cropping and scaling
9    5. Choosing resolution and bitrate
11 II. Containers and codecs
12    1. Where the movie will be played
13    2. Constraints of DVD, SVCD, and VCD
14    3. Limitations of AVI container
16 III. Basic MEncoder usage
17    1. Selecting codecs & format
18    2. Selecting input file or device
19    3. Loading video filters
20    4. Notes on A/V sync
22 IV. Encoding procedures
23    1. Encoding progressive video
24    2. Two-pass encoding
25    3. Encoding interlaced video
26    4. Deinterlacing
27    5. Inverse telecine
28    6. Capturing TV input
29    7. Dealing with mixed-source content
30    8. Low-quality & damaged sources
32 V. Optimizing encoding quality
33    1. Noise removal
34    2. Pure quality-gain options
35    3. Questionable-gain options
36    4. Advanced MPEG-4 features
41 II. Containers and codecs
43 II.1. Where the movie will be played
45 Perhaps the most important factor to choosing the format in which you
46 will encode your movie is where you want to be able to play it.
47 Usually this involves a tradeoff between quality and features, since
48 the formats supported by the widest variety of players are also the
49 worst in regards to compression.
51 If you want to be able to play your encode on standalone/set-top
52 players, your primary choices are DVD, VCD, and SVCD. There are also
53 extensions such as KVCD and XVCD which violate the standards but work
54 on many players and deliver higher quality. Modern players are
55 beginning to support MPEG-4 ("DivX") movies in AVI and perhaps other
56 containers as well, but these are often buggy and require you to
57 restrict your encodes to certain subsets of the full MPEG-4
58 functionality.
60 If you wish to be able to share your movies with Windows or Macintosh
61 users, without them having to install additional software, your
62 choices are very limited. The ancient MPEG-1 format with MP2 or PCM
63 audio is probably the only choice that is universally supported.
64 Interoperability with Windows/Mac also comes into play when deciding
65 how to encode and whether to scale to preserve aspect, since popular
66 media player applications for these systems do not honor the aspect
67 ratio encoding stored in MPEG-4 avi files.
71 IV.2. Two-pass encoding
73 The complexity (and thus the number of bits) required to compress the
74 frames of a movie can vary greatly from one scene to another. Modern
75 video encoders can adjust to these needs as they go and vary the
76 bitrate. However, they cannot exceed the requested average bitrate for
77 long stretches of time, because they do not know the bitrate needs of
78 future scenes.
80 Two-pass encoding solves this problem by encoding the movie twice.
81 During the first pass, statistics are generated regarding the number
82 of bits used by each frame and the quantization level (quality) at
83 which it was encoded. Then, when the second pass begins, the encoder
84 reads these statistics and redistributes the bits from frames where
85 they are in excess to frames that are suffering from low quality.
87 In order for the process to work properly, the encoder should be given
88 exactly the same sequence of frames during both passes. This means
89 that the same filters must be used, the same encoder parameters must
90 be used (with the possible exception of bitrate), and the same frame
91 drops and duplications (if any) must take place.
93 In theory it's possible to use -oac pcm or -oac copy during the first
94 pass to avoid spending time encoding the audio. However, this can
95 result in slight variations in which frames get dropped or duplicated,
96 so it may be preferable to encode the audio during the first pass as
97 well as the second. This also allows you to examine the final audio
98 bitrate and filesize, and to adjust the audio or video bitrate
99 slightly between passes if you don't meet your target size.
101 Here is an example:
103   Encoding from an existing AVI file
104   500 kbit/sec MPEG-4 video
105   96 kbit/sec average-bitrate MP3 audio
107   mencoder bar.avi -vf scale=448:336 -mc 0 -oac mp3lame -lameopts \
108   abr:br=96 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=500:vpass=1
110   mencoder bar.avi -vf scale=448:336 -mc 0 -oac mp3lame -lameopts \
111   abr:br=96 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=500:vpass=2
113 If you do not want to overwrite the output from the first pass when
114 you begin the second, you can use the -o option to choose a different
115 output filename. Note the addition of the vpass option in this
116 example. If vpass is not specified, single-pass encoding is performed.
117 If vpass=1, a log file is written with statistics from the first pass.
118 If vpass=2, the log file is read and the second pass is encoded based
119 on those statistics. If you are short on disk space or don't want the
120 extra disk wear from writing the file twice, you can use -o /dev/null
121 during the first pass. However, sometimes it is beneficial to watch
122 the first-pass file before beginning the second pass to make sure
123 nothing went wrong in the encoding.
125 Next, an example using Xvid instead of libavcodec:
127   Encoding from an existing AVI file
128   500 kbit/sec MPEG-4 video
129   Copying the existing audio stream unmodified
131   mencoder foo.avi -vf scale=320:240 -mc 0 -oac copy -ovc xvid \
132   -xvidencopts bitrate=400:pass=1
134   mencoder foo.avi -vf scale=320:240 -mc 0 -oac copy -ovc xvid \
135   -xvidencopts bitrate=400:pass=2
137 The options used are slightly different, but the process is otherwise
138 the same.