1 <?xml version="1.0" encoding="iso-8859-1"?>
3 <chapter id="encoding-guide">
4 <title>Encoding with <application>MEncoder</application></title>
6 <sect1 id="menc-feat-dvd-mpeg4">
7 <title>Making a high quality MPEG-4 ("DivX") rip of a DVD movie</title>
10 One frequently asked question is "How do I make the highest quality rip for
11 a given size?". Another question is "How do I make the highest quality DVD
12 rip possible? I do not care about file size, I just want the best quality."
16 The latter question is perhaps at least somewhat wrongly posed. After all, if
17 you do not care about file size, why not simply copy the entire MPEG-2 video
18 stream from the the DVD? Sure, your AVI will end up being 5GB, give
19 or take, but if you want the best quality and do not care about size,
20 this is certainly your best option.
24 In fact, the reason you want to transcode a DVD into MPEG-4 is
25 specifically because you <emphasis role="bold">do</emphasis> care about
30 It is difficult to offer a cookbook recipe on how to create a very high
31 quality DVD rip. There are several factors to consider, and you should
32 understand these details or else you are likely to end up disappointed
33 with your results. Below we will investigate some of these issues, and
34 then have a look at an example. We assume you are using
35 <systemitem class="library">libavcodec</systemitem> to encode the video,
36 although the theory applies to other codecs as well.
40 If this seems to be too much for you, you should probably use one of the
41 many fine frontends that are listed in the
42 <ulink url="http://mplayerhq.hu/homepage/design7/projects.html#mencoder_frontends">MEncoder section</ulink>
43 of our related projects page.
44 That way, you should be able to achieve high quality rips without too much
45 thinking, because most of those tools are designed to take clever decisions
49 <sect2 id="menc-feat-dvd-mpeg4-preparing-encode">
50 <title>Preparing to encode: Identifying source material and framerate</title>
52 Before you even think about encoding a movie, you need to take
53 several preliminary steps.
57 The first and most important step before you encode should be
58 determining what type of content you are dealing with.
59 If your source material comes from DVD or broadcast/cable/satellite
60 TV, it will be stored in one of two formats: NTSC for North
61 America and Japan, PAL for Europe, etc.
62 It is important to realize, however, that this is just the formatting for
63 presentation on a television, and often does
64 <emphasis role="bold">not</emphasis> correspond to the
65 original format of the movie.
66 Experience shows that NTSC material is a lot more difficult to encode,
67 because there more elements to identify in the source.
68 In order to produce a suitable encode, you need to know the original
70 Failure to take this into account will result in various flaws in your
71 encode, including ugly combing (interlacing) artifacts and duplicated
73 Besides being ugly, the artifacts also harm coding efficiency:
74 You will get worse quality per unit bitrate.
77 <sect3 id="menc-feat-dvd-mpeg4-preparing-encode-fps">
78 <title>Identifying source framerate</title>
80 Here is a list of common types of source material, where you are
81 likely to find them, and their properties:
85 <emphasis role="bold">Standard Film</emphasis>: Produced for
86 theatrical display at 24fps.
89 <emphasis role="bold">PAL video</emphasis>: Recorded with a PAL
90 video camera at 50 fields per second.
91 A field consists of just the odd- or even-numbered lines of a
93 Television was designed to refresh these in alternation as a
94 cheap form of analog compression.
95 The human eye supposedly compensates for this, but once you
96 understand interlacing you will learn to see it on TV too and
98 Two fields do <emphasis role="bold">not</emphasis> make a
99 complete frame, because they are captured 1/50 of a second apart
100 in time, and thus they do not line up unless there is no motion.
103 <emphasis role="bold">NTSC Video</emphasis>: Recorded with an
104 NTSC video camera at 60000/1001 fields per second, or 60 fields per
105 second in the pre-color era.
106 Otherwise similar to PAL.
109 <emphasis role="bold">Animation</emphasis>: Usually drawn at
110 24fps, but also comes in mixed-framerate varieties.
113 <emphasis role="bold">Computer Graphics (CG)</emphasis>: Can be
114 any framerate, but some are more common than others; 24 and
115 30 frames per second are typical for NTSC, and 25fps is typical
119 <emphasis role="bold">Old Film</emphasis>: Various lower
125 <sect3 id="menc-feat-dvd-mpeg4-preparing-encode-material">
126 <title>Identifying source material</title>
128 Movies consisting of frames are referred to as progressive,
129 while those consisting of independent fields are called
130 either interlaced or video - though this latter term is
134 To further complicate matters, some movies will be a mix of
135 several of the above.
138 The most important distinction to make between all of these
139 formats is that some are frame-based, while others are
141 <emphasis role="bold">Whenever</emphasis> a movie is prepared
142 for display on television (including DVD), it is converted to a
144 The various methods by which this can be done are collectively
145 referred to as "pulldown", of which the infamous NTSC
146 "3:2 telecine" is one variety.
147 Unless the original material was also field-based (and the same
148 fieldrate), you are getting the movie in a format other than the
153 <title>There are several common types of pulldown:</title>
155 <emphasis role="bold">PAL 2:2 pulldown</emphasis>: The nicest of
157 Each frame is shown for the duration of two fields, by extracting the
158 even and odd lines and showing them in alternation.
159 If the original material is 24fps, this process speeds up the
163 <emphasis role="bold">PAL 2:2:2:2:2:2:2:2:2:2:2:3 pulldown</emphasis>:
164 Every 12th frame is shown for the duration of three fields, instead of
166 This avoids the 4% speedup issue, but makes the process much
167 more difficult to reverse.
168 It is usually seen in musical productions where adjusting the
169 speed by 4% would seriously damage the musical score.
172 <emphasis role="bold">NTSC 3:2 telecine</emphasis>: Frames are
173 shown alternately for the duration of 3 fields or 2 fields.
174 This gives a fieldrate 2.5 times the original framerate.
175 The result is also slowed down very slightly from 60 fields per
176 second to 60000/1001 fields per second to maintain NTSC fieldrate.
179 <emphasis role="bold">NTSC 2:2 pulldown</emphasis>: Used for
180 showing 30fps material on NTSC.
181 Nice, just like 2:2 PAL pulldown.
186 There are also methods for converting between NTSC and PAL video,
187 but such topics are beyond the scope of this guide.
188 If you encounter such a movie and want to encode it, your best
189 bet is to find a copy in the original format.
190 Conversion between these two formats is highly destructive and
191 cannot be reversed cleanly, so your encode will greatly suffer
192 if it is made from a converted source.
195 When video is stored on DVD, consecutive pairs of fields are
196 grouped as a frame, even though they are not intended to be shown
197 at the same moment in time.
198 The MPEG-2 standard used on DVD and digital TV provides a
199 way both to encode the original progressive frames and to store
200 the number of fields for which a frame should be shown in the
201 header of that frame.
202 If this method has been used, the movie will often be described
203 as "soft-telecined", since the process only directs the
204 DVD player to apply pulldown to the movie rather than altering
206 This case is highly preferable since it can easily be reversed
207 (actually ignored) by the encoder, and since it preserves maximal
209 However, many DVD and broadcast production studios do not use
210 proper encoding techniques but instead produce movies with
211 "hard telecine", where fields are actually duplicated in the
215 The procedures for dealing with these cases will be covered
216 <link linkend="menc-feat-telecine">later in this guide</link>.
217 For now, we leave you with some guides to identifying which type
218 of material you are dealing with:
222 <title>NTSC regions:</title>
224 If <application>MPlayer</application> prints that the framerate
225 has changed to 24000/1001 when watching your movie, and never changes
226 back, it is almost certainly progressive content that has been
230 If <application>MPlayer</application> shows the framerate
231 switching back and forth between 24000/1001 and 30000/1001, and you see
232 "combing" at times, then there are several possibilities.
233 The 24000/1001 fps segments are almost certainly progressive
234 content, "soft telecined", but the 30000/1001 fps parts could be
235 either hard-telecined 24000/1001 fps content or 60000/1001 fields per second NTSC video.
236 Use the same guidelines as the following two cases to determine
240 If <application>MPlayer</application> never shows the framerate
241 changing, and every single frame with motion appears combed, your
242 movie is NTSC video at 60000/1001 fields per second.
245 If <application>MPlayer</application> never shows the framerate
246 changing, and two frames out of every five appear combed, your
247 movie is "hard telecined" 24000/1001fps content.
252 <title>PAL regions:</title>
254 If you never see any combing, your movie is 2:2 pulldown.
257 If you see combing alternating in and out every half second,
258 then your movie is 2:2:2:2:2:2:2:2:2:2:2:3 pulldown.
261 If you always see combing during motion, then your movie is PAL
262 video at 50 fields per second.
266 <note><title>Hint:</title>
268 <application>MPlayer</application> can slow down movie playback
269 with the -speed option or play it frame-by-frame.
270 Try using <option>-speed</option> 0.2 to watch the movie very
271 slowly or press the "<keycap>.</keycap>" key repeatedly to play one frame at a time
272 and identify the pattern, if you cannot see it at full speed.
278 <sect2 id="menc-feat-dvd-mpeg4-2pass">
279 <title>Constant quantizer vs. multipass</title>
282 It is possible to encode your movie at a wide range of qualities.
283 With modern video encoders and a bit of pre-codec compression
284 (downscaling and denoising), it is possible to achieve very good
285 quality at 700 MB, for a 90-110 minute widescreen movie.
286 Furthermore, all but the longest movies can be encoded with near-perfect
291 There are three approaches to encoding the video: constant bitrate
292 (CBR), constant quantizer, and multipass (ABR, or average bitrate).
296 The complexity of the frames of a movie, and thus the number of bits
297 required to compress them, can vary greatly from one scene to another.
298 Modern video encoders can adjust to these needs as they go and vary
300 In simple modes such as CBR, however, the encoders do not know the
301 bitrate needs of future scenes and so cannot exceed the requested
302 average bitrate for long stretches of time.
303 More advanced modes, such as multipass encode, can take into account
304 the statistics from previous passes; this fixes the problem mentioned
308 <note><title>Note:</title>
310 Most codecs which support ABR encode only support two pass encode
311 while some others such as <systemitem class="library">x264</systemitem>,
312 <systemitem class="library">XviD</systemitem>
313 and <systemitem class="library">libavcodec</systemitem> support
314 multipass, which slightly improves quality at each pass,
315 yet this improvement is no longer measurable nor noticeable after the
317 Therefore, in this section, two pass and multipass will be used
323 In each of these modes, the video codec (such as
324 <systemitem class="library">libavcodec</systemitem>)
325 breaks the video frame into 16x16 pixel macroblocks and then applies a
326 quantizer to each macroblock. The lower the quantizer, the better the
327 quality and higher the bitrate.
328 The method the movie encoder uses to determine
329 which quantizer to use for a given macroblock varies and is highly
330 tunable. (This is an extreme over-simplification of the actual
331 process, but the basic concept is useful to understand.)
335 When you specify a constant bitrate, the video codec will encode the video,
337 detail as much as necessary and as little as possible in order to remain
338 lower than the given bitrate. If you truly do not care about file size,
339 you could as well use CBR and specify a bitrate of infinity. (In
340 practice, this means a value high enough so that it poses no limit, like
341 10000Kbit.) With no real restriction on bitrate, the result is that
342 the codec will use the lowest
343 possible quantizer for each macroblock (as specified by
344 <option>vqmin</option> for
345 <systemitem class="library">libavcodec</systemitem>, which is 2 by default).
346 As soon as you specify a
347 low enough bitrate that the codec
348 is forced to use a higher quantizer, then you are almost certainly ruining
349 the quality of your video.
350 In order to avoid that, you should probably downscale your video, according
351 to the method described later on in this guide.
352 In general, you should avoid CBR altogether if you care about quality.
356 With constant quantizer, the codec uses the same quantizer, as
357 specified by the <option>vqscale</option> option (for
358 <systemitem class="library">libavcodec</systemitem>), on every macroblock.
359 If you want the highest quality rip possible, again ignoring bitrate,
360 you can use <option>vqscale=2</option>.
361 This will yield the same bitrate and PSNR (peak signal-to-noise ratio)
363 <option>vbitrate</option>=infinity and the default <option>vqmin</option>
368 The problem with constant quantizing is that it uses the given quantizer
369 whether the macroblock needs it or not. That is, it might be possible
370 to use a higher quantizer on a macroblock without sacrificing visual
371 quality. Why waste the bits on an unnecessarily low quantizer? Your
372 CPU has as many cycles as there is time, but there is only so many bits
377 With a two pass encode, the first pass will rip the movie as though it
378 were CBR, but it will keep a log of properties for each frame. This
379 data is then used during the second pass in order to make intelligent
380 decisions about which quantizers to use. During fast action or low
381 detail scenes, higher quantizers will likely be used, and during
382 slow moving or high detail scenes, lower quantizers will be used.
386 If you use <option>vqscale=2</option>, then you are wasting bits. If you
387 use <option>vqscale=3</option>, then you are not getting the highest
388 quality rip. Suppose you rip a DVD at <option>vqscale=3</option>, and
389 the result is 1800Kbit. If you do a two pass encode with
390 <option>vbitrate=1800</option>, the resulting video will have <emphasis
391 role="bold">higher quality</emphasis> for the
392 <emphasis role="bold">same bitrate</emphasis>.
396 Since you are now convinced that two pass is the way to go, the real
397 question now is what bitrate to use? The answer is that there is no
398 single answer. Ideally you want to choose a bitrate that yields the
399 best balance between quality and file size. This is going to vary
400 depending on the source video.
404 If size does not matter, a good starting point for a very high quality
405 rip is about 2000Kbit plus or minus 200Kbit.
406 For fast action or high detail source video, or if you just have a very
407 critical eye, you might decide on 2400 or 2600.
408 For some DVDs, you might not notice a difference at 1400Kbit. It is a
409 good idea to experiment with scenes at different bitrates to get a feel.
413 If you aim at a certain size, you will have to somehow calculate the bitrate.
414 But before that, you need to know how much space you should reserve for the
415 audio track(s), so you should <link linkend="menc-feat-dvd-mpeg4-audio">rip
417 You can compute the bitrate with the following equation:
418 <systemitem>bitrate = (target_size_in_Mbytes - sound_size_in_Mbytes) *
419 1024 * 1024 / length_in_secs * 8 / 1000</systemitem>
420 For instance, to squeeze a two-hour movie onto a 702MB CD, with 60MB
421 of audio track, the video bitrate will have to be:
422 <systemitem>(702 - 60) * 1024 * 1024 / (120*60) * 8 / 1000
423 = 740kbps</systemitem>
429 <sect2 id="menc-feat-dvd-mpeg4-constraints">
430 <title>Constraints for efficient encoding</title>
433 Due to the nature of MPEG-type compression, there are various
434 constraints you should follow for maximal quality.
435 MPEG splits the video up into 16x16 squares called macroblocks,
436 each composed of 4 8x8 blocks of luma (intensity) information and two
437 half-resolution 8x8 chroma (color) blocks (one for red-cyan axis and
438 the other for the blue-yellow axis).
439 Even if your movie width and height are not multiples of 16, the
440 encoder will use enough 16x16 macroblocks to cover the whole picture
441 area, and the extra space will go to waste.
442 So in the interests of maximizing quality at a fixed filesize, it is
443 a bad idea to use dimensions that are not multiples of 16.
447 Most DVDs also have some degree of black borders at the edges. Leaving
448 these in place can hurt quality in several ways.
454 MPEG-type compression is also highly dependent on frequency domain
455 transformations, in particular the Discrete Cosine Transform (DCT),
456 which is similar to the Fourier transform. This sort of encoding is
457 efficient for representing patterns and smooth transitions, but it
458 has a hard time with sharp edges. In order to encode them it must
459 use many more bits, or else an artifact known as ringing will
464 The frequency transform (DCT) takes place separately on each
465 macroblock (actually each block), so this problem only applies when
466 the sharp edge is inside a block. If your black borders begin
467 exactly at multiple-of-16 pixel boundaries, this is not a problem.
468 However, the black borders on DVDs rarely come nicely aligned, so
469 in practice you will always need to crop to avoid this penalty.
475 In addition to frequency domain transforms, MPEG-type compression uses
476 motion vectors to represent the change from one frame to the next.
477 Motion vectors naturally work much less efficiently for new content
478 coming in from the edges of the picture, because it is not present in
479 the previous frame. As long as the picture extends all the way to the
480 edge of the encoded region, motion vectors have no problem with
481 content moving out the edges of the picture. However, in the presence
482 of black borders, there can be trouble:
485 <orderedlist continuation="continues">
488 For each macroblock, MPEG-type compression stores a vector
489 identifying which part of the previous frame should be copied into
490 this macroblock as a base for predicting the next frame. Only the
491 remaining differences need to be encoded. If a macroblock spans the
492 edge of the picture and contains part of the black border, then
493 motion vectors from other parts of the picture will overwrite the
494 black border. This means that lots of bits must be spent either
495 re-blackening the border that was overwritten, or (more likely) a
496 motion vector will not be used at all and all the changes in this
497 macroblock will have to be coded explicitly. Either way, encoding
498 efficiency is greatly reduced.
502 Again, this problem only applies if black borders do not line up on
503 multiple-of-16 boundaries.
509 Finally, suppose we have a macroblock in the interior of the
510 picture, and an object is moving into this block from near the edge
511 of the image. MPEG-type coding cannot say "copy the part that is
512 inside the picture but not the black border." So the black border
513 will get copied inside too, and lots of bits will have to be spent
514 encoding the part of the picture that is supposed to be there.
518 If the picture runs all the way to the edge of the encoded area,
519 MPEG has special optimizations to repeatedly copy the pixels at the
520 edge of the picture when a motion vector comes from outside the
521 encoded area. This feature becomes useless when the movie has black
522 borders. Unlike problems 1 and 2, aligning the borders at multiples
523 of 16 does not help here.
529 Despite the borders being entirely black and never changing, there
530 is at least a minimal amount of overhead involved in having more
537 For all of these reasons, it is recommended to fully crop black
538 borders. Further, if there is an area of noise/distortion at the edge
539 of the picture, cropping this will improve encoding efficiency as
540 well. Videophile purists who want to preserve the original as close as
541 possible may object to this cropping, but unless you plan to encode at
542 constant quantizer, the quality you gain from cropping will
543 considerably exceed the amount of information lost at the edges.
548 <sect2 id="menc-feat-dvd-mpeg4-crop">
549 <title>Cropping and Scaling</title>
552 Recall from the previous section that the final picture size you
553 encode should be a multiple of 16 (in both width and height).
554 This can be achieved by cropping, scaling, or a combination of both.
558 When cropping, there are a few guidelines that must be followed to
559 avoid damaging your movie.
560 The normal YUV format, 4:2:0, stores chroma (color) information
561 subsampled, i.e. chroma is only sampled half as often in each
562 direction as luma (intensity) information.
563 Observe this diagram, where L indicates luma sampling points and C
568 <?dbhtml table-width="40%" ?>
569 <?dbfo table-width="40%" ?>
570 <tgroup cols="8" align="center">
571 <colspec colnum="1" colname="col1"/>
572 <colspec colnum="2" colname="col2"/>
573 <colspec colnum="3" colname="col3"/>
574 <colspec colnum="4" colname="col4"/>
575 <colspec colnum="5" colname="col5"/>
576 <colspec colnum="6" colname="col6"/>
577 <colspec colnum="7" colname="col7"/>
578 <colspec colnum="8" colname="col8"/>
579 <spanspec spanname="spa1-2" namest="col1" nameend="col2"/>
580 <spanspec spanname="spa3-4" namest="col3" nameend="col4"/>
581 <spanspec spanname="spa5-6" namest="col5" nameend="col6"/>
582 <spanspec spanname="spa7-8" namest="col7" nameend="col8"/>
595 <entry spanname="spa1-2">C</entry>
596 <entry spanname="spa3-4">C</entry>
597 <entry spanname="spa5-6">C</entry>
598 <entry spanname="spa7-8">C</entry>
621 <entry spanname="spa1-2">C</entry>
622 <entry spanname="spa3-4">C</entry>
623 <entry spanname="spa5-6">C</entry>
624 <entry spanname="spa7-8">C</entry>
641 As you can see, rows and columns of the image naturally come in pairs.
642 Thus your crop offsets and dimensions <emphasis>must</emphasis> be
644 If they are not, the chroma will no longer line up correctly with the
646 In theory, it is possible to crop with odd offsets, but it requires
647 resampling the chroma which is potentially a lossy operation and not
648 supported by the crop filter.
652 Further, interlaced video is sampled as follows:
656 <?dbhtml table-width="80%" ?>
657 <?dbfo table-width="80%" ?>
658 <tgroup cols="16" align="center">
659 <colspec colnum="1" colname="col1"/>
660 <colspec colnum="2" colname="col2"/>
661 <colspec colnum="3" colname="col3"/>
662 <colspec colnum="4" colname="col4"/>
663 <colspec colnum="5" colname="col5"/>
664 <colspec colnum="6" colname="col6"/>
665 <colspec colnum="7" colname="col7"/>
666 <colspec colnum="8" colname="col8"/>
667 <colspec colnum="9" colname="col9"/>
668 <colspec colnum="10" colname="col10"/>
669 <colspec colnum="11" colname="col11"/>
670 <colspec colnum="12" colname="col12"/>
671 <colspec colnum="13" colname="col13"/>
672 <colspec colnum="14" colname="col14"/>
673 <colspec colnum="15" colname="col15"/>
674 <colspec colnum="16" colname="col16"/>
675 <spanspec spanname="spa1-2" namest="col1" nameend="col2"/>
676 <spanspec spanname="spa3-4" namest="col3" nameend="col4"/>
677 <spanspec spanname="spa5-6" namest="col5" nameend="col6"/>
678 <spanspec spanname="spa7-8" namest="col7" nameend="col8"/>
679 <spanspec spanname="spa9-10" namest="col9" nameend="col10"/>
680 <spanspec spanname="spa11-12" namest="col11" nameend="col12"/>
681 <spanspec spanname="spa13-14" namest="col13" nameend="col14"/>
682 <spanspec spanname="spa15-16" namest="col15" nameend="col16"/>
685 <entry namest="col1" nameend="col8">Top field</entry>
686 <entry namest="col9" nameend="col16">Bottom field</entry>
707 <entry spanname="spa1-2">C</entry>
708 <entry spanname="spa3-4">C</entry>
709 <entry spanname="spa5-6">C</entry>
710 <entry spanname="spa7-8">C</entry>
765 <entry spanname="spa9-10">C</entry>
766 <entry spanname="spa11-12">C</entry>
767 <entry spanname="spa13-14">C</entry>
768 <entry spanname="spa15-16">C</entry>
807 <entry spanname="spa1-2">C</entry>
808 <entry spanname="spa3-4">C</entry>
809 <entry spanname="spa5-6">C</entry>
810 <entry spanname="spa7-8">C</entry>
865 <entry spanname="spa9-10">C</entry>
866 <entry spanname="spa11-12">C</entry>
867 <entry spanname="spa13-14">C</entry>
868 <entry spanname="spa15-16">C</entry>
893 As you can see, the pattern does not repeat until after 4 lines.
894 So for interlaced video, your y-offset and height for cropping must
899 Native DVD resolution is 720x480 for NTSC, and 720x576 for PAL, but
900 there is an aspect flag that specifies whether it is full-screen (4:3) or
901 wide-screen (16:9). Many (if not most) widescreen DVDs are not strictly
902 16:9, and will be either 1.85:1 or 2.35:1 (cinescope). This means that
903 there will be black bands in the video that will need to be cropped out.
907 <application>MPlayer</application> provides a crop detection filter that
908 will determine the crop rectangle (<option>-vf cropdetect</option>).
909 Run <application>MPlayer</application> with
910 <option>-vf cropdetect</option> and it will print out the crop
911 settings to remove the borders.
912 You should let the movie run long enough that the whole picture
913 area is used, in order to get accurate crop values.
917 Then, test the values you get with <application>MPlayer</application>,
918 using the command line which was printed by
919 <option>cropdetect</option>, and adjust the rectangle as needed.
920 The <option>rectangle</option> filter can help by allowing you to
921 interactively position the crop rectangle over your movie.
922 Remember to follow the above divisibility guidelines so that you
923 do not misalign the chroma planes.
927 In certain cases, scaling may be undesirable.
928 Scaling in the vertical direction is difficult with interlaced
929 video, and if you wish to preserve the interlacing, you should
930 usually refrain from scaling.
931 If you will not be scaling but you still want to use multiple-of-16
932 dimensions, you will have to overcrop.
933 Do not undercrop, since black borders are very bad for encoding!
937 Because MPEG-4 uses 16x16 macroblocks, you will want to make sure that each
938 dimension of the video you are encoding is a multiple of 16 or else you
939 will be degrading quality, especially at lower bitrates. You can do this
940 by rounding the width and height of the crop rectangle down to the nearest
942 As stated earlier, when cropping, you will want to increase the Y offset by
943 half the difference of the old and the new height so that the resulting
944 video is taken from the center of the frame. And because of the way DVD
945 video is sampled, make sure the offset is an even number. (In fact, as a
946 rule, never use odd values for any parameter when you are cropping and
947 scaling video.) If you are not comfortable throwing a few extra pixels
948 away, you might prefer instead to scale the video instead. We will look
949 at this in our example below.
950 You can actually let the <option>cropdetect</option> filter do all of the
951 above for you, as it has an optional <option>round</option> parameter that
952 is equal to 16 by default.
956 Also, be careful about "half black" pixels at the edges. Make sure you
957 crop these out too, or else you will be wasting bits there that
958 are better spent elsewhere.
962 After all is said and done, you will probably end up with video whose pixels
963 are not quite 1.85:1 or 2.35:1, but rather something close to that. You
964 could calculate the new aspect ratio manually, but
965 <application>MEncoder</application> offers an option for <systemitem
966 class="library">libavcodec</systemitem> called <option>autoaspect</option>
967 that will do this for you. Absolutely do not scale this video up in order to
968 square the pixels unless you like to waste your hard disk space. Scaling
969 should be done on playback, and the player will use the aspect stored in
970 the AVI to determine the correct resolution.
971 Unfortunately, not all players enforce this auto-scaling information,
972 therefore you may still want to rescale.
977 <sect2 id="menc-feat-dvd-mpeg4-resolution-bitrate">
978 <title>Choosing resolution and bitrate</title>
981 If you will not be encoding in constant quantizer mode, you need to
983 The concept of bitrate is quite simple.
984 It is the (average) number of bits that will be consumed to store your
986 Normally bitrate is measured in kilobits (1000 bits) per second.
987 The size of your movie on disk is the bitrate times the length of the
988 movie in time, plus a small amount of "overhead" (see the section on
989 <link linkend="menc-feat-dvd-mpeg4-muxing-avi-limitations">the AVI container</link>
991 Other parameters such as scaling, cropping, etc. will
992 <emphasis role="bold">not</emphasis> alter the file size unless you
993 change the bitrate as well!.
996 Bitrate does <emphasis role="bold">not</emphasis> scale proportionally
998 That is to say, a 320x240 file at 200 kbit/sec will not be the same
999 quality as the same movie at 640x480 and 800 kbit/sec!
1000 There are two reasons for this:
1003 <emphasis role="bold">Perceptual</emphasis>: You notice MPEG
1004 artifacts more if they are scaled up bigger!
1005 Artifacts appear on the scale of blocks (8x8).
1006 Your eye will not see errors in 4800 small blocks as easily as it
1007 sees errors in 1200 large blocks (assuming you will be scaling both
1011 <emphasis role="bold">Theoretical</emphasis>: When you scale down
1012 an image but still use the same size (8x8) blocks for the frequency
1013 space transform, you move more data to the high frequency bands.
1014 Roughly speaking, each pixel contains more of the detail than it
1016 So even though your scaled-down picture contains 1/4 the information
1017 in the spacial directions, it could still contain a large portion
1018 of the information in the frequency domain (assuming that the high
1019 frequencies were underutilized in the original 640x480 image).
1024 Past guides have recommended choosing a bitrate and resolution based
1025 on a "bits per pixel" approach, but this is usually not valid due to
1027 A better estimate seems to be that bitrates scale proportional to the
1028 square root of resolution, so that 320x240 and 400 kbit/sec would be
1029 comparable to 640x480 at 800 kbit/sec.
1030 However this has not been verified with theoretical or empirical
1032 Further, given that movies vary greatly with regard to noise, detail,
1033 degree of motion, etc., it is futile to make general recommendations
1034 for bits per length-of-diagonal (the analog of bits per pixel,
1035 using the square root).
1038 So far we have discussed the difficulty of choosing a bitrate and
1043 <sect3 id="menc-feat-dvd-mpeg4-resolution-bitrate-compute">
1044 <title>Computing the resolution</title>
1046 The following steps will guide you in computing the resolution of your
1047 encode without distorting the video too much, by taking into account several
1048 types of information about the source video.
1049 First, you should compute the encoded aspect ratio:
1050 <systemitem>ARc = (Wc x (ARa / PRdvd )) / Hc</systemitem>
1052 <title>where:</title>
1054 Wc and Hc are the width and height of the cropped video,
1057 ARa is the displayed aspect ratio, which usually is 4/3 or 16/9,
1060 PRdvd is the pixel ratio of the DVD which is equal to 1.25=(720/576) for PAL
1061 DVDs and 1.5=(720/480) for NTSC DVDs,
1067 Then, you can compute the X and Y resolution, according to a certain
1068 Compression Quality (CQ) factor:
1069 <systemitem>ResY = INT(SQRT( 1000*Bitrate/25/ARc/CQ )/16) * 16</systemitem>
1071 <systemitem>ResX = INT( ResY * ARc / 16) * 16</systemitem>
1075 Okay, but what is the CQ?
1076 The CQ represents the number of bits per pixel and per frame of the encode.
1077 Roughly speaking, the greater the CQ, the less the likelihood to see
1079 However, if you have a target size for your movie (1 or 2 CDs for instance),
1080 there is a limited total number of bits that you can spend; therefore it is
1081 necessary to find a good tradeoff between compressibility and quality.
1085 The CQ depends on the bitrate, the video codec efficiency and the
1087 In order to raise the CQ, typically you would downscale the movie given that the
1088 bitrate is computed in function of the target size and the length of the
1089 movie, which are constant.
1090 With MPEG-4 ASP codecs such as <systemitem class="library">XviD</systemitem>
1091 and <systemitem class="library">libavcodec</systemitem>, a CQ below 0.18
1092 usually results in a pretty blocky picture, because there
1093 are not enough bits to code the information of each macroblock. (MPEG4, like
1094 many other codecs, groups pixels by blocks of several pixels to compress the
1095 image; if there are not enough bits, the edges of those blocks are
1097 It is therefore wise to take a CQ ranging from 0.20 to 0.22 for a 1 CD rip,
1098 and 0.26-0.28 for 2 CDs rip with standard encoding options.
1099 More advanced encoding options such as those listed here for
1100 <link linkend="menc-feat-mpeg4-lavc-example-settings"><systemitem class="library">libavcodec</systemitem></link>
1102 <link linkend="menc-feat-xvid-example-settings"><systemitem class="library">XviD</systemitem></link>
1103 should make it possible to get the same quality with CQ ranging from
1104 0.18 to 0.20 for a 1 CD rip, and 0.24 to 0.26 for a 2 CD rip.
1105 With MPEG-4 ASP codecs such as <systemitem class="library">x264</systemitem>,
1106 you can use a CQ ranging from 0.14 to 0.16 with standard encoding options,
1107 and should be able to go as low as 0.10 to 0.12 with
1108 <link linkend="menc-feat-x264-example-settings"><systemitem class="library">x264</systemitem>'s advanced encoding settings</link>.
1112 Please take note that the CQ is just an indicative figure, as depending on
1113 the encoded content, a CQ of 0.18 may look just fine for a Bergman, contrary
1114 to a movie such as The Matrix, which contains many high-motion scenes.
1115 On the other hand, it is worthless to raise CQ higher than 0.30 as you would
1116 be wasting bits without any noticeable quality gain.
1117 Also note that as mentioned earlier in this guide, low resolution videos
1118 need a bigger CQ (compared to, for instance, DVD resolution) to look good.
1124 <sect2 id="menc-feat-dvd-mpeg4-filtering">
1125 <title>Filtering</title>
1128 Learning how to use <application>MEncoder</application>'s video filters
1129 is essential to producing good encodes.
1130 All video processing is performed through the filters -- cropping,
1131 scaling, color adjustment, noise removal, sharpening, deinterlacing,
1132 telecine, inverse telecine, and deblocking, just to name a few.
1133 Along with the vast number of supported input formats, the variety of
1134 filters available in <application>MEncoder</application> is one of its
1135 main advantages over other similar programs.
1139 Filters are loaded in a chain using the -vf option:
1141 <screen>-vf filter1=options,filter2=options,...</screen>
1143 Most filters take several numeric options separated by colons, but
1144 the syntax for options varies from filter to filter, so read the man
1145 page for details on the filters you wish to use.
1149 Filters operate on the video in the order they are loaded.
1150 For example, the following chain:
1152 <screen>-vf crop=688:464:12:4,scale=640:464</screen>
1154 will first crop the 688x464 region of the picture with upper-left
1155 corner at (12,4), and then scale the result down to 640x464.
1159 Certain filters need to be loaded at or near the beginning of the
1160 filter chain, in order to take advantage of information from the
1161 video decoder that will be lost or invalidated by other filters.
1162 The principal examples are <option>pp</option> (postprocessing, only
1163 when it is performing deblock or dering operations),
1164 <option>spp</option> (another postprocessor to remove MPEG artifacts),
1165 <option>pullup</option> (inverse telecine), and
1166 <option>softpulldown</option> (for converting soft telecine to hard
1171 In general, you want to do as little filtering as possible to the movie
1172 in order to remain close to the original DVD source. Cropping is often
1173 necessary (as described above), but avoid to scale the video. Although
1174 scaling down is sometimes preferred to using higher quantizers, we want
1175 to avoid both these things: remember that we decided from the start to
1176 trade bits for quality.
1180 Also, do not adjust gamma, contrast, brightness, etc. What looks good
1181 on your display may not look good on others. These adjustments should
1182 be done on playback only.
1186 One thing you might want to do, however, is pass the video through a
1187 very light denoise filter, such as <option>-vf hqdn3d=2:1:2</option>.
1188 Again, it is a matter of putting those bits to better use: why waste them
1189 encoding noise when you can just add that noise back in during playback?
1190 Increasing the parameters for <option>hqdn3d</option> will further
1191 improve compressibility, but if you increase the values too much, you
1192 risk degrading the image visibily. The suggested values above
1193 (<option>2:1:2</option>) are quite conservative; you should feel free to
1194 experiment with higher values and observe the results for yourself.
1200 <sect2 id="menc-feat-dvd-mpeg4-interlacing">
1201 <title>Interlacing and Telecine</title>
1204 Almost all movies are shot at 24 fps. Because NTSC is 30000/1001 fps, some
1205 processing must be done to this 24 fps video to make it run at the correct
1206 NTSC framerate. The process is called 3:2 pulldown, commonly referred to
1207 as telecine (because pulldown is often applied during the telecine
1208 process), and, naively described, it works by slowing the film down to
1209 24000/1001 fps, and repeating every fourth frame.
1213 No special processing, however, is done to the video for PAL DVDs, which
1214 run at 25 fps. (Technically, PAL can be telecined, called 2:2 pulldown,
1215 but this does not become an issue in practice.) The 24 fps film is simply
1216 played back at 25 fps. The result is that the movie runs slightly faster,
1217 but unless you are an alien, you probably will not notice the difference.
1218 Most PAL DVDs have pitch-corrected audio, so when they are played back at
1219 25 fps things will sound right, even though the audio track (and hence the
1220 whole movie) has a running time that is 4% less than NTSC DVDs.
1224 Because the video in a PAL DVD has not been altered, you need not worry
1225 much about framerate. The source is 25 fps, and your rip will be 25
1226 fps. However, if you are ripping an NTSC DVD movie, you may need to
1227 apply inverse telecine.
1231 For movies shot at 24 fps, the video on the NTSC DVD is either telecined
1232 30000/1001, or else it is progressive 24000/1001 fps and intended to be telecined
1233 on-the-fly by a DVD player. On the other hand, TV series are usually
1234 only interlaced, not telecined. This is not a hard rule: some TV series
1235 are interlaced (such as Buffy the Vampire Slayer) whereas some are a
1236 mixture of progressive and interlaced (such as Angel, or 24).
1240 It is highly recommended that you read the section on
1241 <link linkend="menc-feat-telecine">How to deal with telecine and interlacing in NTSC DVDs</link>
1242 to learn how to handle the different possibilities.
1246 However, if you are mostly just ripping movies, likely you are either
1247 dealing with 24 fps progressive or telecined video, in which case you can
1248 use the <option>pullup</option> filter <option>-vf
1249 pullup,softskip</option>.
1254 <sect2 id="menc-feat-dvd-mpeg4-encoding-interlaced">
1255 <title>Encoding interlaced video</title>
1258 If the movie you want to encode is interlaced (NTSC video or
1259 PAL video), you will need to choose whether you want to
1261 While deinterlacing will make your movie usable on progressive
1262 scan displays such a computer monitors and projectors, it comes
1263 at a cost: The fieldrate of 50 or 60000/1001 fields per second
1264 is halved to 25 or 30000/1001 frames per second, and roughly half of
1265 the information in your movie will be lost during scenes with
1270 Therefore, if you are encoding for high quality archival purposes,
1271 it is recommended not to deinterlace.
1272 You can always deinterlace the movie at playback time when
1273 displaying it on progressive scan devices, and future players will
1274 be able to deinterlace to full fieldrate, interpolating 50 or
1275 60000/1001 entire frames per second from the interlaced video.
1279 Special care must be taken when working with interlaced video:
1284 Crop height and y-offset must be multiples of 4.
1287 Any vertical scaling must be performed in interlaced mode.
1290 Postprocessing and denoising filters may not work as expected
1291 unless you take special care to operate them a field at a time,
1292 and they may damage the video if used incorrectly.
1297 With these things in mind, here is our first example:
1300 mencoder <replaceable>capture.avi</replaceable> -mc 0 -oac lavc -ovc lavc -lavcopts \
1301 vcodec=mpeg2video:vbitrate=6000:ilme:ildct:acodec=mp2:abitrate=224
1304 Note the <option>ilme</option> and <option>ildct</option> options.
1309 <sect2 id="menc-feat-dvd-mpeg4-av-sync">
1310 <title>Notes on Audio/Video synchronization</title>
1312 <application>MEncoder</application>'s audio/video synchronization
1313 algorithms were designed with the intention of recovering files with
1315 However, in some cases they can cause unnecessary skipping and duplication of
1316 frames, and possibly slight A/V desync, when used with proper input
1317 (of course, A/V sync issues apply only if you process or copy the
1318 audio track while transcoding the video, which is strongly encouraged).
1319 Therefore, you may have to switch to basic A/V sync with
1320 the <option>-mc 0</option> option, or put this in your
1321 <systemitem>~/.mplayer/mencoder</systemitem> config file, as long as
1322 you are only working with good sources (DVD, TV capture, high quality
1323 MPEG-4 rips, etc) and not broken ASF/RM/MOV files.
1326 If you want to further guard against strange frame skips and
1327 duplication, you can use both <option>-mc 0</option> and
1328 <option>-noskip</option>.
1329 This will prevent <emphasis>all</emphasis> A/V sync, and copy frames
1330 one-to-one, so you cannot use it if you will be using any filters that
1331 unpredictably add or drop frames, or if your input file has variable
1333 Therefore, using <option>-noskip</option> is not in general recommended.
1336 The so-called "three-pass" audio encoding which <application>MEncoder</application>
1337 supports has been reported to cause A/V desync.
1338 This will definitely happen if it is used in conjunction with certain
1339 filters, therefore, it is now recommended <emphasis>not</emphasis> to
1340 use three-pass audio mode.
1341 This feature is only left for compatibility purposes and for expert
1342 users who understand when it is safe to use and when it is not.
1343 If you have never heard of three-pass mode before, forget that we
1347 There have also been reports of A/V desync when encoding from stdin
1348 with <application>MEncoder</application>.
1349 Do not do this! Always use a file or CD/DVD/etc device as input.
1353 <sect2 id="menc-feat-dvd-mpeg4-codec">
1354 <title>Choosing the video codec</title>
1357 Choosing the video codec to use depends on several factors, some of
1358 which widely depend on personal taste and technical constraints.
1362 <emphasis role="bold">Compression efficiency</emphasis>:
1363 It is quite easy to understand that newer-generation codecs are made
1364 to yield better picture quality than previous generations.
1365 Therefore, you cannot go wrong
1366 <footnote id='fn-menc-feat-dvd-mpeg4-codec-cpu'>
1367 <para>Be careful, however: Decoding DVD-resolution MPEG-4 AVC videos
1368 requires a fast machine (i.e. a Pentium 4 over 1.5Ghz or a Pentium M
1371 when choosing MPEG-4 AVC codecs like
1372 <systemitem class="library">x264</systemitem> instead of MPEG-4 ASP codecs
1373 such as <systemitem class="library">libavcodec</systemitem> MPEG-4 or
1374 <systemitem class="library">XviD</systemitem>.
1375 (To get a better grasp of what the fundamental differences between
1376 MPEG-4 ASP and MPEG-4 AVC are, you would be well advised to read the entry
1377 "<ulink url="http://guru.multimedia.cx/?p=10">15 reasons why MPEG4 sucks</ulink>"
1378 from Michael Niedermayer's blog.)
1379 Likewise, you should get better quality using MPEG-4 ASP instead
1383 However, newer codecs which are in heavy development can suffer from
1384 bugs which have not yet been noticed and which can ruin an encode.
1385 This is simply the tradeoff for using bleeding-edge technology.
1388 What is more, beginning to use a new codec requires that you spend some
1389 time becoming familiar with its options, so that you know what
1390 to adjust to achieve a desired picture quality.
1394 <emphasis role="bold">Hardware compatibility</emphasis>:
1395 It usually takes a long time for standalone video players to begin to
1396 include support for the latest video codecs.
1397 As a result, most only support MPEG-1 (like VCD, XVCD and KVCD), MPEG-2
1398 (like DVD, SVCD and KVCD) and MPEG-4 ASP (like DivX,
1399 <systemitem class="library">libavcodec</systemitem>'s LMP4 and
1400 <systemitem class="library">XviD</systemitem>)
1401 (Beware: Usually, not all MPEG-4 ASP features are supported).
1402 Please refer to the technical specs of your player (if they are available),
1403 or google around for more information.
1407 <emphasis role="bold">Best quality per encoding time</emphasis>:
1408 Codecs that have been around for some time (such as
1409 <systemitem class="library">libavcodec</systemitem> MPEG-4 and
1410 <systemitem class="library">XviD</systemitem>) are usually heavily
1411 optimized with all kinds of smart algorithms and SIMD assembly code.
1412 That is why they tend to yield the best quality quality per
1413 encoding time ratio.
1414 However, they may have some very advanced options that, if enabled,
1415 will make the encode really slow for marginal gains.
1418 If you are after blazing speed you should stick around the default
1419 settings of the video codec (which does not mean you should not experiment
1420 with some of the options which are mentioned in other sections
1424 You may also consider choosing a codec which can do multi-threaded
1426 <systemitem class="library">libavcodec</systemitem> MPEG-4 does
1427 allow that, resulting in small speed gains at the price of lower
1429 <systemitem class="library">XviD</systemitem> has some experimental
1430 patches available to boost encoding speed, by about 40-60% in typical
1431 cases, with low picture degradation.
1432 <systemitem class="library">x264</systemitem> also allows multi-threaded
1433 encoding, which currently speeds-up encoding by 15-30% while lowering
1434 PSNR by about 0.05dB.
1438 <emphasis role="bold">Personal taste</emphasis>:
1439 This is where it gets almost irrational: For the same reason that some
1440 hung on to DivX 3 for years when newer codecs were already doing wonders,
1441 some folks will prefer <systemitem class="library">XviD</systemitem>
1442 or <systemitem class="library">libavcodec</systemitem> MPEG-4 over
1443 <systemitem class="library">x264</systemitem>.
1446 Make your own judgment, and do not always listen to what some people will
1447 tell you to do or think: The best codec is the one you master the best,
1448 and the one that looks best to your eyes on your display
1449 <footnote id='fn-menc-feat-dvd-mpeg4-codec-playback'>
1450 <para>The same encode may not look the same on someone else's monitor or
1451 when played back by a different decoder, so future-proof your encodes by
1452 playing them back on different setups.</para></footnote>!
1456 Please refer to the section
1457 <link linkend="menc-feat-selecting-codec">selecting codecs and container formats</link>
1458 to get a list of supported codecs.
1462 <sect2 id="menc-feat-dvd-mpeg4-audio">
1463 <title>Audio</title>
1466 Audio is a much simpler problem to solve: if you care about quality, just
1468 Even AC3 5.1 streams are at most 448Kbit/s, and they are worth every bit.
1469 You might be tempted to transcode the audio to high quality Vorbis, but
1470 just because you do not have an A/V receiver for AC3 pass-through today
1471 does not mean you will not have one tomorrow. Future-proof your DVD rips by
1472 preserving the AC3 stream.
1473 You can keep the AC3 stream either by copying it directly into the video
1474 stream <link linkend="menc-feat-mpeg4">during the encoding</link>.
1475 You can also extract the AC3 stream in order to mux it into containers such
1477 <screen>mplayer <replaceable>source_file.vob</replaceable> -aid 129 -dumpaudio -dumpfile <replaceable>sound.ac3</replaceable></screen>
1478 will dump into the file <replaceable>sound.ac3</replaceable> the
1479 audio track number 129 from the file
1480 <replaceable>source_file.vob</replaceable> (NB: DVD VOB files
1481 usually use a different audio numbering,
1482 which means that the VOB audio track 129 is the 2nd audio track of the file).
1486 But sometimes you truly have no choice but to further compress the
1487 sound so that more bits can be spent on the video.
1488 Most people choose to compress audio with either MP3 or Vorbis audio
1490 While the latter is a very space-efficient codec, MP3 is better supported
1491 by hardware players, although this trend is changing.
1495 Do <emphasis>not</emphasis> use <option>-nosound</option> when encoding
1496 a file with audio, even if you will be encoding and muxing audio
1498 Though it may work in ideal cases, using <option>-nosound</option> is
1499 likely to hide some problems in your encoding command line setting.
1500 In other words, having a soundtrack during your encode assures you that,
1501 provided you do not see messages such as
1502 <quote>Too many audio packets in the buffer</quote>, you will be able
1507 You need to have <application>MEncoder</application> process the sound.
1508 You can for example copy the orignal soundtrack during the encode with
1509 <option>-oac copy</option> or convert it to a "light" 4 kHz mono WAV
1510 PCM with <option>-oac pcm -channels 1 -srate 4000</option>.
1511 Otherwise, in some cases, it will generate a video file that will not sync
1513 Such cases are when the number of video frames in the source file does
1514 not match up to the total length of audio frames or whenever there
1515 are discontinuities/splices where there are missing or extra audio frames.
1516 The correct way to handle this kind of problem is to insert silence or
1517 cut audio at these points.
1518 However <application>MPlayer</application> cannot do that, so if you
1519 demux the AC3 audio and encode it with a separate app (or dump it to PCM with
1520 <application>MPlayer</application>), the splices will be left incorrect
1521 and the only way to correct them is to drop/dup video frames at the
1523 As long as <application>MEncoder</application> sees the audio when it is
1524 encoding the video, it can do this dropping/duping (which is usually OK
1525 since it takes place at full black/scenechange, but if
1526 <application>MEncoder</application> cannot see the audio, it will just
1527 process all frames as-is and they will not fit the final audio stream when
1528 you for example merge your audio and video track into a Matroska file.
1532 First of all, you will have to convert the DVD sound into a WAV file that the
1533 audio codec can use as input.
1535 <screen>mplayer <replaceable>source_file.vob</replaceable> -ao pcm:file=<replaceable>destination_sound.wav</replaceable> -vc dummy -aid 1 -vo null</screen>
1536 will dump the second audio track from the file
1537 <replaceable>source_file.vob</replaceable> into the file
1538 <replaceable>destination_sound.wav</replaceable>.
1539 You may want to normalize the sound before encoding, as DVD audio tracks
1540 are commonly recorded at low volumes.
1541 You can use the tool <application>normalize</application> for instance,
1542 which is available in most distributions.
1543 If you are using Windows, a tool such as <application>BeSweet</application>
1544 can do the same job.
1545 You will compress in either Vorbis or MP3.
1547 <screen>oggenc -q1 <replaceable>destination_sound.wav</replaceable></screen>
1548 will encode <replaceable>destination_sound.wav</replaceable> with
1549 the encoding quality 1, which is roughly equivalent to 80Kb/s, and
1550 is the minimum quality at which you should encode if you care about
1552 Please note that MEncoder currently cannot mux Vorbis audio tracks
1553 into the output file because it only supports AVI and MPEG
1554 containers as an output, each of which may lead to audio/video
1555 playback synchronization problems with some players when the AVI file
1556 contain VBR audio streams such as Vorbis.
1557 Do not worry, this document will show you how you can do that with third
1564 <sect2 id="menc-feat-dvd-mpeg4-muxing">
1565 <title>Muxing</title>
1567 Now that you have encoded your video, you will most likely want
1568 to mux it with one or more audio tracks into a movie container, such
1569 as AVI, MPEG, Matroska or NUT.
1570 <application>MEncoder</application> is currently only able to natively output
1571 audio and video into MPEG and AVI container formats.
1573 <screen>mencoder -oac copy -ovc copy -o <replaceable>output_movie.avi</replaceable> -audiofile <replaceable>input_audio.mp2</replaceable> <replaceable>input_video.avi</replaceable></screen>
1574 This would merge the video file <replaceable>input_video.avi</replaceable>
1575 and the audio file <replaceable>input_audio.mp2</replaceable>
1576 into the AVI file <replaceable>output_movie.avi</replaceable>.
1577 This command works with MPEG-1 layer I, II and III (more commonly known
1578 as MP3) audio, WAV and a few other audio formats too.
1582 MEncoder features experimental support for
1583 <systemitem class="library">libavformat</systemitem>, which is a
1584 library from the FFmpeg project that supports muxing and demuxing
1585 a variety of containers.
1587 <screen>mencoder -oac copy -ovc copy -o <replaceable>output_movie.asf</replaceable> -audiofile <replaceable>input_audio.mp2</replaceable> <replaceable>input_video.avi</replaceable> -of lavf -lavfopts format=asf</screen>
1588 This will do the same thing as the previous example, except that
1589 the output container will be ASF.
1590 Please note that this support is highly experimental (but getting
1591 better every day), and will only work if you compiled
1592 <application>MPlayer</application> with the support for
1593 <systemitem class="library">libavformat</systemitem> enabled (which
1594 means that a pre-packaged binary version will not work in most cases).
1598 <sect3 id="menc-feat-dvd-mpeg4-muxing-filter-issues">
1599 <title>Improving muxing and A/V sync reliability</title>
1601 You may experience some serious A/V sync problems while trying to mux
1602 your video and some audio tracks, where no matter how you adjust the
1603 audio delay, you will never get proper sync.
1604 That may happen when you use some video filters that will drop or
1605 duplicate some frames, like the inverse telecine filters.
1606 It is strongly encouraged to append the <option>harddup</option> video
1607 filter at the end of the filter chain to avoid this kind of problem.
1611 Without <option>harddup</option>, if <application>MEncoder</application>
1612 wants to duplicate a frame, it relies on the muxer to put a mark on the
1613 container so that the last frame will be displayed again to maintain
1614 sync while writing no actual frame.
1615 With <option>harddup</option>, <application>MEncoder</application>
1616 will instead just push the last frame displayed again into the filter
1618 This means that the encoder receives the <emphasis>exact</emphasis>
1619 same frame twice, and compresses it.
1620 This will result in a slightly bigger file, but will not cause problems
1621 when demuxing or remuxing into other container formats.
1625 You may also have no choice but to use <option>harddup</option> with
1626 container formats that are not too tightly linked with
1627 <application>MEncoder</application> such as the ones supported through
1628 <systemitem class="library">libavformat</systemitem>, which may not
1629 support frame duplication at the container level.
1634 <sect3 id="menc-feat-dvd-mpeg4-muxing-avi-limitations">
1635 <title>Limitations of the AVI container</title>
1637 Although it is the most widely-supported container format after MPEG-1,
1638 AVI also has some major drawbacks.
1639 Perhaps the most obvious is the overhead.
1640 For each chunk of the AVI file, 24 bytes are wasted on headers and
1642 This translates into a little over 5 MB per hour, or 1-2.5%
1643 overhead for a 700 MB movie. This may not seem like much, but it could
1644 mean the difference between being able to use 700 kbit/sec video or
1645 714 kbit/sec, and every bit of quality counts.
1649 In addition this gross inefficiency, AVI also has the following major
1656 Only fixed-fps content can be stored. This is particularly limiting
1657 if the original material you want to encode is mixed content, for
1658 example a mix of NTSC video and film material.
1659 Actually there are hacks that can be used to store mixed-framerate
1660 content in AVI, but they increase the (already huge) overhead
1661 fivefold or more and so are not practical.
1666 Audio in AVI files must be either constant-bitrate (CBR) or
1667 constant-framesize (i.e. all frames decode to the same number of
1669 Unfortunately, the most efficient codec, Vorbis, does not meet
1670 either of these requirements.
1671 Therefore, if you plan to store your movie in AVI, you will have to
1672 use a less efficient codec such as MP3 or AC3.
1678 Having said all that, <application>MEncoder</application> does not
1679 currently support variable-fps output or Vorbis encoding.
1680 Therefore, you may not see these as limitations if
1681 <application>MEncoder</application> is the
1682 only tool you will be using to produce your encodes.
1683 However, it is possible to use <application>MEncoder</application>
1684 only for video encoding, and then use external tools to encode
1685 audio and mux it into another container format.
1689 <sect3 id="menc-feat-dvd-mpeg4-muxing-matroska">
1690 <title>Muxing into the Matroska container</title>
1692 Matroska is a free, open standard container format, aiming
1693 to offer a lot of advanced features, which older containers
1694 like AVI cannot handle.
1695 For example, Matroska supports variable bitrate audio content
1696 (VBR), variable framerates (VFR), chapters, file attachments,
1697 error detection code (EDC) and modern A/V Codecs like "Advanced Audio
1698 Coding" (AAC), "Vorbis" or "MPEG-4 AVC" (H.264), next to nothing
1703 The tools required to create Matroska files are collectively called
1704 <application>mkvtoolnix</application>, and are available for most
1705 Unix platforms as well as <application>Windows</application>.
1706 Because Matroska is an open standard you may find other
1707 tools that suit you better, but since mkvtoolnix is the most
1708 common, and is supported by the Matroska team itself, we will
1709 only cover its usage.
1713 Probably the easiest way to get started with Matroska is to use
1714 <application>MMG</application>, the graphical frontend shipped with
1715 <application>mkvtoolnix</application>, and follow the
1716 <ulink url="http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvmerge-gui.html">guide to mkvmerge GUI (mmg)</ulink>
1720 You may also mux audio and video files using the command line:
1721 <screen>mkvmerge -o <replaceable>output.mkv</replaceable> <replaceable>input_video.avi</replaceable> <replaceable>input_audio1.mp3</replaceable> <replaceable>input_audio2.ac3</replaceable></screen>
1722 This would merge the video file <replaceable>input_video.avi</replaceable>
1723 and the two audio files <replaceable>input_audio1.mp3</replaceable>
1724 and <replaceable>input_audio2.ac3</replaceable> into the Matroska
1725 file <replaceable>output.mkv</replaceable>.
1726 Matroska, as mentioned earlier, is able to do much more than that, like
1727 multiple audio tracks (including fine-tuning of audio/video
1728 synchronization), chapters, subtitles, splitting, etc...
1729 Please refer to the documentation of those applications for
1739 <sect1 id="menc-feat-telecine">
1740 <title>How to deal with telecine and interlacing within NTSC DVDs</title>
1742 <sect2 id="menc-feat-telecine-intro">
1743 <title>Introduction</title>
1745 <title>What is telecine?</title>
1747 I suggest you visit this page if you do not understand much of what
1748 is written in this document:
1749 <ulink url="http://www.divx.com/support/guides/guide.php?gid=10">http://www.divx.com/support/guides/guide.php?gid=10</ulink>
1750 This URL links to an understandable and reasonably comprehensive
1751 description of what telecine is.
1752 </para></formalpara>
1755 <title>A note about the numbers.</title>
1757 Many documents, including the guide linked above, refer to the fields
1758 per second value of NTSC video as 59.94 and the corresponding frames
1759 per second values as 29.97 (for telecined and interlaced) and 23.976
1760 (for progressive). For simplicity, some documents even round these
1761 numbers to 60, 30, and 24.
1762 </para></formalpara>
1765 Strictly speaking, all those numbers are approximations. Black and
1766 white NTSC video was exactly 60 fields per second, but 60000/1001
1767 was later chosen to accomodate color data while remaining compatible
1768 with contemporary black and white televisions. Digital NTSC video
1769 (such as on a DVD) is also 60000/1001 fields per second. From this,
1770 interlaced and telecined video are derived to be 30000/1001 frames
1771 per second; progressive video is 24000/1001 frames per second.
1775 Older versions of the <application>MEncoder</application> documentation
1776 and many archived mailing list posts refer to 59.94, 29.97, and 23.976.
1777 All <application>MEncoder</application> documentation has been updated
1778 to use the fractional values, and you should use them too.
1782 <option>-ofps 23.976</option> is incorrect.
1783 <option>-ofps 24000/1001</option> should be used instead.
1787 <title>How telecine is used.</title>
1789 All video intended to be displayed on an NTSC
1790 television set must be 60000/1001 fields per second. Made-for-TV movies
1791 4 and shows are often filmed directly at 60000/1001 fields per second, but
1792 the majority of cinema is filmed at 24 or 24000/1001 frames per
1793 second. When cinematic movie DVDs are mastered, the video is then
1794 converted for television using a process called telecine.
1795 </para></formalpara>
1798 On a DVD, the video is never actually stored as 60000/1001 fields per
1799 second. For video that was originally 60000/1001, each pair of fields is
1800 combined to form a frame, resulting in 30000/1001 frames per
1801 second. Hardware DVD players then read a flag embedded in the video
1802 stream to determine whether the odd- or even-numbered lines should
1803 form the first field.
1807 Usually, 24000/1001 frames per second content stays as it is when
1808 encoded for a DVD, and the DVD player must perform telecining
1809 on-the-fly. Sometimes, however, the video is telecined
1810 <emphasis>before</emphasis> being stored on the DVD; even though it
1811 was originally 24000/1001 frames per second, it becomes 60000/1001 fields per
1812 second. When it is stored on the DVD, pairs of fields are combined to form
1813 30000/1001 frames per second.
1817 When looking at individual frames formed from 60000/10001 fields per
1818 second video, telecined or otherwise, interlacing is clearly visible
1819 wherever there is any motion, because one field (say, the
1820 even-numbered lines) represents a moment in time 1/(60000/1001)
1821 seconds later than the other. Playing interlaced video on a computer
1822 looks ugly both because the monitor is higher resolution and because
1823 the video is shown frame-after-frame instead of field-after-field.
1827 <title>Notes:</title>
1829 This section only applies to NTSC DVDs, and not PAL.
1832 The example <application>MEncoder</application> lines throughout the
1833 document are <emphasis role="bold">not</emphasis> intended for
1834 actual use. They are simply the bare minimum required to encode the
1835 pertaining video category. How to make good DVD rips or fine-tune
1836 <systemitem class="library">libavcodec</systemitem> for maximal
1837 quality is not within the scope of this document.
1840 There are a couple footnotes specific to this guide, linked like this:
1841 <link linkend="menc-feat-telecine-footnotes">[1]</link>
1846 <sect2 id="menc-feat-telecine-ident">
1847 <title>How to tell what type of video you have</title>
1849 <sect3 id="menc-feat-telecine-ident-progressive">
1850 <title>Progressive</title>
1852 Progressive video was originally filmed at 24000/1001 fps, and stored
1853 on the DVD without alteration.
1857 When you play a progressive DVD in <application>MPlayer</application>,
1858 <application>MPlayer</application> will print the following line as
1859 soon as the movie begins to play:
1861 <screen> demux_mpg: 24000/1001 fps progressive NTSC content detected, switching framerate.</screen>
1863 From this point forward, demux_mpg should never say it finds
1864 "30000/1001 fps NTSC content."
1868 When you watch progressive video, you should never see any
1869 interlacing. Beware, however, because sometimes there is a tiny bit
1870 of telecine mixed in where you would not expect. I have encountered TV
1871 show DVDs that have one second of telecine at every scene change, or
1872 at seemingly random places. I once watched a DVD that had a
1873 progressive first half, and the second half was telecined. If you
1874 want to be <emphasis>really</emphasis> thorough, you can scan the
1877 <screen>mplayer dvd://1 -nosound -vo null -benchmark</screen>
1879 Using <option>-benchmark</option> makes
1880 <application>MPlayer</application> play the movie as quickly as it
1881 possibly can; still, depending on your hardware, it can take a
1882 while. Every time demux_mpg reports a framerate change, the line
1883 immediately above will show you the time at which the change
1888 Sometimes progressive video on DVDs is referred to as
1889 "soft-telecine" because it is intended to
1890 be telecined by the DVD player.
1894 <sect3 id="menc-feat-telecine-ident-telecined">
1895 <title>Telecined</title>
1897 Telecined video was originally filmed at 24000/1001, but was telecined
1898 <emphasis>before</emphasis> it was written to the DVD.
1902 <application>MPlayer</application> does not (ever) report any
1903 framerate changes when it plays telecined video.
1907 Watching a telecined video, you will see interlacing artifacts that
1908 seem to "blink": they repeatedly appear and disappear.
1909 You can look closely at this by
1912 <screen>mplayer dvd://1</screen>
1915 Seek to a part with motion.
1918 Use the <keycap>.</keycap> key to step forward one frame at a time.
1921 Look at the pattern of interlaced-looking and progressive-looking
1922 frames. If the pattern you see is PPPII,PPPII,PPPII,... then the
1923 video is telecined. If you see some other pattern, then the video
1924 may have been telecined using some non-standard method;
1925 <application>MEncoder</application> cannot losslessly convert
1926 non-standard telecine to progressive. If you do not see any
1927 pattern at all, then it is most likely interlaced.
1933 Sometimes telecined video on DVDs is referred to as
1934 "hard-telecine". Since hard-telecine is already 60000/1001 fields
1935 per second, the DVD player plays the video without any manipulation.
1939 Another way to tell if your source is telecined or not is to play
1940 the source with the <option>-vf pullup</option> and <option>-v</option>
1941 command line options to see how <option>pullup</option> matches frames.
1942 If the source is telecined, you should see on the console a 3:2 pattern
1943 with <systemitem>0+.1.+2</systemitem> and <systemitem>0++1</systemitem>
1945 This technique has the advantage that you do not need to watch the
1946 source to identify it, which could be useful if you wish to automate
1947 the encoding procedure, or to carry out said procedure remotely via
1953 <sect3 id="menc-feat-telecine-ident-interlaced">
1954 <title>Interlaced</title>
1956 Interlaced video was originally filmed at 60000/1001 fields per second,
1957 and stored on the DVD as 30000/1001 frames per second. The interlacing effect
1958 (often called "combing") is a result of combining pairs of
1959 fields into frames. Each field is supposed to be 1/(60000/1001) seconds apart,
1960 and when they are displayed simultaneously the difference is apparent.
1964 As with telecined video, <application>MPlayer</application> should
1965 not ever report any framerate changes when playing interlaced content.
1969 When you view an interlaced video closely by frame-stepping with the
1970 <keycap>.</keycap> key, you will see that every single frame is interlaced.
1974 <sect3 id="menc-feat-telecine-ident-mixedpt">
1975 <title>Mixed progressive and telecine</title>
1977 All of a "mixed progressive and telecine" video was originally
1978 24000/1001 frames per second, but some parts of it ended up being telecined.
1982 When <application>MPlayer</application> plays this category, it will
1983 (often repeatedly) switch back and forth between "30000/1001 fps NTSC"
1984 and "24000/1001 fps progressive NTSC". Watch the bottom of
1985 <application>MPlayer</application>'s output to see these messages.
1989 You should check the "30000/1001 fps NTSC" sections to make sure
1990 they are actually telecine, and not just interlaced.
1994 <sect3 id="menc-feat-telecine-ident-mixedpi">
1995 <title>Mixed progressive and interlaced</title>
1997 In "mixed progressive and interlaced" content, progressive
1998 and interlaced video have been spliced together.
2002 This category looks just like "mixed progressive and telecine",
2003 until you examine the 30000/1001 fps sections and see that they do not have the
2010 <sect2 id="menc-feat-telecine-encode">
2011 <title>How to encode each category</title>
2013 As I mentioned in the beginning, example <application>MEncoder</application>
2014 lines below are <emphasis role="bold">not</emphasis> meant to actually be used;
2015 they only demonstrate the minimum parameters to properly encode each category.
2018 <sect3 id="menc-feat-telecine-encode-progressive">
2019 <title>Progressive</title>
2021 Progressive video requires no special filtering to encode. The only
2022 parameter you need to be sure to use is
2023 <option>-ofps 24000/1001</option>. Otherwise, <application>MEncoder</application>
2024 will try to encode at 30000/1001 fps and will duplicate frames.
2028 <screen>mencoder dvd://1 -oac copy -ovc lavc -ofps 24000/1001</screen>
2032 It is often the case, however, that a video that looks progressive
2033 actually has very short parts of telecine mixed in. Unless you are
2034 sure, it is safest to treat the video as
2035 <link linkend="menc-feat-telecine-encode-mixedpt">mixed progressive and telecine</link>.
2036 The performance loss is small
2037 <link linkend="menc-feat-telecine-footnotes">[3]</link>.
2041 <sect3 id="menc-feat-telecine-encode-telecined">
2042 <title>Telecined</title>
2044 Telecine can be reversed to retrieve the original 24000/1001 content,
2045 using a process called inverse-telecine.
2046 <application>MPlayer</application> contains several filters to
2047 accomplish this; the best filter, <option>pullup</option>, is described
2048 in the <link linkend="menc-feat-telecine-encode-mixedpt">mixed
2049 progressive and telecine</link> section.
2053 <sect3 id="menc-feat-telecine-encode-interlaced">
2054 <title>Interlaced</title>
2056 For most practical cases it is not possible to retrieve a complete
2057 progressive video from interlaced content. The only way to do so
2058 without losing half of the vertical resolution is to double the
2059 framerate and try to "guess" what ought to make up the
2060 corresponding lines for each field (this has drawbacks - see method
2067 Encode the video in interlaced form. Normally, interlacing wreaks
2068 havoc with the encoder's ability to compress well, but
2069 <systemitem class="library">libavcodec</systemitem> has two
2070 parameters specifically for dealing with storing interlaced video a
2071 bit better: <option> ildct</option> and <option>ilme</option>. Also,
2072 using <option>mbd=2</option> is strongly recommended
2073 <link linkend="menc-feat-telecine-footnotes">[2] </link> because it
2074 will encode macroblocks as non-interlaced in places where there is
2075 no motion. Note that <option>-ofps</option> is NOT needed here.
2077 <screen>mencoder dvd://1 -oac copy -ovc lavc -lavcopts ildct:ilme:mbd=2</screen>
2080 Use a deinterlacing filter before encoding. There are several of
2081 these filters available to choose from, each with its own advantages
2082 and disadvantages. Consult <option>mplayer -pphelp</option> to see
2083 what is available (grep for "deint"), and search the
2084 <ulink url="http://www.mplayerhq.hu/homepage/design6/info.html#mailing_lists">
2085 MPlayer mailing lists</ulink> to find many discussions about the
2086 various filters. Again, the framerate is not changing, so no
2087 <option>-ofps</option>. Also, deinterlacing should be done after
2088 cropping <link linkend="menc-feat-telecine-footnotes">[1]</link> and
2091 <screen>mencoder dvd://1 -oac copy -vf pp=lb -ovc lavc</screen>
2094 Unfortunately, this option is buggy with
2095 <application>MEncoder</application>; it ought to work well with
2096 <application>MEncoder G2</application>, but that is not here yet. You
2097 might experience crahes. Anyway, the purpose of <option> -vf
2098 tfields</option> is to create a full frame out of each field, which
2099 makes the framerate 60000/1001. The advantage of this approach is that no
2100 data is ever lost; however, since each frame comes from only one
2101 field, the missing lines have to be interpolated somehow. There are
2102 no very good methods of generating the missing data, and so the
2103 result will look a bit similar to when using some deinterlacing
2104 filters. Generating the missing lines creates other issues, as well,
2105 simply because the amount of data doubles. So, higher encoding
2106 bitrates are required to maintain quality, and more CPU power is
2107 used for both encoding and decoding. tfields has several different
2108 options for how to create the missing lines of each frame. If you
2109 use this method, then Reference the manual, and chose whichever
2110 option looks best for your material. Note that when using
2111 <option>tfields</option> you
2112 <emphasis role="bold">have to</emphasis> specify both
2113 <option>-fps</option> and <option>-ofps</option> to be twice the
2114 framerate of your original source.
2116 <screen>mencoder dvd://1 -oac copy -vf tfields=2 -ovc lavc -fps 60000/1001 -ofps 60000/1001</screen>
2119 If you plan on downscaling dramatically, you can extract and encode
2120 only one of the two fields. Of course, you will lose half the vertical
2121 resolution, but if you plan on downscaling to at most 1/2 of the
2122 original, the loss will not matter much. The result will be a
2123 progressive 30000/1001 frames per second file. The procedure is to use
2124 <option>-vf field</option>, then crop
2125 <link linkend="menc-feat-telecine-footnotes">[1]</link> and scale
2126 appropriately. Remember that you will have to adjust the scale to
2127 compensate for the vertical resolution being halved.
2128 <screen>mencoder dvd://1 -oac copy -vf field=0 -ovc lavc</screen>
2133 <sect3 id="menc-feat-telecine-encode-mixedpt">
2134 <title>Mixed progressive and telecine</title>
2136 In order to turn mixed progressive and telecine video into entirely
2137 progressive video, the telecined parts have to be
2138 inverse-telecined. There are three ways to accomplish this,
2139 described below. Note that you should
2140 <emphasis role="bold">always</emphasis> inverse-telecine before any
2141 rescaling; unless you really know what you are doing,
2142 inverse-telecine before cropping, too
2143 <link linkend="menc-feat-telecine-footnotes">[1]</link>.
2144 <option>-ofps 24000/1001</option> is needed here because the output video
2145 will be 24000/1001 frames per second.
2150 <option>-vf pullup</option> is designed to inverse-telecine
2151 telecined material while leaving progressive data alone. In order to
2152 work properly, <option>pullup</option> <emphasis role="bold">must</emphasis>
2153 be followed by the <option>softskip</option> filter or
2154 else <application>MEncoder</application> will crash.
2155 <option>pullup</option> is, however, the cleanest and most
2156 accurate method available for encoding both telecine and
2157 "mixed progressive and telecine".
2159 <screen>mencoder dvd://1 -oac copy -vf pullup,softskip -ovc lavc -ofps 24000/1001</screen>
2166 is to, rather than inverse-telecine the telecined parts, telecine
2167 the non-telecined parts and then inverse-telecine the whole
2168 video. Sound confusing? softpulldown is a filter that goes through
2169 a video and makes the entire file telecined. If we follow
2170 softpulldown with either <option>detc</option> or
2171 <option>ivtc</option>, the final result will be entirely
2172 progressive. <option>-ofps 24000/1001</option> is needed.
2174 <screen>mencoder dvd://1 -oac copy -vf softpulldown,ivtc=1 -ovc lavc -ofps 24000/1001</screen>
2179 I have not used <option>-vf filmdint</option> myself, but here is what
2180 D Richard Felker III has to say:
2182 <blockquote><para>It is OK, but IMO it tries to deinterlace rather
2183 than doing inverse telecine too often (much like settop DVD
2184 players & progressive TVs) which gives ugly flickering and
2185 other artifacts. If you are going to use it, you at least need to
2186 spend some time tuning the options and watching the output first
2187 to make sure it is not messing up.</para></blockquote>
2192 <sect3 id="menc-feat-telecine-encode-mixedpi">
2193 <title>Mixed progressive and interlaced</title>
2195 There are two options for dealing with this category, each of
2196 which is a compromise. You should decide based on the
2197 duration/location of each type.
2202 Treat it as progressive. The interlaced parts will look interlaced,
2203 and some of the interlaced fields will have to be dropped, resulting
2204 in a bit of uneven jumpiness. You can use a postprocessing filter if
2205 you want to, but it may slightly degrade the progressive parts.
2209 This option should definitely not be used if you want to eventually
2210 display the video on an interlaced device (with a TV card, for
2211 example). If you have interlaced frames in a 24000/1001 frames per
2212 second video, they will be telecined along with the progressive
2213 frames. Half of the interlaced "frames" will be displayed for three
2214 fields' duration (3/(60000/1001) seconds), resulting in a flicking
2215 "jump back in time" effect that looks quite bad. If you
2216 even attempt this, you <emphasis role="bold">must</emphasis> use a
2217 deinterlacing filter like <option>lb</option> or
2218 <option>l5</option>.
2222 It may also be a bad idea for progressive display, too. It will drop
2223 pairs of consecutive interlaced fields, resulting in a discontinuity
2224 that can be more visible than with the second method, which shows
2225 some progressive frames twice. 30000/1001 frames per second interlaced
2226 video is already a bit choppy because it really should be shown at
2227 60000/1001 fields per second, so the duplicate frames do not stand out as
2232 Either way, it is best to consider your content and how you intend to
2233 display it. If your video is 90% progressive and you never intend to
2234 show it on a TV, you should favor a progressive approach. If it is
2235 only half progressive, you probably want to encode it as if it is all
2241 Treat it as interlaced. Some frames of the progressive parts will
2242 need to be duplicated, resulting in uneven jumpiness. Again,
2243 deinterlacing filters may slightly degrade the progressive parts.
2251 <sect2 id="menc-feat-telecine-footnotes">
2252 <title>Footnotes</title>
2254 <listitem><formalpara>
2255 <title>About cropping:</title>
2257 Video data on DVDs are stored in a format called YUV 4:2:0. In YUV
2258 video, luma ("brightness") and chroma ("color")
2259 are stored separately. Because the human eye is somewhat less
2260 sensitive to color than it is to brightness, in a YUV 4:2:0 picture
2261 there is only one chroma pixel for every four luma pixels. In a
2262 progressive picture, each square of four luma pixels (two on each
2263 side) has one common chroma pixel. You must crop progressive YUV
2264 4:2:0 to even resolutions, and use even offsets. For example,
2265 <option>crop=716:380:2:26</option> is OK but
2266 <option>crop=716:380:3:26 </option> is not.
2271 When you are dealing with interlaced YUV 4:2:0, the situation is a
2272 bit more complicated. Instead of every four luma pixels in the
2273 <emphasis>frame</emphasis> sharing a chroma pixel, every four luma
2274 pixels in each <emphasis> field</emphasis> share a chroma
2275 pixel. When fields are interlaced to form a frame, each scanline is
2276 one pixel high. Now, instead of all four luma pixels being in a
2277 square, there are two pixels side-by-side, and the other two pixels
2278 are side-by-side two scanlines down. The two luma pixels in the
2279 intermediate scanline are from the other field, and so share a
2280 different chroma pixel with two luma pixels two scanlines away. All
2281 this confusion makes it necessary to have vertical crop dimensions
2282 and offsets be multiples of four. Horizontal can stay even.
2286 For telecined video, I recommend that cropping take place after
2287 inverse telecining. Once the video is progressive you only need to
2288 crop by even numbers. If you really want to gain the slight speedup
2289 that cropping first may offer, you must crop vertically by multiples
2290 of four or else the inverse-telecine filter will not have proper data.
2294 For interlaced (not telecined) video, you must always crop
2295 vertically by multiples of four unless you use <option>-vf
2296 field</option> before cropping.
2300 <listitem><formalpara>
2301 <title>About encoding parameters and quality:</title>
2303 Just because I recommend <option>mbd=2</option> here does not mean it
2304 should not be used elsewhere. Along with <option>trell</option>,
2305 <option>mbd=2</option> is one of the two
2306 <systemitem class="library">libavcodec</systemitem> options that
2307 increases quality the most, and you should always use at least those
2308 two unless the drop in encoding speed is prohibitive (e.g. realtime
2309 encoding). There are many other options to
2310 <systemitem class="library">libavcodec</systemitem> that increase
2311 encoding quality (and decrease encoding speed) but that is beyond
2312 the scope of this document.
2317 <listitem><formalpara>
2318 <title>About the performance of pullup:</title>
2320 It is safe to use <option>pullup</option> (along with <option>softskip
2321 </option>) on progressive video, and is usually a good idea unless
2322 the source has been definitively verified to be entirely progressive.
2323 The performace loss is small for most cases. On a bare-minimum encode,
2324 <option>pullup</option> causes <application>MEncoder</application> to
2325 be 50% slower. Adding sound processing and advanced <option>lavcopts
2326 </option> overshadows that difference, bringing the performance
2327 decrease of using <option>pullup</option> down to 2%.
2339 <sect1 id="menc-feat-enc-libavcodec">
2340 <title>Encoding with the <systemitem class="library">libavcodec</systemitem>
2341 codec family</title>
2344 <link linkend="ffmpeg"><systemitem class="library">libavcodec</systemitem></link>
2345 provides simple encoding to a lot of interesting video and audio formats.
2346 You can encode to the following codecs (more or less up to date):
2349 <sect2 id="menc-feat-enc-libavcodec-video-codecs">
2350 <title><systemitem class="library">libavcodec</systemitem>'s video codecs</title>
2353 <informaltable frame="all">
2356 <row><entry>Video codec name</entry><entry>Description</entry></row>
2359 <row><entry>mjpeg</entry><entry>
2362 <row><entry>ljpeg</entry><entry>
2365 <row><entry>h261</entry><entry>
2368 <row><entry>h263</entry><entry>
2371 <row><entry>h263p</entry><entry>
2374 <row><entry>mpeg4</entry><entry>
2375 ISO standard MPEG-4 (DivX 5, XviD compatible)
2377 <row><entry>msmpeg4</entry><entry>
2378 pre-standard MPEG-4 variant by MS, v3 (AKA DivX3)
2380 <row><entry>msmpeg4v2</entry><entry>
2381 pre-standard MPEG-4 by MS, v2 (used in old ASF files)
2383 <row><entry>wmv1</entry><entry>
2384 Windows Media Video, version 1 (AKA WMV7)
2386 <row><entry>wmv2</entry><entry>
2387 Windows Media Video, version 2 (AKA WMV8)
2389 <row><entry>rv10</entry><entry>
2392 <row><entry>rv20</entry><entry>
2395 <row><entry>mpeg1video</entry><entry>
2398 <row><entry>mpeg2video</entry><entry>
2401 <row><entry>huffyuv</entry><entry>
2402 lossless compression
2404 <row><entry>asv1</entry><entry>
2407 <row><entry>asv2</entry><entry>
2410 <row><entry>ffv1</entry><entry>
2411 FFmpeg's lossless video codec
2413 <row><entry>svq1</entry><entry>
2416 <row><entry>flv</entry><entry>
2417 Sorenson H.263 used in Flash Video
2419 <row><entry>dvvideo</entry><entry>
2422 <row><entry>snow</entry><entry>
2423 FFmpeg's experimental wavelet-based codec
2429 The first column contains the codec names that should be passed after the
2430 <literal>vcodec</literal> config, like: <option>-lavcopts vcodec=msmpeg4</option>
2434 An example with MJPEG compression:
2435 <screen>mencoder dvd://2 -o title2.avi -ovc lavc -lavcopts vcodec=mjpeg -oac copy</screen>
2440 <sect2 id="menc-feat-enc-libavcodec-audio-codecs">
2441 <title><systemitem class="library">libavcodec</systemitem>'s audio codecs</title>
2443 <informaltable frame="all">
2446 <row><entry>Audio codec name</entry><entry>Description</entry></row>
2451 <entry>MPEG Layer 2</entry>
2455 <entry>AC3, AKA Dolby Digital</entry>
2458 <entry>adpcm_ima_wav</entry>
2459 <entry>IMA adaptive PCM (4 bits per sample, 4:1 compression)</entry>
2462 <entry>sonic</entry>
2463 <entry>experimental lossy/lossless codec</entry>
2469 The first column contains the codec names that should be passed after the
2470 <literal>acodec</literal> option, like: <option>-lavcopts acodec=ac3</option>
2475 An example with AC3 compression:
2476 <screen>mencoder dvd://2 -o title2.avi -oac lavc -lavcopts acodec=ac3 -ovc copy</screen>
2481 Contrary to <systemitem class="library">libavcodec</systemitem>'s video
2482 codecs, its audio codecs do not make a wise usage of the bits they are
2483 given as they lack some minimal psychoacoustic model (if at all)
2484 which most other codec implementations feature.
2485 However, note that all these audio codecs are very fast and work
2486 out-of-the-box everywhere <application>MEncoder</application> has been
2487 compiled with <systemitem class="library">libavcodec</systemitem> (which
2488 is the case most of time), and do not depend on external libraries.
2493 <sect2 id="menc-feat-dvd-mpeg4-lavc-encoding-options">
2494 <title>Encoding options of libavcodec</title>
2497 Ideally, you would probably want to be able to just tell the encoder to switch
2498 into "high quality" mode and move on.
2499 That would probably be nice, but unfortunately hard to implement as different
2500 encoding options yield different quality results depending on the source material.
2501 That is because compression depends on the visual properties of the video
2503 For example, anime and live action have very different properties and
2504 thus require different options to obtain optimum encoding.
2505 The good news is that some options should never be left out, like
2506 <option>mbd=2</option>, <option>trell</option>, and <option>v4mv</option>.
2507 See below for a detailed description of common encoding options.
2512 <title>Options to adjust:</title>
2514 <emphasis role="bold">vmax_b_frames</emphasis>: 1 or 2 is good, depending on
2516 Note that if you need to have your encode be decodable by DivX5, you
2517 need to activate closed GOP support, using
2518 <systemitem class="library">libavcodec</systemitem>'s <option>cgop</option>
2519 option, but you need to deactivate scene detection, which
2520 is not a good idea as it will hurt encode efficiency a bit.
2524 <emphasis role="bold">vb_strategy=1</emphasis>: helps in high-motion scenes.
2525 On some videos, vmax_b_frames may hurt quality, but vmax_b_frames=2 along
2526 with vb_strategy=1 helps.
2530 <emphasis role="bold">dia</emphasis>: motion search range. Bigger is better
2532 Negative values are a completely different scale.
2533 Good values are -1 for a fast encode, or 2-4 for slower.
2537 <emphasis role="bold">predia</emphasis>: motion search pre-pass.
2538 Not as important as dia. Good values are 1 (default) to 4. Requires preme=2
2539 to really be useful.
2543 <emphasis role="bold">cmp, subcmp, precmp</emphasis>: Comparison function for
2545 Experiment with values of 0 (default), 2 (hadamard), 3 (dct), and 6 (rate
2547 0 is fastest, and sufficient for precmp.
2548 For cmp and subcmp, 2 is good for anime, and 3 is good for live action.
2549 6 may or may not be slightly better, but is slow.
2553 <emphasis role="bold">last_pred</emphasis>: Number of motion predictors to
2554 take from the previous frame.
2555 1-3 or so help at little speed cost.
2556 Higher values are slow for no extra gain.
2560 <emphasis role="bold">cbp, mv0</emphasis>: Controls the selection of macroblocks.
2561 Small speed cost for small quality gain.
2565 <emphasis role="bold">qprd</emphasis>: adaptive quantization based on the
2566 macroblock's complexity.
2567 May help or hurt depending on the video and other options.
2568 This can cause artifacts unless you set vqmax to some reasonably small value
2569 (6 is good, maybe as low as 4); vqmin=1 should also help.
2573 <emphasis role="bold">qns</emphasis>: very slow, especially when combined
2575 This option will make the encoder minimize noise due to compression
2576 artifacts instead of making the encoded video strictly match the source.
2577 Do not use this unless you have already tweaked everything else as far as it
2578 will go and the results still are not good enough.
2582 <emphasis role="bold">vqcomp</emphasis>: Tweak ratecontrol.
2583 What values are good depends on the movie.
2584 You can safely leave this alone if you want.
2585 Reducing vqcomp puts more bits on low-complexity scenes, increasing it puts
2586 them on high-complexity scenes (default: 0.5, range: 0-1. recommended range:
2591 <emphasis role="bold">vlelim, vcelim</emphasis>: Sets the single coefficient
2592 elimination threshold for luminance and chroma planes.
2593 These are encoded separately in all MPEG-like algorithms.
2594 The idea behind these options is to use some good heuristics to determine
2595 when the change in a block is less than the threshold you specify, and in
2596 such a case, to just encode the block as "no change".
2597 This saves bits and perhaps speeds up encoding. vlelim=-4 and vcelim=9
2598 seem to be good for live movies, but seem not to help with anime;
2599 when encoding animation, you should probably leave them unchanged.
2603 <emphasis role="bold">qpel</emphasis>: Quarter pixel motion estimation.
2604 MPEG-4 uses half pixel precision for its motion search by default,
2605 therefore this option comes with an overhead as more information will be
2606 stored in the encoded file.
2607 The compression gain/loss depends on the movie, but it is usually not very
2609 qpel always incurs a significant cost in CPU decode time (+25% in
2614 <emphasis role="bold">psnr</emphasis>: does not affect the actual encoding,
2615 but writes a log file giving the type/size/quality of each frame, and
2616 prints a summary of PSNR (Peak Signal to Noise Ratio) at the end.
2622 <title>Options not recommended to play with:</title>
2624 <emphasis role="bold">vme</emphasis>: The default is best.
2628 <emphasis role="bold">lumi_mask, dark_mask</emphasis>: Psychovisual adaptive
2630 You do not want to play with those options if you care about quality.
2631 Reasonable values may be effective in your case, but be warned this is very
2636 <emphasis role="bold">scplx_mask</emphasis>: Tries to prevent blocky
2637 artifacts, but postprocessing is better.
2642 <sect2 id="menc-feat-mpeg4-lavc-example-settings">
2643 <title>Encoding setting examples</title>
2646 The following settings are examples of different encoding
2647 option combinations that affect the speed vs quality tradeoff
2648 at the same target bitrate.
2652 All the encoding settings were tested on a 720x448 @30000/1001 fps
2653 video sample, the target bitrate was 900kbps, and the machine was an
2654 AMD-64 3400+ at 2400 Mhz in 64 bits mode.
2655 Each encoding setting features the measured encoding speed (in
2656 frames per second) and the PSNR loss (in dB) compared to the "very
2657 high quality" setting.
2658 Please understand that depending on your source, your machine type
2659 and development advancements, you may get very different results.
2663 <informaltable frame="all">
2666 <row><entry>Description</entry><entry>Encoding options</entry><entry>speed (in fps)</entry><entry>Relative PSNR loss (in dB)</entry></row>
2670 <entry>Very high quality</entry>
2671 <entry><option>vcodec=mpeg4:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2</option></entry>
2676 <entry>High quality</entry>
2677 <entry><option>vcodec=mpeg4:mbd=2:trell:v4mv:last_pred=2:dia=-1:vmax_b_frames=2:vb_strategy=1:cmp=3:subcmp=3:precmp=0:vqcomp=0.6:turbo</option></entry>
2678 <entry>15fps</entry>
2679 <entry>-0.5dB</entry>
2683 <entry><option>vcodec=mpeg4:mbd=2:trell:v4mv:turbo</option></entry>
2684 <entry>42fps</entry>
2685 <entry>-0.74dB</entry>
2688 <entry>Realtime</entry>
2689 <entry><option>vcodec=mpeg4:mbd=2:turbo</option></entry>
2690 <entry>54fps</entry>
2691 <entry>-1.21dB</entry>
2699 <sect2 id="custommatrices"><title>Custom inter/intra matrices</title>
2702 With this feature of
2703 <link linkend="ffmpeg"><systemitem class="library">libavcodec</systemitem></link>
2704 you are able to set custom inter (I-frames/keyframes) and intra
2705 (P-frames/predicted frames) matrices. It is supported by many of the codecs:
2706 <systemitem>mpeg1video</systemitem> and <systemitem>mpeg2video</systemitem>
2707 are reported as working.
2711 A typical usage of this feature is to set the matrices preferred by the
2712 <ulink url="http://www.kvcd.net/">KVCD</ulink> specifications.
2716 The <emphasis role="bold">KVCD "Notch" Quantization Matrix:</emphasis>
2722 8 9 12 22 26 27 29 34
2723 9 10 14 26 27 29 34 37
2724 12 14 18 27 29 34 37 38
2725 22 26 27 31 36 37 38 40
2726 26 27 29 36 39 38 40 48
2727 27 29 34 37 38 40 48 58
2728 29 34 37 38 40 48 58 69
2729 34 37 38 40 48 58 69 79
2734 16 18 20 22 24 26 28 30
2735 18 20 22 24 26 28 30 32
2736 20 22 24 26 28 30 32 34
2737 22 24 26 30 32 32 34 36
2738 24 26 28 32 34 34 36 38
2739 26 28 30 32 34 36 38 40
2740 28 30 32 34 36 38 42 42
2741 30 32 34 36 38 40 42 44
2748 $ mencoder <replaceable>input.avi</replaceable> -o <replaceable>output.avi</replaceable> -oac copy -ovc lavc -lavcopts inter_matrix=...:intra_matrix=...
2754 $ mencoder <replaceable>input.avi</replaceable> -ovc lavc -lavcopts
2755 vcodec=mpeg2video:intra_matrix=8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,
2756 12,14,18,27,29,34,37,38,22,26,27,31,36,37,38,40,26,27,29,36,39,38,40,48,27,
2757 29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79
2758 :inter_matrix=16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,
2759 28,30,32,34,22,24,26,30,32,32,34,36,24,26,28,32,34,34,36,38,26,28,30,32,34,
2760 36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44 -oac copy -o svcd.mpg
2766 <sect2 id="menc-feat-dvd-mpeg4-example">
2767 <title>Example</title>
2770 So, you have just bought your shiny new copy of Harry Potter and the Chamber
2771 of Secrets (widescreen edition, of course), and you want to rip this DVD
2772 so that you can add it to your Home Theatre PC. This is a region 1 DVD,
2773 so it is NTSC. The example below will still apply to PAL, except you will
2774 omit <option>-ofps 24000/1001</option> (because the output framerate is the
2775 same as the input framerate), and of course the crop dimensions will be
2780 After running <option>mplayer dvd://1</option>, we follow the process
2781 detailed in the section <link linkend="menc-feat-telecine">How to deal
2782 with telecine and interlacing in NTSC DVDs</link> and discover that it is
2783 24000/1001 fps progressive video, which means that we need not use an inverse
2784 telecine filter, such as <option>pullup</option> or
2785 <option>filmdint</option>.
2789 Next, we want to determine the appropriate crop rectangle, so we use the
2792 <screen>mplayer dvd://1 -vf cropdetect</screen>
2794 Make sure you seek to a fully filled frame (such as a bright scene), and
2795 you will see in <application>MPlayer</application>'s console output:
2797 <screen>crop area: X: 0..719 Y: 57..419 (-vf crop=720:362:0:58)</screen>
2799 We then play the movie back with this filter to test its correctness:
2801 <screen>mplayer dvd://1 -vf crop=720:362:0:58</screen>
2803 And we see that it looks perfectly fine. Next, we ensure the width and
2804 height are a multiple of 16. The width is fine, however the height is
2805 not. Since we did not fail 7th grade math, we know that the nearest
2806 multiple of 16 lower than 362 is 352.
2810 We could just use <option>crop=720:352:0:58</option>, but it would be nice
2811 to take a little off the top and a little off the bottom so that we
2812 retain the center. We have shrunk the height by 10 pixels, but we do not
2813 want to increase the y-offset by 5-pixels since that is an odd number and
2814 will adversely affect quality. Instead, we will increase the y-offset by
2817 <screen>mplayer dvd://1 -vf crop=720:352:0:62</screen>
2819 Another reason to shave pixels from both the top and the bottom is that we
2820 ensure we have eliminated any half-black pixels if they exist. Note that if
2821 your video is telecined, make sure the <option>pullup</option> filter (or
2822 whichever inverse telecine filter you decide to use) appears in the filter
2823 chain before you crop. If it is interlaced, deinterlace before cropping.
2824 (If you choose to preserve the interlaced video, then make sure your
2825 vertical crop offset is a multiple of 4.)
2829 If you are really concerned about losing those 10 pixels, you might
2830 prefer instead to scale the dimensions down to the nearest multiple of 16.
2831 The filter chain would look like:
2833 <screen>-vf crop=720:362:0:58,scale=720:352</screen>
2835 Scaling the video down like this will mean that some small amount of
2836 detail is lost, though it probably will not be perceptible. Scaling up will
2837 result in lower quality (unless you increase the bitrate). Cropping
2838 discards those pixels altogether. It is a tradeoff that you will want to
2839 consider for each circumstance. For example, if the DVD video was made
2840 for television, you might want to avoid vertical scaling, since the line
2841 sampling corresponds to the way the content was originally recorded.
2845 On inspection, we see that our movie has a fair bit of action and high
2846 amounts of detail, so we pick 2400Kbit for our bitrate.
2850 We are now ready to do the two pass encode. Pass one:
2852 <screen>mencoder dvd://1 -ofps 24000/1001 -oac copy -vf pullup,softskip,crop=720:352:0:62,hqdn3d=2:1:2 -ovc lavc \
2853 -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:autoaspect:vpass=1 \
2854 -o Harry_Potter_2.avi</screen>
2856 And pass two is the same, except that we specify <option>vpass=2</option>:
2858 <screen>mencoder dvd://1 -ofps 24000/1001 -oac copy -vf pullup,softskip,crop=720:352:0:62,hqdn3d=2:1:2 -ovc lavc \
2859 -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:autoaspect:vpass=2 \
2860 -o Harry_Potter_2.avi</screen>
2864 The options <option>v4mv:mbd=2:trell</option> will greatly increase the
2865 quality at the expense of encoding time. There is little reason to leave
2866 these options out when the primary goal is quality. The options
2867 <option>cmp=3:subcmp=3:mbcmp=3</option> select a comparison function that
2868 yields higher quality than the defaults. You might try experimenting with
2869 this parameter (refer to the man page for the possible values) as
2870 different functions can have a large impact on quality depending on the
2871 source material. For example, if you find
2872 <systemitem class="library">libavcodec</systemitem> produces too much
2873 blocky artifacting, you could try selecting the experimental NSSE as
2874 comparison function via <option>*cmp=10</option>.
2878 For this movie, the resulting AVI will be 138 minutes long and nearly
2879 3GB. And because you said that file size does not matter, this is a
2880 perfectly acceptable size. However, if you had wanted it smaller, you
2881 could try a lower bitrate. Increasing bitrates have diminishing
2882 returns, so while we might clearly see an improvement from 1800Kbit to
2883 2000Kbit, it might not be so noticeable above 2000Kbit. Feel
2884 free to experiment until you are happy.
2888 Because we passed the source video through a denoise filter, you may want
2889 to add some of it back during playback. This, along with the
2890 <option>spp</option> post-processing filter, drastically improves the
2891 perception of quality and helps eliminate blocky artifacts in the video.
2892 With <application>MPlayer</application>'s <option>autoq</option> option,
2893 you can vary the amount of post-processing done by the spp filter
2894 depending on available CPU. Also, at this point, you may want to apply
2895 gamma and/or color correction to best suit your display. For example:
2897 <screen>mplayer Harry_Potter_2.avi -vf spp,noise=9ah:5ah,eq2=1.2 -autoq 3</screen>
2904 <sect1 id="menc-feat-xvid">
2905 <title>Encoding with the <systemitem class="library">XviD</systemitem>
2908 <systemitem class="library">XviD</systemitem> is a free library for
2909 encoding MPEG-4 ASP video streams.
2910 Before starting to encode, you need to <link linkend="xvid">
2911 set up <application>MEncoder</application> to support it</link>.
2914 This guide mainly aims at featuring the same kind of information
2915 as x264's encoding guide.
2916 Therefore, please begin by reading
2917 <link linkend="menc-feat-x264-encoding-options-intro">the first part</link>
2922 <sect2 id="menc-feat-xvid-intro">
2923 <title>What options should I use to get the best results?</title>
2926 Please begin by reviewing the
2927 <systemitem class="library">XviD</systemitem> section of
2928 <application>MPlayer</application>'s man page.
2929 This section is intended to be a supplement to the man page.
2932 The XviD default settings are already a good tradeoff between
2933 speed and quality, therefore you can safely stick to them if
2934 the following section puzzles you.
2938 <sect2 id="menc-feat-xvid-encoding-options">
2939 <title>Encoding options of <systemitem class="library">XviD</systemitem></title>
2943 <emphasis role="bold">vhq</emphasis>
2944 This setting affects the macroblock decision algorithm, where the
2945 higher the setting, the wiser the decision.
2946 The default setting may be safely used for every encode, while
2947 higher settings always help PSNR but are significantly slower.
2948 Please note that a better PSNR does not necessarily mean
2949 that the picture will look better, but tells you that it is
2950 closer to the original.
2951 Turning it off will noticeably speed up encoding; if speed is
2952 critical for you, the tradeoff may be worth it.
2956 <emphasis role="bold">bvhq</emphasis>
2957 This does the same job as vhq, but does it on B-frames.
2958 It has a negligible impact on speed, and slightly improves quality
2959 (around +0.1dB PSNR).
2963 <emphasis role="bold">max_bframes</emphasis>
2964 A higher number of consecutive allowed B-frames usually improves
2965 compressibility, although it may also lead to more blocking artifacts.
2966 The default setting is a good tradeoff between compressibility and
2967 quality, but you may increase it up to 3 if you are bitrate-starved.
2968 You may also decrease it to 1 or 0 if you are aiming at perfect
2969 quality, though in that case you should make sure your
2970 target bitrate is high enough to ensure that the encoder does not
2971 have to increase quantizers to reach it.
2975 <emphasis role="bold">bf_threshold</emphasis>
2976 This controls the B-frame sensitivity of the encoder, where a higher
2977 value leads to more B-frames being used (and vice versa).
2978 This setting is to be used together with <option>max_bframes</option>;
2979 if you are bitrate-starved, you should increase both
2980 <option>max_bframes</option> and <option>bf_threshold</option>,
2981 while you may increase <option>max_bframes</option> and reduce
2982 <option>bf_threshold</option> so that the encoder may use more
2983 B-frames in places that only <emphasis role="bold">really</emphasis>
2985 A low number of <option>max_bframes</option> and a high value of
2986 <option>bf_threshold</option> is probably not a wise choice as it
2987 will force the encoder to put B-frames in places that would not
2988 benefit from them, therefore reducing visual quality.
2989 However, if you need to be compatible with standalone players that
2990 only support old DivX profiles (which only supports up to 1
2991 consecutive B-frame), this would be your only way to
2992 increase compressibility through using B-frames.
2996 <emphasis role="bold">trellis</emphasis>
2997 Optimizes the quantization process to get an optimal tradeoff
2998 between PSNR and bitrate, which allows significant bit saving.
2999 These bits will in return be spent elsewhere on the video,
3000 raising overall visual quality.
3001 You should always leave it on as its impact on quality is huge.
3002 Even if you are looking for speed, do not disable it until you
3003 have turned down <option>vhq</option> and all other more
3004 CPU-hungry options to the minimum.
3008 <emphasis role="bold">hq_ac</emphasis>
3009 Activates a better coefficient cost estimation method, which slightly
3010 reduces filesize by around 0.15 to 0.19% (which corresponds to less
3011 than 0.01dB PSNR increase), while having a negligible impact on speed.
3012 It is therefore recommended to always leave it on.
3016 <emphasis role="bold">cartoon</emphasis>
3017 Designed to better encode cartoon content, and has no impact on
3018 speed as it just tunes the mode decision heuristics for this type
3023 <emphasis role="bold">me_quality</emphasis>
3024 This setting is to control the precision of the motion estimation.
3025 The higher <option>me_quality</option>, the more
3026 precise the estimation of the original motion will be, and the
3027 better the resulting clip will capture the original motion.
3030 The default setting is best in all cases;
3031 thus it is not recommended to turn it down unless you are
3032 really looking for speed, as all the bits saved by a good motion
3033 estimation would be spent elsewhere, raising overall quality.
3034 Therefore, do not go any lower than 5, and even that only as a last
3039 <emphasis role="bold">chroma_me</emphasis>
3040 Improves motion estimation by also taking the chroma (color)
3041 information into account, whereas <option>me_quality</option>
3042 alone only uses luma (grayscale).
3043 This slows down encoding by 5-10% but improves visual quality
3044 quite a bit by reducing blocking effects and reduces filesize by
3046 If you are looking for speed, you should disable this option before
3047 starting to consider reducing <option>me_quality</option>.
3051 <emphasis role="bold">chroma_opt</emphasis>
3052 Is intended to increase chroma image quality around pure
3053 white/black edges, rather than improving compression.
3054 This can help to reduce the "red stairs" effect.
3058 <emphasis role="bold">lumi_mask</emphasis>
3059 Tries to give less bitrate to part of the picture that the
3060 human eye cannot see very well, which should allow the encoder
3061 to spend the saved bits on more important parts of the picture.
3062 The quality of the encode yielded by this option highly depends
3063 on personal preferences and on the type and monitor settings
3064 used to watch it (typically, it will not look as good if it is
3065 bright or if it is a TFT monitor).
3069 <emphasis role="bold">qpel</emphasis>
3070 Raise the number of candidate motion vectors by increasing
3071 the precision of the motion estimation from halfpel to
3073 The idea is to find better motion vectors which will in return
3074 reduce bitrate (hence increasing quality).
3075 However, motion vectors with quarterpel precision require a
3076 few extra bits to code, but the candidate vectors do not always
3077 give (much) better results.
3078 Quite often, the codec still spends bits on the extra precision,
3079 but little or no extra quality is gained in return.
3080 Unfortunately, there is no way to foresee the possible gains of
3081 <option>qpel</option>, so you need to actually encode with and
3082 without it to know for sure.
3084 <option>qpel</option> can be almost double encoding time, and
3085 requires as much as 25% more processing power to decode.
3086 It is not supported by all standalone players.
3090 <emphasis role="bold">gmc</emphasis>
3091 Tries to save bits on panning scenes by using a single motion
3092 vector for the whole frame.
3093 This almost always raises PSNR, but significantly slows down
3094 encoding (as well as decoding).
3095 Therefore, you should only use it when you have turned
3096 <option>vhq</option> to the maximum.
3097 <systemitem class="library">XviD</systemitem>'s GMC is more
3098 sophisticated than DivX's, but is only supported by few
3105 <sect2 id="menc-feat-xvid-encoding-profiles">
3106 <title>Encoding profiles</title>
3108 XviD supports encoding profiles through the <option>profile</option> option,
3109 which are used to impose restrictions on the properties of the XviD video
3110 stream such that it will be playable on anything which supports the
3112 The restrictions relate to resolutions, bitrates and certain MPEG-4
3114 The following table shows what each profile supports.
3117 <tgroup cols="16" align="center">
3118 <colspec colnum="1" colname="col1"/>
3119 <colspec colnum="2" colname="col2"/>
3120 <colspec colnum="3" colname="col3"/>
3121 <colspec colnum="4" colname="col4"/>
3122 <colspec colnum="5" colname="col5"/>
3123 <colspec colnum="6" colname="col6"/>
3124 <colspec colnum="7" colname="col7"/>
3125 <colspec colnum="8" colname="col8"/>
3126 <colspec colnum="9" colname="col9"/>
3127 <colspec colnum="10" colname="col10"/>
3128 <colspec colnum="11" colname="col11"/>
3129 <colspec colnum="12" colname="col12"/>
3130 <colspec colnum="13" colname="col13"/>
3131 <colspec colnum="14" colname="col14"/>
3132 <colspec colnum="15" colname="col15"/>
3133 <colspec colnum="16" colname="col16"/>
3134 <colspec colnum="17" colname="col17"/>
3135 <spanspec spanname="spa2-5" namest="col2" nameend="col5"/>
3136 <spanspec spanname="spa6-11" namest="col6" nameend="col11"/>
3137 <spanspec spanname="spa12-17" namest="col12" nameend="col17"/>
3141 <entry spanname="spa2-5">Simple</entry>
3142 <entry spanname="spa6-11">Advanced Simple</entry>
3143 <entry spanname="spa12-17">DivX</entry>
3146 <entry>Profile name</entry>
3157 <entry>Handheld</entry>
3158 <entry>Portable NTSC</entry>
3159 <entry>Portable PAL</entry>
3160 <entry>Home Theater NTSC</entry>
3161 <entry>Home Theater PAL</entry>
3165 <entry>Width [pixels]</entry>
3184 <entry>Height [pixels]</entry>
3203 <entry>Frame rate [fps]</entry>
3222 <entry>Max average bitrate [kbps]</entry>
3233 <entry>537.6</entry>
3238 <entry>9708.4</entry>
3241 <entry>Peak average bitrate over 3 secs [kbps]</entry>
3257 <entry>16000</entry>
3260 <entry>Max. B-frames</entry>
3279 <entry>MPEG quantization</entry>
3298 <entry>Adaptive quantization</entry>
3317 <entry>Interlaced encoding</entry>
3336 <entry>Quaterpixel</entry>
3355 <entry>Global motion compensation</entry>
3378 <sect2 id="menc-feat-xvid-example-settings">
3379 <title>Encoding setting examples</title>
3382 The following settings are examples of different encoding
3383 option combinations that affect the speed vs quality tradeoff
3384 at the same target bitrate.
3388 All the encoding settings were tested on a 720x448 @30000/1001 fps
3389 video sample, the target bitrate was 900kbps, and the machine was an
3390 AMD-64 3400+ at 2400 Mhz in 64 bits mode.
3391 Each encoding setting features the measured encoding speed (in
3392 frames per second) and the PSNR loss (in dB) compared to the "very
3393 high quality" setting.
3394 Please understand that depending on your source, your machine type
3395 and development advancements, you may get very different results.
3399 <informaltable frame="all">
3402 <row><entry>Description</entry><entry>Encoding options</entry><entry>speed (in fps)</entry><entry>Relative PSNR loss (in dB)</entry></row>
3406 <entry>Very high quality</entry>
3407 <entry><option>chroma_opt:vhq=4:bvhq=1:quant_type=mpeg</option></entry>
3408 <entry>16fps</entry>
3412 <entry>High quality</entry>
3413 <entry><option>vhq=2:bvhq=1:chroma_opt:quant_type=mpeg</option></entry>
3414 <entry>18fps</entry>
3415 <entry>-0.1dB</entry>
3419 <entry><option>turbo:vhq=0</option></entry>
3420 <entry>28fps</entry>
3421 <entry>-0.69dB</entry>
3424 <entry>Realtime</entry>
3425 <entry><option>turbo:nochroma_me:notrellis:max_bframes=0:vhq=0</option></entry>
3426 <entry>38fps</entry>
3427 <entry>-1.48dB</entry>
3437 <sect1 id="menc-feat-x264">
3438 <title>Encoding with the <systemitem class="library">x264</systemitem> codec</title>
3440 <systemitem class="library">x264</systemitem> is a free library for
3441 encoding H.264/AVC video streams.
3442 Before starting to encode, you need to <link linkend="codec-x264-encode">
3443 set up <application>MEncoder</application> to support it</link>.
3446 <sect2 id="menc-feat-x264-encoding-options">
3447 <title>Encoding options of x264</title>
3450 Please begin by reviewing the
3451 <systemitem class="library">x264</systemitem> section of
3452 <application>MPlayer</application>'s man page.
3453 This section is intended to be a supplement to the man page.
3454 Here you will find quick hints about which options are most
3455 likely to interest most people. The man page is more terse,
3456 but also more exhaustive, and it sometimes offers much better
3460 <sect3 id="menc-feat-x264-encoding-options-intro">
3461 <title>Introduction</title>
3462 <para>This guide considers two major categories of encoding options:</para>
3465 <listitem><para>Options which mainly trade off encoding time vs. quality
3467 <listitem><para>Options which may be useful for fulfilling various personal
3468 preferences and special requirements</para></listitem>
3472 Ultimately, only you can decide which options are best for your
3473 purposes. The decision for the first class of options is the simplest:
3474 you only have to decide whether you think the quality differences
3475 justify the speed differences. For the second class of options,
3476 preferences may be far more subjective, and more factors may be
3477 involved. Note that some of the "personal preferences and special
3478 requirements" options can still have large impacts on speed or quality,
3479 but that is not what they are primarily useful for. A couple of the
3480 "personal preference" options may even cause changes that look better
3481 to some people, but look worse to others.
3485 Before continuing, you need to understand that this guide uses only one
3486 quality metric: global PSNR.
3487 For a brief explanation of what PSNR is, see
3488 <ulink url="http://en.wikipedia.org/wiki/PSNR">the Wikipedia article on PSNR</ulink>.
3489 Global PSNR is the last PSNR number reported when you include
3490 the <option>psnr</option> option in <option>x264encopts</option>.
3491 Any time you read a claim about PSNR, one of the assumptions
3492 behind the claim is that equal bitrates are used.
3496 Nearly all of this guide's comments assume you are using
3498 When comparing options, there are two major reasons for using
3500 First, using two pass often gains around 1dB PSNR, which is a
3501 very big difference.
3502 Secondly, testing options by doing direct quality comparisons
3503 with one pass encodes introduces a major confounding
3504 factor: bitrate often varies significantly with each encode.
3505 It is not always easy to tell whether quality changes are due
3506 mainly to changed options, or if they mostly reflect essentially
3507 random differences in the achieved bitrate.
3512 <sect3 id="menc-feat-x264-encoding-options-speedvquality">
3513 <title>Options which primarily affect speed and quality</title>
3517 <emphasis role="bold">subq</emphasis>:
3518 Of the options which allow you to trade off speed for quality,
3519 <option>subq</option> and <option>frameref</option> (see below) are usually
3520 by far the most important.
3521 If you are interested in tweaking either speed or quality, these
3522 are the first options you should consider.
3523 On the speed dimension, the <option>frameref</option> and
3524 <option>subq</option> options interact with each other fairly
3526 Experience shows that, with one reference frame,
3527 <option>subq=5</option> (the default setting) takes about 35% more time than
3528 <option>subq=1</option>.
3529 With 6 reference frames, the penalty grows to over 60%.
3530 <option>subq</option>'s effect on PSNR seems fairly constant
3531 regardless of the number of reference frames.
3532 Typically, <option>subq=5</option> achieves 0.2-0.5 dB higher global
3533 PSNR in comparison <option>subq=1</option>.
3534 This is usually enough to be visible.
3537 <option>subq=6</option> is the slowest, highest quality mode.
3538 In comparison to <option>subq=5</option>, it usually gains 0.1-0.4 dB
3539 global PSNR with speed costs varying from 25%-100%.
3540 Unlike other levels of <option>subq</option>, the behavior of
3541 <option>subq=6</option> does not depend much on <option>frameref</option>
3542 and <option>me</option>. Instead, the effectiveness of <option>subq=6
3543 </option> depends mostly upon the number of B-frames used. In normal
3544 usage, this means <option>subq=6</option> has a large impact on both speed
3545 and quality in complex, high motion scenes, but it may not have much effect
3546 in low-motion scenes. Note that it is still recommended to always set
3547 <option>bframes</option> to something other than zero (see below).
3550 <emphasis role="bold">frameref</emphasis>:
3551 <option>frameref</option> is set to 1 by default, but this
3552 should not be taken to imply that it is reasonable to set it
3554 Merely raising <option>frameref</option> to 2 gains around
3555 0.15dB PSNR with a 5-10% speed penalty; this seems like a
3557 <option>frameref=3</option> gains around 0.25dB PSNR over
3558 <option>frameref=1</option>, which should be a visible
3560 <option>frameref=3</option> is around 15% slower than
3561 <option>frameref=1</option>.
3562 Unfortunately, diminishing returns set in rapidly.
3563 <option>frameref=6</option> can be expected to gain only
3564 0.05-0.1 dB over <option>frameref=3</option> at an additional
3566 Above <option>frameref=6</option>, the quality gains are
3567 usually very small (although you should keep in mind throughout
3568 this whole discussion that it can vary quite a lot depending on
3570 In a fairly typical case, <option>frameref=12</option>
3571 will improve global PSNR by a tiny 0.02dB over
3572 <option>frameref=6</option>, at a speed cost of 15%-20%.
3573 At such high <option>frameref</option> values, the only really
3574 good thing that can be said is that increasing it even further will
3575 almost certainly never <emphasis role="bold">harm</emphasis>
3576 PSNR, but the additional quality benefits are barely even
3577 measurable, let alone perceptible.
3579 <note><title>Note:</title>
3581 Raising <option>frameref</option> to unnecessarily high values
3582 <emphasis role="bold">can</emphasis> and
3583 <emphasis role="bold">usually does</emphasis>
3584 hurt coding efficiency if you turn CABAC off.
3585 With CABAC on (the default behavior), the possibility of setting
3586 <option>frameref</option> "too high" currently seems too remote
3587 to even worry about, and in the future, optimizations may remove
3588 the possibility altogether.
3592 If you care about speed, a reasonable compromise is to use low
3593 <option>subq</option> and <option>frameref</option> values on
3594 the first pass, and then raise them on the second pass.
3595 Typically, this has a negligible negative effect on the final
3596 quality: You will probably lose well under 0.1dB PSNR, which
3597 should be much too small of a difference to see.
3598 However, different values of <option>frameref</option> can
3599 occasionally affect frametype decision.
3600 Most likely, these are rare outlying cases, but if you want to
3601 be pretty sure, consider whether your video has either
3602 fullscreen repetitive flashing patterns or very large temporary
3603 occlusions which might force an I-frame.
3604 Adjust the first-pass <option>frameref</option> so it is large
3605 enough to contain the duration of the flashing cycle (or occlusion).
3606 For example, if the scene flashes back and forth between two images
3607 over a duration of three frames, set the first pass
3608 <option>frameref</option> to 3 or higher.
3609 This issue is probably extremely rare in live action video material,
3610 but it does sometimes come up in video game captures.
3614 <emphasis role="bold">me</emphasis>:
3615 This option is for choosing the motion estimation search method.
3616 Altering this option provides a straightforward quality-vs-speed
3617 tradeoff. <option>me=1</option> is only a few percent faster than
3618 the default search, at a cost of under 0.1dB global PSNR. The
3619 default setting (<option>me=2</option>) is a reasonable tradeoff
3620 between speed and quality. <option>me=3</option> gains a little under
3621 0.1dB global PSNR, with a speed penalty that varies depending on
3622 <option>frameref</option>. At high values of
3623 <option>frameref</option> (e.g. 12 or so), <option>me=3</option>
3624 is about 40% slower than the default <option> me=2</option>. With
3625 <option>frameref=3</option>, the speed penalty incurred drops to
3629 <option>me=4</option> uses an exhaustive search that is too slow for
3635 <emphasis role="bold">4x4mv</emphasis>:
3636 This option enables the use of 8x4, 4x8 and 4x4 subpartitions in
3637 predicted macroblocks. Enabling it results in a fairly consistent
3638 10%-15% loss of speed. This option is rather useless in source
3639 containing only low motion, however in some high-motion source,
3640 particularly source with lots of small moving objects, gains of
3641 about 0.1dB can be expected.
3646 <emphasis role="bold">bframes</emphasis>:
3647 If you are used to encoding with other codecs, you may have found
3648 that B-frames are not always useful.
3649 In H.264, this has changed: there are new techniques and block
3650 types that are possible in B-frames.
3651 Usually, even a naive B-frame choice algorithm can have a
3652 significant PSNR benefit.
3653 It is interesting to note that using B-frames usually speeds up
3654 the second pass somewhat, and may also speed up a single
3655 pass encode if adaptive B-frame decision is turned off.
3658 With adaptive B-frame decision turned off
3659 (<option>x264encopts</option>'s <option>nob_adapt</option>),
3660 the optimal value for this setting is usually no more than
3661 <option>bframes=1</option>, or else high-motion scenes can suffer.
3662 With adaptive B-frame decision on (the default behavior), it is
3663 safe to use higher values; the encoder will reduce the use of
3664 B-frames in scenes where they would hurt compression.
3665 The encoder rarely chooses to use more than 3 or 4 B-frames;
3666 setting this option any higher will have little effect.
3670 <emphasis role="bold">b_adapt</emphasis>:
3671 Note: This is on by default.
3674 With this option enabled, the encoder will use a reasonably fast
3675 decision process to reduce the number of B-frames used in scenes that
3676 might not benefit from them as much.
3677 You can use <option>b_bias</option> to tweak how B-frame-happy
3679 The speed penalty of adaptive B-frames is currently rather modest,
3680 but so is the potential quality gain.
3681 It usually does not hurt, however.
3682 Note that this only affects speed and frametype decision on the
3684 <option>b_adapt</option> and <option>b_bias</option> have no
3685 effect on subsequent passes.
3689 <emphasis role="bold">b_pyramid</emphasis>:
3690 You might as well enable this option if you are using >=2 B-frames;
3691 as the man page says, you get a little quality improvement at no
3693 Note that these videos cannot be read by libavcodec-based decoders
3694 older than about March 5, 2005.
3698 <emphasis role="bold">weight_b</emphasis>:
3699 In typical cases, there is not much gain with this option.
3700 However, in crossfades or fade-to-black scenes, weighted
3701 prediction gives rather large bitrate savings.
3702 In MPEG-4 ASP, a fade-to-black is usually best coded as a series
3703 of expensive I-frames; using weighted prediction in B-frames
3704 makes it possible to turn at least some of these into much smaller
3706 Encoding time cost is minimal, as no extra decisions need to be made.
3707 Also, contrary to what some people seem to guess, the decoder
3708 CPU requirements are not much affected by weighted prediction,
3709 all else being equal.
3712 Unfortunately, the current adaptive B-frame decision algorithm
3713 has a strong tendency to avoid B-frames during fades.
3714 Until this changes, it may be a good idea to add
3715 <option>nob_adapt</option> to your x264encopts, if you expect
3716 fades to have a large effect in your particular video
3722 <sect3 id="menc-feat-x264-encoding-options-misc-preferences">
3723 <title>Options pertaining to miscellaneous preferences</title>
3726 <emphasis role="bold">Two pass encoding</emphasis>:
3727 Above, it was suggested to always use two pass encoding, but there
3728 are still reasons for not using it. For instance, if you are capturing
3729 live TV and encoding in realtime, you are forced to use single-pass.
3730 Also, one pass is obviously faster than two passes; if you use the
3731 exact same set of options on both passes, two pass encoding is almost
3735 Still, there are very good reasons for using two pass encoding. For
3736 one thing, single pass ratecontrol is not psychic, and it often makes
3737 unreasonable choices because it cannot see the big picture. For example,
3738 suppose you have a two minute long video consisting of two distinct
3739 halves. The first half is a very high-motion scene lasting 60 seconds
3740 which, in isolation, requires about 2500kbps in order to look decent.
3741 Immediately following it is a much less demanding 60-second scene
3742 that looks good at 300kbps. Suppose you ask for 1400kbps on the theory
3743 that this is enough to accomodate both scenes. Single pass ratecontrol
3744 will make a couple of "mistakes" in such a case. First of all, it
3745 will target 1400kbps in both segments. The first segment may end up
3746 heavily overquantized, causing it to look unacceptably and unreasonably
3747 blocky. The second segment will be heavily underquantized; it may look
3748 perfect, but the bitrate cost of that perfection will be completely
3749 unreasonable. What is even harder to avoid is the problem at the
3750 transition between the two scenes. The first seconds of the low motion
3751 half will be hugely over-quantized, because the ratecontrol is still
3752 expecting the kind of bitrate requirements it met in the first half
3753 of the video. This "error period" of heavily over-quantized low motion
3754 will look jarringly bad, and will actually use less than the 300kbps
3755 it would have taken to make it look decent. There are ways to
3756 mitigate the pitfalls of single-pass encoding, but they may tend to
3757 increase bitrate misprediction.
3760 Multipass ratecontrol can offer huge advantages over a single pass.
3761 Using the statistics gathered from the first pass encode, the encoder
3762 can estimate, with reasonable accuracy, the "cost" (in bits) of
3763 encoding any given frame, at any given quantizer. This allows for
3764 a much more rational, better planned allocation of bits between the
3765 expensive (high-motion) and cheap (low-motion) scenes. See
3766 <option>qcomp</option> below for some ideas on how to tweak this
3767 allocation to your liking.
3770 Moreover, two passes need not take twice as long as one pass. You can
3771 tweak the options in the first pass for higher speed and lower quality.
3772 If you choose your options well, you can get a very fast first pass.
3773 The resulting quality in the second pass will be slightly lower because size
3774 prediction is less accurate, but the quality difference is normally much
3775 too small to be visible. Try, for example, adding
3776 <option>subq=1:frameref=1</option> to the first pass
3777 <option>x264encopts</option>. Then, on the second pass, use slower,
3778 higher-quality options:
3779 <option>subq=6:frameref=15:4x4mv:me=3</option>
3782 <emphasis role="bold">Three pass encoding</emphasis>?
3784 x264 offers the ability to make an arbitrary number of consecutive
3785 passes. If you specify <option>pass=1</option> on the first pass,
3786 then use <option>pass=3</option> on a subsequent pass, the subsequent
3787 pass will both read the statistics from the previous pass, and write
3788 its own statistics. An additional pass following this one will have
3789 a very good base from which to make highly accurate predictions of
3790 framesizes at a chosen quantizer. In practice, the overall quality
3791 gain from this is usually close to zero, and quite possibly a third
3792 pass will result in slightly worse global PSNR than the pass before
3793 it. In typical usage, three passes help if you get either bad bitrate
3794 prediction or bad looking scene transitions when using only two passes.
3795 This is somewhat likely to happen on extremely short clips. There are
3796 also a few special cases in which three (or more) passes are handy
3797 for advanced users, but for brevity, this guide omits discussing those
3802 <emphasis role="bold">qcomp</emphasis>:
3803 <option>qcomp</option> trades off the number of bits allocated
3804 to "expensive" high-motion versus "cheap" low-motion frames. At
3805 one extreme, <option>qcomp=0</option> aims for true constant
3806 bitrate. Typically this would make high-motion scenes look completely
3807 awful, while low-motion scenes would probably look absolutely
3808 perfect, but would also use many times more bitrate than they
3809 would need in order to look merely excellent. At the other extreme,
3810 <option>qcomp=1</option> achieves nearly constant quantization parameter
3811 (QP). Constant QP does not look bad, but most people think it is more
3812 reasonable to shave some bitrate off of the extremely expensive scenes
3813 (where the loss of quality is not as noticeable) and reallocate it to
3814 the scenes that are easier to encode at excellent quality.
3815 <option>qcomp</option> is set to 0.6 by default, which may be slightly
3816 low for many peoples' taste (0.7-0.8 are also commonly used).
3819 <emphasis role="bold">keyint</emphasis>:
3820 <option>keyint</option> is solely for trading off file seekability against
3821 coding efficiency. By default, <option>keyint</option> is set to 250. In
3822 25fps material, this guarantees the ability to seek to within 10 seconds
3823 precision. If you think it would be important and useful to be able to
3824 seek within 5 seconds of precision, set <option>keyint=125</option>;
3825 this will hurt quality/bitrate slightly. If you care only about quality
3826 and not about seekability, you can set it to much higher values
3827 (understanding that there are diminishing returns which may become
3828 vanishingly low, or even zero). The video stream will still have seekable
3829 points as long as there are some scene changes.
3832 <emphasis role="bold">deblockalpha, deblockbeta</emphasis>:
3833 This topic is going to be a bit controversial.
3836 H.264 defines a simple deblocking procedure on I-blocks that uses
3837 pre-set strengths and thresholds depending on the QP of the block
3839 By default, high QP blocks are filtered heavily, and low QP blocks
3840 are not deblocked at all.
3841 The pre-set strengths defined by the standard are well-chosen and
3842 the odds are very good that they are PSNR-optimal for whatever
3843 video you are trying to encode.
3844 The <option>deblockalpha</option> and <option>deblockbeta</option>
3845 parameters allow you to specify offsets to the preset deblocking
3849 Many people seem to think it is a good idea to lower the deblocking
3850 filter strength by large amounts (say, -3).
3851 This is however almost never a good idea, and in most cases,
3852 people who are doing this do not understand very well how
3853 deblocking works by default.
3856 The first and most important thing to know about the in-loop
3857 deblocking filter is that the default thresholds are almost always
3859 In the rare cases that they are not optimal, the ideal offset is
3861 Adjusting deblocking parameters by a larger amount is almost
3862 guaranteed to hurt PSNR.
3863 Strengthening the filter will smear more details; weakening the
3864 filter will increase the appearance of blockiness.
3867 It is definitely a bad idea to lower the deblocking thresholds if
3868 your source is mainly low in spacial complexity (i.e., not a lot
3869 of detail or noise).
3870 The in-loop filter does a rather excellent job of concealing
3871 the artifacts that occur.
3872 If the source is high in spacial complexity, however, artifacts
3873 are less noticeable.
3874 This is because the ringing tends to look like detail or noise.
3875 Human visual perception easily notices when detail is removed,
3876 but it does not so easily notice when the noise is wrongly
3878 When it comes to subjective quality, noise and detail are somewhat
3880 By lowering the deblocking filter strength, you are most likely
3881 increasing error by adding ringing artifacts, but the eye does
3882 not notice because it confuses the artifacts with detail.
3886 This <emphasis role="bold">still</emphasis> does not justify
3887 lowering the deblocking filter strength, however.
3888 You can generally get better quality noise from postprocessing.
3889 If your H.264 encodes look too blurry or smeared, try playing with
3890 <option>-vf noise</option> when you play your encoded movie.
3891 <option>-vf noise=8a:4a</option> should conceal most mild
3893 It will almost certainly look better than the results you
3894 would have gotten just by fiddling with the deblocking filter.
3900 <sect2 id="menc-feat-x264-example-settings">
3901 <title>Encoding setting examples</title>
3904 The following settings are examples of different encoding
3905 option combinations that affect the speed vs quality tradeoff
3906 at the same target bitrate.
3910 All the encoding settings were tested on a 720x448 @30000/1001 fps
3911 video sample, the target bitrate was 900kbps, and the machine was an
3912 AMD-64 3400+ at 2400 Mhz in 64 bits mode.
3913 Each encoding setting features the measured encoding speed (in
3914 frames per second) and the PSNR loss (in dB) compared to the "very
3915 high quality" setting.
3916 Please understand that depending on your source, your machine type
3917 and development advancements, you may get very different results.
3921 <informaltable frame="all">
3924 <row><entry>Description</entry><entry>Encoding options</entry><entry>speed (in fps)</entry><entry>Relative PSNR loss (in dB)</entry></row>
3928 <entry>Very high quality</entry>
3929 <entry><option>subq=6:4x4mv:8x8dct:me=3:frameref=5:bframes=3:b_pyramid:weight_b</option></entry>
3934 <entry>High quality</entry>
3935 <entry><option>subq=5:4x4mv:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b</option></entry>
3936 <entry>13fps</entry>
3937 <entry>-0.89dB</entry>
3941 <entry><option>subq=4:bframes=2:b_pyramid:weight_b</option></entry>
3942 <entry>17fps</entry>
3943 <entry>-1.48dB</entry>
3953 <sect1 id="menc-feat-vcd-dvd">
3954 <title>Using MEncoder to create VCD/SVCD/DVD-compliant files.</title>
3956 <sect2 id="menc-feat-vcd-dvd-constraints">
3957 <title>Format Constraints</title>
3959 <application>MEncoder</application> is capable of creating VCD, SCVD
3960 and DVD format MPEG files using the
3961 <systemitem class="library">libavcodec</systemitem> library.
3962 These files can then be used in conjunction with
3963 <ulink url="http://www.gnu.org/software/vcdimager/vcdimager.html">vcdimager</ulink>
3965 <ulink url="http://dvdauthor.sourceforge.net/">dvdauthor</ulink>
3966 to create discs that will play on a standard set-top player.
3970 The DVD, SVCD, and VCD formats are subject to heavy constraints.
3971 Only a small selection of encoded picture sizes and aspect ratios are
3973 If your movie does not already meet these requirements, you may have
3974 to scale,crop or add black borders to the picture to make it
3978 <sect3 id="menc-feat-vcd-dvd-constraints-resolution">
3979 <title>Format Constraints</title>
3981 <informaltable frame="all">
3985 <entry>Format</entry>
3986 <entry>Resolution</entry>
3987 <entry>V. Codec</entry>
3988 <entry>V. Bitrate</entry>
3989 <entry>Sample Rate</entry>
3990 <entry>A. Codec</entry>
3991 <entry>A. Bitrate</entry>
3993 <entry>Aspect</entry>
3998 <entry>NTSC DVD</entry>
3999 <entry>720x480, 704x480, 352x480, 352x240</entry>
4000 <entry>MPEG-2</entry>
4001 <entry>9800 kbps</entry>
4002 <entry>48000 Hz</entry>
4003 <entry>AC3,PCM</entry>
4004 <entry>1536 kbps (max)</entry>
4005 <entry>30000/1001, 24000/1001</entry>
4006 <entry>4:3, 16:9 (only for 720x480)</entry>
4009 <entry>NTSC DVD</entry>
4010 <entry>352x240<footnote id='fn-rare-resolutions'><para>
4011 These resolutions are rarely used for DVDs because
4012 they are fairly low quality.</para></footnote></entry>
4013 <entry>MPEG-1</entry>
4014 <entry>1856 kbps</entry>
4015 <entry>48000 Hz</entry>
4016 <entry>AC3,PCM</entry>
4017 <entry>1536 kbps (max)</entry>
4018 <entry>30000/1001, 24000/1001</entry>
4019 <entry>4:3, 16:9</entry>
4022 <entry>NTSC SVCD</entry>
4023 <entry>480x480</entry>
4024 <entry>MPEG-2</entry>
4025 <entry>2600 kbps</entry>
4026 <entry>44100 Hz</entry>
4028 <entry>384 kbps (max)</entry>
4029 <entry>30000/1001</entry>
4033 <entry>NTSC VCD</entry>
4034 <entry>352x240</entry>
4035 <entry>MPEG-1</entry>
4036 <entry>1150 kbps</entry>
4037 <entry>44100 Hz</entry>
4039 <entry>224 kbps</entry>
4040 <entry>24000/1001, 30000/1001</entry>
4044 <entry>PAL DVD</entry>
4045 <entry>720x576, 704x576, 352x576, 352x288</entry>
4046 <entry>MPEG-2</entry>
4047 <entry>9800 kbps</entry>
4048 <entry>48000 Hz</entry>
4049 <entry>MP2,AC3,PCM</entry>
4050 <entry>1536 kbps (max)</entry>
4052 <entry>4:3, 16:9 (only for 720x576)</entry>
4055 <entry>PAL DVD</entry>
4056 <entry>352x288<footnoteref linkend='fn-rare-resolutions'/></entry>
4057 <entry>MPEG-1</entry>
4058 <entry>1856 kbps</entry>
4059 <entry>48000 Hz</entry>
4060 <entry>MP2,AC3,PCM</entry>
4061 <entry>1536 kbps (max)</entry>
4063 <entry>4:3, 16:9</entry>
4066 <entry>PAL SVCD</entry>
4067 <entry>480x576</entry>
4068 <entry>MPEG-2</entry>
4069 <entry>2600 kbps</entry>
4070 <entry>44100 Hz</entry>
4072 <entry>384 kbps (max)</entry>
4077 <entry>PAL VCD</entry>
4078 <entry>352x288</entry>
4079 <entry>MPEG-1</entry>
4080 <entry>1152 kbps</entry>
4081 <entry>44100 Hz</entry>
4083 <entry>224 kbps</entry>
4092 If your movie has 2.35:1 aspect (most recent action movies), you will
4093 have to add black borders or crop the movie down to 16:9 to make a DVD
4095 If you add black borders, try to align them at 16-pixel boundaries in
4096 order to minimize the impact on encoding performance.
4097 Thankfully DVD has sufficiently excessive bitrate that you do not have
4098 to worry too much about encoding efficiency, but SVCD and VCD are
4099 highly bitrate-starved and require effort to obtain acceptable quality.
4103 <sect3 id="menc-feat-vcd-dvd-constraints-gop">
4104 <title>GOP Size Constraints</title>
4106 DVD, VCD, and SVCD also constrain you to relatively low
4107 GOP (Group of Pictures) sizes.
4108 For 30 fps material the largest allowed GOP size is 18.
4109 For 25 or 24 fps, the maximum is 15.
4110 The GOP size is set using the <option>keyint</option> option.
4114 <sect3 id="menc-feat-vcd-dvd-constraints-bitrate">
4115 <title>Bitrate Constraints</title>
4117 VCD video is required to be CBR at 1152 kbps.
4118 This highly limiting constraint also comes along with an extremly low vbv
4119 buffer size of 327 kilobits.
4120 SVCD allows varying video bitrates up to 2500 kbps, and a somewhat less
4121 restrictive vbv buffer size of 917 kilobits is allowed.
4122 DVD video bitrates may range anywhere up to 9800 kbps (though typical
4123 bitrates are about half that), and the vbv buffer size is 1835 kilobits.
4128 <sect2 id="menc-feat-vcd-dvd-output">
4129 <title>Output Options</title>
4131 <application>MEncoder</application> has options to control the output
4133 Using these options we can instruct it to create the correct type of
4138 The options for VCD and SVCD are called xvcd and xsvcd, because they
4139 are extended formats.
4140 They are not strictly compliant, mainly because the output does not
4141 contain scan offsets.
4142 If you need to generate an SVCD image, you should pass the output file
4144 <ulink url="http://www.gnu.org/software/vcdimager/vcdimager.html">vcdimager</ulink>.
4150 -of mpeg -mpegopts format=xvcd
4157 -of mpeg -mpegopts format=xsvcd
4164 -of mpeg -mpegopts format=dvd
4169 DVD with NTSC Pullup:
4171 -of mpeg -mpegopts format=dvd:telecine -ofps 24000/1001
4173 This allows 24000/1001 fps progressive content to be encoded at 30000/1001
4174 fps whilst maintaing DVD-compliance.
4177 <sect3 id="menc-feat-vcd-dvd-output-aspect">
4178 <title>Aspect Ratio</title>
4180 The aspect argument of <option>-lavcopts</option> is used to encode
4181 the aspect ratio of the file.
4182 During playback the aspect ratio is used to restore the video to the
4187 16:9 or "Widescreen"
4189 -lavcopts aspect=16/9
4196 -lavcopts aspect=4/3
4201 2.35:1 or "Cinemascope" NTSC
4203 -vf scale=720:368,expand=720:480 -lavcopts aspect=16/9
4205 To calculate the correct scaling size, use the expanded NTSC width of
4210 2.35:1 or "Cinemascope" PAL
4212 -vf scale="720:432,expand=720:576 -lavcopts aspect=16/9
4214 To calculate the correct scaling size, use the expanded PAL width of
4220 <sect3 id="menc-feat-vcd-dvd-a-v-sync">
4221 <title>Maintaining A/V sync</title>
4223 In order to maintain audio/video synchronization throughout the encode,
4224 <application>MEncoder</application> has to drop or duplicate frames.
4225 This works rather well when muxing into an AVI file, but is almost
4226 guaranteed to fail to maintain A/V sync with other muxers such as MPEG.
4227 This is why it is necessary to append the
4228 <option>harddup</option> video filter at the end of the filter chain
4229 to avoid this kind of problem.
4230 You can find more technical information about <option>harddup</option>
4232 <link linkend="menc-feat-dvd-mpeg4-muxing-filter-issues">Improving muxing and A/V sync reliability</link>
4233 or in the manual page.
4237 <sect3 id="menc-feat-vcd-dvd-output-srate">
4238 <title>Sample Rate Conversion</title>
4240 If the audio sample rate in the original file is not the same as
4241 required by the target format, sample rate conversion is required.
4242 This is achieved using the <option>-srate</option> option and
4243 the <option>-af lavcresample</option> audio filter together.
4248 -srate 48000 -af lavcresample=48000
4254 -srate 44100 -af lavcresample=44100
4260 <sect2 id="menc-feat-vcd-dvd-lavc">
4261 <title>Using libavcodec for VCD/SVCD/DVD Encoding</title>
4263 <sect3 id="menc-feat-vcd-dvd-lavc-intro">
4264 <title>Introduction</title>
4266 <systemitem class="library">libavcodec</systemitem> can be used to
4267 create VCD/SVCD/DVD compliant video by using the appropriate options.
4271 <sect3 id="menc-feat-vcd-dvd-lavc-options">
4272 <title>lavcopts</title>
4274 This is a list of fields in <option>-lavcopts</option> that you may
4275 be required to change in order to make a complaint movie for VCD, SVCD,
4281 <emphasis role="bold">acodec</emphasis>:
4282 <option>mp2</option> for VCD, SVCD, or PAL DVD;
4283 <option>ac3</option> is most commonly used for DVD.
4284 PCM audio may also be used for DVD, but this is mostly a big waste of
4286 Note that MP3 audio is not compliant for any of these formats, but
4287 players often have no problem playing it anyway.
4291 <emphasis role="bold">abitrate</emphasis>:
4292 224 for VCD; up to 384 for SVCD; up to 1536 for DVD, but commonly
4293 used values range from 192 kbps for stereo to 384 kbps for 5.1 channel
4298 <emphasis role="bold">vcodec</emphasis>:
4299 <option>mpeg1video</option> for VCD;
4300 <option>mpeg2video</option> for SVCD;
4301 <option>mpeg2video</option> is usually used for DVD but you may also use
4302 <option>mpeg1video</option> for CIF resolutions.
4306 <emphasis role="bold">keyint</emphasis>:
4307 Used to set the GOP size.
4308 18 for 30fps material, or 15 for 25/24 fps material.
4309 Commercial producers seem to prefer keyframe intervals of 12.
4310 It is possible to make this much larger and still retain compatibility
4312 A <option>keyint</option> of 25 should never cause any problems.
4316 <emphasis role="bold">vrc_buf_size</emphasis>:
4317 327 for VCD, 917 for SVCD, and 1835 for DVD.
4321 <emphasis role="bold">vrc_minrate</emphasis>:
4322 1152, for VCD. May be left alone for SVCD and DVD.
4326 <emphasis role="bold">vrc_maxrate</emphasis>:
4327 1152 for VCD; 2500 for SVCD; 9800 for DVD.
4328 For SVCD and DVD, you might wish to use lower values depending on your
4329 own personal preferences and requirements.
4333 <emphasis role="bold">vbitrate</emphasis>:
4335 up to 2500 for SVCD;
4337 For the latter two formats, vbitrate should be set based on personal
4339 For instance, if you insist on fitting 20 or so hours on a DVD, you
4340 could use vbitrate=400.
4341 The resulting video quality would probably be quite bad.
4342 If you are trying to squeeze out the maximum possible quality on a DVD,
4343 use vbitrate=9800, but be warned that this could constrain you to less
4344 than an hour of video on a single-layer DVD.
4349 <sect3 id="menc-feat-vcd-dvd-lavc-examples">
4350 <title>Examples</title>
4352 This is a typical minimum set of <option>-lavcopts</option> for
4358 -lavcopts vcodec=mpeg1video:vrc_buf_size=327:vrc_minrate=1152:\
4359 vrc_maxrate=1152:vbitrate=1152:keyint=15:acodec=mp2
4366 -lavcopts vcodec=mpeg2video:vrc_buf_size=917:vrc_maxrate=2500:vbitrate=1800:\
4367 keyint=15:acodec=mp2
4374 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
4375 keyint=15:acodec=ac3
4381 <sect3 id="menc-feat-vcd-dvd-lavc-advanced">
4382 <title>Advanced Options</title>
4384 For higher quality encoding, you may also wish to add quality-enhancing
4385 options to lavcopts, such as <option>trell</option>,
4386 <option>mbd=2</option>, and others.
4387 Note that <option>qpel</option> and <option>v4mv</option>, while often
4388 useful with MPEG-4, are not usable with MPEG-1 or MPEG-2.
4389 Also, if you are trying to make a very high quality DVD encode, it may
4390 be useful to add <option>dc=10</option> to lavcopts.
4391 Doing so may help reduce the appearance of blocks in flat-colored areas.
4392 Putting it all together, this is an example of a set of lavcopts for a
4398 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=8000:\
4399 keyint=15:trell:mbd=2:precmp=2:subcmp=2:cmp=2:dia=-10:predia=-10:cbp:mv0:\
4400 vqmin=1:lmin=1:dc=10
4407 <sect2 id="menc-feat-vcd-dvd-audio">
4408 <title>Encoding Audio</title>
4410 VCD and SVCD support MPEG-1 layer II audio, using one of
4411 <systemitem class="library">toolame</systemitem>,
4412 <systemitem class="library">twolame</systemitem>,
4413 or <systemitem class="library">libavcodec</systemitem>'s MP2 encoder.
4414 The libavcodec MP2 is far from being as good as the other two libraries,
4415 however it should always be available to use.
4416 VCD only supports constant bitrate audio (CBR) whereas SVCD supports
4417 variable bitrate (VBR), too.
4418 Be careful when using VBR because some bad standalone players might not
4419 support it too well.
4423 For DVD audio, <systemitem class="library">libavcodec</systemitem>'s
4427 <sect3 id="menc-feat-vcd-dvd-audio-toolame">
4428 <title>toolame</title>
4432 -oac toolame -toolameopts br=224
4437 <sect3 id="menc-feat-vcd-dvd-audio-twolame">
4438 <title>twolame</title>
4442 -oac twolame -twolameopts br=224
4447 <sect3 id="menc-feat-vcd-dvd-audio-lavc">
4448 <title>libavcodec</title>
4450 For DVD with 2 channel sound:
4452 -oac lavc -lavcopts acodec=ac3:abitrate=192
4456 For DVD with 5.1 channel sound:
4458 -channels 6 -oac lavc -lavcopts acodec=ac3:abitrate=384
4464 -oac lavc -lavcopts acodec=mp2:abitrate=224
4471 <sect2 id="menc-feat-vcd-dvd-all">
4472 <title>Putting it all Together</title>
4474 This section shows some complete commands for creating VCD/SVCD/DVD
4478 <sect3 id="menc-feat-vcd-dvd-all-pal-dvd">
4479 <title>PAL DVD</title>
4482 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,\
4483 harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:\
4484 vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:acodec=ac3:\
4485 abitrate=192:aspect=16/9 -ofps 25 \
4486 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
4491 <sect3 id="menc-feat-vcd-dvd-all-ntsc-dvd">
4492 <title>NTSC DVD</title>
4495 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:480,\
4496 harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:\
4497 vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:acodec=ac3:\
4498 abitrate=192:aspect=16/9 -ofps 30000/1001 \
4499 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
4504 <sect3 id="menc-feat-vcd-dvd-all-pal-ac3-copy">
4505 <title>PAL AVI Containing AC3 Audio to DVD</title>
4507 If the source already has AC3 audio, use -oac copy instead of re-encoding it.
4509 mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,\
4510 harddup -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:\
4511 vbitrate=5000:keyint=15:aspect=16/9 -ofps 25 \
4512 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
4517 <sect3 id="menc-feat-vcd-dvd-all-ntsc-ac3-copy">
4518 <title>NTSC AVI Containing AC3 Audio to DVD</title>
4520 If the source already has AC3 audio, and is NTSC @ 24000/1001 fps:
4522 mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd:telecine \
4523 -vf scale=720:480,harddup -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:\
4524 vrc_maxrate=9800:vbitrate=5000:keyint=15:aspect=16/9 -ofps 24000/1001 \
4525 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
4530 <sect3 id="menc-feat-vcd-dvd-all-pal-svcd">
4531 <title>PAL SVCD</title>
4534 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xsvcd -vf \
4535 scale=480:576,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
4536 vcodec=mpeg2video:mbd=2:keyint=15:vrc_buf_size=917:vrc_minrate=600:\
4537 vbitrate=2500:vrc_maxrate=2500:acodec=mp2:abitrate=224 -ofps 25 \
4538 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
4543 <sect3 id="menc-feat-vcd-dvd-all-ntsc-svcd">
4544 <title>NTSC SVCD</title>
4547 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xsvcd -vf \
4548 scale=480:480,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
4549 vcodec=mpeg2video:mbd=2:keyint=18:vrc_buf_size=917:vrc_minrate=600:\
4550 vbitrate=2500:vrc_maxrate=2500:acodec=mp2:abitrate=224 -ofps 30000/1001 \
4551 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
4556 <sect3 id="menc-feat-vcd-dvd-all-pal-vcd">
4557 <title>PAL VCD</title>
4560 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf \
4561 scale=352:288,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
4562 vcodec=mpeg1video:keyint=15:vrc_buf_size=327:vrc_minrate=1152:vbitrate=1152:\
4563 vrc_maxrate=1152:acodec=mp2:abitrate=224 -ofps 25 \
4564 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
4569 <sect3 id="menc-feat-vcd-dvd-all-ntsc-vcd">
4570 <title>NTSC VCD</title>
4573 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf \
4574 scale=352:240,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
4575 vcodec=mpeg1video:keyint=18:vrc_buf_size=327:vrc_minrate=1152:vbitrate=1152:\
4576 vrc_maxrate=1152:acodec=mp2:abitrate=224 -ofps 30000/1001 \
4577 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>