comparison DOCS/xml/en/mencoder.xml @ 15915:b3924612667a

Update of the x264 encoding guide: - Reorganized things, options are now divided into "speed vs quality" and "other" (more or less). subq is now where it belongs. - subq=6 is documented - explanation of what 2-pass really does, and why you'd better use it - mention 3-pass (and the fact that it usually doesn't help) - documented qcomp - documented keyint (not like it needed any more explanation, though) - deblocking parameter tweaking no longer categorized as options that "affect speed and quality ;) - updated example cpu requirements for decoding, in codecs.xml (720x480 @ 1500kbps 50%->35%, for my CPU)
author gpoirier
date Mon, 04 Jul 2005 05:37:27 +0000
parents c4974449b18c
children ad2a3e29c0d1
comparison
equal deleted inserted replaced
15914:4a643fe42324 15915:b3924612667a
2117 encoding H.264/AVC video streams. 2117 encoding H.264/AVC video streams.
2118 Before starting to encode, you need to <link linkend="codec-x264-encode"> 2118 Before starting to encode, you need to <link linkend="codec-x264-encode">
2119 set up <application>MEncoder</application> to support it</link>. 2119 set up <application>MEncoder</application> to support it</link>.
2120 </para> 2120 </para>
2121 2121
2122 <sect2 id="menc-feat-x264-intro"> 2122 <sect2 id="menc-feat-x264-encoding-options">
2123 <title>What options should I use to get the best results?</title> 2123 <title>Encoding options of x264</title>
2124 2124
2125 <para> 2125 <para>
2126 Please begin by reviewing the 2126 Please begin by reviewing the
2127 <systemitem class="library">x264</systemitem> section of 2127 <systemitem class="library">x264</systemitem> section of
2128 <application>MPlayer</application>'s man page. 2128 <application>MPlayer</application>'s man page.
2129 This section is intended to be a supplement to the man page. 2129 This section is intended to be a supplement to the man page.
2130 </para> 2130 Here you will find quick hints about which options are most
2131 likely to interest most people. The man page is more terse,
2132 but also more exhaustive, and it sometimes offers much better
2133 technical detail.
2134 </para>
2135
2136 <sect3 id="menc-feat-x264-encoding-options-intro">
2137 <title>Introduction</title>
2138 <para>This guide considers two major categories of encoding options:</para>
2131 2139
2132 <orderedlist> 2140 <orderedlist>
2133 <title>There are mainly three types of considerations when choosing encoding 2141 <listitem><para>Options which mainly trade off encoding time vs. quality
2134 options:</title> 2142 </para></listitem>
2135 <listitem><para>Trading off encoding time vs. quality</para></listitem> 2143 <listitem><para>Options which may be useful for fulfilling various personal
2136 <listitem><para>Frame type decision options</para></listitem> 2144 preferences and special requirements</para></listitem>
2137 <listitem><para>Ratecontrol and quantization decision options</para></listitem>
2138 </orderedlist> 2145 </orderedlist>
2139 2146
2140 <para> 2147 <para>
2141 This guide is mostly concerned with the first class of options. 2148 Ultimately, only you can decide which options are best for your
2142 The other two types often have more to do with personal 2149 purposes. The decision for the first class of options is the simplest:
2143 preferences and individual requirements. 2150 you only have to decide whether you think the quality differences
2144 </para> 2151 justify the speed differences. For the second class of options,
2145 2152 preferences may be far more subjective, and more factors may be
2146 <para> 2153 involved. Note that some of the "personal preferences and special
2147 Before continuing, please note that this guide uses only one 2154 requirements" options can still have large impacts on speed or quality,
2155 but that is not what they are primarily useful for. A couple of the
2156 "personal preference" options may even cause changes that look better
2157 to some people, but look worse to others.
2158 </para>
2159
2160 <para>
2161 Before continuing, you need to understand that this guide uses only one
2148 quality metric: global PSNR. 2162 quality metric: global PSNR.
2149 For a brief explanation of what PSNR is, see 2163 For a brief explanation of what PSNR is, see
2150 <ulink url="http://en.wikipedia.org/wiki/PSNR">the Wikipedia article on PSNR</ulink>. 2164 <ulink url="http://en.wikipedia.org/wiki/PSNR">the Wikipedia article on PSNR</ulink>.
2151 Global PSNR is the last PSNR number reported when you include 2165 Global PSNR is the last PSNR number reported when you include
2152 the <option>psnr</option> option in <option>x264encopts</option>. 2166 the <option>psnr</option> option in <option>x264encopts</option>.
2160 When comparing options, there are two major reasons for using 2174 When comparing options, there are two major reasons for using
2161 two pass encoding. 2175 two pass encoding.
2162 First, using two pass often gains around 1dB PSNR, which is a 2176 First, using two pass often gains around 1dB PSNR, which is a
2163 very big difference. 2177 very big difference.
2164 Secondly, testing options by doing direct quality comparisons 2178 Secondly, testing options by doing direct quality comparisons
2165 with one pass encodes is a dubious proposition because bitrate 2179 with one pass encodes introduces a major confounding
2166 often varies significantly with each encode. 2180 factor: bitrate often varies significantly with each encode.
2167 It is not always easy to tell whether quality changes are due 2181 It is not always easy to tell whether quality changes are due
2168 mainly to changed options, or if they mostly reflect 2182 mainly to changed options, or if they mostly reflect essentially
2169 differences in the achieved bitrate. 2183 random differences in the achieved bitrate.
2170 </para> 2184 </para>
2171 2185
2172 <para> 2186 </sect3>
2187
2188 <sect3 id="menc-feat-x264-encoding-options-speedvquality">
2189 <title>Options which primarily affect speed and quality</title>
2190
2191 <itemizedlist>
2192 <listitem><para>
2193 <emphasis role="bold">subq</emphasis>:
2173 Of the options which allow you to trade off speed for quality, 2194 Of the options which allow you to trade off speed for quality,
2174 <option>subq</option> and <option>frameref</option> are usually 2195 <option>subq</option> and <option>frameref</option> (see below) are usually
2175 by far the most important. 2196 by far the most important.
2176 If you are interested in tweaking either speed or quality, these 2197 If you are interested in tweaking either speed or quality, these
2177 are the first options you should consider. 2198 are the first options you should consider.
2178 </para>
2179
2180 <para>
2181 On the speed dimension, the <option>frameref</option> and 2199 On the speed dimension, the <option>frameref</option> and
2182 <option>subq</option> options interact with each other fairly 2200 <option>subq</option> options interact with each other fairly
2183 strongly. 2201 strongly.
2184 Experience shows that, with one reference frame, 2202 Experience shows that, with one reference frame,
2185 <option>subq=5</option> takes about 35% more time than 2203 <option>subq=5</option> (the default setting) takes about 35% more time than
2186 <option>subq=1</option>. 2204 <option>subq=1</option>.
2187 With 6 reference frames, the penalty grows to over 60%. 2205 With 6 reference frames, the penalty grows to over 60%.
2188 <option>subq</option>'s effect on PSNR seems fairly constant 2206 <option>subq</option>'s effect on PSNR seems fairly constant
2189 regardless of the number of reference frames. 2207 regardless of the number of reference frames.
2190 Typically, <option>subq=5</option> gains 0.2-0.5 dB 2208 Typically, <option>subq=5</option> achieves 0.2-0.5 dB higher global
2191 global PSNR over <option>subq=1</option>. 2209 PSNR in comparison <option>subq=1</option>.
2192 This is usually enough to be visible. 2210 This is usually enough to be visible.
2193 </para> 2211 </para>
2194 2212 <para>
2195 </sect2> 2213 <option>subq=6</option> is the slowest, highest quality mode.
2196 2214 In comparison to <option>subq=5</option>, it usually gains 0.1-0.4 dB
2197 <sect2 id="menc-feat-x264-encoding-options"> 2215 global PSNR with speed costs varying from 25%-100%.
2198 <title>Encoding options of x264</title> 2216 Unlike other levels of <option>subq</option>, the behavior of
2199 2217 <option>subq=6</option> does not depend much on <option>frameref</option>
2200 <itemizedlist> 2218 and <option>me</option>. Instead, the effectiveness of <option>subq=6
2219 </option> depends mostly upon the number of B-frames used. In normal
2220 usage, this means <option>subq=6</option> has a large impact on both speed
2221 and quality in complex, high motion scenes, but it may not have much effect
2222 in low-motion scenes. Note that it is still recommended to always set
2223 <option>bframes</option> to something other than zero (see below).
2224 </para></listitem>
2201 <listitem><para> 2225 <listitem><para>
2202 <emphasis role="bold">frameref</emphasis>: 2226 <emphasis role="bold">frameref</emphasis>:
2203 <option>frameref</option> is set to 1 by default, but this 2227 <option>frameref</option> is set to 1 by default, but this
2204 should not be taken to imply that it is reasonable to set it 2228 should not be taken to imply that it is reasonable to set it
2205 to 1. 2229 to 1.
2221 your source). 2245 your source).
2222 In a fairly typical case, <option>frameref=12</option> 2246 In a fairly typical case, <option>frameref=12</option>
2223 will improve global PSNR by a tiny 0.02dB over 2247 will improve global PSNR by a tiny 0.02dB over
2224 <option>frameref=6</option>, at a speed cost of 15%-20%. 2248 <option>frameref=6</option>, at a speed cost of 15%-20%.
2225 At such high <option>frameref</option> values, the only really 2249 At such high <option>frameref</option> values, the only really
2226 good thing that can be said is that increasing even further will 2250 good thing that can be said is that increasing it even further will
2227 almost certainly never <emphasis role="bold">harm</emphasis> 2251 almost certainly never <emphasis role="bold">harm</emphasis>
2228 PSNR, but the additional quality benefits are barely even 2252 PSNR, but the additional quality benefits are barely even
2229 measurable, let alone perceptible. 2253 measurable, let alone perceptible.
2230 </para> 2254 </para>
2231 <note><title>Note:</title> 2255 <note><title>Note:</title>
2294 </para> 2318 </para>
2295 </listitem> 2319 </listitem>
2296 2320
2297 <listitem><para> 2321 <listitem><para>
2298 <emphasis role="bold">bframes</emphasis>: 2322 <emphasis role="bold">bframes</emphasis>:
2299 The usefulness of B-frames is questionable in most other codecs 2323 If you are used to encoding with other codecs, you may have found
2300 you may be used to. 2324 that B-frames are not always useful.
2301 In H.264, this has changed: there are new techniques and block 2325 In H.264, this has changed: there are new techniques and block
2302 types that are possible in B-frames. 2326 types that are possible in B-frames.
2303 Usually, even a naive B-frame choice algorithm can have a 2327 Usually, even a naive B-frame choice algorithm can have a
2304 significant PSNR benefit. 2328 significant PSNR benefit.
2305 It is interesting to note that using B-frames usually speeds up 2329 It is interesting to note that using B-frames usually speeds up
2306 the second pass somewhat, and may also speed up a single pass 2330 the second pass somewhat, and may also speed up a single
2307 encode if adaptive B-frame decision is turned off. 2331 pass encode if adaptive B-frame decision is turned off.
2308 </para> 2332 </para>
2309 <para> 2333 <para>
2310 With adaptive B-frame decision turned off 2334 With adaptive B-frame decision turned off
2311 (<option>x264encopts</option>'s <option>nob_adapt</option>), 2335 (<option>x264encopts</option>'s <option>nob_adapt</option>),
2312 the optimal value for this setting is usually no more than 2336 the optimal value for this setting is usually no more than
2321 <listitem><para> 2345 <listitem><para>
2322 <emphasis role="bold">b_adapt</emphasis>: 2346 <emphasis role="bold">b_adapt</emphasis>:
2323 Note: This is on by default. 2347 Note: This is on by default.
2324 </para> 2348 </para>
2325 <para> 2349 <para>
2326 With this option enabled, the encoder will use some simple 2350 With this option enabled, the encoder will use a reasonably fast
2327 heuristics to reduce the number of B-frames used in scenes that 2351 decision process to reduce the number of B-frames used in scenes that
2328 might not benefit from them as much. 2352 might not benefit from them as much.
2329 You can use <option>b_bias</option> to tweak how B-frame-happy 2353 You can use <option>b_bias</option> to tweak how B-frame-happy
2330 the encoder is. 2354 the encoder is.
2331 The speed penalty of adaptive B-frames is currently rather modest, 2355 The speed penalty of adaptive B-frames is currently rather modest,
2332 but so is the potential quality gain. 2356 but so is the potential quality gain.
2351 In typical cases, there is not much gain with this option. 2375 In typical cases, there is not much gain with this option.
2352 However, in crossfades or fade-to-black scenes, weighted 2376 However, in crossfades or fade-to-black scenes, weighted
2353 prediction gives rather large bitrate savings. 2377 prediction gives rather large bitrate savings.
2354 In MPEG-4 ASP, a fade-to-black is usually best coded as a series 2378 In MPEG-4 ASP, a fade-to-black is usually best coded as a series
2355 of expensive I-frames; using weighted prediction in B-frames 2379 of expensive I-frames; using weighted prediction in B-frames
2356 makes it possible to turn at least some of these into much more 2380 makes it possible to turn at least some of these into much smaller
2357 reasonably-sized B-frames. 2381 B-frames.
2358 Encoding time cost is minimal, as no extra decisions need to be made. 2382 Encoding time cost is minimal, as no extra decisions need to be made.
2359 Also, contrary to what some people seem to guess, the decoder 2383 Also, contrary to what some people seem to guess, the decoder
2360 CPU requirements are not much affected by weighted prediction, 2384 CPU requirements are not much affected by weighted prediction,
2361 all else being equal. 2385 all else being equal.
2362 </para> 2386 </para>
2363 <para> 2387 <para>
2364 Unfortunately, the current adaptive B-frame decision algorithm 2388 Unfortunately, the current adaptive B-frame decision algorithm
2365 has a strong tendency to avoid B-frames during fades. 2389 has a strong tendency to avoid B-frames during fades.
2366 Until this changes, it may be a good idea to add 2390 Until this changes, it may be a good idea to add
2367 <option>nob_adapt</option> to your x264encopts, if you expect 2391 <option>nob_adapt</option> to your x264encopts, if you expect
2368 fades to have a significant effect in your particular video 2392 fades to have a large effect in your particular video
2369 clip. 2393 clip.
2370 </para></listitem> 2394 </para></listitem>
2371 2395 </itemizedlist>
2396 </sect3>
2397
2398 <sect3 id="menc-feat-x264-encoding-options-misc-preferences">
2399 <title>Options pertaining to miscellaneous preferences</title>
2400 <itemizedlist>
2401 <listitem><para>
2402 <emphasis role="bold">Two pass encoding</emphasis>:
2403 Above, it was suggested to always use two pass encoding, but there
2404 are still reasons for not using it. For instance, if you are capturing
2405 live TV and encoding in realtime, you are forced to use single-pass.
2406 Also, one pass is obviously faster than two passes; if you use the
2407 exact same set of options on both passes, two pass encoding is almost
2408 twice as slow.
2409 </para>
2410 <para>
2411 Still, there are very good reasons for using two pass encoding. For
2412 one thing, single pass ratecontrol isn't psychic, and it often makes
2413 unreasonable choices because it can't see the big picture. For example,
2414 suppose you have a two minute long video consisting of two distinct
2415 halves. The first half is a very high-motion scene lasting 60 seconds
2416 which, in isolation, requires about 2500kbps in order to look decent.
2417 Immediately following it is a much less demanding 60-second scene
2418 that looks good at 300kbps. Suppose you ask for 1400kbps on the theory
2419 that this is enough to accomodate both scenes. Single pass ratecontrol
2420 will make a couple of "mistakes" in such a case. First of all, it
2421 will target 1400kbps in both segments. The first segment may end up
2422 heavily overquantized, causing it to look unacceptably and unreasonably
2423 blocky. The second segment will be heavily underquantized; it may look
2424 perfect, but the bitrate cost of that perfection will be completely
2425 unreasonable. What's even harder to avoid is the problem at the
2426 transition between the two scenes. The first seconds of the low motion
2427 half will be hugely over-quantized, because the ratecontrol is still
2428 expecting the kind of bitrate requirements it met in the first half
2429 of the video. This "error period" of heavily over-quantized low motion
2430 will look jarringly bad, and will actually use less than the 300kbps
2431 it would have taken to make it look decent. There are ways to
2432 mitigate the pitfalls of single-pass encoding, but they may tend to
2433 increase bitrate misprediction.
2434 </para>
2435 <para>
2436 Multipass ratecontrol can offer huge advantages over a single pass.
2437 Using the statistics gathered from the first pass encode, the encoder
2438 can estimate, with reasonable accuracy, the "cost" (in bits) of
2439 encoding any given frame, at any given quantizer. This allows for
2440 a much more rational, better planned allocation of bits between the
2441 expensive (high-motion) and cheap (low-motion) scenes. See
2442 <option>qcomp</option> below for some ideas on how to tweak this
2443 allocation to your liking.
2444 </para>
2445 <para>
2446 Moreover, two passes need not take twice as long as one pass. You can
2447 tweak the options in the first pass for higher speed and lower quality.
2448 If you choose your options well, you can get a very fast first pass.
2449 The resulting quality in the second pass will be slightly lower because size
2450 prediction is less accurate, but the quality difference is normally much
2451 too small to be visible. Try, for example, adding
2452 <option>subq=1:frameref=1</option> to the first pass
2453 <option>x264encopts</option>. Then, on the second pass, use slower,
2454 higher-quality options:
2455 <option>subq=6:frameref=15:4x4mv:me=3</option>
2456 </para></listitem>
2457 <listitem><para>
2458 <emphasis role="bold">Three pass encoding</emphasis>?
2459
2460 x264 offers the ability to make an arbitrary number of consecutive
2461 passes. If you specify <option>pass=1</option> on the first pass,
2462 then use <option>pass=3</option> on a subsequent pass, the subsequent
2463 pass will both read the statistics from the previous pass, and write
2464 its own statistics. An additional pass following this one will have
2465 a very good base from which to make highly accurate predictions of
2466 framesizes at a chosen quantizer. In practice, the overall quality
2467 gain from this is usually close to zero, and quite possibly a third
2468 pass will result in slightly worse global PSNR than the pass before
2469 it. In typical usage, three passes help if you get either bad bitrate
2470 prediction or bad looking scene transitions when using only two passes.
2471 This is somewhat likely to happen on extremely short clips. There are
2472 also a few special cases in which three (or more) passes are handy
2473 for advanced users, but for brevity, this guide omits discussing those
2474 special cases.
2475
2476 </para></listitem>
2477 <listitem><para>
2478 <emphasis role="bold">qcomp</emphasis>:
2479 <option>qcomp</option> trades off the number of bits allocated
2480 to "expensive" high-motion versus "cheap" low-motion frames. At
2481 one extreme, <option>qcomp=0</option> aims for true constant
2482 bitrate. Typically this would make high-motion scenes look completely
2483 awful, while low-motion scenes would probably look absolutely
2484 perfect, but would also use many times more bitrate than they
2485 would need in order to look merely excellent. At the other extreme,
2486 <option>qcomp=1</option> achieves nearly constant quantization parameter
2487 (QP). Constant QP doesn't look bad, but most people think it's more
2488 reasonable to shave some bitrate off of the extremely expensive scenes
2489 (where the loss of quality isn't as noticeable) and reallocate it to
2490 the scenes that are easier to encode at excellent quality.
2491 <option>qcomp</option> is set to 0.6 by default, which may be slightly
2492 low for many peoples' taste (0.7-0.8 are also commonly used).
2493 </para></listitem>
2494 <listitem><para>
2495 <emphasis role="bold">keyint</emphasis>:
2496 <option>keyint</option> is solely for trading off file seekability against
2497 coding efficiency. By default, <option>keyint</option> is set to 250. In
2498 25fps material, this guarantees the ability to seek to within 10 seconds
2499 precision. If you think it would be important and useful to be able to
2500 seek within 5 seconds of precision, set <option>keyint=125</option>;
2501 this will hurt quality/bitrate slightly. If you care only about quality
2502 and not about seekability, you can set it to much higher values
2503 (understanding that there are diminishing returns which may become
2504 vanishingly low, or even zero). The video stream will still have seekable
2505 points as long as there are some scene changes.
2506 </para></listitem>
2372 <listitem><para> 2507 <listitem><para>
2373 <emphasis role="bold">deblockalpha, deblockbeta</emphasis>: 2508 <emphasis role="bold">deblockalpha, deblockbeta</emphasis>:
2374 This topic is going to be a bit controversial. 2509 This topic is going to be a bit controversial.
2375 </para> 2510 </para>
2376 <para> 2511 <para>
2433 artifacting. 2568 artifacting.
2434 It will almost certainly look better than the results you 2569 It will almost certainly look better than the results you
2435 would have gotten just by fiddling with the deblocking filter. 2570 would have gotten just by fiddling with the deblocking filter.
2436 </para></listitem> 2571 </para></listitem>
2437 </itemizedlist> 2572 </itemizedlist>
2573 </sect3>
2438 </sect2> 2574 </sect2>
2439 </sect1> 2575 </sect1>
2440 2576
2441 <sect1 id="menc-feat-xvid"> 2577 <sect1 id="menc-feat-xvid">
2442 <title>Encoding with the <systemitem class="library">XviD</systemitem> 2578 <title>Encoding with the <systemitem class="library">XviD</systemitem>
2449 </para> 2585 </para>
2450 <para> 2586 <para>
2451 This guide mainly aims at featuring the same kind of information 2587 This guide mainly aims at featuring the same kind of information
2452 as x264's encoding guide. 2588 as x264's encoding guide.
2453 Therefore, please begin by reading 2589 Therefore, please begin by reading
2454 <link linkend="menc-feat-x264-intro">the first part</link> of that 2590 <link linkend="menc-feat-x264-encoding-options-intro">the first part</link>
2455 guide. 2591 of that guide.
2456 </para> 2592 </para>
2457 2593
2458 2594
2459 <sect2 id="menc-feat-xvid-intro"> 2595 <sect2 id="menc-feat-xvid-intro">
2460 <title>What options should I use to get the best results?</title> 2596 <title>What options should I use to get the best results?</title>