📄 menc-feat-enc-libavcodec.html
字号:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>14.3.聽Encoding with the libavcodec codec family</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 - The Movie Player"><link rel="up" href="encoding-guide.html" title="Chapter聽14.聽Encoding with MEncoder"><link rel="prev" href="menc-feat-telecine.html" title="14.2.聽How to deal with telecine and interlacing within NTSC DVDs"><link rel="next" href="menc-feat-xvid.html" title="14.4.聽Encoding with the Xvid codec"><link rel="preface" href="howtoread.html" title="How to read this documentation"><link rel="chapter" href="intro.html" title="Chapter聽1.聽Introduction"><link rel="chapter" href="install.html" title="Chapter聽2.聽Installation"><link rel="chapter" href="usage.html" title="Chapter聽3.聽Usage"><link rel="chapter" href="cd-dvd.html" title="Chapter聽4.聽CD/DVD usage"><link rel="chapter" href="faq.html" title="Chapter聽5.聽Frequently Asked Questions"><link rel="chapter" href="containers.html" title="Chapter聽6.聽Containers"><link rel="chapter" href="codecs.html" title="Chapter聽7.聽Codecs"><link rel="chapter" href="video.html" title="Chapter聽8.聽Video output devices"><link rel="chapter" href="audio.html" title="Chapter聽9.聽Audio output devices"><link rel="chapter" href="tv.html" title="Chapter聽10.聽TV"><link rel="chapter" href="radio.html" title="Chapter聽11.聽Radio"><link rel="chapter" href="ports.html" title="Chapter聽12.聽Ports"><link rel="chapter" href="mencoder.html" title="Chapter聽13.聽Basic usage of MEncoder"><link rel="chapter" href="encoding-guide.html" title="Chapter聽14.聽Encoding with MEncoder"><link rel="appendix" href="bugreports.html" title="Appendix聽A.聽How to report bugs"><link rel="appendix" href="bugs.html" title="Appendix聽B.聽Known bugs"><link rel="appendix" href="skin.html" title="Appendix聽C.聽MPlayer skin format"><link rel="appendix" href="history.html" title="Appendix聽D.聽History"><link rel="subsection" href="menc-feat-enc-libavcodec.html#menc-feat-enc-libavcodec-video-codecs" title="14.3.1.聽libavcodec's video codecs"><link rel="subsection" href="menc-feat-enc-libavcodec.html#menc-feat-enc-libavcodec-audio-codecs" title="14.3.2.聽libavcodec's audio codecs"><link rel="subsection" href="menc-feat-enc-libavcodec.html#menc-feat-dvd-mpeg4-lavc-encoding-options" title="14.3.3.聽Encoding options of libavcodec"><link rel="subsection" href="menc-feat-enc-libavcodec.html#menc-feat-mpeg4-lavc-example-settings" title="14.3.4.聽Encoding setting examples"><link rel="subsection" href="menc-feat-enc-libavcodec.html#custommatrices" title="14.3.5.聽Custom inter/intra matrices"><link rel="subsection" href="menc-feat-enc-libavcodec.html#menc-feat-dvd-mpeg4-example" title="14.3.6.聽Example"></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.3.聽Encoding with the <code class="systemitem">libavcodec</code>
codec family</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="menc-feat-telecine.html">Prev</a>聽</td><th width="60%" align="center">Chapter聽14.聽Encoding with <span class="application">MEncoder</span></th><td width="20%" align="right">聽<a accesskey="n" href="menc-feat-xvid.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="menc-feat-enc-libavcodec"></a>14.3.聽Encoding with the <code class="systemitem">libavcodec</code>
codec family</h2></div></div></div><p>
<a class="link" href="video-codecs.html#ffmpeg" title="7.1.1.聽FFmpeg/libavcodec"><code class="systemitem">libavcodec</code></a>
provides simple encoding to a lot of interesting video and audio formats.
You can encode to the following codecs (more or less up to date):
</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-enc-libavcodec-video-codecs"></a>14.3.1.聽<code class="systemitem">libavcodec</code>'s
video codecs</h3></div></div></div><p>
</p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><thead><tr><th>Video codec name</th><th>Description</th></tr></thead><tbody><tr><td>mjpeg</td><td>Motion JPEG</td></tr><tr><td>ljpeg</td><td>lossless JPEG</td></tr><tr><td>jpegls</td><td>JPEG LS</td></tr><tr><td>targa</td><td>Targa image</td></tr><tr><td>gif</td><td>GIF image</td></tr><tr><td>bmp</td><td>BMP image</td></tr><tr><td>png</td><td>PNG image</td></tr><tr><td>h261</td><td>H.261</td></tr><tr><td>h263</td><td>H.263 </td></tr><tr><td>h263p</td><td>H.263+</td></tr><tr><td>mpeg4</td><td>ISO standard MPEG-4 (DivX, Xvid compatible)</td></tr><tr><td>msmpeg4</td><td>pre-standard MPEG-4 variant by MS, v3 (AKA DivX3)</td></tr><tr><td>msmpeg4v2</td><td>pre-standard MPEG-4 by MS, v2 (used in old ASF files)</td></tr><tr><td>wmv1</td><td>Windows Media Video, version 1 (AKA WMV7)</td></tr><tr><td>wmv2</td><td>Windows Media Video, version 2 (AKA WMV8)</td></tr><tr><td>rv10</td><td>RealVideo 1.0</td></tr><tr><td>rv20</td><td>RealVideo 2.0</td></tr><tr><td>mpeg1video</td><td>MPEG-1 video</td></tr><tr><td>mpeg2video</td><td>MPEG-2 video</td></tr><tr><td>huffyuv</td><td>lossless compression</td></tr><tr><td>ffvhuff</td><td>FFmpeg modified huffyuv lossless</td></tr><tr><td>asv1</td><td>ASUS Video v1</td></tr><tr><td>asv2</td><td>ASUS Video v2</td></tr><tr><td>ffv1</td><td>FFmpeg's lossless video codec</td></tr><tr><td>svq1</td><td>Sorenson video 1</td></tr><tr><td>flv</td><td>Sorenson H.263 used in Flash Video</td></tr><tr><td>flashsv</td><td>Flash Screen Video</td></tr><tr><td>dvvideo</td><td>Sony Digital Video</td></tr><tr><td>snow</td><td>FFmpeg's experimental wavelet-based codec</td></tr><tr><td>zbmv</td><td>Zip Blocks Motion Video</td></tr></tbody></table></div><p>
The first column contains the codec names that should be passed after the
<code class="literal">vcodec</code> config,
like: <tt class="option">-lavcopts vcodec=msmpeg4</tt>
</p><div class="informalexample"><p>
An example with MJPEG compression:
</p><pre class="screen">
mencoder dvd://2 -o <em class="replaceable"><code>title2.avi</code></em> -ovc lavc -lavcopts vcodec=mjpeg -oac copy
</pre><p>
</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-enc-libavcodec-audio-codecs"></a>14.3.2.聽<code class="systemitem">libavcodec</code>'s
audio codecs</h3></div></div></div><p>
</p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><thead><tr><th>Audio codec name</th><th>Description</th></tr></thead><tbody><tr><td>ac3</td><td>Dolby Digital (AC-3)</td></tr><tr><td>adpcm_*</td><td>Adaptive PCM formats - see supplementary table</td></tr><tr><td>flac</td><td>Free Lossless Audio Codec (FLAC)</td></tr><tr><td>g726</td><td>G.726 ADPCM</td></tr><tr><td>libamr_nb</td><td>3GPP Adaptive Multi-Rate (AMR) narrow-band</td></tr><tr><td>libamr_wb</td><td>3GPP Adaptive Multi-Rate (AMR) wide-band</td></tr><tr><td>libfaac</td><td>Advanced Audio Coding (AAC) - using FAAC</td></tr><tr><td>libgsm</td><td>ETSI GSM 06.10 full rate</td></tr><tr><td>libgsm_ms</td><td>Microsoft GSM</td></tr><tr><td>libmp3lame</td><td>MPEG-1 audio layer 3 (MP3) - using LAME</td></tr><tr><td>mp2</td><td>MPEG-1 audio layer 2 (MP2)</td></tr><tr><td>pcm_*</td><td>PCM formats - see supplementary table</td></tr><tr><td>roq_dpcm</td><td>Id Software RoQ DPCM</td></tr><tr><td>sonic</td><td>experimental FFmpeg lossy codec</td></tr><tr><td>sonicls</td><td>experimental FFmpeg lossless codec</td></tr><tr><td>vorbis</td><td>Vorbis</td></tr><tr><td>wmav1</td><td>Windows Media Audio v1</td></tr><tr><td>wmav2</td><td>Windows Media Audio v2</td></tr></tbody></table></div><p>
The first column contains the codec names that should be passed after the
<code class="literal">acodec</code> option, like: <tt class="option">-lavcopts acodec=ac3</tt>
</p><div class="informalexample"><p>
An example with AC-3 compression:
</p><pre class="screen">
mencoder dvd://2 -o <em class="replaceable"><code>title2.avi</code></em> -oac lavc -lavcopts acodec=ac3 -ovc copy
</pre><p>
</p></div><p>
Contrary to <code class="systemitem">libavcodec</code>'s video
codecs, its audio codecs do not make a wise usage of the bits they are
given as they lack some minimal psychoacoustic model (if at all)
which most other codec implementations feature.
However, note that all these audio codecs are very fast and work
out-of-the-box everywhere <span class="application">MEncoder</span> has been
compiled with <code class="systemitem">libavcodec</code> (which
is the case most of time), and do not depend on external libraries.
</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="menc-feat-enc-libavcodec-audio-codecs-pcmadpcm"></a>14.3.2.1.聽PCM/ADPCM format supplementary table</h4></div></div></div><p>
</p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><thead><tr><th>PCM/ADPCM codec name</th><th>Description</th></tr></thead><tbody><tr><td>pcm_s32le</td><td>signed 32-bit little-endian</td></tr><tr><td>pcm_s32be</td><td>signed 32-bit big-endian</td></tr><tr><td>pcm_u32le</td><td>unsigned 32-bit little-endian</td></tr><tr><td>pcm_u32be</td><td>unsigned 32-bit big-endian</td></tr><tr><td>pcm_s24le</td><td>signed 24-bit little-endian</td></tr><tr><td>pcm_s24be</td><td>signed 24-bit big-endian</td></tr><tr><td>pcm_u24le</td><td>unsigned 24-bit little-endian</td></tr><tr><td>pcm_u24be</td><td>unsigned 24-bit big-endian</td></tr><tr><td>pcm_s16le</td><td>signed 16-bit little-endian</td></tr><tr><td>pcm_s16be</td><td>signed 16-bit big-endian</td></tr><tr><td>pcm_u16le</td><td>unsigned 16-bit little-endian</td></tr><tr><td>pcm_u16be</td><td>unsigned 16-bit big-endian</td></tr><tr><td>pcm_s8</td><td>signed 8-bit</td></tr><tr><td>pcm_u8</td><td>unsigned 8-bit</td></tr><tr><td>pcm_alaw</td><td>G.711 A-LAW </td></tr><tr><td>pcm_mulaw</td><td>G.711 渭-LAW</td></tr><tr><td>pcm_s24daud</td><td>signed 24-bit D-Cinema Audio format</td></tr><tr><td>pcm_zork</td><td>Activision Zork Nemesis</td></tr><tr><td>adpcm_ima_qt</td><td>Apple QuickTime</td></tr><tr><td>adpcm_ima_wav</td><td>Microsoft/IBM WAVE</td></tr><tr><td>adpcm_ima_dk3</td><td>Duck DK3</td></tr><tr><td>adpcm_ima_dk4</td><td>Duck DK4</td></tr><tr><td>adpcm_ima_ws</td><td>Westwood Studios</td></tr><tr><td>adpcm_ima_smjpeg</td><td>SDL Motion JPEG</td></tr><tr><td>adpcm_ms</td><td>Microsoft</td></tr><tr><td>adpcm_4xm</td><td>4X Technologies</td></tr><tr><td>adpcm_xa</td><td>Phillips Yellow Book CD-ROM eXtended Architecture</td></tr><tr><td>adpcm_ea</td><td>Electronic Arts</td></tr><tr><td>adpcm_ct</td><td>Creative 16->4-bit</td></tr><tr><td>adpcm_swf</td><td>Adobe Shockwave Flash</td></tr><tr><td>adpcm_yamaha</td><td>Yamaha</td></tr><tr><td>adpcm_sbpro_4</td><td>Creative VOC SoundBlaster Pro 8->4-bit</td></tr><tr><td>adpcm_sbpro_3</td><td>Creative VOC SoundBlaster Pro 8->2.6-bit</td></tr><tr><td>adpcm_sbpro_2</td><td>Creative VOC SoundBlaster Pro 8->2-bit</td></tr><tr><td>adpcm_thp</td><td>Nintendo GameCube FMV THP</td></tr><tr><td>adpcm_adx</td><td>Sega/CRI ADX</td></tr></tbody></table></div><p>
</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-dvd-mpeg4-lavc-encoding-options"></a>14.3.3.聽Encoding options of libavcodec</h3></div></div></div><p>
Ideally, you would probably want to be able to just tell the encoder to switch
into "high quality" mode and move on.
That would probably be nice, but unfortunately hard to implement as different
encoding options yield different quality results depending on the source
material. That is because compression depends on the visual properties of the
video in question.
For example, anime and live action have very different properties and
thus require different options to obtain optimum encoding.
The good news is that some options should never be left out, like
<tt class="option">mbd=2</tt>, <tt class="option">trell</tt>, and <tt class="option">v4mv</tt>.
See below for a detailed description of common encoding options.
</p><div class="itemizedlist"><p class="title"><b>Options to adjust:</b></p><ul type="disc"><li><p>
<span class="bold"><strong>vmax_b_frames</strong></span>: 1 or 2 is good, depending on
the movie.
Note that if you need to have your encode be decodable by DivX5, you
need to activate closed GOP support, using
<code class="systemitem">libavcodec</code>'s <tt class="option">cgop</tt>
option, but you need to deactivate scene detection, which
is not a good idea as it will hurt encode efficiency a bit.
</p></li><li><p>
<span class="bold"><strong>vb_strategy=1</strong></span>: helps in high-motion scenes.
On some videos, vmax_b_frames may hurt quality, but vmax_b_frames=2 along
with vb_strategy=1 helps.
</p></li><li><p>
<span class="bold"><strong>dia</strong></span>: motion search range. Bigger is better
and slower.
Negative values are a completely different scale.
Good values are -1 for a fast encode, or 2-4 for slower.
</p></li><li><p>
<span class="bold"><strong>predia</strong></span>: motion search pre-pass.
Not as important as dia. Good values are 1 (default) to 4. Requires preme=2
to really be useful.
</p></li><li><p>
<span class="bold"><strong>cmp, subcmp, precmp</strong></span>: Comparison function for
motion estimation.
Experiment with values of 0 (default), 2 (hadamard), 3 (dct), and 6 (rate
distortion).
0 is fastest, and sufficient for precmp.
For cmp and subcmp, 2 is good for anime, and 3 is good for live action.
6 may or may not be slightly better, but is slow.
</p></li><li><p>
<span class="bold"><strong>last_pred</strong></span>: Number of motion predictors to
take from the previous frame.
1-3 or so help at little speed cost.
Higher values are slow for no extra gain.
</p></li><li><p>
<span class="bold"><strong>cbp, mv0</strong></span>: Controls the selection of
macroblocks. Small speed cost for small quality gain.
</p></li><li><p>
<span class="bold"><strong>qprd</strong></span>: adaptive quantization based on the
macroblock's complexity.
May help or hurt depending on the video and other options.
This can cause artifacts unless you set vqmax to some reasonably small value
(6 is good, maybe as low as 4); vqmin=1 should also help.
</p></li><li><p>
<span class="bold"><strong>qns</strong></span>: very slow, especially when combined
with qprd.
This option will make the encoder minimize noise due to compression
artifacts instead of making the encoded video strictly match the source.
Do not use this unless you have already tweaked everything else as far as it
will go and the results still are not good enough.
</p></li><li><p>
<span class="bold"><strong>vqcomp</strong></span>: Tweak ratecontrol.
What values are good depends on the movie.
You can safely leave this alone if you want.
Reducing vqcomp puts more bits on low-complexity scenes, increasing it puts
them on high-complexity scenes (default: 0.5, range: 0-1. recommended range:
0.5-0.7).
</p></li><li><p>
<span class="bold"><strong>vlelim, vcelim</strong></span>: Sets the single coefficient
elimination threshold for luminance and chroma planes.
These are encoded separately in all MPEG-like algorithms.
The idea behind these options is to use some good heuristics to determine
when the change in a block is less than the threshold you specify, and in
such a case, to just encode the block as "no change".
This saves bits and perhaps speeds up encoding. vlelim=-4 and vcelim=9
seem to be good for live movies, but seem not to help with anime;
when encoding animation, you should probably leave them unchanged.
</p></li><li><p>
<span class="bold"><strong>qpel</strong></span>: Quarter pixel motion estimation.
MPEG-4 uses half pixel precision for its motion search by default,
therefore this option comes with an overhead as more information will be
stored in the encoded file.
The compression gain/loss depends on the movie, but it is usually not very
effective on anime.
qpel always incurs a significant cost in CPU decode time (+25% in
practice).
</p></li><li><p>
<span class="bold"><strong>psnr</strong></span>: does not affect the actual encoding,
but writes a log file giving the type/size/quality of each frame, and
prints a summary of PSNR (Peak Signal to Noise Ratio) at the end.
</p></li></ul></div><div class="itemizedlist"><p class="title"><b>Options not recommended to play with:</b></p><ul type="disc"><li><p>
<span class="bold"><strong>vme</strong></span>: The default is best.
</p></li><li><p>
<span class="bold"><strong>lumi_mask, dark_mask</strong></span>: Psychovisual adaptive
quantization.
You do not want to play with those options if you care about quality.
Reasonable values may be effective in your case, but be warned this is very
subjective.
</p></li><li><p>
<span class="bold"><strong>scplx_mask</strong></span>: Tries to prevent blocky
artifacts, but postprocessing is better.
</p></li></ul></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="menc-feat-mpeg4-lavc-example-settings"></a>14.3.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><p>
</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">vcodec=mpeg4:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2</tt></td><td>6fps</td><td>0dB</td></tr><tr><td>High quality</td><td><tt class="option">vcodec=mpeg4:mbd=2:trell:v4mv:last_pred=2:dia=-1:vmax_b_frames=2:vb_strategy=1:cmp=3:subcmp=3:precmp=0:vqcomp=0.6:turbo</tt></td><td>15fps</td><td>-0.5dB</td></tr><tr><td>Fast</td><td><tt class="option">vcodec=mpeg4:mbd=2:trell:v4mv:turbo</tt></td><td>42fps</td><td>-0.74dB</td></tr><tr><td>Realtime</td><td><tt class="option">vcodec=mpeg4:mbd=2:turbo</tt></td><td>54fps</td><td>-1.21dB</td></tr></tbody></table></div><p>
</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="custommatrices"></a>14.3.5.聽Custom inter/intra matrices</h3></div></div></div><p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -