Encoders
********

Encoders are configured elements in Libav which allow the encoding of multimedia streams.

When you configure your Libav build, all the supported native encoders are enabled by default. Encoders requiring an external library must be enabled manually via the corresponding --enable-lib option. You can list all available encoders using the configure option --list-encoders.

You can disable all the encoders with the configure option --disable-encoders and selectively enable / disable single encoders with the options --enable-encoder=ENCODER / --disable-encoder=ENCODER.

The option -codecs of the av* tools will display the list of enabled encoders.

Audio Encoders
**************

A description of some of the currently available audio encoders follows.

ac3 and ac3_fixed
=================

AC-3 audio encoders.

These encoders implement part of ATSC A/52:2010 and ETSI TS 102 366, as well as the undocumented RealAudio 3 (a.k.a. dnet).

The AC3 encoder uses floating-point math, while the AC3_FIXED encoder only uses fixed-point integer math. This does not mean that one is always faster, just that one or the other may be better suited to a particular system. The floating-point encoder will generally produce better quality audio for a given bitrate. The AC3_FIXED encoder is not the default codec for any of the output formats, so it must be specified explicitly using the option -acodec ac3_fixed in order to use it.

AC-3 Metadata
-------------

The AC-3 metadata options are used to set parameters that describe the audio, but in most cases do not affect the audio encoding itself. Some of the options do directly affect or influence the decoding and playback of the resulting bitstream, while others are just for informational purposes. A few of the options will add bits to the output stream that could otherwise be used for audio data, and will thus affect the quality of the output. Those will be indicated accordingly with a note in the option list below.

