How to Pass Custom Options to libaom via FFmpeg?
This article provides a practical guide on using specific FFmpeg
flags to pass custom encoding options to the libaom-av1
library. When encoding video to the AV1 format using FFmpeg, the
standard parameters often fall short of utilizing every advanced tuning
knob available in the Alliance for Open Media (AOM) reference encoder.
By leveraging the -aom-params flag, developers and video
engineers can fine-tune compression efficiency, control specific
keyframe behaviors, and optimize encoding speeds.
Understanding the
-aom-params Flag
The primary and most efficient way to pass custom options directly to
the underlying libaom encoder in FFmpeg is by using the
-aom-params flag. This flag accepts a list of
key=value pairs, with each pair separated by a colon
(:). It acts as a direct bridge to the internal
libaom API configuration structure, overriding or
supplementing standard FFmpeg options.
Using -aom-params is highly recommended over older,
generic options like -x265-params or
-vsprofile equivalents because it is tailored explicitly
for AV1’s distinct encoder architecture.
Basic Syntax Structure
ffmpeg -i input.mp4 -c:v libaom-av1 -aom-params key1=value1:key2=value2 output.mkvCommon Custom Options for libaom
When constructing your -aom-params string, several
high-impact variables can be fine-tuned to maximize your encoding
workflow.
1. Keyframe and GOP Adjustments
- **
kf-min-dist/kf-max-dist**: Sets the minimum and maximum distance between keyframes (GOP size). While FFmpeg has native-gflags, passing these directly to libaom can ensure strict adherence. strict-gop-compliance: Disables or enables adaptive keyframe placement, ensuring that scene cuts do not override predetermined intra-frame boundaries when set to1.
2. Rate Control Tuning
end-usage: Defines the rate control mode. While FFmpeg maps this via-b:vor-crf, you can force modes directly:q(Constant Quality)vbr(Variable Bitrate)cbr(Constant Bitrate)cq(Constrained Quality)cq-level: Sets the visual quality metric (0 to 63), where lower values mean higher quality.
3. Tiling and Threading
AV1 relies heavily on tiling to achieve multi-threaded encoding efficiency.
tile-columns: Determines how many vertical tile columns the video frame is split into (expressed as \(\log_2\), so a value of2means \(2^2 = 4\) columns).tile-rows: Determines horizontal tile split options (\(\log_2\), so a value of1means \(2^1 = 2\) rows).row-mt: Enables row-based multi-threading (1for enabled,0for disabled), which significantly accelerates encoding speeds on multi-core processors.
Advanced Implementation Example
To combine these concepts into a production-ready command line, you might look at a scenario aiming for high-efficiency multi-threaded 4K encoding.
The following command utilizes -aom-params to enforce a
specific tile layout for parallel processing while forcing row-based
multi-threading:
ffmpeg -i input.mov -c:v libaom-av1 -b:v 0 -crf 28 -aom-params tile-columns=2:tile-rows=1:row-mt=1:enable-tpl-model=1 output.mp4In this setup, enable-tpl-model=1 activates Temporal
Dependency Model R-D optimization, which improves bit allocation across
frames based on motion and complexity, yielding a noticeably better
quality-to-bitrate ratio.