annotate DOCS/tech/encoding-guide.txt @ 34332:18b362493e28

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