aomenc
aomenc, AOM-AV1, or just libaom is a command line application for encoding AV1 written in C and Assembly developed by AOMedia, which is also the reference encoder for AV1.
FFmpegâ
aomenc is available in FFmpeg via libaom-av1
, check if you have it by running ffmpeg -h encoder=libaom-av1
. You can input non-FFmpeg standard aomenc parameters via -aom-params
.
Supported Color Spaceâ
aomenc supports the following color spaces:
Format | Chroma Subsampling | Supported Bit Depth(s) |
---|---|---|
YUV420P | 4:2:0 | 8-bit |
YUV422P | 4:2:2 | 8-bit |
YUV444P | 4:4:4 | 8-bit |
GBRP | - | 8-bit |
GRAY8 | - | 8-bit |
YUV420P10LE | 4:2:0 | 10-bit |
YUV422P10LE | 4:2:2 | 10-bit |
YUV444P10LE | 4:4:4 | 10-bit |
GBRP10LE | - | 10-bit |
GRAY10LE | - | 10-bit |
YUV420P12LE | 4:2:0 | 12-bit |
YUV422P12LE | 4:2:2 | 12-bit |
YUV444P12LE | 4:4:4 | 12-bit |
GBRP12LE | - | 12-bit |
GRAY12LE | - | 12-bit |
Installationâ
- Linux & macOS
- Windows
- Clone the mainline aom repo:
git clone https://aomedia.googlesource.com/aom
cd aom && mkdir aom_build && cd aom_build
- Configure compilation. The following flags are set to ensure the
aomenc
binary is build for optimal performance:
cmake .. -DBUILD_SHARED_LIBS=0 -DENABLE_DOCS=0 -DCONFIG_TUNE_BUTTERAUGLI=0 -DCONFIG_TUNE_VMAF=0 -DCONFIG_AV1_DECODER=0 -DENABLE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-flto -O3 -march=native" -DCMAKE_C_FLAGS="-flto -O3 -march=native -pipe -fno-plt" -DCMAKE_LD_FLAGS="-flto -O3 -march=native"
- Compile:
make -j$(nproc)
- Install to your system. This may require elevated privileges:
make install
MSYS2 is the best option for building in Windows, as it provides a Unix-like environment for compilation.
-
Make sure you have downloaded & installed MSYS2 from the MSYS2 website before beginning the build process.
-
Start the UCRT64 console & install the required dependencies:
pacman -S cmake git perl yasm nasm python3 doxygen mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake base-devel
- Clone the mainline aom repo:
git clone https://aomedia.googlesource.com/aom
cd aom && mkdir aom_build && cd aom_build
- Configure compilation. The following flags are set to ensure the
aomenc
binary is build for optimal performance:
cmake .. -DBUILD_SHARED_LIBS=0 -DENABLE_DOCS=0 -DCONFIG_TUNE_BUTTERAUGLI=0 -DCONFIG_TUNE_VMAF=0 -DCONFIG_AV1_DECODER=0 -DENABLE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-flto -O3 -march=native" -DCMAKE_C_FLAGS="-flto -O3 -march=native -pipe -fno-plt" -DCMAKE_LD_FLAGS="-flto -O3 -march=native"
- Compile:
make -j$(nproc)
The resulting binary will be available within the home folder of the location where you installed MSYS2 (usually C:
). Navigate there, and then to the aom
folder; the binary should be there.
Built files should be in the "Debug" folder.
Avoid sharing binaries compiled with native CPU optimizations unless the person you're sharing to has the same CPU architecture, as this can lead to incorrect encoder behavior.
Usageâ
AV1 Encodingâ
The way aomenc was developed requires 2-pass to take full advantage of its efficiency which include better rate controls and encoding features. So always specify the encoder to use 2 passes when encoding.
aomenc --end-usage=q --cq-level=32 --bit-depth=10 --passes=1 --ivf -o output.ivf input.y4m
ffmpeg -v error -i input.mkv -f yuv4mpegpipe -strict -1 - | aomenc - --end-usage=q --cq-level=32 --bit-depth=10 --passes=1 --ivf -o output.ivf
ffmpeg -v error -i input.mkv -f yuv4mpegpipe -strict -1 - | aomenc - --end-usage=q --cq-level=32 --bit-depth=10 --passes=2 --pass=1 --fpf-log=aom-pass.log --ivf -o output.ivf
ffmpeg -v error -i input.mkv -f yuv4mpegpipe -strict -1 - | aomenc - --end-usage=q --cq-level=32 --bit-depth=10 --passes=2 --pass=2 --fpf-log=aom-pass.log --ivf -o output.ivf
AVIF Encodingâ
Using aomenc through avifenc is widely considered to be the best way to encode AVIF images, as SVT-AV1 only supports 4:2:0 chroma subsampling, rav1e isn't fast enough for still images, & the libaom team have put more effort into intra coding than the teams responsible for producing the other prominent open source AV1 encoders. A sample command for encoding AVIF looks like this:
avifenc -c aom -s 4 -j 8 -d 10 -y 444 --min 1 --max 63 -a end-usage=q -a cq-level=16 -a tune=ssim [input] output.avif
Where:
-c aom
is the encoder-s 4
is the speed. Speeds 4 & below offer the best compression quality at the expense of longer encode times.-j 8
is the number of threads the encoder is allowed to use. Increasing this past 12 will sometimes hurt encode times, as AVIF encoding via aomenc doesn't parallelize perfectly. Test using a speed benchmark to verify which value works best for you.-d 10
is the bit depth. Specifying a value below 10 isn't recommended, as it will hurt coding efficiency even with an 8-bit source image.-y 444
is the chroma subsampling mode. 4:4:4 chroma subsampling tends to provide better compression than 4:2:0 with AVIF, though on some images 4:2:0 chroma subsampling might be the better choice.cq-level=16
is how you specify quality. Lower values correspond to higher quality & filesize, while higher values mean a smaller, lower-quality output is desired. This is preceded by-a
because it is an aomenc option, not an avifenc one.tune=ssim
is how the encoder handles RDO (rate-distortion optimization). This may be redundant with the default aomenc parameters, but specifying doesn't hurt to avoid an unintended change if a default is modified sometime in the future.
Recommendationsâ
aomenc is largely lacking in its ability to take advantage of multiple threads, so a tool like Av1an should be utilized for effective parallelization. The parameters shown will be biased towards Av1an and aom-av1-lavish usage, so if you plan on using standalone aomenc please adjust as needed.
Here are some recommended parameters:
--bit-depth=10 --cpu-used=4 --end-usage=q --cq-level=24 --threads=2 --tile-columns=0 --tile-rows=0 --lag-in-frames=64 --tune=ssim --enable-keyframe-filtering=1 --disable-kf --kf-max-dist=9999 --enable-qm=1 --deltaq-mode=0 --aq-mode=0 --enable-fwd-kf=0 --arnr-strength=1 --sb-size=dynamic --enable-dnl-denoising=0 --denoise-noise-level=8
Now let's break it down.
-
--bit-depth=10
We're using 10bit because weird linear algebra allows the video to become smaller and reduces banding. -
--cpu-used=4
This is the preset which ranges from 0-9, you can go to 3 if you want more efficiency, 2 if you have a lot of time, 4 is the sweet spot, and 6 if you want speed. Don't go above 6 (Worst efficiency) or even 0 (It would take WEEKS to finish). -
--end-usage=q --cq-level=24
This specifies that we are going to use a knockoff version of CRF level similar to x264/x265 encoders, in this case CRF 24. -
--tile-columns=0 --tile-rows=0
This is the tiles options, where the encoder splits the videos into tiles to encode faster. See the image below (Yellow lines):
Do NOT use tiles for 1080p and below, use 1 tile-columns
at 1440p (2K), 2 tile-columns
and 1 tile-rows
for 2160p (4K).
If you would like an easy way to calculate the necessary number of tiles for your video, you can use the AV1 Encoding Calculator online or run this local tile calculator.
-
--lag-in-frames=64
Similar to x264/x265rc-lookahead
. Sets a number of frames to look ahead for frametype and ratecontrol, allowing for better compression decision making. Setting to a value greater than 64 is generally not considered useful. -
--aq-mode=0
adaptive quantization mode, a mostly debatable area nowadays. 0 is better most of the time but some say 1 is also good. -
--enable-keyframe-filtering=1
We're setting it to 1 because of compatibility reasons, 2 is more efficient but there are seeking issues and FFmpeg can't input it. -
--sb-size=dynamic
Allows the encoder to use 128x128 block partitioning besides 64x64 which gives an efficiency boost. -
--deltaq-mode=0
This value has been tested to be more perceptually efficient. -
--arnr-strength=1
Controls how strong the filtering (smoothing) will be, always been a hot topic. Most agree on the default of 4. Others think 1 is good for 3D Pixar CGI-like and 2D animation and 4 for live action content, and a higher value for lower bitrate encodes. -
--disable-kf --enable-fwd-kf=0
We're disabling keyframes cause Av1an already did scene detection, so we wont have to. Plus it speeds things up. -
--kf-max-dist=9999
Maximum keyframe interval, we're setting it at the highest possible value since Av1an's scene detection keyframe interval is already 240 by default -
--enable-chroma-deltaq=1 --enable-qm=1
Parameters that give you free efficiency boost discovered via testing. -
--enable-dnl-denoising=0
Disables the encoder's built-in denoising technique when grain synthesis is enabled, you can optionally set it to 1 when you have a pretty noisy video since it works quite well (NLMeans is the denoiser used). -
--denoise-noise-level=8
AV1 grain synthesis, which is a technique where the encoder puts fake grain in so it looks more natural and potentially hiding video artifacts (cause grain is hard to encode and explodes bitrate usage because of their randomness). Don't attempt to use it at high values (>12) since it creates noticeable grain patterns.
You can use photon noise tables as an alternative via --film-grain-table
, which is also conveniently available in Av1an as --photon-noise=X
Community Forksâ
Mainline aomenc is unfortunately not perfect. It suffers from bad defaults, a heavy focus on the perceptually flawed PSNR metric, misleading settings, and other issues. Fortunately, there are a couple of forks developed by the encoding community that were created to combat aomenc's underlying issues.
- aom-av1-psy No longer maintained as of 13th January 2023
- aom-av1-lavish No longer maintained as of 4th June 2024
- aom-psy101
- aom-av1ador
These forks fix up the poor decisions made by the original AOM devs and most importantly introduce new parameters and tunes to help fine-tune the encoder even more.