These parameters are described in detail in several publicly-available documents.

  * A/52:2010 - Digital Audio Compression (AC-3) (E-AC-3) Standard (http://www.atsc.org/cms/standards/a_52-2010.pdf)

  * A/54 - Guide to the Use of the ATSC Digital Television Standard (http://www.atsc.org/cms/standards/a_54a_with_corr_1.pdf)

  * Dolby Metadata Guide (http://www.dolby.com/uploadedFiles/zz-_Shared_Assets/English_PDFs/Professional/18_Metadata.Guide.pdf)

  * Dolby Digital Professional Encoding Guidelines (http://www.dolby.com/uploadedFiles/zz-_Shared_Assets/English_PDFs/Professional/46_DDEncodingGuidelines.pdf)

Metadata Control Options
........................

-per_frame_metadata BOOLEAN
     Allow Per-Frame Metadata. Specifies if the encoder should check for changing metadata for each frame.

     0
          The metadata values set at initialization will be used for every frame in the stream. (default)

     1
          Metadata values can be changed before encoding each frame.

Downmix Levels
..............

-center_mixlev LEVEL
     Center Mix Level. The amount of gain the decoder should apply to the center channel when downmixing to stereo. This field will only be written to the bitstream if a center channel is present. The value is specified as a scale factor. There are 3 valid values:

     0.707
          Apply -3dB gain

     0.595
          Apply -4.5dB gain (default)

     0.500
          Apply -6dB gain

-surround_mixlev LEVEL
     Surround Mix Level. The amount of gain the decoder should apply to the surround channel(s) when downmixing to stereo. This field will only be written to the bitstream if one or more surround channels are present. The value is specified as a scale factor.  There are 3 valid values:

     0.707
          Apply -3dB gain

     0.500
          Apply -6dB gain (default)

     0.000
          Silence Surround Channel(s)

Audio Production Information
............................

Audio Production Information is optional information describing the mixing environment.  Either none or both of the fields are written to the bitstream.

-mixing_level NUMBER
     Mixing Level. Specifies peak sound pressure level (SPL) in the production environment when the mix was mastered. Valid values are 80 to 111, or -1 for unknown or not indicated. The default value is -1, but that value cannot be used if the Audio Production Information is written to the bitstream. Therefore, if the room_type option is not the default value, the mixing_level option must not be -1.

-room_type TYPE
     Room Type. Describes the equalization used during the final mixing session at the studio or on the dubbing stage. A large room is a dubbing stage with the industry standard X-curve equalization; a small room has flat equalization. This field will not be written to the bitstream if both the mixing_level option and the room_type option have the default values.

     0
     notindicated
          Not Indicated (default)

     1
     large
          Large Room

     2
     small
          Small Room

Other Metadata Options
......................

-copyright BOOLEAN
     Copyright Indicator. Specifies whether a copyright exists for this audio.

     0
     off
          No Copyright Exists (default)

     1
     on
          Copyright Exists

-dialnorm VALUE
     Dialogue Normalization. Indicates how far the average dialogue level of the program is below digital 100% full scale (0 dBFS). This parameter determines a level shift during audio reproduction that sets the average volume of the dialogue to a preset level. The goal is to match volume level between program sources. A value of -31dB will result in no volume level change, relative to the source volume, during audio reproduction. Valid values are whole numbers in the range -31 to -1, with -31 being the default.

-dsur_mode MODE
     Dolby Surround Mode. Specifies whether the stereo signal uses Dolby Surround (Pro Logic). This field will only be written to the bitstream if the audio stream is stereo. Using this option does NOT mean the encoder will actually apply Dolby Surround processing.

     0
     notindicated
          Not Indicated (default)

     1
     off
          Not Dolby Surround Encoded

     2
     on
          Dolby Surround Encoded

-original BOOLEAN
     Original Bit Stream Indicator. Specifies whether this audio is from the original source and not a copy.

     0
     off
          Not Original Source

     1
     on
          Original Source (default)

Extended Bitstream Information
------------------------------

The extended bitstream options are part of the Alternate Bit Stream Syntax as specified in Annex D of the A/52:2010 standard. It is grouped into 2 parts. If any one parameter in a group is specified, all values in that group will be written to the bitstream.  Default values are used for those that are written but have not been specified.  If the mixing levels are written, the decoder will use these values instead of the ones specified in the center_mixlev and surround_mixlev options if it supports the Alternate Bit Stream Syntax.

Extended Bitstream Information - Part 1
.......................................

-dmix_mode MODE
     Preferred Stereo Downmix Mode. Allows the user to select either Lt/Rt (Dolby Surround) or Lo/Ro (normal stereo) as the preferred stereo downmix mode.

     0
     notindicated
          Not Indicated (default)

     1
     ltrt
          Lt/Rt Downmix Preferred

     2
     loro
          Lo/Ro Downmix Preferred

-ltrt_cmixlev LEVEL
     Lt/Rt Center Mix Level. The amount of gain the decoder should apply to the center channel when downmixing to stereo in Lt/Rt mode.

     1.414
          Apply +3dB gain

     1.189
          Apply +1.5dB gain

     1.000
          Apply 0dB gain

     0.841
          Apply -1.5dB gain

     0.707
          Apply -3.0dB gain

     0.595
          Apply -4.5dB gain (default)

     0.500
          Apply -6.0dB gain

     0.000
          Silence Center Channel

-ltrt_surmixlev LEVEL
     Lt/Rt Surround Mix Level. The amount of gain the decoder should apply to the surround channel(s) when downmixing to stereo in Lt/Rt mode.

     0.841
          Apply -1.5dB gain

     0.707
          Apply -3.0dB gain

     0.595
          Apply -4.5dB gain

     0.500
          Apply -6.0dB gain (default)

     0.000
          Silence Surround Channel(s)

-loro_cmixlev LEVEL
     Lo/Ro Center Mix Level. The amount of gain the decoder should apply to the center channel when downmixing to stereo in Lo/Ro mode.

     1.414
          Apply +3dB gain

     1.189
          Apply +1.5dB gain

     1.000
          Apply 0dB gain

     0.841
          Apply -1.5dB gain

     0.707
          Apply -3.0dB gain

     0.595
          Apply -4.5dB gain (default)

     0.500
          Apply -6.0dB gain

     0.000
          Silence Center Channel

-loro_surmixlev LEVEL
     Lo/Ro Surround Mix Level. The amount of gain the decoder should apply to the surround channel(s) when downmixing to stereo in Lo/Ro mode.

     0.841
          Apply -1.5dB gain

     0.707
          Apply -3.0dB gain

     0.595
          Apply -4.5dB gain

     0.500
          Apply -6.0dB gain (default)

     0.000
          Silence Surround Channel(s)

Extended Bitstream Information - Part 2
.......................................

-dsurex_mode MODE
     Dolby Surround EX Mode. Indicates whether the stream uses Dolby Surround EX (7.1 matrixed to 5.1). Using this option does NOT mean the encoder will actually apply Dolby Surround EX processing.

     0
     notindicated
          Not Indicated (default)

     1
     on
          Dolby Surround EX Off

     2
     off
          Dolby Surround EX On

-dheadphone_mode MODE
     Dolby Headphone Mode. Indicates whether the stream uses Dolby Headphone encoding (multi-channel matrixed to 2.0 for use with headphones). Using this option does NOT mean the encoder will actually apply Dolby Headphone processing.

     0
     notindicated
          Not Indicated (default)

     1
     on
          Dolby Headphone Off

     2
     off
          Dolby Headphone On

-ad_conv_type TYPE
     A/D Converter Type. Indicates whether the audio has passed through HDCD A/D conversion.

     0
     standard
          Standard A/D Converter (default)

     1
     hdcd
          HDCD A/D Converter

Other AC-3 Encoding Options
---------------------------

-stereo_rematrixing BOOLEAN
     Stereo Rematrixing. Enables/Disables use of rematrixing for stereo input. This is an optional AC-3 feature that increases quality by selectively encoding the left/right channels as mid/side. This option is enabled by default, and it is highly recommended that it be left as enabled except for testing purposes.

Floating-Point-Only AC-3 Encoding Options
-----------------------------------------

These options are only valid for the floating-point encoder and do not exist for the fixed-point encoder due to the corresponding features not being implemented in fixed-point.

-channel_coupling BOOLEAN
     Enables/Disables use of channel coupling, which is an optional AC-3 feature that increases quality by combining high frequency information from multiple channels into a single channel. The per-channel high frequency information is sent with less accuracy in both the frequency and time domains. This allows more bits to be used for lower frequencies while preserving enough information to reconstruct the high frequencies. This option is enabled by default for the floating-point encoder and should generally be left as enabled except for testing purposes or to increase encoding speed.

     -1
     auto
          Selected by Encoder (default)

     0
     off
          Disable Channel Coupling

     1
     on
          Enable Channel Coupling

-cpl_start_band NUMBER
     Coupling Start Band. Sets the channel coupling start band, from 1 to 15. If a value higher than the bandwidth is used, it will be reduced to 1 less than the coupling end band. If AUTO is used, the start band will be determined by the encoder based on the bit rate, sample rate, and channel layout. This option has no effect if channel coupling is disabled.

     -1
     auto
          Selected by Encoder (default)

Video Encoders
**************

libx264
=======

x264 H.264/MPEG-4 AVC encoder wrapper

x264 supports an impressive number of features, including 8x8 and 4x4 adaptive spatial transform, adaptive B-frame placement, CAVLC/CABAC entropy coding, interlacing (MBAFF), lossless mode, psy optimizations for detail retention (adaptive quantization, psy-RD, psy-trellis).

The Libav wrapper provides a mapping for most of them using global options that match those of the encoders and provides private options for the unique encoder options. Additionally an expert override is provided to directly pass a list of key=value tuples as accepted by x264_param_parse.

Option Mapping
--------------

The following options are supported by the x264 wrapper, the x264-equivalent options follow the Libav ones.

b                   bitrate
Libav b option is expressed in bits/s, x264 bitrate in kilobits/s.
bf                  bframes
Maximum number of B-frames.
g                   keyint
Maximum GOP size.
qmin                qpmin
qmax                qpmax
qdiff               qpstep
qblur               qblur
qcomp               qcomp
refs                ref
sc_threshold        scenecut
trellis             trellis
nr                  nr
Noise reduction.
me_range            merange
me_method           me
subq                subme
b_strategy          b-adapt
keyint_min          keyint-min
coder               cabac
Set coder to ac to use CABAC.
cmp                 chroma-me
Set to chroma to use chroma motion estimation.
threads             threads
thread_type         sliced_threads
Set to slice to use sliced threading instead of frame threading.
flags -cgop         open-gop
Set -cgop to use recovery points to close GOPs.
rc_init_occupancy   vbv-init
Initial buffer occupancy.

Private Options
---------------

-preset STRING
     Set the encoding preset (cf. x264 --fullhelp).

-tune STRING
     Tune the encoding params (cf. x264 --fullhelp).

-profile STRING
     Set profile restrictions (cf. x264 --fullhelp).

-fastfirstpass INTEGER
     Use fast settings when encoding first pass.

-crf FLOAT
     Select the quality for constant quality mode.

-crf_max FLOAT
     In CRF mode, prevents VBV from lowering quality beyond this point.

-qp INTEGER
     Constant quantization parameter rate control method.

-aq-mode INTEGER
     AQ method

     Possible values:

     none

     variance
          Variance AQ (complexity mask).

     autovariance
          Auto-variance AQ (experimental).

-aq-strength FLOAT
     AQ strength, reduces blocking and blurring in flat and textured areas.

-psy INTEGER
     Use psychovisual optimizations.

-psy-rd STRING
     Strength of psychovisual optimization, in <psy-rd>:<psy-trellis> format.

-rc-lookahead INTEGER
     Number of frames to look ahead for frametype and ratecontrol.

-weightb INTEGER
     Weighted prediction for B-frames.

-weightp INTEGER
     Weighted prediction analysis method.

     Possible values:

     none

     simple

     smart

-ssim INTEGER
     Calculate and print SSIM stats.

-intra-refresh INTEGER
     Use Periodic Intra Refresh instead of IDR frames.

-b-bias INTEGER
     Influences how often B-frames are used.

-b-pyramid INTEGER
     Keep some B-frames as references.

     Possible values:

     none

     strict
          Strictly hierarchical pyramid.

     normal
          Non-strict (not Blu-ray compatible).

-mixed-refs INTEGER
     One reference per partition, as opposed to one reference per macroblock.

-8x8dct INTEGER
     High profile 8x8 transform.

-fast-pskip INTEGER

-aud INTEGER
     Use access unit delimiters.

-mbtree INTEGER
     Use macroblock tree ratecontrol.

-deblock STRING
     Loop filter parameters, in <alpha:beta> form.

-cplxblur FLOAT
     Reduce fluctuations in QP (before curve compression).

-partitions STRING
     A comma-separated list of partitions to consider, possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all.

-direct-pred INTEGER
     Direct MV prediction mode

     Possible values:

     none

     spatial

     temporal

     auto

-slice-max-size INTEGER
     Limit the size of each slice in bytes.

-stats STRING
     Filename for 2 pass stats.

-nal-hrd INTEGER
     Signal HRD information (requires vbv-bufsize; cbr not allowed in .mp4).

     Possible values:

     none

     vbr

     cbr

-x264-params STRING
     Override the x264 configuration using a :-separated list of key=value parameters.

          -x264-params level=30:bframes=0:weightp=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:subq=6:8x8dct=0:trellis=0

Encoding avpresets for common usages are provided so they can be used with the general presets system (e.g. passing the -pre option).

ProRes
======

Apple ProRes encoder.

Private Options
---------------

profile INTEGER
     Select the ProRes profile to encode

     proxy

     lt

     standard

     hq

     4444

quant_mat INTEGER
     Select quantization matrix.

     auto

     default

     proxy

     lt

     standard

     hq

     If set to AUTO, the matrix matching the profile will be picked. If not set, the matrix providing the highest quality, DEFAULT, will be picked.

bits_per_mb INTEGER
     How many bits to allot for coding one macroblock. Different profiles use between 200 and 2400 bits per macroblock, the maximum is 8000.

mbs_per_slice INTEGER
     Number of macroblocks in each slice (1-8); the default value (8) should be good in almost all situations.

vendor STRING
     Override the 4-byte vendor ID. A custom vendor ID like APL0 would claim the stream was produced by the Apple encoder.

alpha_bits INTEGER
     Specify number of bits for alpha component. Possible values are 0, 8 and 16. Use 0 to disable alpha plane coding.

Speed considerations
--------------------

In the default mode of operation the encoder has to honor frame constraints (i.e. not produc frames with size bigger than requested) while still making output picture as good as possible. A frame containing a lot of small details is harder to compress and the encoder would spend more time searching for appropriate quantizers for each slice.

Setting a higher bits_per_mb limit will improve the speed.

For the fastest encoding speed set the qscale parameter (4 is the recommended value) and do not set a size constraint.