<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>14.4. Encoding with the Xvid codec</title><link rel="stylesheet" href="default.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="MPlayer - Il Visualizzatore di film"><link rel="up" href="encoding-guide.html" title="Capitolo 14. Encoding with MEncoder"><link rel="prev" href="menc-feat-enc-libavcodec.html" title="14.3. Encoding with the libavcodec codec family"><link rel="next" href="menc-feat-x264.html" title="14.5. Encoding with the x264 codec"><link rel="preface" href="howtoread.html" title="Come leggere questa documentazione"><link rel="chapter" href="intro.html" title="Capitolo 1. Introduzione"><link rel="chapter" href="install.html" title="Capitolo 2. Installazione"><link rel="chapter" href="usage.html" title="Capitolo 3. Utilizzo"><link rel="chapter" href="cd-dvd.html" title="Capitolo 4. Utilizzo CD/DVD"><link rel="chapter" href="faq.html" title="Capitolo 5. Frequently Asked Questions"><link rel="chapter" href="containers.html" title="Capitolo 6. Contenitori"><link rel="chapter" href="codecs.html" title="Capitolo 7. Codec"><link rel="chapter" href="video.html" title="Capitolo 8. Dispositivi di uscita video"><link rel="chapter" href="audio.html" title="Capitolo 9. Dispositivi di uscita audio"><link rel="chapter" href="tv.html" title="Capitolo 10. TV"><link rel="chapter" href="radio.html" title="Capitolo 11. Radio"><link rel="chapter" href="ports.html" title="Capitolo 12. Ports"><link rel="chapter" href="mencoder.html" title="Capitolo 13. Utilizzo base di MEncoder"><link rel="chapter" href="encoding-guide.html" title="Capitolo 14. Encoding with MEncoder"><link rel="appendix" href="bugreports.html" title="Appendice A. Come segnalare i bug (errori)"><link rel="appendix" href="bugs.html" title="Appendice B. Bug conosciuti"><link rel="appendix" href="skin.html" title="Appendice C. MPlayer skin format"><link rel="appendix" href="history.html" title="Appendice D. Storia"><link rel="subsection" href="menc-feat-xvid.html#menc-feat-xvid-intro" title="14.4.1. What options should I use to get the best results?"><link rel="subsection" href="menc-feat-xvid.html#menc-feat-xvid-encoding-options" title="14.4.2. Encoding options of Xvid"><link rel="subsection" href="menc-feat-xvid.html#menc-feat-xvid-encoding-profiles" title="14.4.3. Encoding profiles"><link rel="subsection" href="menc-feat-xvid.html#menc-feat-xvid-example-settings" title="14.4.4. Encoding setting examples"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">14.4. Encoding with the <code class="systemitem">Xvid</code> codec</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="menc-feat-enc-libavcodec.html">Indietro</a> </td><th width="60%" align="center">Capitolo 14. Encoding with <span class="application">MEncoder</span></th><td width="20%" align="right"> <a accesskey="n" href="menc-feat-x264.html">Avanti</a></td></tr></table><hr></div><div class="sect1" lang="it"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="menc-feat-xvid"></a>14.4. Encoding with the <code class="systemitem">Xvid</code> codec</h2></div></div></div><p> <code class="systemitem">Xvid</code> is a free library for encoding MPEG-4 ASP video streams. Before starting to encode, you need to <a class="link" href="video-codecs.html#xvid" title="7.1.2. Xvid"> set up <span class="application">MEncoder</span> to support it</a>. </p><p> This guide mainly aims at featuring the same kind of information as x264's encoding guide. Therefore, please begin by reading <a class="link" href="menc-feat-x264.html#menc-feat-x264-encoding-options-intro" title="14.5.1.1. Introduction">the first part</a> of that guide. </p><div class="sect2" lang="it"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-xvid-intro"></a>14.4.1. What options should I use to get the best results?</h3></div></div></div><p> Please begin by reviewing the <code class="systemitem">Xvid</code> section of <span class="application">MPlayer</span>'s man page. This section is intended to be a supplement to the man page. </p><p> The Xvid default settings are already a good tradeoff between speed and quality, therefore you can safely stick to them if the following section puzzles you. </p></div><div class="sect2" lang="it"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-xvid-encoding-options"></a>14.4.2. Encoding options of <code class="systemitem">Xvid</code></h3></div></div></div><div class="itemizedlist"><ul type="disc"><li><p> <span class="bold"><strong>vhq</strong></span> This setting affects the macroblock decision algorithm, where the higher the setting, the wiser the decision. The default setting may be safely used for every encode, while higher settings always help PSNR but are significantly slower. Please note that a better PSNR does not necessarily mean that the picture will look better, but tells you that it is closer to the original. Turning it off will noticeably speed up encoding; if speed is critical for you, the tradeoff may be worth it. </p></li><li><p> <span class="bold"><strong>bvhq</strong></span> This does the same job as vhq, but does it on B-frames. It has a negligible impact on speed, and slightly improves quality (around +0.1dB PSNR). </p></li><li><p> <span class="bold"><strong>max_bframes</strong></span> A higher number of consecutive allowed B-frames usually improves compressibility, although it may also lead to more blocking artifacts. The default setting is a good tradeoff between compressibility and quality, but you may increase it up to 3 if you are bitrate-starved. You may also decrease it to 1 or 0 if you are aiming at perfect quality, though in that case you should make sure your target bitrate is high enough to ensure that the encoder does not have to increase quantizers to reach it. </p></li><li><p> <span class="bold"><strong>bf_threshold</strong></span> This controls the B-frame sensitivity of the encoder, where a higher value leads to more B-frames being used (and vice versa). This setting is to be used together with <tt class="option">max_bframes</tt>; if you are bitrate-starved, you should increase both <tt class="option">max_bframes</tt> and <tt class="option">bf_threshold</tt>, while you may increase <tt class="option">max_bframes</tt> and reduce <tt class="option">bf_threshold</tt> so that the encoder may use more B-frames in places that only <span class="bold"><strong>really</strong></span> need them. A low number of <tt class="option">max_bframes</tt> and a high value of <tt class="option">bf_threshold</tt> is probably not a wise choice as it will force the encoder to put B-frames in places that would not benefit from them, therefore reducing visual quality. However, if you need to be compatible with standalone players that only support old DivX profiles (which only supports up to 1 consecutive B-frame), this would be your only way to increase compressibility through using B-frames. </p></li><li><p> <span class="bold"><strong>trellis</strong></span> Optimizes the quantization process to get an optimal tradeoff between PSNR and bitrate, which allows significant bit saving. These bits will in return be spent elsewhere on the video, raising overall visual quality. You should always leave it on as its impact on quality is huge. Even if you are looking for speed, do not disable it until you have turned down <tt class="option">vhq</tt> and all other more CPU-hungry options to the minimum. </p></li><li><p> <span class="bold"><strong>hq_ac</strong></span> Activates a better coefficient cost estimation method, which slightly reduces filesize by around 0.15 to 0.19% (which corresponds to less than 0.01dB PSNR increase), while having a negligible impact on speed. It is therefore recommended to always leave it on. </p></li><li><p> <span class="bold"><strong>cartoon</strong></span> Designed to better encode cartoon content, and has no impact on speed as it just tunes the mode decision heuristics for this type of content. </p></li><li><p> <span class="bold"><strong>me_quality</strong></span> This setting is to control the precision of the motion estimation. The higher <tt class="option">me_quality</tt>, the more precise the estimation of the original motion will be, and the better the resulting clip will capture the original motion. </p><p> The default setting is best in all cases; thus it is not recommended to turn it down unless you are really looking for speed, as all the bits saved by a good motion estimation would be spent elsewhere, raising overall quality. Therefore, do not go any lower than 5, and even that only as a last resort. </p></li><li><p> <span class="bold"><strong>chroma_me</strong></span> Improves motion estimation by also taking the chroma (color) information into account, whereas <tt class="option">me_quality</tt> alone only uses luma (grayscale). This slows down encoding by 5-10% but improves visual quality quite a bit by reducing blocking effects and reduces filesize by around 1.3%. If you are looking for speed, you should disable this option before starting to consider reducing <tt class="option">me_quality</tt>. </p></li><li><p> <span class="bold"><strong>chroma_opt</strong></span> Is intended to increase chroma image quality around pure white/black edges, rather than improving compression. This can help to reduce the "red stairs" effect. </p></li><li><p> <span class="bold"><strong>lumi_mask</strong></span> Tries to give less bitrate to part of the picture that the human eye cannot see very well, which should allow the encoder to spend the saved bits on more important parts of the picture. The quality of the encode yielded by this option highly depends on personal preferences and on the type and monitor settings used to watch it (typically, it will not look as good if it is bright or if it is a TFT monitor). </p></li><li><p> <span class="bold"><strong>qpel</strong></span> Raise the number of candidate motion vectors by increasing the precision of the motion estimation from halfpel to quarterpel. The idea is to find better motion vectors which will in return reduce bitrate (hence increasing quality). However, motion vectors with quarterpel precision require a few extra bits to code, but the candidate vectors do not always give (much) better results. Quite often, the codec still spends bits on the extra precision, but little or no extra quality is gained in return. Unfortunately, there is no way to foresee the possible gains of <tt class="option">qpel</tt>, so you need to actually encode with and without it to know for sure. </p><p> <tt class="option">qpel</tt> can be almost double encoding time, and requires as much as 25% more processing power to decode. It is not supported by all standalone players. </p></li><li><p> <span class="bold"><strong>gmc</strong></span> Tries to save bits on panning scenes by using a single motion vector for the whole frame. This almost always raises PSNR, but significantly slows down encoding (as well as decoding). Therefore, you should only use it when you have turned <tt class="option">vhq</tt> to the maximum. <code class="systemitem">Xvid</code>'s GMC is more sophisticated than DivX's, but is only supported by few standalone players. </p></li></ul></div></div><div class="sect2" lang="it"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-xvid-encoding-profiles"></a>14.4.3. Encoding profiles</h3></div></div></div><p> Xvid supports encoding profiles through the <tt class="option">profile</tt> option, which are used to impose restrictions on the properties of the Xvid video stream such that it will be playable on anything which supports the chosen profile. The restrictions relate to resolutions, bitrates and certain MPEG-4 features. The following table shows what each profile supports. </p><div class="informaltable"><table border="1"><colgroup><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"><col align="center"></colgroup><tbody><tr><td align="center"> </td><td colspan="4" align="center">Simple</td><td colspan="6" align="center">Advanced Simple</td><td colspan="6" align="center">DivX</td></tr><tr><td align="center">Profile name</td><td align="center">0</td><td align="center">1</td><td align="center">2</td><td align="center">3</td><td align="center">0</td><td align="center">1</td><td align="center">2</td><td align="center">3</td><td align="center">4</td><td align="center">5</td><td align="center">Handheld</td><td align="center">Portable NTSC</td><td align="center">Portable PAL</td><td align="center">Home Theater NTSC</td><td align="center">Home Theater PAL</td><td align="center">HDTV</td></tr><tr><td align="center">Width [pixels]</td><td align="center">176</td><td align="center">176</td><td align="center">352</td><td align="center">352</td><td align="center">176</td><td align="center">176</td><td align="center">352</td><td align="center">352</td><td align="center">352</td><td align="center">720</td><td align="center">176</td><td align="center">352</td><td align="center">352</td><td align="center">720</td><td align="center">720</td><td align="center">1280</td></tr><tr><td align="center">Height [pixels]</td><td align="center">144</td><td align="center">144</td><td align="center">288</td><td align="center">288</td><td align="center">144</td><td align="center">144</td><td align="center">288</td><td align="center">288</td><td align="center">576</td><td align="center">576</td><td align="center">144</td><td align="center">240</td><td align="center">288</td><td align="center">480</td><td align="center">576</td><td align="center">720</td></tr><tr><td align="center">Frame rate [fps]</td><td align="center">15</td><td align="center">15</td><td align="center">15</td><td align="center">15</td><td align="center">30</td><td align="center">30</td><td align="center">15</td><td align="center">30</td><td align="center">30</td><td align="center">30</td><td align="center">15</td><td align="center">30</td><td align="center">25</td><td align="center">30</td><td align="center">25</td><td align="center">30</td></tr><tr><td align="center">Max average bitrate [kbps]</td><td align="center">64</td><td align="center">64</td><td align="center">128</td><td align="center">384</td><td align="center">128</td><td align="center">128</td><td align="center">384</td><td align="center">768</td><td align="center">3000</td><td align="center">8000</td><td align="center">537.6</td><td align="center">4854</td><td align="center">4854</td><td align="center">4854</td><td align="center">4854</td><td align="center">9708.4</td></tr><tr><td align="center">Peak average bitrate over 3 secs [kbps]</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">800</td><td align="center">8000</td><td align="center">8000</td><td align="center">8000</td><td align="center">8000</td><td align="center">16000</td></tr><tr><td align="center">Max. B-frames</td><td align="center">0</td><td align="center">0</td><td align="center">0</td><td align="center">0</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">0</td><td align="center">1</td><td align="center">1</td><td align="center">1</td><td align="center">1</td><td align="center">2</td></tr><tr><td align="center">MPEG quantization</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td></tr><tr><td align="center">Adaptive quantization</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td></tr><tr><td align="center">Interlaced encoding</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">X</td><td align="center">X</td><td align="center">X</td></tr><tr><td align="center">Quaterpixel</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td></tr><tr><td align="center">Global motion compensation</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center">X</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center"> </td></tr></tbody></table></div></div><div class="sect2" lang="it"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-xvid-example-settings"></a>14.4.4. Encoding setting examples</h3></div></div></div><p> The following settings are examples of different encoding option combinations that affect the speed vs quality tradeoff at the same target bitrate. </p><p> All the encoding settings were tested on a 720x448 @30000/1001 fps video sample, the target bitrate was 900kbps, and the machine was an AMD-64 3400+ at 2400 MHz in 64 bits mode. Each encoding setting features the measured encoding speed (in frames per second) and the PSNR loss (in dB) compared to the "very high quality" setting. Please understand that depending on your source, your machine type and development advancements, you may get very different results. </p><div class="informaltable"><table border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Description</th><th>Encoding options</th><th>speed (in fps)</th><th>Relative PSNR loss (in dB)</th></tr></thead><tbody><tr><td>Very high quality</td><td><tt class="option">chroma_opt:vhq=4:bvhq=1:quant_type=mpeg</tt></td><td>16fps</td><td>0dB</td></tr><tr><td>High quality</td><td><tt class="option">vhq=2:bvhq=1:chroma_opt:quant_type=mpeg</tt></td><td>18fps</td><td>-0.1dB</td></tr><tr><td>Fast</td><td><tt class="option">turbo:vhq=0</tt></td><td>28fps</td><td>-0.69dB</td></tr><tr><td>Realtime</td><td><tt class="option">turbo:nochroma_me:notrellis:max_bframes=0:vhq=0</tt></td><td>38fps</td><td>-1.48dB</td></tr></tbody></table></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="menc-feat-enc-libavcodec.html">Indietro</a> </td><td width="20%" align="center"><a accesskey="u" href="encoding-guide.html">Risali</a></td><td width="40%" align="right"> <a accesskey="n" href="menc-feat-x264.html">Avanti</a></td></tr><tr><td width="40%" align="left" valign="top">14.3. Encoding with the <code class="systemitem">libavcodec</code> codec family </td><td width="20%" align="center"><a accesskey="h" href="index.html">Partenza</a></td><td width="40%" align="right" valign="top"> 14.5. Encoding with the <code class="systemitem">x264</code> codec</td></tr></table></div></body></html>