comparison DOCS/xml/en/encoding-guide.xml @ 16080:baae7cdb0726

re-organize MEncoder doc in a more sensible way: splitting "basic mencoder usage" and "encoding with mencoder". note: if you can't generate the doc on your machine, make sure you run "make distclean" beforehand
author gpoirier
date Sun, 24 Jul 2005 14:22:14 +0000
parents
children c1dd920e736c
comparison
equal deleted inserted replaced
16079:96d10b705bc6 16080:baae7cdb0726
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!-- $Revision$ -->
3 <chapter id="encoding-guide">
4 <title>Encoding with <application>MEncoder</application></title>
5
6 <sect1 id="menc-feat-dvd-mpeg4">
7 <title>Making a high quality MPEG-4 (&quot;DivX&quot;) rip of a DVD movie</title>
8
9 <para>
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."
13 </para>
14
15 <para>
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.
21 </para>
22
23 <para>
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
26 file size.
27 </para>
28
29 <para>
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.
37 </para>
38
39 <para>
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
46 for you.
47 </para>
48
49 <sect2 id="menc-feat-dvd-mpeg4-preparing-encode">
50 <title>Preparing to encode: Identifying source material and framerate</title>
51 <para>
52 Before you even think about encoding a movie, you need to take
53 several preliminary steps.
54 </para>
55
56 <para>
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 In order to produce a suitable encode, you need to know the original
67 format.
68 Failure to take this into account will result in ugly combing
69 (interlacing) artifacts in your encode.
70 Besides being ugly, the artifacts also harm coding efficiency:
71 You will get worse quality per bitrate.
72 </para>
73
74 <sect3 id="menc-feat-dvd-mpeg4-preparing-encode-fps">
75 <title>Identifying source framerate</title>
76 <para>
77 Here is a list of common types of source material, where you are
78 likely to find them, and their properties:
79 </para>
80 <itemizedlist>
81 <listitem><para>
82 <emphasis role="bold">Standard Film</emphasis>: Produced for
83 theatrical display at 24fps.
84 </para></listitem>
85 <listitem><para>
86 <emphasis role="bold">PAL video</emphasis>: Recorded with a PAL
87 video camera at 50 fields per second.
88 A field consists of just the odd- or even-numbered lines of a
89 frame.
90 Television was designed to refresh these in alternation as a
91 cheap form of analog compression.
92 The human eye supposedly compensates for this, but once you
93 understand interlacing you will learn to see it on TV too and
94 never enjoy TV again.
95 Two fields do <emphasis role="bold">not</emphasis> make a
96 complete frame, because they are captured 1/50 of a second apart
97 in time, and thus they do not line up unless there is no motion.
98 </para></listitem>
99 <listitem><para>
100 <emphasis role="bold">NTSC Video</emphasis>: Recorded with an
101 NTSC video camera at 60000/1001 fields per second, or 60 fields per
102 second in the pre-color era.
103 Otherwise similar to PAL.
104 </para></listitem>
105 <listitem><para>
106 <emphasis role="bold">Animation</emphasis>: Usually drawn at
107 24fps, but also comes in mixed-framerate varieties.
108 </para></listitem>
109 <listitem><para>
110 <emphasis role="bold">Computer Graphics (CG)</emphasis>: Can be
111 any framerate, but some are more common than others; 24 and
112 30 frames per second are typical for NTSC, and 25fps is typical
113 for PAL.
114 </para></listitem>
115 <listitem><para>
116 <emphasis role="bold">Old Film</emphasis>: Various lower
117 framerates.
118 </para></listitem>
119 </itemizedlist>
120 </sect3>
121
122 <sect3 id="menc-feat-dvd-mpeg4-preparing-encode-material">
123 <title>Identifying source material</title>
124 <para>
125 Movies consisting of frames are referred to as progressive,
126 while those consisting of independent fields are called
127 either interlaced or video - though this latter term is
128 ambiguous.
129 </para>
130 <para>
131 To further complicate matters, some movies will be a mix of
132 several of the above.
133 </para>
134 <para>
135 The most important distinction to make between all of these
136 formats is that some are frame-based, while others are
137 field-based.
138 <emphasis role="bold">Whenever</emphasis> a movie is prepared
139 for display on television (including DVD), it is converted to a
140 field-based format.
141 The various methods by which this can be done are collectively
142 referred to as "pulldown", of which the infamous NTSC
143 "3:2 telecine" is one variety.
144 Unless the original material was also field-based (and the same
145 fieldrate), you are getting the movie in a format other than the
146 original.
147 </para>
148
149 <itemizedlist>
150 <title>There are several common types of pulldown:</title>
151 <listitem><para>
152 <emphasis role="bold">PAL 2:2 pulldown</emphasis>: The nicest of
153 them all.
154 Each frame is shown for the duration of two fields, by extracting the
155 even and odd lines and showing them in alternation.
156 If the original material is 24fps, this process speeds up the
157 movie by 4%.
158 </para></listitem>
159 <listitem><para>
160 <emphasis role="bold">PAL 2:2:2:2:2:2:2:2:2:2:2:3 pulldown</emphasis>:
161 Every 12th frame is shown for the duration of three fields, instead of
162 just two.
163 This avoids the 4% speedup issue, but makes the process much
164 more difficult to reverse.
165 It is usually seen in musical productions where adjusting the
166 speed by 4% would seriously damage the musical score.
167 </para></listitem>
168 <listitem><para>
169 <emphasis role="bold">NTSC 3:2 telecine</emphasis>: Frames are
170 shown alternately for the duration of 3 fields or 2 fields.
171 This gives a fieldrate 2.5 times the original framerate.
172 The result is also slowed down very slightly from 60 fields per
173 second to 60000/1001 fields per second to maintain NTSC fieldrate.
174 </para></listitem>
175 <listitem><para>
176 <emphasis role="bold">NTSC 2:2 pulldown</emphasis>: Used for
177 showing 30fps material on NTSC.
178 Nice, just like 2:2 PAL pulldown.
179 </para></listitem>
180 </itemizedlist>
181
182 <para>
183 There are also methods for converting between NTSC and PAL video,
184 but such topics are beyond the scope of this guide.
185 If you encounter such a movie and want to encode it, your best
186 bet is to find a copy in the original format.
187 Conversion between these two formats is highly destructive and
188 cannot be reversed cleanly, so your encode will greatly suffer
189 if it is made from a converted source.
190 </para>
191 <para>
192 When video is stored on DVD, consecutive pairs of fields are
193 grouped as a frame, even though they are not intended to be shown
194 at the same moment in time.
195 The MPEG-2 standard used on DVD and digital TV provides a
196 way both to encode the original progressive frames and to store
197 the number of fields for which a frame should be shown in the
198 header of that frame.
199 If this method has been used, the movie will often be described
200 as "soft-telecined", since the process only directs the
201 DVD player to apply pulldown to the movie rather than altering
202 the movie itself.
203 This case is highly preferable since it can easily be reversed
204 (actually ignored) by the encoder, and since it preserves maximal
205 quality.
206 However, many DVD and broadcast production studios do not use
207 proper encoding techniques but instead produce movies with
208 "hard telecine", where fields are actually duplicated in the
209 encoded MPEG-2.
210 </para>
211 <para>
212 The procedures for dealing with these cases will be covered later
213 in this guide.
214 For now, we leave you with some guides to identifying which type
215 of material you are dealing with:
216 </para>
217
218 <itemizedlist>
219 <title>NTSC regions:</title>
220 <listitem><para>
221 If <application>MPlayer</application> prints that the framerate
222 has changed to 24000/1001 when watching your movie, and never changes
223 back, it is almost certainly progressive content that has been
224 "soft telecined".
225 </para></listitem>
226 <listitem><para>
227 If <application>MPlayer</application> shows the framerate
228 switching back and forth between 24000/1001 and 30000/1001, and you see
229 "combing" at times, then there are several possibilities.
230 The 24000/1001 fps segments are almost certainly progressive
231 content, "soft telecined", but the 30000/1001 fps parts could be
232 either hard-telecined 24000/1001 fps content or 60000/1001 fields per second NTSC video.
233 Use the same guidelines as the following two cases to determine
234 which.
235 </para></listitem>
236 <listitem><para>
237 If <application>MPlayer</application> never shows the framerate
238 changing, and every single frame with motion appears combed, your
239 movie is NTSC video at 60000/1001 fields per second.
240 </para></listitem>
241 <listitem><para>
242 If <application>MPlayer</application> never shows the framerate
243 changing, and two frames out of every five appear combed, your
244 movie is "hard telecined" 24000/1001fps content.
245 </para></listitem>
246 </itemizedlist>
247
248 <itemizedlist>
249 <title>PAL regions:</title>
250 <listitem><para>
251 If you never see any combing, your movie is 2:2 pulldown.
252 </para></listitem>
253 <listitem><para>
254 If you see combing alternating in and out every half second,
255 then your movie is 2:2:2:2:2:2:2:2:2:2:2:3 pulldown.
256 </para></listitem>
257 <listitem><para>
258 If you always see combing during motion, then your movie is PAL
259 video at 50 fields per second.
260 </para></listitem>
261 </itemizedlist>
262
263 <note><title>Hint:</title>
264 <para>
265 <application>MPlayer</application> can slow down movie playback
266 with the -speed option or play it frame-by-frame.
267 Try using <option>-speed</option> 0.2 to watch the movie very
268 slowly or press the "<keycap>.</keycap>" key repeatedly to play one frame at a time
269 and identify the pattern, if you cannot see it at full speed.
270 </para>
271 </note>
272 </sect3>
273 </sect2>
274
275 <sect2 id="menc-feat-dvd-mpeg4-2pass">
276 <title>Constant quantizer vs. multipass</title>
277
278 <para>
279 It is possible to encode your movie at a wide range of qualities.
280 With modern video encoders and a bit of pre-codec compression
281 (downscaling and denoising), it is possible to achieve very good
282 quality at 700 MB, for a 90-110 minute widescreen movie.
283 Furthermore, all but the longest movies can be encoded with near-perfect
284 quality at 1400 MB.
285 </para>
286
287 <para>
288 There are three approaches to encoding the video: constant bitrate
289 (CBR), constant quantizer, and multipass (ABR, or average bitrate).
290 </para>
291
292 <note><title>Note:</title>
293 <para>
294 Most codecs which support ABR encode only support two pass encode
295 while some others such as <systemitem class="library">x264</systemitem>
296 and <systemitem class="library">libavcodec</systemitem> support
297 multipass, which slightly improves quality at each pass,
298 yet this improvement is no longer measurable nor noticeable after the
299 4th or so pass.
300 Therefore, in this section, two pass and multipass will be used
301 interchangeably.
302 </para>
303 </note>
304
305 <para>
306 In each of these modes, <systemitem class="library">libavcodec</systemitem>
307 breaks the video frame into 16x16 pixel macroblocks and then applies a
308 quantizer to each macroblock. The lower the quantizer, the better the
309 quality and higher the bitrate. The method
310 <systemitem class="library">libavcodec</systemitem> uses to determine
311 which quantizer to use for a given macroblock varies and is highly
312 tunable. (This is an extreme over-simplification of the actual
313 process, but the basic concept is useful to understand.)
314 </para>
315
316 <para>
317 When you specify a constant bitrate, <systemitem
318 class="library">libavcodec</systemitem> will encode the video, discarding
319 detail as much as necessary and as little as possible in order to remain
320 lower than the given bitrate. If you truly do not care about file size,
321 you could as well use CBR and specify a bitrate of infinity. (In
322 practice, this means a value high enough so that it poses no limit, like
323 10000Kbit.) With no real restriction on bitrate, the result is that
324 <systemitem class="library">libavcodec</systemitem> will use the lowest
325 possible quantizer for each macroblock (as specified by
326 <option>vqmin</option>, which is 2 by default). As soon as you specify a
327 low enough bitrate that <systemitem class="library">libavcodec</systemitem>
328 is forced to use a higher quantizer, then you are almost certainly ruining
329 the quality of your video.
330 In order to avoid that, you should probably downscale your video, according
331 to the method described later on in this guide.
332 In general, you should avoid CBR altogether if you care about quality.
333 </para>
334
335 <para>
336 With constant quantizer, <systemitem
337 class="library">libavcodec</systemitem> uses the same quantizer, as
338 specified by the <option>vqscale</option> option, on every macroblock. If
339 you want the highest quality rip possible, again ignoring bitrate, you can
340 use <option>vqscale=2</option>. This will yield the same bitrate and PSNR
341 (peak signal-to-noise ratio) as CBR with
342 <option>vbitrate</option>=infinity and the default <option>vqmin</option>
343 of 2.
344 </para>
345
346 <para>
347 The problem with constant quantizing is that it uses the given quantizer
348 whether the macroblock needs it or not. That is, it might be possible
349 to use a higher quantizer on a macroblock without sacrificing visual
350 quality. Why waste the bits on an unnecessarily low quantizer? Your
351 CPU has as many cycles as there is time, but there is only so many bits
352 on your hard disk.
353 </para>
354
355 <para>
356 With a two pass encode, the first pass will rip the movie as though it
357 were CBR, but it will keep a log of properties for each frame. This
358 data is then used during the second pass in order to make intelligent
359 decisions about which quantizers to use. During fast action or low
360 detail scenes, higher quantizers will likely be used, and during
361 slow moving or high detail scenes, lower quantizers will be used.
362 </para>
363
364 <para>
365 If you use <option>vqscale=2</option>, then you are wasting bits. If you
366 use <option>vqscale=3</option>, then you are not getting the highest
367 quality rip. Suppose you rip a DVD at <option>vqscale=3</option>, and
368 the result is 1800Kbit. If you do a two pass encode with
369 <option>vbitrate=1800</option>, the resulting video will have <emphasis
370 role="bold">higher quality</emphasis> for the
371 <emphasis role="bold">same bitrate</emphasis>.
372 </para>
373
374 <para>
375 Since you are now convinced that two pass is the way to go, the real
376 question now is what bitrate to use? The answer is that there is no
377 single answer. Ideally you want to choose a bitrate that yields the
378 best balance between quality and file size. This is going to vary
379 depending on the source video.
380 </para>
381
382 <para>
383 If size does not matter, a good starting point for a very high quality
384 rip is about 2000Kbit plus or minus 200Kbit.
385 For fast action or high detail source video, or if you just have a very
386 critical eye, you might decide on 2400 or 2600.
387 For some DVDs, you might not notice a difference at 1400Kbit. It is a
388 good idea to experiment with scenes at different bitrates to get a feel.
389 </para>
390
391 <para>
392 If you aim at a certain size, you will have to somehow calculate the bitrate.
393 But before that, you need to know how much space you should reserve for the
394 audio track(s), so you should <link linkend="menc-feat-dvd-mpeg4-audio">rip
395 those</link> first.
396 You can compute the bitrate with the following equation:
397 <systemitem>bitrate = (target_size_in_Mbytes - sound_size_in_Mbytes) *
398 1024 * 1024 / length_in_secs * 8 / 1000</systemitem>
399 For instance, to squeeze a two-hour movie onto a 702MB CD, with 60MB
400 of audio track, the video bitrate will have to be:
401 <systemitem>(702 - 60) * 1024 * 1024 / (120*60) * 8 / 1000
402 = 740kbps</systemitem>
403 </para>
404
405 </sect2>
406
407
408 <sect2 id="menc-feat-dvd-mpeg4-constraints">
409 <title>Constraints for efficient encoding</title>
410
411 <para>
412 Due to the nature of MPEG-type compression, there are various
413 constraints you should follow for maximal quality.
414 MPEG splits the video up into 16x16 squares called macroblocks,
415 each composed of 4 8x8 blocks of luma (intensity) information and two
416 half-resolution 8x8 chroma (color) blocks (one for red-cyan axis and
417 the other for the blue-yellow axis).
418 Even if your movie width and height are not multiples of 16, the
419 encoder will use enough 16x16 macroblocks to cover the whole picture
420 area, and the extra space will go to waste.
421 So in the interests of maximizing quality at a fixed filesize, it is
422 a bad idea to use dimensions that are not multiples of 16.
423 </para>
424
425 <para>
426 Most DVDs also have some degree of black borders at the edges. Leaving
427 these in place can hurt quality in several ways.
428 </para>
429
430 <orderedlist>
431 <listitem>
432 <para>
433 MPEG-type compression is also highly dependent on frequency domain
434 transformations, in particular the Discrete Cosine Transform (DCT),
435 which is similar to the Fourier transform. This sort of encoding is
436 efficient for representing patterns and smooth transitions, but it
437 has a hard time with sharp edges. In order to encode them it must
438 use many more bits, or else an artifact known as ringing will
439 appear.
440 </para>
441
442 <para>
443 The frequency transform (DCT) takes place separately on each
444 macroblock (actually each block), so this problem only applies when
445 the sharp edge is inside a block. If your black borders begin
446 exactly at multiple-of-16 pixel boundaries, this is not a problem.
447 However, the black borders on DVDs rarely come nicely aligned, so
448 in practice you will always need to crop to avoid this penalty.
449 </para>
450 </listitem>
451 </orderedlist>
452
453 <para>
454 In addition to frequency domain transforms, MPEG-type compression uses
455 motion vectors to represent the change from one frame to the next.
456 Motion vectors naturally work much less efficiently for new content
457 coming in from the edges of the picture, because it is not present in
458 the previous frame. As long as the picture extends all the way to the
459 edge of the encoded region, motion vectors have no problem with
460 content moving out the edges of the picture. However, in the presence
461 of black borders, there can be trouble:
462 </para>
463
464 <orderedlist continuation="continues">
465 <listitem>
466 <para>
467 For each macroblock, MPEG-type compression stores a vector
468 identifying which part of the previous frame should be copied into
469 this macroblock as a base for predicting the next frame. Only the
470 remaining differences need to be encoded. If a macroblock spans the
471 edge of the picture and contains part of the black border, then
472 motion vectors from other parts of the picture will overwrite the
473 black border. This means that lots of bits must be spent either
474 re-blackening the border that was overwritten, or (more likely) a
475 motion vector will not be used at all and all the changes in this
476 macroblock will have to be coded explicitly. Either way, encoding
477 efficiency is greatly reduced.
478 </para>
479
480 <para>
481 Again, this problem only applies if black borders do not line up on
482 multiple-of-16 boundaries.
483 </para>
484 </listitem>
485
486 <listitem>
487 <para>
488 Finally, suppose we have a macroblock in the interior of the
489 picture, and an object is moving into this block from near the edge
490 of the image. MPEG-type coding cannot say "copy the part that is
491 inside the picture but not the black border." So the black border
492 will get copied inside too, and lots of bits will have to be spent
493 encoding the part of the picture that is supposed to be there.
494 </para>
495
496 <para>
497 If the picture runs all the way to the edge of the encoded area,
498 MPEG has special optimizations to repeatedly copy the pixels at the
499 edge of the picture when a motion vector comes from outside the
500 encoded area. This feature becomes useless when the movie has black
501 borders. Unlike problems 1 and 2, aligning the borders at multiples
502 of 16 does not help here.
503 </para>
504 </listitem>
505
506 <listitem>
507 <para>
508 Despite the borders being entirely black and never changing, there
509 is at least a minimal amount of overhead involved in having more
510 macroblocks.
511 </para>
512 </listitem>
513 </orderedlist>
514
515 <para>
516 For all of these reasons, it is recommended to fully crop black
517 borders. Further, if there is an area of noise/distortion at the edge
518 of the picture, cropping this will improve encoding efficiency as
519 well. Videophile purists who want to preserve the original as close as
520 possible may object to this cropping, but unless you plan to encode at
521 constant quantizer, the quality you gain from cropping will
522 considerably exceed the amount of information lost at the edges.
523 </para>
524 </sect2>
525
526
527 <sect2 id="menc-feat-dvd-mpeg4-crop">
528 <title>Cropping and Scaling</title>
529
530 <para>
531 Recall from the previous section that the final picture size you
532 encode should be a multiple of 16 (in both width and height).
533 This can be achieved by cropping, scaling, or a combination of both.
534 </para>
535
536 <para>
537 When cropping, there are a few guidelines that must be followed to
538 avoid damaging your movie.
539 The normal YUV format, 4:2:0, stores chroma (color) information
540 subsampled, i.e. chroma is only sampled half as often in each
541 direction as luma (intensity) information.
542 Observe this diagram, where L indicates luma sampling points and C
543 chroma.
544 </para>
545
546 <informaltable>
547 <?dbhtml table-width="40%" ?>
548 <?dbfo table-width="40%" ?>
549 <tgroup cols="8" align="center">
550 <colspec colnum="1" colname="col1"/>
551 <colspec colnum="2" colname="col2"/>
552 <colspec colnum="3" colname="col3"/>
553 <colspec colnum="4" colname="col4"/>
554 <colspec colnum="5" colname="col5"/>
555 <colspec colnum="6" colname="col6"/>
556 <colspec colnum="7" colname="col7"/>
557 <colspec colnum="8" colname="col8"/>
558 <spanspec spanname="spa1-2" namest="col1" nameend="col2"/>
559 <spanspec spanname="spa3-4" namest="col3" nameend="col4"/>
560 <spanspec spanname="spa5-6" namest="col5" nameend="col6"/>
561 <spanspec spanname="spa7-8" namest="col7" nameend="col8"/>
562 <tbody>
563 <row>
564 <entry>L</entry>
565 <entry>L</entry>
566 <entry>L</entry>
567 <entry>L</entry>
568 <entry>L</entry>
569 <entry>L</entry>
570 <entry>L</entry>
571 <entry>L</entry>
572 </row>
573 <row>
574 <entry spanname="spa1-2">C</entry>
575 <entry spanname="spa3-4">C</entry>
576 <entry spanname="spa5-6">C</entry>
577 <entry spanname="spa7-8">C</entry>
578 </row>
579 <row>
580 <entry>L</entry>
581 <entry>L</entry>
582 <entry>L</entry>
583 <entry>L</entry>
584 <entry>L</entry>
585 <entry>L</entry>
586 <entry>L</entry>
587 <entry>L</entry>
588 </row>
589 <row>
590 <entry>L</entry>
591 <entry>L</entry>
592 <entry>L</entry>
593 <entry>L</entry>
594 <entry>L</entry>
595 <entry>L</entry>
596 <entry>L</entry>
597 <entry>L</entry>
598 </row>
599 <row>
600 <entry spanname="spa1-2">C</entry>
601 <entry spanname="spa3-4">C</entry>
602 <entry spanname="spa5-6">C</entry>
603 <entry spanname="spa7-8">C</entry>
604 </row>
605 <row>
606 <entry>L</entry>
607 <entry>L</entry>
608 <entry>L</entry>
609 <entry>L</entry>
610 <entry>L</entry>
611 <entry>L</entry>
612 <entry>L</entry>
613 <entry>L</entry>
614 </row>
615 </tbody>
616 </tgroup>
617 </informaltable>
618
619 <para>
620 As you can see, rows and columns of the image naturally come in pairs.
621 Thus your crop offsets and dimensions <emphasis>must</emphasis> be
622 even numbers.
623 If they are not, the chroma will no longer line up correctly with the
624 luma.
625 In theory, it is possible to crop with odd offsets, but it requires
626 resampling the chroma which is potentially a lossy operation and not
627 supported by the crop filter.
628 </para>
629
630 <para>
631 Further, interlaced video is sampled as follows:
632 </para>
633
634 <informaltable>
635 <?dbhtml table-width="80%" ?>
636 <?dbfo table-width="80%" ?>
637 <tgroup cols="16" align="center">
638 <colspec colnum="1" colname="col1"/>
639 <colspec colnum="2" colname="col2"/>
640 <colspec colnum="3" colname="col3"/>
641 <colspec colnum="4" colname="col4"/>
642 <colspec colnum="5" colname="col5"/>
643 <colspec colnum="6" colname="col6"/>
644 <colspec colnum="7" colname="col7"/>
645 <colspec colnum="8" colname="col8"/>
646 <colspec colnum="9" colname="col9"/>
647 <colspec colnum="10" colname="col10"/>
648 <colspec colnum="11" colname="col11"/>
649 <colspec colnum="12" colname="col12"/>
650 <colspec colnum="13" colname="col13"/>
651 <colspec colnum="14" colname="col14"/>
652 <colspec colnum="15" colname="col15"/>
653 <colspec colnum="16" colname="col16"/>
654 <spanspec spanname="spa1-2" namest="col1" nameend="col2"/>
655 <spanspec spanname="spa3-4" namest="col3" nameend="col4"/>
656 <spanspec spanname="spa5-6" namest="col5" nameend="col6"/>
657 <spanspec spanname="spa7-8" namest="col7" nameend="col8"/>
658 <spanspec spanname="spa9-10" namest="col9" nameend="col10"/>
659 <spanspec spanname="spa11-12" namest="col11" nameend="col12"/>
660 <spanspec spanname="spa13-14" namest="col13" nameend="col14"/>
661 <spanspec spanname="spa15-16" namest="col15" nameend="col16"/>
662 <tbody>
663 <row>
664 <entry namest="col1" nameend="col8">Top field</entry>
665 <entry namest="col9" nameend="col16">Bottom field</entry>
666 </row>
667 <row>
668 <entry>L</entry>
669 <entry>L</entry>
670 <entry>L</entry>
671 <entry>L</entry>
672 <entry>L</entry>
673 <entry>L</entry>
674 <entry>L</entry>
675 <entry>L</entry>
676 <entry></entry>
677 <entry></entry>
678 <entry></entry>
679 <entry></entry>
680 <entry></entry>
681 <entry></entry>
682 <entry></entry>
683 <entry></entry>
684 </row>
685 <row>
686 <entry spanname="spa1-2">C</entry>
687 <entry spanname="spa3-4">C</entry>
688 <entry spanname="spa5-6">C</entry>
689 <entry spanname="spa7-8">C</entry>
690 <entry></entry>
691 <entry></entry>
692 <entry></entry>
693 <entry></entry>
694 <entry></entry>
695 <entry></entry>
696 <entry></entry>
697 <entry></entry>
698 </row>
699 <row>
700 <entry></entry>
701 <entry></entry>
702 <entry></entry>
703 <entry></entry>
704 <entry></entry>
705 <entry></entry>
706 <entry></entry>
707 <entry></entry>
708 <entry>L</entry>
709 <entry>L</entry>
710 <entry>L</entry>
711 <entry>L</entry>
712 <entry>L</entry>
713 <entry>L</entry>
714 <entry>L</entry>
715 <entry>L</entry>
716 </row>
717 <row>
718 <entry>L</entry>
719 <entry>L</entry>
720 <entry>L</entry>
721 <entry>L</entry>
722 <entry>L</entry>
723 <entry>L</entry>
724 <entry>L</entry>
725 <entry>L</entry>
726 <entry></entry>
727 <entry></entry>
728 <entry></entry>
729 <entry></entry>
730 <entry></entry>
731 <entry></entry>
732 <entry></entry>
733 <entry></entry>
734 </row>
735 <row>
736 <entry></entry>
737 <entry></entry>
738 <entry></entry>
739 <entry></entry>
740 <entry></entry>
741 <entry></entry>
742 <entry></entry>
743 <entry></entry>
744 <entry spanname="spa9-10">C</entry>
745 <entry spanname="spa11-12">C</entry>
746 <entry spanname="spa13-14">C</entry>
747 <entry spanname="spa15-16">C</entry>
748 </row>
749 <row>
750 <entry></entry>
751 <entry></entry>
752 <entry></entry>
753 <entry></entry>
754 <entry></entry>
755 <entry></entry>
756 <entry></entry>
757 <entry></entry>
758 <entry>L</entry>
759 <entry>L</entry>
760 <entry>L</entry>
761 <entry>L</entry>
762 <entry>L</entry>
763 <entry>L</entry>
764 <entry>L</entry>
765 <entry>L</entry>
766 </row>
767 <row>
768 <entry>L</entry>
769 <entry>L</entry>
770 <entry>L</entry>
771 <entry>L</entry>
772 <entry>L</entry>
773 <entry>L</entry>
774 <entry>L</entry>
775 <entry>L</entry>
776 <entry></entry>
777 <entry></entry>
778 <entry></entry>
779 <entry></entry>
780 <entry></entry>
781 <entry></entry>
782 <entry></entry>
783 <entry></entry>
784 </row>
785 <row>
786 <entry spanname="spa1-2">C</entry>
787 <entry spanname="spa3-4">C</entry>
788 <entry spanname="spa5-6">C</entry>
789 <entry spanname="spa7-8">C</entry>
790 <entry></entry>
791 <entry></entry>
792 <entry></entry>
793 <entry></entry>
794 <entry></entry>
795 <entry></entry>
796 <entry></entry>
797 <entry></entry>
798 </row>
799 <row>
800 <entry></entry>
801 <entry></entry>
802 <entry></entry>
803 <entry></entry>
804 <entry></entry>
805 <entry></entry>
806 <entry></entry>
807 <entry></entry>
808 <entry>L</entry>
809 <entry>L</entry>
810 <entry>L</entry>
811 <entry>L</entry>
812 <entry>L</entry>
813 <entry>L</entry>
814 <entry>L</entry>
815 <entry>L</entry>
816 </row>
817 <row>
818 <entry>L</entry>
819 <entry>L</entry>
820 <entry>L</entry>
821 <entry>L</entry>
822 <entry>L</entry>
823 <entry>L</entry>
824 <entry>L</entry>
825 <entry>L</entry>
826 <entry></entry>
827 <entry></entry>
828 <entry></entry>
829 <entry></entry>
830 <entry></entry>
831 <entry></entry>
832 <entry></entry>
833 <entry></entry>
834 </row>
835 <row>
836 <entry></entry>
837 <entry></entry>
838 <entry></entry>
839 <entry></entry>
840 <entry></entry>
841 <entry></entry>
842 <entry></entry>
843 <entry></entry>
844 <entry spanname="spa9-10">C</entry>
845 <entry spanname="spa11-12">C</entry>
846 <entry spanname="spa13-14">C</entry>
847 <entry spanname="spa15-16">C</entry>
848 </row>
849 <row>
850 <entry></entry>
851 <entry></entry>
852 <entry></entry>
853 <entry></entry>
854 <entry></entry>
855 <entry></entry>
856 <entry></entry>
857 <entry></entry>
858 <entry>L</entry>
859 <entry>L</entry>
860 <entry>L</entry>
861 <entry>L</entry>
862 <entry>L</entry>
863 <entry>L</entry>
864 <entry>L</entry>
865 <entry>L</entry>
866 </row>
867 </tbody>
868 </tgroup>
869 </informaltable>
870
871 <para>
872 As you can see, the pattern does not repeat until after 4 lines.
873 So for interlaced video, your y-offset and height for cropping must
874 be multiples of 4.
875 </para>
876
877 <para>
878 Native DVD resolution is 720x480 for NTSC, and 720x576 for PAL, but
879 there is an aspect flag that specifies whether it is full-screen (4:3) or
880 wide-screen (16:9). Many (if not most) widescreen DVDs are not strictly
881 16:9, and will be either 1.85:1 or 2.35:1 (cinescope). This means that
882 there will be black bands in the video that will need to be cropped out.
883 </para>
884
885 <para>
886 <application>MPlayer</application> provides a crop detection filter that
887 will determine the crop rectangle (<option>-vf cropdetect</option>).
888 Run <application>MPlayer</application> with
889 <option>-vf cropdetect</option> and it will print out the crop
890 settings to remove the borders.
891 You should let the movie run long enough that the whole picture
892 area is used, in order to get accurate crop values.
893 </para>
894
895 <para>
896 Then, test the values you get with <application>MPlayer</application>,
897 using the command line which was printed by
898 <option>cropdetect</option>, and adjust the rectangle as needed.
899 The <option>rectangle</option> filter can help by allowing you to
900 interactively position the crop rectangle over your movie.
901 Remember to follow the above divisibility guidelines so that you
902 do not misalign the chroma planes.
903 </para>
904
905 <para>
906 In certain cases, scaling may be undesirable.
907 Scaling in the vertical direction is difficult with interlaced
908 video, and if you wish to preserve the interlacing, you should
909 usually refrain from scaling.
910 If you will not be scaling but you still want to use multiple-of-16
911 dimensions, you will have to overcrop.
912 Do not undercrop, since black borders are very bad for encoding!
913 </para>
914
915 <para>
916 Because MPEG-4 uses 16x16 macroblocks, you will want to make sure that each
917 dimension of the video you are encoding is a multiple of 16 or else you
918 will be degrading quality, especially at lower bitrates. You can do this
919 by rounding the width and height of the crop rectangle down to the nearest
920 multiple of 16.
921 As stated earlier, when cropping, you will want to increase the Y offset by
922 half the difference of the old and the new height so that the resulting
923 video is taken from the center of the frame. And because of the way DVD
924 video is sampled, make sure the offset is an even number. (In fact, as a
925 rule, never use odd values for any parameter when you are cropping and
926 scaling video.) If you are not comfortable throwing a few extra pixels
927 away, you might prefer instead to scale the video instead. We will look
928 at this in our example below.
929 You can actually let the <option>cropdetect</option> filter do all of the
930 above for you, as it has an optional <option>round</option> parameter that
931 is equal to 16 by default.
932 </para>
933
934 <para>
935 Also, be careful about "half black" pixels at the edges. Make sure you
936 crop these out too, or else you will be wasting bits there that
937 are better spent elsewhere.
938 </para>
939
940 <para>
941 After all is said and done, you will probably end up with video whose pixels
942 are not quite 1.85:1 or 2.35:1, but rather something close to that. You
943 could calculate the new aspect ratio manually, but
944 <application>MEncoder</application> offers an option for <systemitem
945 class="library">libavcodec</systemitem> called <option>autoaspect</option>
946 that will do this for you. Absolutely do not scale this video up in order to
947 square the pixels unless you like to waste your hard disk space. Scaling
948 should be done on playback, and the player will use the aspect stored in
949 the AVI to determine the correct resolution.
950 Unfortunately, not all players enforce this auto-scaling information,
951 therefore you may still want to rescale.
952 </para>
953
954 <para>
955 First, you should compute the encoded aspect ratio:
956 <systemitem>ARc = (Wc x (ARa / PRdvd )) / Hc</systemitem>
957 <itemizedlist>
958 <title>where:</title>
959 <listitem><para>
960 Wc and Hc are the width and height of the cropped video,
961 </para></listitem>
962 <listitem><para>
963 ARa is the displayed aspect ratio, which usually is 4/3 or 16/9,
964 </para></listitem>
965 <listitem><para>
966 PRdvd is the pixel ratio of the DVD which is equal to 1.25=(720/576) for PAL
967 DVDs and 1.5=(720/480) for NTSC DVDs,
968 </para></listitem>
969 </itemizedlist>
970 </para>
971
972 <para>
973 Then, you can compute the X and Y resolution, according to a certain
974 Compression Quality (CQ) factor:
975 <systemitem>ResY = INT(SQRT( 1000*Bitrate/25/ARc/CQ )/16) * 16</systemitem>
976 and
977 <systemitem>ResX = INT( ResY * ARc / 16) * 16</systemitem>
978 </para>
979
980 <para>
981 Okay, but what is the CQ?
982 The CQ represents the number of bits per pixel and per frame of the encode.
983 Roughly speaking, the greater the CQ, the less the likelihood to see
984 encoding artifacts.
985 However, if you have a target size for your movie (1 or 2 CDs for instance),
986 there is a limited total number of bits that you can spend; therefore it is
987 necessary to find a good tradeoff between compressibility and quality.
988 </para>
989
990 <para>
991 The CQ depends both on the bitrate and the movie resolution.
992 In order to raise the CQ, typically you would downscale the movie given that the
993 bitrate is computed in function of the target size and the length of the
994 movie, which are constant.
995 A CQ below 0.18 usually ends up in a very blocky picture, because there
996 are not enough bits to code the information of each macroblock (MPEG4, like
997 many other codecs, groups pixels by blocks of several pixels to compress the
998 image; if there are not enough bits, the edges of those blocks are
999 visible).
1000 It is therefore wise to take a CQ ranging from 0.20 to 0.22 for a 1 CD rip,
1001 and 0.26-0.28 for 2 CDs.
1002 </para>
1003
1004 <para>
1005 Please take note that the CQ is just an indicative figure, as depending on
1006 the encoded content, a CQ of 0.18 may look just fine for a Bergman, contrary
1007 to a movie such as The Matrix, which contains many high-motion scenes.
1008 On the other hand, it is worthless to raise CQ higher than 0.30 as you would
1009 be wasting bits without any noticeable quality gain.
1010 </para>
1011
1012 </sect2>
1013
1014 <sect2 id="menc-feat-dvd-mpeg4-audio">
1015 <title>Audio</title>
1016
1017 <para>
1018 Audio is a much simpler problem to solve: if you care about quality, just
1019 leave it as is.
1020 Even AC3 5.1 streams are at most 448Kbit/s, and they are worth every bit.
1021 You might be tempted to transcode the audio to high quality Vorbis, but
1022 just because you do not have an A/V receiver for AC3 pass-through today
1023 does not mean you will not have one tomorrow. Future-proof your DVD rips by
1024 preserving the AC3 stream.
1025 You can keep the AC3 stream either by copying it directly into the video
1026 stream <link linkend="menc-feat-mpeg4">during the encoding</link>.
1027 You can also extract the AC3 stream in order to mux it into containers such
1028 as NUT or Matroska.
1029 <screen>mplayer <replaceable>source_file.vob</replaceable> -aid 129 -dumpaudio -dumpfile <replaceable>sound.ac3</replaceable></screen>
1030 will dump into the file <replaceable>sound.ac3</replaceable> the
1031 audio track number 129 from the file
1032 <replaceable>source_file.vob</replaceable> (NB: DVD VOB files
1033 usually use a different audio numbering,
1034 which means that the VOB audio track 129 is the 2nd audio track of the file).
1035 </para>
1036
1037 <para>
1038 But sometimes you truly have no choice but to further compress the
1039 sound so that more bits can be spent on the video.
1040 Most people choose to compress audio with either MP3 or Vorbis audio
1041 codecs.
1042 While the latter is a very space-efficient codec, MP3 is better supported
1043 by hardware players, although this trend is changing.
1044 </para>
1045
1046 <para>
1047 First of all, you will have to convert the DVD sound into a WAV file that the
1048 audio codec can use as input.
1049 For example:
1050 <screen>mplayer <replaceable>source_file.vob</replaceable> -ao pcm:file=<replaceable>destination_sound.wav</replaceable> -vc dummy -aid 1 -vo null</screen>
1051 will dump the second audio track from the file
1052 <replaceable>source_file.vob</replaceable> into the file
1053 <replaceable>destination_sound.wav</replaceable>.
1054 You may want to normalize the sound before encoding, as DVD audio tracks
1055 are commonly recorded at low volumes.
1056 You can use the tool <application>normalize</application> for instance,
1057 which is available in most distributions.
1058 If you are using Windows, a tool such as <application>BeSweet</application>
1059 can do the same job.
1060 You will compress in either Vorbis or MP3.
1061 For example:
1062 <screen>oggenc -q1 <replaceable>destination_sound.wav</replaceable></screen>
1063 will encode <replaceable>destination_sound.wav</replaceable> with
1064 the encoding quality 1, which is roughly equivalent to 80Kb/s, and
1065 is the minimum quality at which you should encode if you care about
1066 quality.
1067 Please note that MEncoder currently cannot mux Vorbis audio tracks
1068 into the output file because it only supports AVI and MPEG
1069 containers as an output, each of which may lead to audio/video
1070 playback synchronization problems with some players when the AVI file
1071 contain VBR audio streams such as Vorbis.
1072 Do not worry, this document will show you how you can do that with third
1073 party programs.
1074 </para>
1075
1076 </sect2>
1077
1078 <sect2 id="menc-feat-dvd-mpeg4-interlacing">
1079 <title>Interlacing and Telecine</title>
1080
1081 <para>
1082 Almost all movies are shot at 24 fps. Because NTSC is 30000/1001 fps, some
1083 processing must be done to this 24 fps video to make it run at the correct
1084 NTSC framerate. The process is called 3:2 pulldown, commonly referred to
1085 as telecine (because pulldown is often applied during the telecine
1086 process), and, naively described, it works by slowing the film down to
1087 24000/1001 fps, and repeating every fourth frame.
1088 </para>
1089
1090 <para>
1091 No special processing, however, is done to the video for PAL DVDs, which
1092 run at 25 fps. (Technically, PAL can be telecined, called 2:2 pulldown,
1093 but this does not become an issue in practice.) The 24 fps film is simply
1094 played back at 25 fps. The result is that the movie runs slightly faster,
1095 but unless you are an alien, you probably will not notice the difference.
1096 Most PAL DVDs have pitch-corrected audio, so when they are played back at
1097 25 fps things will sound right, even though the audio track (and hence the
1098 whole movie) has a running time that is 4% less than NTSC DVDs.
1099 </para>
1100
1101 <para>
1102 Because the video in a PAL DVD has not been altered, you needn't worry
1103 much about framerate. The source is 25 fps, and your rip will be 25
1104 fps. However, if you are ripping an NTSC DVD movie, you may need to
1105 apply inverse telecine.
1106 </para>
1107
1108 <para>
1109 For movies shot at 24 fps, the video on the NTSC DVD is either telecined
1110 30000/1001, or else it is progressive 24000/1001 fps and intended to be telecined
1111 on-the-fly by a DVD player. On the other hand, TV series are usually
1112 only interlaced, not telecined. This is not a hard rule: some TV series
1113 are interlaced (such as Buffy the Vampire Slayer) whereas some are a
1114 mixture of progressive and interlaced (such as Angel, or 24).
1115 </para>
1116
1117 <para>
1118 It is highly recommended that you read the section on
1119 <link linkend="menc-feat-telecine">How to deal with telecine and interlacing in NTSC DVDs</link>
1120 to learn how to handle the different possibilities.
1121 </para>
1122
1123 <para>
1124 However, if you are mostly just ripping movies, likely you are either
1125 dealing with 24 fps progressive or telecined video, in which case you can
1126 use the <option>pullup</option> filter <option>-vf
1127 pullup,softskip</option>.
1128 </para>
1129
1130 </sect2>
1131
1132 <sect2 id="menc-feat-dvd-mpeg4-encoding-interlaced">
1133 <title>Encoding interlaced video</title>
1134
1135 <para>
1136 If the movie you want to encode is interlaced (NTSC video or
1137 PAL video), you will need to choose whether you want to
1138 deinterlace or not.
1139 While deinterlacing will make your movie usable on progressive
1140 scan displays such a computer monitors and projectors, it comes
1141 at a cost: The fieldrate of 50 or 60000/1001 fields per second
1142 is halved to 25 or 30000/1001 frames per second, and roughly half of
1143 the information in your movie will be lost during scenes with
1144 significant motion.
1145 </para>
1146
1147 <para>
1148 Therefore, if you are encoding for high quality archival purposes,
1149 it is recommended not to deinterlace.
1150 You can always deinterlace the movie at playback time when
1151 displaying it on progressive scan devices, and future players will
1152 be able to deinterlace to full fieldrate, interpolating 50 or
1153 60000/1001 entire frames per second from the interlaced video.
1154 </para>
1155
1156 <para>
1157 Special care must be taken when working with interlaced video:
1158 </para>
1159
1160 <orderedlist>
1161 <listitem><para>
1162 Crop height and y-offset must be multiples of 4.
1163 </para></listitem>
1164 <listitem><para>
1165 Any vertical scaling must be performed in interlaced mode.
1166 </para></listitem>
1167 <listitem><para>
1168 Postprocessing and denoising filters may not work as expected
1169 unless you take special care to operate them a field at a time,
1170 and they may damage the video if used incorrectly.
1171 </para></listitem>
1172 </orderedlist>
1173
1174 <para>
1175 With these things in mind, here is our first example:
1176 </para>
1177 <screen>
1178 mencoder <replaceable>capture.avi</replaceable> -mc 0 -oac lavc -ovc lavc -lavcopts \
1179 vcodec=mpeg2video:vbitrate=6000:ilmv:ildct:acodec=mp2:abitrate=224
1180 </screen>
1181 <para>
1182 Note the <option>ilmv</option> and <option>ildct</option> options.
1183 </para>
1184 </sect2>
1185
1186 <sect2 id="menc-feat-dvd-mpeg4-filtering">
1187 <title>Filtering</title>
1188
1189 <para>
1190 In general, you want to do as little filtering as possible to the movie
1191 in order to remain close to the original DVD source. Cropping is often
1192 necessary (as described above), but do not scale the video. Although
1193 scaling down is sometimes preferred to using higher quantizers, we want
1194 to avoid both these things: remember that we decided from the start to
1195 trade bits for quality.
1196 </para>
1197
1198 <para>
1199 Also, do not adjust gamma, contrast, brightness, etc. What looks good
1200 on your display may not look good on others. These adjustments should
1201 be done on playback only.
1202 </para>
1203
1204 <para>
1205 One thing you might want to do, however, is pass the video through a
1206 very light denoise filter, such as <option>-vf hqdn3d=2:1:2</option>.
1207 Again, it is a matter of putting those bits to better use: why waste them
1208 encoding noise when you can just add that noise back in during playback?
1209 Increasing the parameters for <option>hqdn3d</option> will further
1210 improve compressibility, but if you increase the values too much, you
1211 risk degrading the image visibily. The suggested values above
1212 (<option>2:1:2</option>) are quite conservative; you should feel free to
1213 experiment with higher values and observe the results for yourself.
1214 </para>
1215
1216 </sect2>
1217
1218
1219 <sect2 id="menc-feat-dvd-mpeg4-muxing">
1220 <title>Muxing</title>
1221 <para>
1222 Now that you have encoded your video, you will most likely want
1223 to mux it with one or more audio tracks into a movie container, such
1224 as AVI, MPEG, Matroska or NUT.
1225 <application>MEncoder</application> is currently only able to output
1226 audio and video into MPEG and AVI container formats.
1227 for example:
1228 <screen>mencoder -oac copy -ovc copy -o <replaceable>output_movie.avi</replaceable> -audiofile <replaceable>input_audio.mp2</replaceable> <replaceable>input_video.avi</replaceable></screen>
1229 This would merge the video file <replaceable>input_video.avi</replaceable>
1230 and the audio file <replaceable>input_audio.mp2</replaceable>
1231 into the AVI file <replaceable>output_movie.avi</replaceable>.
1232 This command works with MPEG-1 layer I, II and III (more commonly known
1233 as MP3) audio, WAV and a few other audio formats too.
1234 </para>
1235
1236 <para>
1237 MEncoder features experimental support for
1238 <systemitem class="library">libavformat</systemitem>, which is a
1239 library from the FFmpeg project that supports muxing and demuxing
1240 a variety of containers.
1241 For example:
1242 <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>
1243 This will do the same thing as the previous example, except that
1244 the output container will be ASF.
1245 Please note that this support is highly experimental (but getting
1246 better every day), and will only work if you compiled
1247 <application>MPlayer</application> with the support for
1248 <systemitem class="library">libavformat</systemitem> enabled (which
1249 means that a pre-packaged binary version will not work in most cases).
1250 </para>
1251
1252 <sect3 id="menc-feat-dvd-mpeg4-muxing-avi-limitations">
1253 <title>Limitations of the AVI container</title>
1254 <para>
1255 Although it is the most widely-supported container format after MPEG-1,
1256 AVI also has some major drawbacks.
1257 Perhaps the most obvious is the overhead.
1258 For each chunk of the AVI file, 24 bytes are wasted on headers and
1259 index.
1260 This translates into a little over 5 MB per hour, or 1-2.5%
1261 overhead for a 700 MB movie. This may not seem like much, but it could
1262 mean the difference between being able to use 700 kbit/sec video or
1263 714 kbit/sec, and every bit of quality counts.
1264 </para>
1265
1266 <para>
1267 In addition this gross inefficiency, AVI also has the following major
1268 limitations:
1269 </para>
1270
1271 <orderedlist>
1272 <listitem>
1273 <para>
1274 Only fixed-fps content can be stored. This is particularly limiting
1275 if the original material you want to encode is mixed content, for
1276 example a mix of NTSC video and film material.
1277 Actually there are hacks that can be used to store mixed-framerate
1278 content in AVI, but they increase the (already huge) overhead
1279 fivefold or more and so are not practical.
1280 </para>
1281 </listitem>
1282 <listitem>
1283 <para>
1284 Audio in AVI files must be either constant-bitrate (CBR) or
1285 constant-framesize (i.e. all frames decode to the same number of
1286 samples).
1287 Unfortunately, the most efficient codec, Vorbis, does not meet
1288 either of these requirements.
1289 Therefore, if you plan to store your movie in AVI, you will have to
1290 use a less efficient codec such as MP3 or AC3.
1291 </para>
1292 </listitem>
1293 </orderedlist>
1294
1295 <para>
1296 Having said all that, <application>MEncoder</application> does not
1297 currently support variable-fps output or Vorbis encoding.
1298 Therefore, you may not see these as limitations if
1299 <application>MEncoder</application> is the
1300 only tool you will be using to produce your encodes.
1301 However, it is possible to use <application>MEncoder</application>
1302 only for video encoding, and then use external tools to encode
1303 audio and mux it into another container format.
1304 </para>
1305 </sect3>
1306
1307 <sect3 id="menc-feat-dvd-mpeg4-muxing-matroska">
1308 <title>Muxing into the Matroska container</title>
1309 <para>
1310 Matroska is a free, open standard container format, aiming
1311 to offer a lot of advanced features, which older containers
1312 like AVI cannot handle.
1313 For example, Matroska supports variable bitrate audio content
1314 (VBR), variable framerates (VFR), chapters, file attachments,
1315 error detection code (EDC) and modern A/V Codecs like "Advanced Audio
1316 Coding" (AAC), "Vorbis" or "MPEG-4 AVC" (H.264), next to nothing
1317 handled by AVI.
1318 </para>
1319
1320 <para>
1321 The tools required to create Matroska files are collectively called
1322 <application>mkvtoolnix</application>, and are available for most
1323 Unix platforms as well as <application>Windows</application>.
1324 Because Matroska is an open standard you may find other
1325 tools that suit you better, but since mkvtoolnix is the most
1326 common, and is supported by the Matroska team itself, we will
1327 only cover its usage.
1328 </para>
1329
1330 <para>
1331 Probably the easiest way to get started with Matroska is to use
1332 <application>MMG</application>, the graphical frontend shipped with
1333 <application>mkvtoolnix</application>, and follow the
1334 <ulink url="http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvmerge-gui.html">guide to mkvmerge GUI (mmg)</ulink>
1335 </para>
1336
1337 <para>
1338 You may also mux audio and video files using the command line:
1339 <screen>mkvmerge -o <replaceable>output.mkv</replaceable> <replaceable>input_video.avi</replaceable> <replaceable>input_audio1.mp3</replaceable> <replaceable>input_audio2.ac3</replaceable></screen>
1340 This would merge the video file <replaceable>input_video.avi</replaceable>
1341 and the two audio files <replaceable>input_audio1.mp3</replaceable>
1342 and <replaceable>input_audio2.ac3</replaceable> into the Matroska
1343 file <replaceable>output.mkv</replaceable>.
1344 Matroska, as mentioned earlier, is able to do much more than that, like
1345 multiple audio tracks (including fine-tuning of audio/video
1346 synchronization), chapters, subtitles, splitting, etc...
1347 Please refer to the documentation of those applications for
1348 more details.
1349 </para>
1350
1351 </sect3>
1352
1353 </sect2>
1354
1355 </sect1>
1356
1357 <sect1 id="menc-feat-telecine">
1358 <title>How to deal with telecine and interlacing within NTSC DVDs</title>
1359
1360 <sect2 id="menc-feat-telecine-intro">
1361 <title>Introduction</title>
1362 <formalpara>
1363 <title>What is telecine?</title>
1364 <para>
1365 I suggest you visit this page if you do not understand much of what
1366 is written in this document:
1367 <ulink url="http://www.divx.com/support/guides/guide.php?gid=10">http://www.divx.com/support/guides/guide.php?gid=10</ulink>
1368 This URL links to an understandable and reasonably comprehensive
1369 description of what telecine is.
1370 </para></formalpara>
1371
1372 <formalpara>
1373 <title>A note about the numbers.</title>
1374 <para>
1375 Many documents, including the guide linked above, refer to the fields
1376 per second value of NTSC video as 59.94 and the corresponding frames
1377 per second values as 29.97 (for telecined and interlaced) and 23.976
1378 (for progressive). For simplicity, some documents even round these
1379 numbers to 60, 30, and 24.
1380 </para></formalpara>
1381
1382 <para>
1383 Strictly speaking, all those numbers are approximations. Black and
1384 white NTSC video was exactly 60 fields per second, but 60000/1001
1385 was later chosen to accomodate color data while remaining compatible
1386 with contemporary black and white televisions. Digital NTSC video
1387 (such as on a DVD) is also 60000/1001 fields per second. From this,
1388 interlaced and telecined video are derived to be 30000/1001 frames
1389 per second; progressive video is 24000/1001 frames per second.
1390 </para>
1391
1392 <para>
1393 Older versions of the <application>MEncoder</application> documentation
1394 and many archived mailing list posts refer to 59.94, 29.97, and 23.976.
1395 All <application>MEncoder</application> documentation has been updated
1396 to use the fractional values, and you should use them too.
1397 </para>
1398
1399 <para>
1400 <option>-ofps 23.976</option> is incorrect.
1401 <option>-ofps 24000/1001</option> should be used instead.
1402 </para>
1403
1404 <formalpara>
1405 <title>How telecine is used.</title>
1406 <para>
1407 All video intended to be displayed on an NTSC
1408 television set must be 60000/1001 fields per second. Made-for-TV movies
1409 4 and shows are often filmed directly at 60000/1001 fields per second, but
1410 the majority of cinema is filmed at 24 or 24000/1001 frames per
1411 second. When cinematic movie DVDs are mastered, the video is then
1412 converted for television using a process called telecine.
1413 </para></formalpara>
1414
1415 <para>
1416 On a DVD, the video is never actually stored as 60000/1001 fields per
1417 second. For video that was originally 60000/1001, each pair of fields is
1418 combined to form a frame, resulting in 30000/1001 frames per
1419 second. Hardware DVD players then read a flag embedded in the video
1420 stream to determine whether the odd- or even-numbered lines should
1421 form the first field.
1422 </para>
1423
1424 <para>
1425 Usually, 24000/1001 frames per second content stays as it is when
1426 encoded for a DVD, and the DVD player must perform telecining
1427 on-the-fly. Sometimes, however, the video is telecined
1428 <emphasis>before</emphasis> being stored on the DVD; even though it
1429 was originally 24000/1001 frames per second, it becomes 60000/1001 fields per
1430 second. When it is stored on the DVD, pairs of fields are combined to form
1431 30000/1001 frames per second.
1432 </para>
1433
1434 <para>
1435 When looking at individual frames formed from 60000/10001 fields per
1436 second video, telecined or otherwise, interlacing is clearly visible
1437 wherever there is any motion, because one field (say, the
1438 even-numbered lines) represents a moment in time 1/(60000/1001)
1439 seconds later than the other. Playing interlaced video on a computer
1440 looks ugly both because the monitor is higher resolution and because
1441 the video is shown frame-after-frame instead of field-after-field.
1442 </para>
1443
1444 <itemizedlist>
1445 <title>Notes:</title>
1446 <listitem><para>
1447 This section only applies to NTSC DVDs, and not PAL.
1448 </para></listitem>
1449 <listitem><para>
1450 The example <application>MEncoder</application> lines throughout the
1451 document are <emphasis role="bold">not</emphasis> intended for
1452 actual use. They are simply the bare minimum required to encode the
1453 pertaining video category. How to make good DVD rips or fine-tune
1454 <systemitem class="library">libavcodec</systemitem> for maximal
1455 quality is not within the scope of this document.
1456 </para></listitem>
1457 <listitem><para>
1458 There are a couple footnotes specific to this guide, linked like this:
1459 <link linkend="menc-feat-telecine-footnotes">[1]</link>
1460 </para></listitem>
1461 </itemizedlist>
1462 </sect2>
1463
1464 <sect2 id="menc-feat-telecine-ident">
1465 <title>How to tell what type of video you have</title>
1466
1467 <sect3 id="menc-feat-telecine-ident-progressive">
1468 <title>Progressive</title>
1469 <para>
1470 Progressive video was originally filmed at 24000/1001 fps, and stored
1471 on the DVD without alteration.
1472 </para>
1473
1474 <para>
1475 When you play a progressive DVD in <application>MPlayer</application>,
1476 <application>MPlayer</application> will print the following line as
1477 soon as the movie begins to play:
1478
1479 <screen> demux_mpg: 24000/1001 fps progressive NTSC content detected, switching framerate.</screen>
1480
1481 From this point forward, demux_mpg should never say it finds
1482 &quot;30000/1001 fps NTSC content.&quot;
1483 </para>
1484
1485 <para>
1486 When you watch progressive video, you should never see any
1487 interlacing. Beware, however, because sometimes there is a tiny bit
1488 of telecine mixed in where you would not expect. I have encountered TV
1489 show DVDs that have one second of telecine at every scene change, or
1490 at seemingly random places. I once watched a DVD that had a
1491 progressive first half, and the second half was telecined. If you
1492 want to be <emphasis>really</emphasis> thorough, you can scan the
1493 entire movie:
1494
1495 <screen>mplayer dvd://1 -nosound -vo null -benchmark</screen>
1496
1497 Using <option>-benchmark</option> makes
1498 <application>MPlayer</application> play the movie as quickly as it
1499 possibly can; still, depending on your hardware, it can take a
1500 while. Every time demux_mpg reports a framerate change, the line
1501 immediately above will show you the time at which the change
1502 occurred.
1503 </para>
1504
1505 <para>
1506 Sometimes progressive video on DVDs is referred to as
1507 &quot;soft-telecine&quot; because it is intended to
1508 be telecined by the DVD player.
1509 </para>
1510 </sect3>
1511
1512 <sect3 id="menc-feat-telecine-ident-telecined">
1513 <title>Telecined</title>
1514 <para>
1515 Telecined video was originally filmed at 24000/1001, but was telecined
1516 <emphasis>before</emphasis> it was written to the DVD.
1517 </para>
1518
1519 <para>
1520 <application>MPlayer</application> does not (ever) report any
1521 framerate changes when it plays telecined video.
1522 </para>
1523
1524 <para>
1525 Watching a telecined video, you will see interlacing artifacts that
1526 seem to &quot;blink&quot;: they repeatedly appear and disappear.
1527 You can look closely at this by
1528 <orderedlist>
1529 <listitem>
1530 <screen>mplayer dvd://1</screen>
1531 </listitem>
1532 <listitem><para>
1533 Seek to a part with motion.
1534 </para></listitem>
1535 <listitem><para>
1536 Use the <keycap>.</keycap> key to step forward one frame at a time.
1537 </para></listitem>
1538 <listitem><para>
1539 Look at the pattern of interlaced-looking and progressive-looking
1540 frames. If the pattern you see is PPPII,PPPII,PPPII,... then the
1541 video is telecined. If you see some other pattern, then the video
1542 may have been telecined using some non-standard method;
1543 <application>MEncoder</application> cannot losslessly convert
1544 non-standard telecine to progressive. If you do not see any
1545 pattern at all, then it is most likely interlaced.
1546 </para></listitem>
1547 </orderedlist>
1548 </para>
1549
1550 <para>
1551 Sometimes telecined video on DVDs is referred to as
1552 &quot;hard-telecine&quot;. Since hard-telecine is already 60000/1001 fields
1553 per second, the DVD player plays the video without any manipulation.
1554 </para>
1555 </sect3>
1556
1557 <sect3 id="menc-feat-telecine-ident-interlaced">
1558 <title>Interlaced</title>
1559 <para>
1560 Interlaced video was originally filmed at 60000/1001 fields per second,
1561 and stored on the DVD as 30000/1001 frames per second. The interlacing effect
1562 (often called &quot;combing&quot;) is a result of combining pairs of
1563 fields into frames. Each field is supposed to be 1/(60000/1001) seconds apart,
1564 and when they are displayed simultaneously the difference is apparent.
1565 </para>
1566
1567 <para>
1568 As with telecined video, <application>MPlayer</application> should
1569 not ever report any framerate changes when playing interlaced content.
1570 </para>
1571
1572 <para>
1573 When you view an interlaced video closely by frame-stepping with the
1574 <keycap>.</keycap> key, you will see that every single frame is interlaced.
1575 </para>
1576 </sect3>
1577
1578 <sect3 id="menc-feat-telecine-ident-mixedpt">
1579 <title>Mixed progressive and telecine</title>
1580 <para>
1581 All of a &quot;mixed progressive and telecine&quot; video was originally
1582 24000/1001 frames per second, but some parts of it ended up being telecined.
1583 </para>
1584
1585 <para>
1586 When <application>MPlayer</application> plays this category, it will
1587 (often repeatedly) switch back and forth between &quot;30000/1001 fps NTSC&quot;
1588 and &quot;24000/1001 fps progressive NTSC&quot;. Watch the bottom of
1589 <application>MPlayer</application>'s output to see these messages.
1590 </para>
1591
1592 <para>
1593 You should check the &quot;30000/1001 fps NTSC&quot; sections to make sure
1594 they are actually telecine, and not just interlaced.
1595 </para>
1596 </sect3>
1597
1598 <sect3 id="menc-feat-telecine-ident-mixedpi">
1599 <title>Mixed progressive and interlaced</title>
1600 <para>
1601 In &quot;mixed progressive and interlaced&quot; content, progressive
1602 and interlaced video have been spliced together.
1603 </para>
1604
1605 <para>
1606 This category looks just like &quot;mixed progressive and telecine&quot;,
1607 until you examine the 30000/1001 fps sections and see that they do not have the
1608 telecine pattern.
1609 </para>
1610 </sect3>
1611
1612 </sect2>
1613
1614 <sect2 id="menc-feat-telecine-encode">
1615 <title>How to encode each category</title>
1616 <para>
1617 As I mentioned in the beginning, example <application>MEncoder</application>
1618 lines below are <emphasis role="bold">not</emphasis> meant to actually be used;
1619 they only demonstrate the minimum parameters to properly encode each category.
1620 </para>
1621
1622 <sect3 id="menc-feat-telecine-encode-progressive">
1623 <title>Progressive</title>
1624 <para>
1625 Progressive video requires no special filtering to encode. The only
1626 parameter you need to be sure to use is
1627 <option>-ofps 24000/1001</option>. Otherwise, <application>MEncoder</application>
1628 will try to encode at 30000/1001 fps and will duplicate frames.
1629 </para>
1630
1631 <para>
1632 <screen>mencoder dvd://1 -nosound -ovc lavc -ofps 24000/1001</screen>
1633 </para>
1634
1635 <para>
1636 It is often the case, however, that a video that looks progressive
1637 actually has very short parts of telecine mixed in. Unless you are
1638 sure, it is safest to treat the video as
1639 <link linkend="menc-feat-telecine-encode-mixedpt">mixed progressive and telecine</link>.
1640 The performance loss is small
1641 <link linkend="menc-feat-telecine-footnotes">[3]</link>.
1642 </para>
1643 </sect3>
1644
1645 <sect3 id="menc-feat-telecine-encode-telecined">
1646 <title>Telecined</title>
1647 <para>
1648 Telecine can be reversed to retrieve the original 24000/1001 content,
1649 using a process called inverse-telecine.
1650 <application>MPlayer</application> contains several filters to
1651 accomplish this; the best filter, <option>pullup</option>, is described
1652 in the <link linkend="menc-feat-telecine-encode-mixedpt">mixed
1653 progressive and telecine</link> section.
1654 </para>
1655 </sect3>
1656
1657 <sect3 id="menc-feat-telecine-encode-interlaced">
1658 <title>Interlaced</title>
1659 <para>
1660 For most practical cases it is not possible to retrieve a complete
1661 progressive video from interlaced content. The only way to do so
1662 without losing half of the vertical resolution is to double the
1663 framerate and try to &quot;guess&quot; what ought to make up the
1664 corresponding lines for each field (this has drawbacks - see method
1665 3).
1666 </para>
1667
1668 <orderedlist>
1669 <listitem><para>
1670
1671 Encode the video in interlaced form. Normally, interlacing wreaks
1672 havoc with the encoder's ability to compress well, but
1673 <systemitem class="library">libavcodec</systemitem> has two
1674 parameters specifically for dealing with storing interlaced video a
1675 bit better: <option> ildct</option> and <option>ilme</option>. Also,
1676 using <option>mbd=2</option> is strongly recommended
1677 <link linkend="menc-feat-telecine-footnotes">[2] </link> because it
1678 will encode macroblocks as non-interlaced in places where there is
1679 no motion. Note that <option>-ofps</option> is NOT needed here.
1680
1681 <screen>mencoder dvd://1 -nosound -ovc lavc -lavcopts ildct:ilme:mbd=2</screen>
1682 </para></listitem>
1683 <listitem><para>
1684 Use a deinterlacing filter before encoding. There are several of
1685 these filters available to choose from, each with its own advantages
1686 and disadvantages. Consult <option>mplayer -pphelp</option> to see
1687 what is available (grep for &quot;deint&quot;), and search the
1688 <ulink url="http://www.mplayerhq.hu/homepage/design6/info.html#mailing_lists">
1689 MPlayer mailing lists</ulink> to find many discussions about the
1690 various filters. Again, the framerate is not changing, so no
1691 <option>-ofps</option>. Also, deinterlacing should be done after
1692 cropping <link linkend="menc-feat-telecine-footnotes">[1]</link> and
1693 before scaling.
1694
1695 <screen>mencoder dvd://1 -nosound -vf pp=lb -ovc lavc</screen>
1696 </para></listitem>
1697 <listitem><para>
1698 Unfortunately, this option is buggy with
1699 <application>MEncoder</application>; it ought to work well with
1700 <application>MEncoder G2</application>, but that is not here yet. You
1701 might experience crahes. Anyway, the purpose of <option> -vf
1702 tfields</option> is to create a full frame out of each field, which
1703 makes the framerate 60000/1001. The advantage of this approach is that no
1704 data is ever lost; however, since each frame comes from only one
1705 field, the missing lines have to be interpolated somehow. There are
1706 no very good methods of generating the missing data, and so the
1707 result will look a bit similar to when using some deinterlacing
1708 filters. Generating the missing lines creates other issues, as well,
1709 simply because the amount of data doubles. So, higher encoding
1710 bitrates are required to maintain quality, and more CPU power is
1711 used for both encoding and decoding. tfields has several different
1712 options for how to create the missing lines of each frame. If you
1713 use this method, then Reference the manual, and chose whichever
1714 option looks best for your material. Note that when using
1715 <option>tfields</option> you
1716 <emphasis role="bold">have to</emphasis> specify both
1717 <option>-fps</option> and <option>-ofps</option> to be twice the
1718 framerate of your original source.
1719
1720 <screen>mencoder dvd://1 -nosound -vf tfields=2 -ovc lavc -fps 60000/1001 -ofps 60000/1001</screen>
1721 </para></listitem>
1722 <listitem><para>
1723 If you plan on downscaling dramatically, you can extract and encode
1724 only one of the two fields. Of course, you will lose half the vertical
1725 resolution, but if you plan on downscaling to at most 1/2 of the
1726 original, the loss will not matter much. The result will be a
1727 progressive 30000/1001 frames per second file. The procedure is to use
1728 <option>-vf field</option>, then crop
1729 <link linkend="menc-feat-telecine-footnotes">[1]</link> and scale
1730 appropriately. Remember that you will have to adjust the scale to
1731 compensate for the vertical resolution being halved.
1732 <screen>mencoder dvd://1 -nosound -vf field=0 -ovc lavc</screen>
1733 </para></listitem>
1734 </orderedlist>
1735 </sect3>
1736
1737 <sect3 id="menc-feat-telecine-encode-mixedpt">
1738 <title>Mixed progressive and telecine</title>
1739 <para>
1740 In order to turn mixed progressive and telecine video into entirely
1741 progressive video, the telecined parts have to be
1742 inverse-telecined. There are three ways to accomplish this,
1743 described below. Note that you should
1744 <emphasis role="bold">always</emphasis> inverse-telecine before any
1745 rescaling; unless you really know what you are doing,
1746 inverse-telecine before cropping, too
1747 <link linkend="menc-feat-telecine-footnotes">[1]</link>.
1748 <option>-ofps 24000/1001</option> is needed here because the output video
1749 will be 24000/1001 frames per second.
1750 </para>
1751
1752 <itemizedlist>
1753 <listitem><para>
1754 <option>-vf pullup</option> is designed to inverse-telecine
1755 telecined material while leaving progressive data alone. In order to
1756 work properly, <option>pullup</option> <emphasis role="bold">must</emphasis>
1757 be followed by the <option>softskip</option> filter or
1758 else <application>MEncoder</application> will crash.
1759 <option>pullup</option> is, however, the cleanest and most
1760 accurate method available for encoding both telecine and
1761 &quot;mixed progressive and telecine&quot;.
1762
1763 <screen>mencoder dvd://1 -nosound -vf pullup,softskip -ovc lavc -ofps 24000/1001</screen>
1764 </para>
1765
1766
1767 </listitem>
1768 <listitem><para>
1769 An older method
1770 is to, rather than inverse-telecine the telecined parts, telecine
1771 the non-telecined parts and then inverse-telecine the whole
1772 video. Sound confusing? softpulldown is a filter that goes through
1773 a video and makes the entire file telecined. If we follow
1774 softpulldown with either <option>detc</option> or
1775 <option>ivtc</option>, the final result will be entirely
1776 progressive. <option>-ofps 24000/1001</option> is needed.
1777
1778 <screen>mencoder dvd://1 -nosound -vf softpulldown,ivtc=1 -ovc lavc -ofps 24000/1001</screen>
1779 </para>
1780 </listitem>
1781
1782 <listitem><para>
1783 I have not used <option>-vf filmdint</option> myself, but here is what
1784 D Richard Felker III has to say:
1785
1786 <blockquote><para>It is OK, but IMO it tries to deinterlace rather
1787 than doing inverse telecine too often (much like settop DVD
1788 players &amp; progressive TVs) which gives ugly flickering and
1789 other artifacts. If you are going to use it, you at least need to
1790 spend some time tuning the options and watching the output first
1791 to make sure it is not messing up.</para></blockquote>
1792 </para></listitem>
1793 </itemizedlist>
1794 </sect3>
1795
1796 <sect3 id="menc-feat-telecine-encode-mixedpi">
1797 <title>Mixed progressive and interlaced</title>
1798 <para>
1799 There are two options for dealing with this category, each of
1800 which is a compromise. You should decide based on the
1801 duration/location of each type.
1802 </para>
1803
1804 <itemizedlist>
1805 <listitem><para>
1806 Treat it as progressive. The interlaced parts will look interlaced,
1807 and some of the interlaced fields will have to be dropped, resulting
1808 in a bit of uneven jumpiness. You can use a postprocessing filter if
1809 you want to, but it may slightly degrade the progressive parts.
1810 </para>
1811
1812 <para>
1813 This option should definitely not be used if you want to eventually
1814 display the video on an interlaced device (with a TV card, for
1815 example). If you have interlaced frames in a 24000/1001 frames per
1816 second video, they will be telecined along with the progressive
1817 frames. Half of the interlaced "frames" will be displayed for three
1818 fields' duration (3/(60000/1001) seconds), resulting in a flicking
1819 &quot;jump back in time&quot; effect that looks quite bad. If you
1820 even attempt this, you <emphasis role="bold">must</emphasis> use a
1821 deinterlacing filter like <option>lb</option> or
1822 <option>l5</option>.
1823 </para>
1824
1825 <para>
1826 It may also be a bad idea for progressive display, too. It will drop
1827 pairs of consecutive interlaced fields, resulting in a discontinuity
1828 that can be more visible than with the second method, which shows
1829 some progressive frames twice. 30000/1001 frames per second interlaced
1830 video is already a bit choppy because it really should be shown at
1831 60000/1001 fields per second, so the duplicate frames do not stand out as
1832 much.
1833 </para>
1834
1835 <para>
1836 Either way, it is best to consider your content and how you intend to
1837 display it. If your video is 90% progressive and you never intend to
1838 show it on a TV, you should favor a progressive approach. If it is
1839 only half progressive, you probably want to encode it as if it is all
1840 interlaced.
1841 </para>
1842 </listitem>
1843
1844 <listitem><para>
1845 Treat it as interlaced. Some frames of the progressive parts will
1846 need to be duplicated, resulting in uneven jumpiness. Again,
1847 deinterlacing filters may slightly degrade the progressive parts.
1848 </para></listitem>
1849
1850 </itemizedlist>
1851 </sect3>
1852
1853 </sect2>
1854
1855 <sect2 id="menc-feat-telecine-footnotes">
1856 <title>Footnotes</title>
1857 <orderedlist>
1858 <listitem><formalpara>
1859 <title>About cropping:</title>
1860 <para>
1861 Video data on DVDs are stored in a format called YUV 4:2:0. In YUV
1862 video, luma (&quot;brightness&quot;) and chroma (&quot;color&quot;)
1863 are stored separately. Because the human eye is somewhat less
1864 sensitive to color than it is to brightness, in a YUV 4:2:0 picture
1865 there is only one chroma pixel for every four luma pixels. In a
1866 progressive picture, each square of four luma pixels (two on each
1867 side) has one common chroma pixel. You must crop progressive YUV
1868 4:2:0 to even resolutions, and use even offsets. For example,
1869 <option>crop=716:380:2:26</option> is OK but
1870 <option>crop=716:380:3:26 </option> is not.
1871 </para>
1872 </formalpara>
1873
1874 <para>
1875 When you are dealing with interlaced YUV 4:2:0, the situation is a
1876 bit more complicated. Instead of every four luma pixels in the
1877 <emphasis>frame</emphasis> sharing a chroma pixel, every four luma
1878 pixels in each <emphasis> field</emphasis> share a chroma
1879 pixel. When fields are interlaced to form a frame, each scanline is
1880 one pixel high. Now, instead of all four luma pixels being in a
1881 square, there are two pixels side-by-side, and the other two pixels
1882 are side-by-side two scanlines down. The two luma pixels in the
1883 intermediate scanline are from the other field, and so share a
1884 different chroma pixel with two luma pixels two scanlines away. All
1885 this confusion makes it necessary to have vertical crop dimensions
1886 and offsets be multiples of four. Horizontal can stay even.
1887 </para>
1888
1889 <para>
1890 For telecined video, I recommend that cropping take place after
1891 inverse telecining. Once the video is progressive you only need to
1892 crop by even numbers. If you really want to gain the slight speedup
1893 that cropping first may offer, you must crop vertically by multiples
1894 of four or else the inverse-telecine filter will not have proper data.
1895 </para>
1896
1897 <para>
1898 For interlaced (not telecined) video, you must always crop
1899 vertically by multiples of four unless you use <option>-vf
1900 field</option> before cropping.
1901 </para>
1902 </listitem>
1903
1904 <listitem><formalpara>
1905 <title>About encoding parameters and quality:</title>
1906 <para>
1907 Just because I recommend <option>mbd=2</option> here does not mean it
1908 should not be used elsewhere. Along with <option>trell</option>,
1909 <option>mbd=2</option> is one of the two
1910 <systemitem class="library">libavcodec</systemitem> options that
1911 increases quality the most, and you should always use at least those
1912 two unless the drop in encoding speed is prohibitive (e.g. realtime
1913 encoding). There are many other options to
1914 <systemitem class="library">libavcodec</systemitem> that increase
1915 encoding quality (and decrease encoding speed) but that is beyond
1916 the scope of this document.
1917 </para>
1918 </formalpara>
1919 </listitem>
1920
1921 <listitem><formalpara>
1922 <title>About the performance of pullup:</title>
1923 <para>
1924 It is safe to use <option>pullup</option> (along with <option>softskip
1925 </option>) on progressive video, and is usually a good idea unless
1926 the source has been definitively verified to be entirely progressive.
1927 The performace loss is small for most cases. On a bare-minimum encode,
1928 <option>pullup</option> causes <application>MEncoder</application> to
1929 be 50% slower. Adding sound processing and advanced <option>lavcopts
1930 </option> overshadows that difference, bringing the performance
1931 decrease of using <option>pullup</option> down to 2%.
1932 </para>
1933 </formalpara>
1934 </listitem>
1935
1936 </orderedlist>
1937
1938 </sect2>
1939
1940 </sect1>
1941
1942
1943 <sect1 id="menc-feat-enc-libavcodec">
1944 <title>Encoding with the <systemitem class="library">libavcodec</systemitem>
1945 codec family</title>
1946
1947 <para>
1948 <link linkend="ffmpeg"><systemitem class="library">libavcodec</systemitem></link>
1949 provides simple encoding to a lot of interesting video and audio formats.
1950 You can encode to the following codecs (more or less up to date):
1951
1952 <informaltable frame="all">
1953 <tgroup cols="2">
1954 <thead>
1955 <row><entry>Codec name</entry><entry>Description</entry></row>
1956 </thead>
1957 <tbody>
1958 <row><entry>mjpeg</entry><entry>
1959 Motion JPEG
1960 </entry></row>
1961 <row><entry>ljpeg</entry><entry>
1962 Lossless JPEG
1963 </entry></row>
1964 <row><entry>h263</entry><entry>
1965 H.263
1966 </entry></row>
1967 <row><entry>h263p</entry><entry>
1968 H.263+
1969 </entry></row>
1970 <row><entry>mpeg4</entry><entry>
1971 ISO standard MPEG-4 (DivX 5, XVID compatible)
1972 </entry></row>
1973 <row><entry>msmpeg4</entry><entry>
1974 pre-standard MPEG-4 variant by MS, v3 (AKA DivX3)
1975 </entry></row>
1976 <row><entry>msmpeg4v2</entry><entry>
1977 pre-standard MPEG-4 by MS, v2 (used in old asf files)
1978 </entry></row>
1979 <row><entry>wmv1</entry><entry>
1980 Windows Media Video, version 1 (AKA WMV7)
1981 </entry></row>
1982 <row><entry>wmv2</entry><entry>
1983 Windows Media Video, version 2 (AKA WMV8)
1984 </entry></row>
1985 <row><entry>rv10</entry><entry>
1986 an old RealVideo codec
1987 </entry></row>
1988 <row><entry>mpeg1video</entry><entry>
1989 MPEG-1 video
1990 </entry></row>
1991 <row><entry>mpeg2video</entry><entry>
1992 MPEG-2 video
1993 </entry></row>
1994 <row><entry>huffyuv</entry><entry>
1995 lossless compression
1996 </entry></row>
1997 <row><entry>asv1</entry><entry>
1998 ASUS Video v1
1999 </entry></row>
2000 <row><entry>asv2</entry><entry>
2001 ASUS Video v2
2002 </entry></row>
2003 <row><entry>ffv1</entry><entry>
2004 FFmpeg's lossless video codec
2005 </entry></row>
2006 </tbody>
2007 </tgroup>
2008 </informaltable>
2009
2010 The first column contains the codec names that should be passed after the
2011 <literal>vcodec</literal> config, like: <option>-lavcopts vcodec=msmpeg4</option>
2012 </para>
2013
2014 <informalexample>
2015 <para>
2016 An example, with MJPEG compression:
2017 <screen>mencoder dvd://2 -o title2.avi -ovc lavc -lavcopts vcodec=mjpeg -oac copy</screen>
2018 </para>
2019 </informalexample>
2020
2021 <sect2 id="menc-feat-dvd-mpeg4-lavc-encoding-options">
2022 <title>Encoding options of libavcodec</title>
2023
2024 <para>
2025 Ideally, you would probably want to be able to just tell the encoder to switch
2026 into "high quality" mode and move on.
2027 That would probably be nice, but unfortunately hard to implement as different
2028 encoding options yield different quality results depending on the source material.
2029 That is because compression depends on the visual properties of the video
2030 in question.
2031 For example, anime and live action have very different properties and
2032 thus require different options to obtain optimum encoding.
2033 The good news is that some options should never be left out, like
2034 <option>mbd=2</option>, <option>trell</option>, and <option>v4mv</option>.
2035 See below for a detailed description of common encoding options.
2036 </para>
2037
2038
2039 <itemizedlist>
2040 <title>Options to adjust:</title>
2041 <listitem><para>
2042 <emphasis role="bold">vmax_b_frames</emphasis>: 1 or 2 is good, depending on
2043 the movie.
2044 Note that if you need to have your encode be decodable by DivX5, you
2045 need to activate closed GOP support, using
2046 <systemitem class="library">libavcodec</systemitem>'s <option>cgop</option>
2047 option, but you need to deactivate scene detection, which
2048 is not a good idea as it will hurt encode efficiency a bit.
2049 </para></listitem>
2050
2051 <listitem><para>
2052 <emphasis role="bold">vb_strategy=1</emphasis>: helps in high-motion scenes.
2053 Requires vmax_b_frames >= 2.
2054 On some videos, vmax_b_frames may hurt quality, but vmax_b_frames=2 along
2055 with vb_strategy=1 helps.
2056 </para></listitem>
2057
2058 <listitem><para>
2059 <emphasis role="bold">dia</emphasis>: motion search range. Bigger is better
2060 and slower.
2061 Negative values are a completely different scale.
2062 Good values are -1 for a fast encode, or 2-4 for slower.
2063 </para></listitem>
2064
2065 <listitem><para>
2066 <emphasis role="bold">predia</emphasis>: motion search pre-pass.
2067 Not as important as dia. Good values are 1 (default) to 4. Requires preme=2
2068 to really be useful.
2069 </para></listitem>
2070
2071 <listitem><para>
2072 <emphasis role="bold">cmp, subcmp, precmp</emphasis>: Comparison function for
2073 motion estimation.
2074 Experiment with values of 0 (default), 2 (hadamard), 3 (dct), and 6 (rate
2075 distortion).
2076 0 is fastest, and sufficient for precmp.
2077 For cmp and subcmp, 2 is good for anime, and 3 is good for live action.
2078 6 may or may not be slightly better, but is slow.
2079 </para></listitem>
2080
2081 <listitem><para>
2082 <emphasis role="bold">last_pred</emphasis>: Number of motion predictors to
2083 take from the previous frame.
2084 1-3 or so help at little speed cost.
2085 Higher values are slow for no extra gain.
2086 </para></listitem>
2087
2088 <listitem><para>
2089 <emphasis role="bold">cbp, mv0</emphasis>: Controls the selection of macroblocks.
2090 Small speed cost for small quality gain.
2091 </para></listitem>
2092
2093 <listitem><para>
2094 <emphasis role="bold">qprd</emphasis>: adaptive quantization based on the
2095 macroblock's complexity.
2096 May help or hurt depending on the video and other options.
2097 This can cause artifacts unless you set vqmax to some reasonably small value
2098 (6 is good, maybe as low as 4); vqmin=1 should also help.
2099 </para></listitem>
2100
2101 <listitem><para>
2102 <emphasis role="bold">qns</emphasis>: very slow, especially when combined
2103 with qprd.
2104 This option will make the encoder minimize noise due to compression
2105 artifacts instead of making the encoded video strictly match the source.
2106 Do not use this unless you have already tweaked everything else as far as it
2107 will go and the results still are not good enough.
2108 </para></listitem>
2109
2110 <listitem><para>
2111 <emphasis role="bold">vqcomp</emphasis>: Tweak ratecontrol.
2112 What values are good depends on the movie.
2113 You can safely leave this alone if you want.
2114 Reducing vqcomp puts more bits on low-complexity scenes, increasing it puts
2115 them on high-complexity scenes (default: 0.5, range: 0-1. recommended range:
2116 0.5-0.7).
2117 </para></listitem>
2118
2119 <listitem><para>
2120 <emphasis role="bold">vlelim, vcelim</emphasis>: Sets the single coefficient
2121 elimination threshold for luminance and chroma planes.
2122 These are encoded separately in all MPEG-like algorithms.
2123 The idea behind these options is to use some good heuristics to determine
2124 when the change in a block is less than the threshold you specify, and in
2125 such a case, to just encode the block as "no change".
2126 This saves bits and perhaps speeds up encoding. vlelim=-4 and vcelim=9
2127 seem to be good for live movies, but seem not to help with anime;
2128 when encoding animation, you should probably leave them unchanged.
2129 </para></listitem>
2130
2131 <listitem><para>
2132 <emphasis role="bold">qpel</emphasis>: Quarter pixel motion estimation.
2133 MPEG-4 uses half pixel precision for its motion search by default,
2134 therefore this option comes with an overhead as more information will be
2135 stored in the encoded file.
2136 The compression gain/loss depends on the movie, but it is usually not very
2137 effective on anime.
2138 qpel always incurs a significant cost in CPU decode time (+20% in
2139 practice).
2140 </para></listitem>
2141
2142 <listitem><para>
2143 <emphasis role="bold">psnr</emphasis>: does not affect the actual encoding,
2144 but writes a log file giving the type/size/quality of each frame, and
2145 prints a summary of PSNR (Peak Signal to Noise Ratio) at the end.
2146 </para></listitem>
2147
2148 </itemizedlist>
2149
2150 <itemizedlist>
2151 <title>Options not recommended to play with:</title>
2152 <listitem><para>
2153 <emphasis role="bold">vme</emphasis>: The default is best.
2154 </para></listitem>
2155
2156 <listitem><para>
2157 <emphasis role="bold">lumi_mask, dark_mask</emphasis>: Psychovisual adaptive
2158 quantization.
2159 You do not want to play with those options if you care about quality.
2160 Reasonable values may be effective in your case, but be warned this is very
2161 subjective.
2162 </para></listitem>
2163
2164 <listitem><para>
2165 <emphasis role="bold">scplx_mask</emphasis>: Tries to prevent blocky
2166 artifacts, but postprocessing is better.
2167 </para></listitem>
2168 </itemizedlist>
2169 </sect2>
2170
2171
2172 <sect2 id="custommatrices"><title>Custom inter/intra matrices</title>
2173
2174 <para>
2175 With this feature of
2176 <link linkend="ffmpeg"><systemitem class="library">libavcodec</systemitem></link>
2177 you are able to set custom inter (I-frames/keyframes) and intra
2178 (P-frames/predicted frames) matrices. It is supported by many of the codecs:
2179 <systemitem>mpeg1video</systemitem> and <systemitem>mpeg2video</systemitem>
2180 are reported as working.
2181 </para>
2182
2183 <para>
2184 A typical usage of this feature is to set the matrices preferred by the
2185 <ulink url="http://www.kvcd.net/">KVCD</ulink> specifications.
2186 </para>
2187
2188 <para>
2189 The <emphasis role="bold">KVCD &quot;Notch&quot; Quantization Matrix:</emphasis>
2190 </para>
2191
2192 <para>
2193 Intra:
2194 <screen>
2195 8 9 12 22 26 27 29 34
2196 9 10 14 26 27 29 34 37
2197 12 14 18 27 29 34 37 38
2198 22 26 27 31 36 37 38 40
2199 26 27 29 36 39 38 40 48
2200 27 29 34 37 38 40 48 58
2201 29 34 37 38 40 48 58 69
2202 34 37 38 40 48 58 69 79
2203 </screen>
2204
2205 Inter:
2206 <screen>
2207 16 18 20 22 24 26 28 30
2208 18 20 22 24 26 28 30 32
2209 20 22 24 26 28 30 32 34
2210 22 24 26 30 32 32 34 36
2211 24 26 28 32 34 34 36 38
2212 26 28 30 32 34 36 38 40
2213 28 30 32 34 36 38 42 42
2214 30 32 34 36 38 40 42 44
2215 </screen>
2216 </para>
2217
2218 <para>
2219 Usage:
2220 <screen>
2221 $ mencoder <replaceable>input.avi</replaceable> -o <replaceable>output.avi</replaceable> -oac copy -ovc lavc -lavcopts inter_matrix=...:intra_matrix=...
2222 </screen>
2223 </para>
2224
2225 <para>
2226 <screen>
2227 $ mencoder <replaceable>input.avi</replaceable> -ovc lavc -lavcopts
2228 vcodec=mpeg2video:intra_matrix=8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,
2229 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,
2230 29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79
2231 :inter_matrix=16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,
2232 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,
2233 36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44 -oac copy -o svcd.mpg
2234 </screen>
2235 </para>
2236 </sect2>
2237
2238
2239 <sect2 id="menc-feat-dvd-mpeg4-example">
2240 <title>Example</title>
2241
2242 <para>
2243 So, you have just bought your shiny new copy of Harry Potter and the Chamber
2244 of Secrets (widescreen edition, of course), and you want to rip this DVD
2245 so that you can add it to your Home Theatre PC. This is a region 1 DVD,
2246 so it is NTSC. The example below will still apply to PAL, except you will
2247 omit <option>-ofps 24000/1001</option> (because the output framerate is the
2248 same as the input framerate), and of course the crop dimensions will be
2249 different.
2250 </para>
2251
2252 <para>
2253 After running <option>mplayer dvd://1</option>, we follow the process
2254 detailed in the section <link linkend="menc-feat-telecine">How to deal
2255 with telecine and interlacing in NTSC DVDs</link> and discover that it is
2256 24000/1001 fps progressive video, which means that we needn't use an inverse
2257 telecine filter, such as <option>pullup</option> or
2258 <option>filmdint</option>.
2259 </para>
2260
2261 <para>
2262 Next, we want to determine the appropriate crop rectangle, so we use the
2263 cropdetect filter:
2264
2265 <screen>mplayer dvd://1 -vf cropdetect</screen>
2266
2267 Make sure you seek to a fully filled frame (such as a bright scene), and
2268 you will see in <application>MPlayer</application>'s console output:
2269
2270 <screen>crop area: X: 0..719 Y: 57..419 (-vf crop=720:362:0:58)</screen>
2271
2272 We then play the movie back with this filter to test its correctness:
2273
2274 <screen>mplayer dvd://1 -vf crop=720:362:0:58</screen>
2275
2276 And we see that it looks perfectly fine. Next, we ensure the width and
2277 height are a multiple of 16. The width is fine, however the height is
2278 not. Since we did not fail 7th grade math, we know that the nearest
2279 multiple of 16 lower than 362 is 352.
2280 </para>
2281
2282 <para>
2283 We could just use <option>crop=720:352:0:58</option>, but it would be nice
2284 to take a little off the top and a little off the bottom so that we
2285 retain the center. We have shrunk the height by 10 pixels, but we do not
2286 want to increase the y-offset by 5-pixels since that is an odd number and
2287 will adversely affect quality. Instead, we will increase the y-offset by
2288 4 pixels:
2289
2290 <screen>mplayer dvd://1 -vf crop=720:352:0:62</screen>
2291
2292 Another reason to shave pixels from both the top and the bottom is that we
2293 ensure we have eliminated any half-black pixels if they exist. Note that if
2294 your video is telecined, make sure the <option>pullup</option> filter (or
2295 whichever inverse telecine filter you decide to use) appears in the filter
2296 chain before you crop. If it is interlaced, deinterlace before cropping.
2297 (If you choose to preserve the interlaced video, then make sure your
2298 vertical crop offset is a multiple of 4.)
2299 </para>
2300
2301 <para>
2302 If you are really concerned about losing those 10 pixels, you might
2303 prefer instead to scale the dimensions down to the nearest multiple of 16.
2304 The filter chain would look like:
2305
2306 <screen>-vf crop=720:362:0:58,scale=720:352</screen>
2307
2308 Scaling the video down like this will mean that some small amount of
2309 detail is lost, though it probably will not be perceptible. Scaling up will
2310 result in lower quality (unless you increase the bitrate). Cropping
2311 discards those pixels altogether. It is a tradeoff that you will want to
2312 consider for each circumstance. For example, if the DVD video was made
2313 for television, you might want to avoid vertical scaling, since the line
2314 sampling corresponds to the way the content was originally recorded.
2315 </para>
2316
2317 <para>
2318 On inspection, we see that our movie has a fair bit of action and high
2319 amounts of detail, so we pick 2400Kbit for our bitrate.
2320 </para>
2321
2322 <para>
2323 We are now ready to do the two pass encode. Pass one:
2324
2325 <screen>mencoder dvd://1 -ofps 24000/1001 -oac copy -vf crop=720:352:0:62,hqdn3d=2:1:2 -ovc lavc \
2326 -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:autoaspect:vpass=1 \
2327 -o Harry_Potter_2.avi</screen>
2328
2329 And pass two is the same, except that we specify <option>vpass=2</option>:
2330
2331 <screen>mencoder dvd://1 -ofps 24000/1001 -oac copy -vf crop=720:352:0:62,hqdn3d=2:1:2 -ovc lavc \
2332 -lavcopts vcodec=mpeg4:vbitrate=2400:v4mv:mbd=2:trell:cmp=3:subcmp=3:mbcmp=3:autoaspect:vpass=2 \
2333 -o Harry_Potter_2.avi</screen>
2334 </para>
2335
2336 <para>
2337 The options <option>v4mv:mbd=2:trell</option> will greatly increase the
2338 quality at the expense of encoding time. There is little reason to leave
2339 these options out when the primary goal is quality. The options
2340 <option>cmp=3:subcmp=3:mbcmp=3</option> select a comparison function that
2341 yields higher quality than the defaults. You might try experimenting with
2342 this parameter (refer to the man page for the possible values) as
2343 different functions can have a large impact on quality depending on the
2344 source material. For example, if you find
2345 <systemitem class="library">libavcodec</systemitem> produces too much
2346 blocky artifacting, you could try selecting the experimental NSSE as
2347 comparison function via <option>*cmp=10</option>.
2348 </para>
2349
2350 <para>
2351 For this movie, the resulting AVI will be 138 minutes long and nearly
2352 3GB. And because you said that file size does not matter, this is a
2353 perfectly acceptable size. However, if you had wanted it smaller, you
2354 could try a lower bitrate. Increasing bitrates have diminishing
2355 returns, so while we might clearly see an improvement from 1800Kbit to
2356 2000Kbit, it might not be so noticeable above 2000Kbit. Feel
2357 free to experiment until you are happy.
2358 </para>
2359
2360 <para>
2361 Because we passed the source video through a denoise filter, you may want
2362 to add some of it back during playback. This, along with the
2363 <option>spp</option> post-processing filter, drastically improves the
2364 perception of quality and helps eliminate blocky artifacts in the video.
2365 With <application>MPlayer</application>'s <option>autoq</option> option,
2366 you can vary the amount of post-processing done by the spp filter
2367 depending on available CPU. Also, at this point, you may want to apply
2368 gamma and/or color correction to best suit your display. For example:
2369
2370 <screen>mplayer Harry_Potter_2.avi -vf spp,noise=9ah:5ah,eq2=1.2 -autoq 3</screen>
2371
2372 </para>
2373 </sect2>
2374 </sect1>
2375
2376
2377 <sect1 id="menc-feat-xvid">
2378 <title>Encoding with the <systemitem class="library">XviD</systemitem>
2379 codec</title>
2380 <para>
2381 <systemitem class="library">XviD</systemitem> is a free library for
2382 encoding MPEG-4 ASP video streams.
2383 Before starting to encode, you need to <link linkend="xvid">
2384 set up <application>MEncoder</application> to support it</link>.
2385 </para>
2386 <para>
2387 This guide mainly aims at featuring the same kind of information
2388 as x264's encoding guide.
2389 Therefore, please begin by reading
2390 <link linkend="menc-feat-x264-encoding-options-intro">the first part</link>
2391 of that guide.
2392 </para>
2393
2394
2395 <sect2 id="menc-feat-xvid-intro">
2396 <title>What options should I use to get the best results?</title>
2397
2398 <para>
2399 Please begin by reviewing the
2400 <systemitem class="library">XviD</systemitem> section of
2401 <application>MPlayer</application>'s man page.
2402 This section is intended to be a supplement to the man page.
2403 </para>
2404 <para>
2405 The XviD default settings are already a good tradeoff between
2406 speed and quality, therefore you can safely stick to them if
2407 the following section puzzles you.
2408 </para>
2409 </sect2>
2410
2411 <sect2 id="menc-feat-xvid-encoding-options">
2412 <title>Encoding options of <systemitem class="library">XviD</systemitem></title>
2413
2414 <itemizedlist>
2415 <listitem><para>
2416 <emphasis role="bold">vhq</emphasis>
2417 This setting affects the macroblock decision algorithm, where the
2418 higher the setting, the wiser the decision.
2419 The default setting may be safely used for every encode, while
2420 higher settings always help PSNR but are significantly slower.
2421 Please note that a better PSNR does not necessarily mean
2422 that the picture will look better, but tells you that it is
2423 closer to the original.
2424 Turning it off will noticeably speed up encoding; if speed is
2425 critical for you, the tradeoff may be worth it.
2426 </para></listitem>
2427
2428 <listitem><para>
2429 <emphasis role="bold">bvhq</emphasis>
2430 This does the same job as vhq, but does it on B-frames.
2431 It has a negligible impact on speed, and slightly improves quality
2432 (around +0.1dB PSNR).
2433 </para></listitem>
2434
2435 <listitem><para>
2436 <emphasis role="bold">max_bframes</emphasis>
2437 A higher number of consecutive allowed B-frames usually improves
2438 compressibility, although it may also lead to more blocking artifacts.
2439 The default setting is a good tradeoff between compressibility and
2440 quality, but you may increase it up to 3 if you are bitrate-starved.
2441 You may also decrease it to 1 or 0 if you are aiming at perfect
2442 quality, though in that case you should make sure your
2443 target bitrate is high enough to ensure that the encoder does not
2444 have to increase quantizers to reach it.
2445 </para></listitem>
2446
2447 <listitem><para>
2448 <emphasis role="bold">bf_threshold</emphasis>
2449 This controls the B-frame sensitivity of the encoder, where a higher
2450 value leads to more B-frames being used (and vice versa).
2451 This setting is to be used together with <option>max_bframes</option>;
2452 if you are bitrate-starved, you should increase both
2453 <option>max_bframes</option> and <option>bf_threshold</option>,
2454 while you may increase <option>max_bframes</option> and reduce
2455 <option>bf_threshold</option> so that the encoder may use more
2456 B-frames in places that only <emphasis role="bold">really</emphasis>
2457 need them.
2458 A low number of <option>max_bframes</option> and a high value of
2459 <option>bf_threshold</option> is probably not a wise choice as it
2460 will force the encoder to put B-frames in places that would not
2461 benefit from them, therefore reducing visual quality.
2462 However, if you need to be compatible with standalone players that
2463 only support old DivX profiles (which only supports up to 1
2464 consecutive B-frame), this would be your only way to
2465 increase compressibility through using B-frames.
2466 </para></listitem>
2467
2468 <listitem><para>
2469 <emphasis role="bold">trellis</emphasis>
2470 Optimizes the quantization process to get an optimal tradeoff
2471 between PSNR and bitrate, which allows significant bit saving.
2472 These bits will in return be spent elsewhere on the video,
2473 raising overall visual quality.
2474 You should always leave it on as its impact on quality is huge.
2475 Even if you are looking for speed, do not disable it until you
2476 have turned down <option>vhq</option> and all other more
2477 CPU-hungry options to the minimum.
2478 </para></listitem>
2479
2480 <listitem><para>
2481 <emphasis role="bold">hq_ac</emphasis>
2482 Activates a better coefficient cost estimation method, which slightly
2483 reduces filesize by around 0.15 to 0.19%, while having a negligible
2484 impact on speed.
2485 It is therefore recommended to always leave it on.
2486 </para></listitem>
2487
2488 <listitem><para>
2489 <emphasis role="bold">cartoon</emphasis>
2490 Designed to better encode cartoon content, and has no impact on
2491 speed as it just tunes the mode decision heuristics for this type
2492 of content.
2493 </para></listitem>
2494
2495 <listitem><para>
2496 <emphasis role="bold">me_quality</emphasis>
2497 This setting is to control the precision of the motion estimation.
2498 The higher <option>me_quality</option>, the more
2499 precise the estimation of the original motion will be, and the
2500 better the resulting clip will capture the original motion.
2501 </para>
2502 <para>
2503 The default setting is best in all cases;
2504 thus it is not recommended to turn it down unless you are
2505 really looking for speed, as all the bits saved by a good motion
2506 estimation would be spent elsewhere, raising overall quality.
2507 Therefore, do not go any lower than 5, and even that only as a last
2508 resort.
2509 </para></listitem>
2510
2511 <listitem><para>
2512 <emphasis role="bold">chroma_me</emphasis>
2513 Improves motion estimation by also taking the chroma (color)
2514 information into account, whereas <option>me_quality</option>
2515 alone only uses luma (grayscale).
2516 This slows down encoding by 5-10% but improves visual quality
2517 quite a bit by reducing blocking effects and reduces filesize by
2518 around 1.3%.
2519 If you are looking for speed, you should disable this option before
2520 starting to consider reducing <option>me_quality</option>.
2521 </para></listitem>
2522
2523 <listitem><para>
2524 <emphasis role="bold">chroma_opt</emphasis>
2525 Is intended to increase chroma image quality around pure
2526 white/black edges, rather than improving compression.
2527 This can help to reduce the "red stairs" effect.
2528 </para></listitem>
2529
2530 <listitem><para>
2531 <emphasis role="bold">lumi_mask</emphasis>
2532 Tries to give less bitrate to part of the picture that the
2533 human eye cannot see very well, which should allow the encoder
2534 to spend the saved bits on more important parts of the picture.
2535 The quality of the encode yielded by this option highly depends
2536 on personal preferences and on the type and monitor settings
2537 used to watch it (typically, it will not look as good if it is
2538 bright or if it is a TFT monitor).
2539 </para></listitem>
2540
2541 <listitem><para>
2542 <emphasis role="bold">qpel</emphasis>
2543 Raise the number of candidate motion vectors by increasing
2544 the precision of the motion estimation from halfpel to
2545 quarterpel.
2546 The idea is to find better motion vectors which will in return
2547 reduce bitrate (hence increasing quality).
2548 However, motion vectors with quarterpel precision require a
2549 few extra bits to code, but the candidate vectors do not always
2550 give (much) better results.
2551 Quite often, the codec still spends bits on the extra precision,
2552 but little or no extra quality is gained in return.
2553 Unfortunately, there is no way to foresee the possible gains of
2554 <option>qpel</option>, so you need to actually encode with and
2555 without it to know for sure.
2556 </para><para>
2557 <option>qpel</option> can be almost double encoding time, and
2558 requires as much as 25% more processing power to decode.
2559 It is not supported by all standalone players.
2560 </para></listitem>
2561
2562 <listitem><para>
2563 <emphasis role="bold">gmc</emphasis>
2564 Tries to save bits on panning scenes by using a single motion
2565 vector for the whole frame.
2566 This almost always raises PSNR, but significantly slows down
2567 encoding (as well as decoding).
2568 Therefore, you should only use it when you have turned
2569 <option>vhq</option> to the maximum.
2570 <systemitem class="library">XviD</systemitem>'s GMC is more
2571 sophisticated than DivX's, but is only supported by few
2572 standalone players.
2573 </para></listitem>
2574
2575 </itemizedlist>
2576 </sect2>
2577 </sect1>
2578
2579 <sect1 id="menc-feat-x264">
2580 <title>Encoding with the <systemitem class="library">x264</systemitem> codec</title>
2581 <para>
2582 <systemitem class="library">x264</systemitem> is a free library for
2583 encoding H.264/AVC video streams.
2584 Before starting to encode, you need to <link linkend="codec-x264-encode">
2585 set up <application>MEncoder</application> to support it</link>.
2586 </para>
2587
2588 <sect2 id="menc-feat-x264-encoding-options">
2589 <title>Encoding options of x264</title>
2590
2591 <para>
2592 Please begin by reviewing the
2593 <systemitem class="library">x264</systemitem> section of
2594 <application>MPlayer</application>'s man page.
2595 This section is intended to be a supplement to the man page.
2596 Here you will find quick hints about which options are most
2597 likely to interest most people. The man page is more terse,
2598 but also more exhaustive, and it sometimes offers much better
2599 technical detail.
2600 </para>
2601
2602 <sect3 id="menc-feat-x264-encoding-options-intro">
2603 <title>Introduction</title>
2604 <para>This guide considers two major categories of encoding options:</para>
2605
2606 <orderedlist>
2607 <listitem><para>Options which mainly trade off encoding time vs. quality
2608 </para></listitem>
2609 <listitem><para>Options which may be useful for fulfilling various personal
2610 preferences and special requirements</para></listitem>
2611 </orderedlist>
2612
2613 <para>
2614 Ultimately, only you can decide which options are best for your
2615 purposes. The decision for the first class of options is the simplest:
2616 you only have to decide whether you think the quality differences
2617 justify the speed differences. For the second class of options,
2618 preferences may be far more subjective, and more factors may be
2619 involved. Note that some of the "personal preferences and special
2620 requirements" options can still have large impacts on speed or quality,
2621 but that is not what they are primarily useful for. A couple of the
2622 "personal preference" options may even cause changes that look better
2623 to some people, but look worse to others.
2624 </para>
2625
2626 <para>
2627 Before continuing, you need to understand that this guide uses only one
2628 quality metric: global PSNR.
2629 For a brief explanation of what PSNR is, see
2630 <ulink url="http://en.wikipedia.org/wiki/PSNR">the Wikipedia article on PSNR</ulink>.
2631 Global PSNR is the last PSNR number reported when you include
2632 the <option>psnr</option> option in <option>x264encopts</option>.
2633 Any time you read a claim about PSNR, one of the assumptions
2634 behind the claim is that equal bitrates are used.
2635 </para>
2636
2637 <para>
2638 Nearly all of this guide's comments assume you are using
2639 two pass.
2640 When comparing options, there are two major reasons for using
2641 two pass encoding.
2642 First, using two pass often gains around 1dB PSNR, which is a
2643 very big difference.
2644 Secondly, testing options by doing direct quality comparisons
2645 with one pass encodes introduces a major confounding
2646 factor: bitrate often varies significantly with each encode.
2647 It is not always easy to tell whether quality changes are due
2648 mainly to changed options, or if they mostly reflect essentially
2649 random differences in the achieved bitrate.
2650 </para>
2651
2652 </sect3>
2653
2654 <sect3 id="menc-feat-x264-encoding-options-speedvquality">
2655 <title>Options which primarily affect speed and quality</title>
2656
2657 <itemizedlist>
2658 <listitem><para>
2659 <emphasis role="bold">subq</emphasis>:
2660 Of the options which allow you to trade off speed for quality,
2661 <option>subq</option> and <option>frameref</option> (see below) are usually
2662 by far the most important.
2663 If you are interested in tweaking either speed or quality, these
2664 are the first options you should consider.
2665 On the speed dimension, the <option>frameref</option> and
2666 <option>subq</option> options interact with each other fairly
2667 strongly.
2668 Experience shows that, with one reference frame,
2669 <option>subq=5</option> (the default setting) takes about 35% more time than
2670 <option>subq=1</option>.
2671 With 6 reference frames, the penalty grows to over 60%.
2672 <option>subq</option>'s effect on PSNR seems fairly constant
2673 regardless of the number of reference frames.
2674 Typically, <option>subq=5</option> achieves 0.2-0.5 dB higher global
2675 PSNR in comparison <option>subq=1</option>.
2676 This is usually enough to be visible.
2677 </para>
2678 <para>
2679 <option>subq=6</option> is the slowest, highest quality mode.
2680 In comparison to <option>subq=5</option>, it usually gains 0.1-0.4 dB
2681 global PSNR with speed costs varying from 25%-100%.
2682 Unlike other levels of <option>subq</option>, the behavior of
2683 <option>subq=6</option> does not depend much on <option>frameref</option>
2684 and <option>me</option>. Instead, the effectiveness of <option>subq=6
2685 </option> depends mostly upon the number of B-frames used. In normal
2686 usage, this means <option>subq=6</option> has a large impact on both speed
2687 and quality in complex, high motion scenes, but it may not have much effect
2688 in low-motion scenes. Note that it is still recommended to always set
2689 <option>bframes</option> to something other than zero (see below).
2690 </para></listitem>
2691 <listitem><para>
2692 <emphasis role="bold">frameref</emphasis>:
2693 <option>frameref</option> is set to 1 by default, but this
2694 should not be taken to imply that it is reasonable to set it
2695 to 1.
2696 Merely raising <option>frameref</option> to 2 gains around
2697 0.15dB PSNR with a 5-10% speed penalty; this seems like a
2698 good tradeoff.
2699 <option>frameref=3</option> gains around 0.25dB PSNR over
2700 <option>frameref=1</option>, which should be a visible
2701 difference.
2702 <option>frameref=3</option> is around 15% slower than
2703 <option>frameref=1</option>.
2704 Unfortunately, diminishing returns set in rapidly.
2705 <option>frameref=6</option> can be expected to gain only
2706 0.05-0.1 dB over <option>frameref=3</option> at an additional
2707 15% speed penalty.
2708 Above <option>frameref=6</option>, the quality gains are
2709 usually very small (although you should keep in mind throughout
2710 this whole discussion that it can vary quite a lot depending on
2711 your source).
2712 In a fairly typical case, <option>frameref=12</option>
2713 will improve global PSNR by a tiny 0.02dB over
2714 <option>frameref=6</option>, at a speed cost of 15%-20%.
2715 At such high <option>frameref</option> values, the only really
2716 good thing that can be said is that increasing it even further will
2717 almost certainly never <emphasis role="bold">harm</emphasis>
2718 PSNR, but the additional quality benefits are barely even
2719 measurable, let alone perceptible.
2720 </para>
2721 <note><title>Note:</title>
2722 <para>
2723 Raising <option>frameref</option> to unnecessarily high values
2724 <emphasis role="bold">can</emphasis> and
2725 <emphasis role="bold">usually does</emphasis>
2726 hurt coding efficiency if you turn CABAC off.
2727 With CABAC on (the default behavior), the possibility of setting
2728 <option>frameref</option> "too high" currently seems too remote
2729 to even worry about, and in the future, optimizations may remove
2730 the possibility altogether.
2731 </para>
2732 </note>
2733 <para>
2734 If you care about speed, a reasonable compromise is to use low
2735 <option>subq</option> and <option>frameref</option> values on
2736 the first pass, and then raise them on the second pass.
2737 Typically, this has a negligible negative effect on the final
2738 quality: You will probably lose well under 0.1dB PSNR, which
2739 should be much too small of a difference to see.
2740 However, different values of <option>frameref</option> can
2741 occasionally affect frametype decision.
2742 Most likely, these are rare outlying cases, but if you want to
2743 be pretty sure, consider whether your video has either
2744 fullscreen repetitive flashing patterns or very large temporary
2745 occlusions which might force an I-frame.
2746 Adjust the first-pass <option>frameref</option> so it is large
2747 enough to contain the duration of the flashing cycle (or occlusion).
2748 For example, if the scene flashes back and forth between two images
2749 over a duration of three frames, set the first pass
2750 <option>frameref</option> to 3 or higher.
2751 This issue is probably extremely rare in live action video material,
2752 but it does sometimes come up in video game captures.
2753 </para></listitem>
2754
2755 <listitem><para>
2756 <emphasis role="bold">me</emphasis>:
2757 This option is for choosing the motion estimation search method.
2758 Altering this option provides a straightforward quality-vs-speed
2759 tradeoff. <option>me=1</option> is only a few percent faster than
2760 the default search, at a cost of under 0.1dB global PSNR. The
2761 default setting (<option>me=2</option>) is a reasonable tradeoff
2762 between speed and quality. <option>me=3</option> gains a little under
2763 0.1dB global PSNR, with a speed penalty that varies depending on
2764 <option>frameref</option>. At high values of
2765 <option>frameref</option> (e.g. 12 or so), <option>me=3</option>
2766 is about 40% slower than the default <option> me=2</option>. With
2767 <option>frameref=3</option>, the speed penalty incurred drops to
2768 25%-30%.
2769 </para>
2770 <para>
2771 <option>me=4</option> uses an exhaustive search that is too slow for
2772 practical use.
2773 </para>
2774 </listitem>
2775
2776 <listitem><para>
2777 <emphasis role="bold">4x4mv</emphasis>:
2778 This option enables the use of 8x4, 4x8 and 4x4 subpartitions in
2779 predicted macroblocks. Enabling it results in a fairly consistent
2780 10%-15% loss of speed. This option is rather useless in source
2781 containing only low motion, however in some high-motion source,
2782 particularly source with lots of small moving objects, gains of
2783 about 0.1dB can be expected.
2784 </para>
2785 </listitem>
2786
2787 <listitem><para>
2788 <emphasis role="bold">bframes</emphasis>:
2789 If you are used to encoding with other codecs, you may have found
2790 that B-frames are not always useful.
2791 In H.264, this has changed: there are new techniques and block
2792 types that are possible in B-frames.
2793 Usually, even a naive B-frame choice algorithm can have a
2794 significant PSNR benefit.
2795 It is interesting to note that using B-frames usually speeds up
2796 the second pass somewhat, and may also speed up a single
2797 pass encode if adaptive B-frame decision is turned off.
2798 </para>
2799 <para>
2800 With adaptive B-frame decision turned off
2801 (<option>x264encopts</option>'s <option>nob_adapt</option>),
2802 the optimal value for this setting is usually no more than
2803 <option>bframes=1</option>, or else high-motion scenes can suffer.
2804 With adaptive B-frame decision on (the default behavior), it is
2805 safe to use higher values; the encoder will reduce the use of
2806 B-frames in scenes where they would hurt compression.
2807 The encoder rarely chooses to use more than 3 or 4 B-frames;
2808 setting this option any higher will have little effect.
2809 </para></listitem>
2810
2811 <listitem><para>
2812 <emphasis role="bold">b_adapt</emphasis>:
2813 Note: This is on by default.
2814 </para>
2815 <para>
2816 With this option enabled, the encoder will use a reasonably fast
2817 decision process to reduce the number of B-frames used in scenes that
2818 might not benefit from them as much.
2819 You can use <option>b_bias</option> to tweak how B-frame-happy
2820 the encoder is.
2821 The speed penalty of adaptive B-frames is currently rather modest,
2822 but so is the potential quality gain.
2823 It usually does not hurt, however.
2824 Note that this only affects speed and frametype decision on the
2825 first pass.
2826 <option>b_adapt</option> and <option>b_bias</option> have no
2827 effect on subsequent passes.
2828 </para></listitem>
2829
2830 <listitem><para>
2831 <emphasis role="bold">b_pyramid</emphasis>:
2832 You might as well enable this option if you are using >=2 B-frames;
2833 as the man page says, you get a little quality improvement at no
2834 speed cost.
2835 Note that these videos cannot be read by libavcodec-based decoders
2836 older than about March 5, 2005.
2837 </para></listitem>
2838
2839 <listitem><para>
2840 <emphasis role="bold">weight_b</emphasis>:
2841 In typical cases, there is not much gain with this option.
2842 However, in crossfades or fade-to-black scenes, weighted
2843 prediction gives rather large bitrate savings.
2844 In MPEG-4 ASP, a fade-to-black is usually best coded as a series
2845 of expensive I-frames; using weighted prediction in B-frames
2846 makes it possible to turn at least some of these into much smaller
2847 B-frames.
2848 Encoding time cost is minimal, as no extra decisions need to be made.
2849 Also, contrary to what some people seem to guess, the decoder
2850 CPU requirements are not much affected by weighted prediction,
2851 all else being equal.
2852 </para>
2853 <para>
2854 Unfortunately, the current adaptive B-frame decision algorithm
2855 has a strong tendency to avoid B-frames during fades.
2856 Until this changes, it may be a good idea to add
2857 <option>nob_adapt</option> to your x264encopts, if you expect
2858 fades to have a large effect in your particular video
2859 clip.
2860 </para></listitem>
2861 </itemizedlist>
2862 </sect3>
2863
2864 <sect3 id="menc-feat-x264-encoding-options-misc-preferences">
2865 <title>Options pertaining to miscellaneous preferences</title>
2866 <itemizedlist>
2867 <listitem><para>
2868 <emphasis role="bold">Two pass encoding</emphasis>:
2869 Above, it was suggested to always use two pass encoding, but there
2870 are still reasons for not using it. For instance, if you are capturing
2871 live TV and encoding in realtime, you are forced to use single-pass.
2872 Also, one pass is obviously faster than two passes; if you use the
2873 exact same set of options on both passes, two pass encoding is almost
2874 twice as slow.
2875 </para>
2876 <para>
2877 Still, there are very good reasons for using two pass encoding. For
2878 one thing, single pass ratecontrol isn't psychic, and it often makes
2879 unreasonable choices because it can't see the big picture. For example,
2880 suppose you have a two minute long video consisting of two distinct
2881 halves. The first half is a very high-motion scene lasting 60 seconds
2882 which, in isolation, requires about 2500kbps in order to look decent.
2883 Immediately following it is a much less demanding 60-second scene
2884 that looks good at 300kbps. Suppose you ask for 1400kbps on the theory
2885 that this is enough to accomodate both scenes. Single pass ratecontrol
2886 will make a couple of "mistakes" in such a case. First of all, it
2887 will target 1400kbps in both segments. The first segment may end up
2888 heavily overquantized, causing it to look unacceptably and unreasonably
2889 blocky. The second segment will be heavily underquantized; it may look
2890 perfect, but the bitrate cost of that perfection will be completely
2891 unreasonable. What's even harder to avoid is the problem at the
2892 transition between the two scenes. The first seconds of the low motion
2893 half will be hugely over-quantized, because the ratecontrol is still
2894 expecting the kind of bitrate requirements it met in the first half
2895 of the video. This "error period" of heavily over-quantized low motion
2896 will look jarringly bad, and will actually use less than the 300kbps
2897 it would have taken to make it look decent. There are ways to
2898 mitigate the pitfalls of single-pass encoding, but they may tend to
2899 increase bitrate misprediction.
2900 </para>
2901 <para>
2902 Multipass ratecontrol can offer huge advantages over a single pass.
2903 Using the statistics gathered from the first pass encode, the encoder
2904 can estimate, with reasonable accuracy, the "cost" (in bits) of
2905 encoding any given frame, at any given quantizer. This allows for
2906 a much more rational, better planned allocation of bits between the
2907 expensive (high-motion) and cheap (low-motion) scenes. See
2908 <option>qcomp</option> below for some ideas on how to tweak this
2909 allocation to your liking.
2910 </para>
2911 <para>
2912 Moreover, two passes need not take twice as long as one pass. You can
2913 tweak the options in the first pass for higher speed and lower quality.
2914 If you choose your options well, you can get a very fast first pass.
2915 The resulting quality in the second pass will be slightly lower because size
2916 prediction is less accurate, but the quality difference is normally much
2917 too small to be visible. Try, for example, adding
2918 <option>subq=1:frameref=1</option> to the first pass
2919 <option>x264encopts</option>. Then, on the second pass, use slower,
2920 higher-quality options:
2921 <option>subq=6:frameref=15:4x4mv:me=3</option>
2922 </para></listitem>
2923 <listitem><para>
2924 <emphasis role="bold">Three pass encoding</emphasis>?
2925
2926 x264 offers the ability to make an arbitrary number of consecutive
2927 passes. If you specify <option>pass=1</option> on the first pass,
2928 then use <option>pass=3</option> on a subsequent pass, the subsequent
2929 pass will both read the statistics from the previous pass, and write
2930 its own statistics. An additional pass following this one will have
2931 a very good base from which to make highly accurate predictions of
2932 framesizes at a chosen quantizer. In practice, the overall quality
2933 gain from this is usually close to zero, and quite possibly a third
2934 pass will result in slightly worse global PSNR than the pass before
2935 it. In typical usage, three passes help if you get either bad bitrate
2936 prediction or bad looking scene transitions when using only two passes.
2937 This is somewhat likely to happen on extremely short clips. There are
2938 also a few special cases in which three (or more) passes are handy
2939 for advanced users, but for brevity, this guide omits discussing those
2940 special cases.
2941
2942 </para></listitem>
2943 <listitem><para>
2944 <emphasis role="bold">qcomp</emphasis>:
2945 <option>qcomp</option> trades off the number of bits allocated
2946 to "expensive" high-motion versus "cheap" low-motion frames. At
2947 one extreme, <option>qcomp=0</option> aims for true constant
2948 bitrate. Typically this would make high-motion scenes look completely
2949 awful, while low-motion scenes would probably look absolutely
2950 perfect, but would also use many times more bitrate than they
2951 would need in order to look merely excellent. At the other extreme,
2952 <option>qcomp=1</option> achieves nearly constant quantization parameter
2953 (QP). Constant QP doesn't look bad, but most people think it's more
2954 reasonable to shave some bitrate off of the extremely expensive scenes
2955 (where the loss of quality isn't as noticeable) and reallocate it to
2956 the scenes that are easier to encode at excellent quality.
2957 <option>qcomp</option> is set to 0.6 by default, which may be slightly
2958 low for many peoples' taste (0.7-0.8 are also commonly used).
2959 </para></listitem>
2960 <listitem><para>
2961 <emphasis role="bold">keyint</emphasis>:
2962 <option>keyint</option> is solely for trading off file seekability against
2963 coding efficiency. By default, <option>keyint</option> is set to 250. In
2964 25fps material, this guarantees the ability to seek to within 10 seconds
2965 precision. If you think it would be important and useful to be able to
2966 seek within 5 seconds of precision, set <option>keyint=125</option>;
2967 this will hurt quality/bitrate slightly. If you care only about quality
2968 and not about seekability, you can set it to much higher values
2969 (understanding that there are diminishing returns which may become
2970 vanishingly low, or even zero). The video stream will still have seekable
2971 points as long as there are some scene changes.
2972 </para></listitem>
2973 <listitem><para>
2974 <emphasis role="bold">deblockalpha, deblockbeta</emphasis>:
2975 This topic is going to be a bit controversial.
2976 </para>
2977 <para>
2978 H.264 defines a simple deblocking procedure on I-blocks that uses
2979 pre-set strengths and thresholds depending on the QP of the block
2980 in question.
2981 By default, high QP blocks are filtered heavily, and low QP blocks
2982 are not deblocked at all.
2983 The pre-set strengths defined by the standard are well-chosen and
2984 the odds are very good that they are PSNR-optimal for whatever
2985 video you are trying to encode.
2986 The <option>deblockalpha</option> and <option>deblockbeta</option>
2987 parameters allow you to specify offsets to the preset deblocking
2988 thresholds.
2989 </para>
2990 <para>
2991 Many people seem to think it is a good idea to lower the deblocking
2992 filter strength by large amounts (say, -3).
2993 This is however almost never a good idea, and in most cases,
2994 people who are doing this do not understand very well how
2995 deblocking works by default.
2996 </para>
2997 <para>
2998 The first and most important thing to know about the in-loop
2999 deblocking filter is that the default thresholds are almost always
3000 PSNR-optimal.
3001 In the rare cases that they are not optimal, the ideal offset is
3002 plus or minus 1.
3003 Adjusting deblocking parameters by a larger amount is almost
3004 guaranteed to hurt PSNR.
3005 Strengthening the filter will smear more details; weakening the
3006 filter will increase the appearance of blockiness.
3007 </para>
3008 <para>
3009 It is definitely a bad idea to lower the deblocking thresholds if
3010 your source is mainly low in spacial complexity (i.e., not a lot
3011 of detail or noise).
3012 The in-loop filter does a rather excellent job of concealing
3013 the artifacts that occur.
3014 If the source is high in spacial complexity, however, artifacts
3015 are less noticeable.
3016 This is because the ringing tends to look like detail or noise.
3017 Human visual perception easily notices when detail is removed,
3018 but it does not so easily notice when the noise is wrongly
3019 represented.
3020 When it comes to subjective quality, noise and detail are somewhat
3021 interchangeable.
3022 By lowering the deblocking filter strength, you are most likely
3023 increasing error by adding ringing artifacts, but the eye does
3024 not notice because it confuses the artifacts with detail.
3025 </para>
3026
3027 <para>
3028 This <emphasis role="bold">still</emphasis> does not justify
3029 lowering the deblocking filter strength, however.
3030 You can generally get better quality noise from postprocessing.
3031 If your H.264 encodes look too blurry or smeared, try playing with
3032 <option>-vf noise</option> when you play your encoded movie.
3033 <option>-vf noise=8a:4a</option> should conceal most mild
3034 artifacting.
3035 It will almost certainly look better than the results you
3036 would have gotten just by fiddling with the deblocking filter.
3037 </para></listitem>
3038 </itemizedlist>
3039 </sect3>
3040 </sect2>
3041 </sect1>
3042
3043 <sect1 id="menc-feat-vcd-dvd">
3044 <title>Using MEncoder to create VCD/SVCD/DVD-compliant files.</title>
3045
3046 <sect2 id="menc-feat-vcd-dvd-constraints">
3047 <title>Format Constraints</title>
3048 <para>
3049 <application>MEncoder</application> is capable of creating VCD, SCVD
3050 and DVD format MPEG files using the
3051 <systemitem class="library">libavcodec</systemitem> library.
3052 These files can then be used in conjunction with
3053 <ulink url="http://www.gnu.org/software/vcdimager/vcdimager.html">vcdimager</ulink>
3054 or
3055 <ulink url="http://dvdauthor.sourceforge.net/">dvdauthor</ulink>
3056 to create discs that will play on a standard set-top player.
3057 </para>
3058
3059 <para>
3060 The DVD, SVCD, and VCD formats are subject to heavy constraints.
3061 Only a small selection of encoded picture sizes and aspect ratios are
3062 available.
3063 If your movie does not already meet these requirements, you may have
3064 to scale,crop or add black borders to the picture to make it
3065 compliant.
3066 </para>
3067
3068 <sect3 id="menc-feat-vcd-dvd-constraints-resolution">
3069 <title>Format Constraints</title>
3070
3071 <informaltable frame="all">
3072 <tgroup cols="9">
3073 <thead>
3074 <row>
3075 <entry>Format</entry>
3076 <entry>Resolution</entry>
3077 <entry>V. Codec</entry>
3078 <entry>V. Bitrate</entry>
3079 <entry>Sample Rate</entry>
3080 <entry>A. Codec</entry>
3081 <entry>A. Bitrate</entry>
3082 <entry>FPS</entry>
3083 <entry>Aspect</entry>
3084 </row>
3085 </thead>
3086 <tbody>
3087 <row>
3088 <entry>NTSC DVD</entry>
3089 <entry>720x480, 704x480, 352x480, 352x240</entry>
3090 <entry>MPEG-2</entry>
3091 <entry>9800 kbps</entry>
3092 <entry>48000 Hz</entry>
3093 <entry>AC3,PCM</entry>
3094 <entry>1536 kbps</entry>
3095 <entry>23.976, 29.97</entry>
3096 <entry>4:3, 16:9 (only for 720x480)</entry>
3097 </row>
3098 <row>
3099 <entry>NTSC DVD</entry>
3100 <entry>352x240<footnote id='fn-rare-resolutions'><para>
3101 These resolutions are rarely used for DVDs because
3102 they are fairly low quality.</para></footnote></entry>
3103 <entry>MPEG-1</entry>
3104 <entry>1856 kbps</entry>
3105 <entry>48000 Hz</entry>
3106 <entry>AC3,PCM</entry>
3107 <entry>1536 kbps</entry>
3108 <entry>23.976, 29.97</entry>
3109 <entry>4:3, 16:9</entry>
3110 </row>
3111 <row>
3112 <entry>NTSC SVCD</entry>
3113 <entry>480x480</entry>
3114 <entry>MPEG-2</entry>
3115 <entry>2600 kbps</entry>
3116 <entry>44100 Hz</entry>
3117 <entry>MP2</entry>
3118 <entry>384 kbps</entry>
3119 <entry>29.97</entry>
3120 <entry>4:3</entry>
3121 </row>
3122 <row>
3123 <entry>NTSC VCD</entry>
3124 <entry>352x240</entry>
3125 <entry>MPEG-1</entry>
3126 <entry>1150 kbps</entry>
3127 <entry>44100 Hz</entry>
3128 <entry>MP2</entry>
3129 <entry>224 kbps</entry>
3130 <entry>23.976, 29.97</entry>
3131 <entry>4:3</entry>
3132 </row>
3133 <row>
3134 <entry>PAL DVD</entry>
3135 <entry>720x576, 704x576, 352x576, 352x288</entry>
3136 <entry>MPEG-2</entry>
3137 <entry>9800 kbps</entry>
3138 <entry>48000 Hz</entry>
3139 <entry>MP2,AC3,PCM</entry>
3140 <entry>1536 kbps</entry>
3141 <entry>25</entry>
3142 <entry>4:3, 16:9 (only for 720x576)</entry>
3143 </row>
3144 <row>
3145 <entry>PAL DVD</entry>
3146 <entry>352x288<footnoteref linkend='fn-rare-resolutions'/></entry>
3147 <entry>MPEG-1</entry>
3148 <entry>1856 kbps</entry>
3149 <entry>48000 Hz</entry>
3150 <entry>MP2,AC3,PCM</entry>
3151 <entry>1536 kbps</entry>
3152 <entry>25</entry>
3153 <entry>4:3, 16:9</entry>
3154 </row>
3155 <row>
3156 <entry>PAL SVCD</entry>
3157 <entry>480x576</entry>
3158 <entry>MPEG-2</entry>
3159 <entry>2600 kbps</entry>
3160 <entry>44100 Hz</entry>
3161 <entry>MP2</entry>
3162 <entry>384 kbps</entry>
3163 <entry>25</entry>
3164 <entry>4:3</entry>
3165 </row>
3166 <row>
3167 <entry>PAL VCD</entry>
3168 <entry>352x288</entry>
3169 <entry>MPEG-1</entry>
3170 <entry>1150 kbps</entry>
3171 <entry>44100 Hz</entry>
3172 <entry>MP2</entry>
3173 <entry>224 kbps</entry>
3174 <entry>25</entry>
3175 <entry>4:3</entry>
3176 </row>
3177 </tbody>
3178 </tgroup>
3179 </informaltable>
3180
3181 <para>
3182 If your movie has 2.35:1 aspect (most recent action movies), you will
3183 have to add black borders or crop the movie down to 16:9 to make a DVD
3184 or VCD.
3185 If you add black borders, try to align them at 16-pixel boundaries in
3186 order to minimize the impact on encoding performance.
3187 Thankfully DVD has sufficiently excessive bitrate that you do not have
3188 to worry too much about encoding efficiency, but SVCD and VCD are
3189 highly bitrate-starved and require effort to obtain acceptable quality.
3190 </para>
3191 </sect3>
3192
3193 <sect3 id="menc-feat-vcd-dvd-constraints-gop">
3194 <title>GOP Size Constraints</title>
3195 <para>
3196 DVD, VCD, and SVCD also constrain you to relatively low
3197 GOP (Group of Pictures) sizes.
3198 For 30 fps material the largest allowed GOP size is 18.
3199 For 25 or 24 fps, the maximum is 15.
3200 The GOP size is set using the <option>keyint</option> option.
3201 </para>
3202 </sect3>
3203
3204 <sect3 id="menc-feat-vcd-dvd-constraints-bitrate">
3205 <title>Bitrate Constraints</title>
3206 <para>
3207 VCD video is required to be CBR at 1152 kbps.
3208 This highly limiting constraint also comes along with an extremly low vbv
3209 buffer size of 327 kilobits.
3210 SVCD allows varying video bitrates up to 2500 kbps, and a somewhat less
3211 restrictive vbv buffer size of 917 kilobits is allowed.
3212 DVD video bitrates may range anywhere up to 9800 kbps (though typical
3213 bitrates are about half that), and the vbv buffer size is 1835 kilobits.
3214 </para>
3215 </sect3>
3216 </sect2>
3217
3218 <sect2 id="menc-feat-vcd-dvd-output">
3219 <title>Output Options</title>
3220 <para>
3221 <application>MEncoder</application> has options to control the output
3222 format.
3223 Using these options we can instruct it to create the correct type of
3224 file.
3225 </para>
3226
3227 <para>
3228 The options for VCD and SVCD are called xvcd and xsvcd, because they
3229 are extended formats.
3230 They are not strictly compliant, mainly because the output does not
3231 contain scan offsets.
3232 If you need to generate an SVCD image, you should pass the output file
3233 to
3234 <ulink url="http://www.gnu.org/software/vcdimager/vcdimager.html">vcdimager</ulink>.
3235 </para>
3236
3237 <para>
3238 VCD:
3239 <screen>
3240 -of mpeg -mpegopts format=xvcd
3241 </screen>
3242 </para>
3243
3244 <para>
3245 SVCD:
3246 <screen>
3247 -of mpeg -mpegopts format=xsvcd
3248 </screen>
3249 </para>
3250
3251 <para>
3252 DVD:
3253 <screen>
3254 -of mpeg -mpegopts format=dvd
3255 </screen>
3256 </para>
3257
3258 <sect3 id="menc-feat-vcd-dvd-output-aspect">
3259 <title>Aspect Ratio</title>
3260 <para>
3261 The aspect argument of <option>-lavcopts</option> is used to encode
3262 the aspect ratio of the file.
3263 During playback the aspect ratio is used to restore the video to the
3264 correct size.
3265 </para>
3266
3267 <para>
3268 16:9 or "Widescreen"
3269 <screen>
3270 -lavcopts aspect=16/9
3271 </screen>
3272 </para>
3273
3274 <para>
3275 4:3 or "Fullscreen"
3276 <screen>
3277 -lavcopts aspect=4/3
3278 </screen>
3279 </para>
3280
3281 <para>
3282 2.35:1 or "Cinemascope" NTSC
3283 <screen>
3284 -vf scale=720:368,expand=720:480 -lavcopts aspect=16/9
3285 </screen>
3286 To calculate the correct scaling size, use the expanded NTSC width of
3287 854/2.35 = 368
3288 </para>
3289
3290 <para>
3291 2.35:1 or "Cinemascope" PAL
3292 <screen>
3293 -vf scale="720:432,expand=720:576 -lavcopts aspect=16/9
3294 </screen>
3295 To calculate the correct scaling size, use the expanded PAL width of
3296 1024/2.35 = 432
3297 </para>
3298
3299 </sect3>
3300
3301 <sect3 id="menc-feat-vcd-dvd-output-srate">
3302 <title>Sample Rate Conversion</title>
3303 <para>
3304 If the audio sample rate in the original file is not the same as
3305 required by the target format, sample rate conversion is required.
3306 This is achieved using the <option>-srate</option> option and
3307 the <option>-af lavcresample</option> audio filter together.
3308 </para>
3309 <para>
3310 DVD:
3311 <screen>
3312 -srate 48000 -af lavcresample=48000
3313 </screen>
3314 </para>
3315 <para>
3316 VCD and SVCD:
3317 <screen>
3318 -srate 44100 -af lavcresample=44100
3319 </screen>
3320 </para>
3321 </sect3>
3322 </sect2>
3323
3324 <sect2 id="menc-feat-vcd-dvd-lavc">
3325 <title>Using libavcodec for VCD/SVCD/DVD Encoding</title>
3326
3327 <sect3 id="menc-feat-vcd-dvd-lavc-intro">
3328 <title>Introduction</title>
3329 <para>
3330 <systemitem class="library">libavcodec</systemitem> can be used to
3331 create VCD/SVCD/DVD compliant video by using the appropriate options.
3332 </para>
3333 </sect3>
3334
3335 <sect3 id="menc-feat-vcd-dvd-lavc-options">
3336 <title>lavcopts</title>
3337 <para>
3338 This is a list of fields in <option>-lavcopts</option> that you may
3339 be required to change in order to make a complaint movie for VCD, SVCD,
3340 or DVD:
3341 </para>
3342
3343 <itemizedlist>
3344 <listitem><para>
3345 <emphasis role="bold">acodec</emphasis>:
3346 <option>mp2</option> for VCD, SVCD, or PAL DVD;
3347 <option>ac3</option> is most commonly used for DVD.
3348 PCM audio may also be used for DVD, but this is mostly a big waste of
3349 space.
3350 Note that MP3 audio is not compliant for any of these formats, but
3351 players often have no problem playing it anyway.
3352 </para></listitem>
3353
3354 <listitem><para>
3355 <emphasis role="bold">abitrate</emphasis>:
3356 224 for VCD; up to 384 for SVCD; up to 1536 for DVD, but commonly
3357 used values range from 192 kbps for stereo to 384 kbps for 5.1 channel
3358 sound.
3359 </para></listitem>
3360
3361 <listitem><para>
3362 <emphasis role="bold">vcodec</emphasis>:
3363 <option>mpeg1video</option> for VCD;
3364 <option>mpeg2video</option> for SVCD;
3365 <option>mpeg2video</option> is usually used for DVD but you may also use
3366 <option>mpeg1video</option> for CIF resolutions.
3367 </para></listitem>
3368
3369 <listitem><para>
3370 <emphasis role="bold">keyint</emphasis>:
3371 Used to set the GOP size.
3372 18 for 30fps material, or 15 for 25/24 fps material.
3373 Commercial producers seem to prefer keyframe intervals of 12.
3374 It is possible to make this much larger and still retain compatibility
3375 with most players.
3376 A <option>keyint</option> of 25 should never cause any problems.
3377 </para></listitem>
3378
3379 <listitem><para>
3380 <emphasis role="bold">vrc_buf_size</emphasis>:
3381 327 for VCD, 917 for SVCD, and 1835 for DVD.
3382 </para></listitem>
3383
3384 <listitem><para>
3385 <emphasis role="bold">vrc_minrate</emphasis>:
3386 1152, for VCD. May be left alone for SVCD and DVD.
3387 </para></listitem>
3388
3389 <listitem><para>
3390 <emphasis role="bold">vrc_maxrate</emphasis>:
3391 1152 for VCD; 2500 for SVCD; 9800 for DVD.
3392 For SVCD and DVD, you might wish to use lower values depending on your
3393 own personal preferences and requirements.
3394 </para></listitem>
3395
3396 <listitem><para>
3397 <emphasis role="bold">vbitrate</emphasis>:
3398 1152 for VCD;
3399 up to 2500 for SVCD;
3400 up to 9800 for DVD.
3401 For the latter two formats, vbitrate should be set based on personal
3402 preference.
3403 For instance, if you insist on fitting 20 or so hours on a DVD, you
3404 could use vbitrate=400.
3405 The resulting video quality would probably be quite bad.
3406 If you are trying to squeeze out the maximum possible quality on a DVD,
3407 use vbitrate=9800, but be warned that this could constrain you to less
3408 than an hour of video on a single-layer DVD.
3409 </para></listitem>
3410 </itemizedlist>
3411 </sect3>
3412
3413 <sect3 id="menc-feat-vcd-dvd-lavc-examples">
3414 <title>Examples</title>
3415 <para>
3416 This is a typical minimum set of <option>-lavcopts</option> for
3417 encoding video:
3418 </para>
3419 <para>
3420 VCD:
3421 <screen>
3422 -lavcopts vcodec=mpeg1video:vrc_buf_size=327:vrc_minrate=1152:\
3423 vrc_maxrate=1152:vbitrate=1152:keyint=15:acodec=mp2
3424 </screen>
3425 </para>
3426
3427 <para>
3428 SVCD:
3429 <screen>
3430 -lavcopts vcodec=mpeg2video:vrc_buf_size=917:vrc_maxrate=2500:vbitrate=1800:\
3431 keyint=15:acodec=mp2
3432 </screen>
3433 </para>
3434
3435 <para>
3436 DVD:
3437 <screen>
3438 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
3439 keyint=15:acodec=ac3
3440 </screen>
3441 </para>
3442
3443 </sect3>
3444
3445 <sect3 id="menc-feat-vcd-dvd-lavc-advanced">
3446 <title>Advanced Options</title>
3447 <para>
3448 For higher quality encoding, you may also wish to add quality-enhancing
3449 options to lavcopts, such as <option>trell</option>,
3450 <option>mbd=2</option>, and others.
3451 Note that <option>qpel</option> and <option>v4mv</option>, while often
3452 useful with MPEG-4, are not usable with MPEG-1 or MPEG-2.
3453 Also, if you are trying to make a very high quality DVD encode, it may
3454 be useful to add <option>dc=10</option> to lavcopts.
3455 Doing so may help reduce the appearance of blocks in flat-colored areas.
3456 Putting it all together, this is an example of a set of lavcopts for a
3457 higher quality DVD:
3458 </para>
3459
3460 <para>
3461 <screen>
3462 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=8000:\
3463 keyint=15:trell:mbd=2:precmp=2:subcmp=2:cmp=2:dia=-10:predia=-10:cbp:mv0:\
3464 vqmin=1:lmin=1:dc=10
3465 </screen>
3466 </para>
3467
3468 </sect3>
3469 </sect2>
3470
3471 <sect2 id="menc-feat-vcd-dvd-audio">
3472 <title>Encoding Audio</title>
3473 <para>
3474 VCD and SVCD support MPEG-1 layer II audio, using one of
3475 <systemitem class="library">toolame</systemitem>,
3476 <systemitem class="library">twolame</systemitem>,
3477 or <systemitem class="library">libavcodec</systemitem>'s MP2 encoder.
3478 The libavcodec MP2 is far from being as good as the other two libraries,
3479 however it should always be available to use.
3480 VCD only supports constant bitrate audio (CBR) whereas SVCD supports
3481 variable bitrate (VBR), too.
3482 Be careful when using VBR because some bad standalone players might not
3483 support it too well.
3484 </para>
3485
3486 <para>
3487 For DVD audio, <systemitem class="library">libavcodec</systemitem>'s
3488 AC3 codec is used.
3489 </para>
3490
3491 <sect3 id="menc-feat-vcd-dvd-audio-toolame">
3492 <title>toolame</title>
3493 <para>
3494 For VCD and SVCD:
3495 <screen>
3496 -oac toolame -toolameopts br=224
3497 </screen>
3498 </para>
3499 </sect3>
3500
3501 <sect3 id="menc-feat-vcd-dvd-audio-twolame">
3502 <title>twolame</title>
3503 <para>
3504 For VCD and SVCD:
3505 <screen>
3506 -oac twolame -twolameopts br=224
3507 </screen>
3508 </para>
3509 </sect3>
3510
3511 <sect3 id="menc-feat-vcd-dvd-audio-lavc">
3512 <title>libavcodec</title>
3513 <para>
3514 For DVD with 2 channel sound:
3515 <screen>
3516 -oac lavc -lavcopts acodec=ac3:abitrate=192
3517 </screen>
3518 </para>
3519 <para>
3520 For DVD with 5.1 channel sound:
3521 <screen>
3522 -channels 6 -oac lavc -lavcopts acodec=ac3:abitrate=384
3523 </screen>
3524 </para>
3525 <para>
3526 For VCD and SVCD:
3527 <screen>
3528 -oac lavc -lavcopts acodec=mp2:abitrate=224
3529 </screen>
3530 </para>
3531 </sect3>
3532
3533 </sect2>
3534
3535 <sect2 id="menc-feat-vcd-dvd-all">
3536 <title>Putting it all Together</title>
3537 <para>
3538 This section shows some complete commands for creating VCD/SVCD/DVD
3539 compliant videos.
3540 </para>
3541
3542 <sect3 id="menc-feat-vcd-dvd-all-pal-dvd">
3543 <title>PAL DVD</title>
3544 <para>
3545 <screen>
3546 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,\
3547 harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:\
3548 vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:acodec=ac3:\
3549 abitrate=192:aspect=16/9 -ofps 25 \
3550 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
3551 </screen>
3552 </para>
3553 </sect3>
3554
3555 <sect3 id="menc-feat-vcd-dvd-all-ntsc-dvd">
3556 <title>NTSC DVD</title>
3557 <para>
3558 <screen>
3559 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:480,\
3560 harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:\
3561 vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:acodec=ac3:\
3562 abitrate=192:aspect=16/9 -ofps 30000/1001 \
3563 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
3564 </screen>
3565 </para>
3566 </sect3>
3567
3568 <sect3 id="menc-feat-vcd-dvd-all-pal-ac3-copy">
3569 <title>PAL AVI Containing AC3 Audio to DVD</title>
3570 <para>
3571 If the source already has AC3 audio, use -oac copy instead of re-encoding it.
3572 <screen>
3573 mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:576,\
3574 harddup -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:\
3575 vbitrate=5000:keyint=15:aspect=16/9 -ofps 25 \
3576 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
3577 </screen>
3578 </para>
3579 </sect3>
3580
3581 <sect3 id="menc-feat-vcd-dvd-all-ntsc-ac3-copy">
3582 <title>NTSC AVI Containing AC3 Audio to DVD</title>
3583 <para>
3584 If the source already has AC3 audio, and is NTSC @ 23.976 fps:
3585 <screen>
3586 mencoder -oac copy -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:480,\
3587 harddup -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:\
3588 vbitrate=5000:keyint=15:aspect=16/9 -ofps 24000/1001 \
3589 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
3590 </screen>
3591 </para>
3592 </sect3>
3593
3594 <sect3 id="menc-feat-vcd-dvd-all-pal-svcd">
3595 <title>PAL SVCD</title>
3596 <para>
3597 <screen>
3598 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xsvcd -vf \
3599 scale=480:576,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
3600 vcodec=mpeg2video:mbd=2:keyint=15:vrc_buf_size=917:vrc_minrate=600:\
3601 vbitrate=2500:vrc_maxrate=2500:acodec=mp2:abitrate=224 -ofps 25 \
3602 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
3603 </screen>
3604 </para>
3605 </sect3>
3606
3607 <sect3 id="menc-feat-vcd-dvd-all-ntsc-svcd">
3608 <title>NTSC SVCD</title>
3609 <para>
3610 <screen>
3611 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xsvcd -vf \
3612 scale=480:480,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
3613 vcodec=mpeg2video:mbd=2:keyint=18:vrc_buf_size=917:vrc_minrate=600:\
3614 vbitrate=2500:vrc_maxrate=2500:acodec=mp2:abitrate=224 -ofps 30000/1001 \
3615 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
3616 </screen>
3617 </para>
3618 </sect3>
3619
3620 <sect3 id="menc-feat-vcd-dvd-all-pal-vcd">
3621 <title>PAL VCD</title>
3622 <para>
3623 <screen>
3624 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf \
3625 scale=352:288,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
3626 vcodec=mpeg1video:keyint=15:vrc_buf_size=327:vrc_minrate=1152:vbitrate=1152:\
3627 vrc_maxrate=1152:acodec=mp2:abitrate=224 -ofps 25 \
3628 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
3629 </screen>
3630 </para>
3631 </sect3>
3632
3633 <sect3 id="menc-feat-vcd-dvd-all-ntsc-vcd">
3634 <title>NTSC VCD</title>
3635 <para>
3636 <screen>
3637 mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf \
3638 scale=352:240,harddup -srate 44100 -af lavcresample=44100 -lavcopts \
3639 vcodec=mpeg1video:keyint=18:vrc_buf_size=327:vrc_minrate=1152:vbitrate=1152:\
3640 vrc_maxrate=1152:acodec=mp2:abitrate=224 -ofps 30000/1001 \
3641 -o <replaceable>movie.mpg</replaceable> <replaceable>movie.avi</replaceable>
3642 </screen>
3643 </para>
3644 </sect3>
3645
3646 </sect2>
3647
3648 </sect1>
3649
3650 </chapter>