aom-av1-lavish
This entry is about a fork of aomenc called aom-psy101. If you'd like to learn about the mainline aomenc encoder before reading, visit our aomenc wiki entry.
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-lavish is no longer maintained as of 4th June 2024. The information in this entry is unaffected by this, but the fact that the project is no longer maintained should be taken into consideration as a user.
- 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.
aom-av1-lavish is a fork of aomenc that aims to improve the encoding quality and speed of AV1. It is developed by Clybius, a talented AV1 community developer also well-known for working on SVT-AV1-PSY.
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
.
Unless you compile FFmpeg yourself with aom-av1-lavish, you will be using the mainline aomenc. Compiling from source yourself with the aomenc libraries provided by aom-av1-lavish is the only way to use it with FFmpeg.
Installationâ
- Linux
- macOS
- Windows
A precompiled AVX2-optimized binary of aom-av1-lavish can be installed for x86_64 Linux via rAV1ator CLI. However, it is always recommended to build from source.
But if you want to compile the community forks, you can also do that. CMake, Perl, GNU Make, and nasm (assuming x64, if x86 use yasm) will be needed for compilation.
git clone https://github.com/Clybius/aom-av1-lavish -b Endless_Merging
cd aom-av1-lavish && mkdir -p aom_build && cd aom_build
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"
The CMake config above will statically build aomenc while disabling docs (which requires Doxygen), extra tunes, tests, and decoders. While also applying native CPU optimizations to help speed up the encoder.
make -j$(nproc)
The resulting binary will be in the same folder you are on (aom_build
).
Or, optionally, you can install it to your system, which may need elevated permissions.
make install
macOS is very similar to Linux. Note that some commands may have to be run with sudo
, which I won't explicitly include for security reasons.
Homebrew
Installing the Homebrew package manager is a well documented process at this point:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Installing mainline libaom is as simple as running the following:
brew update && brew upgrade
brew install aom
FFmpeg can also be installed via brew.
Building From Source
If you want aom-av1-lavish instead of mainline, you'll have to compile from source. Things are very similar to Linux, with a few oddities:
- macOS sometimes doesn't have a
/usr/local/bin
by default. You can fix this by doingmkdir /usr/local/bin
. - Homebrew installs everything in its own directory structure. If you're building things from source that rely on libraries from libvmaf, libjxl, etc, make sure to copy them from
/opt/homebrew/lib
to/usr/local/lib
. Finding them is a matter ofls | grep "keyword"
& copying what looks reasonable to be associated with the tool you're using. - Building most things from source will have instructions for *nix which work for both macOS & Linux. Even if it says Linux, there's a good chance it'll work on macOS as well, & it is always worth trying Linux build instructions on Mac. aom-av1-lavish requires some additional steps, though.
If you want to make the most out of your hardware & eke out every last drop of quality, it may be worth building aom-av1-lavish from source. The first step is to clone it from the Endless Merging branch, which contains all of the latest lavish improvements:
git clone https://github.com/Clybius/aom-av1-lavish -b Endless_Merging
cd aom-av1-lavish
Now, you need to make some manual changes to the source code until this commit is merged to fix build errors.
- Add the line
#include "aq_variance.h"
at line 19 inav1/encoder/encodeframe_utils.c
- Comment out line 2546 in
av1/encoder/speed_features.c
. This line isconst int qindex_thresh_cdef_sf_s1_s3_l2[2] = { 92, 48 };
& becomes// const int qindex_thresh_cdef_sf_s1_s3_l2[2] = { 92, 48 };
.
Now you can continue to build according to the Linux instructions below. Obviously you'll need cmake, which you can install with homebrew along with any other tools. While still in the aom-av1-lavish
directory:
mkdir -p aom_build && cd aom_build
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"
make -j$(nproc)
# This may need to be run as root. If it doesn't work properly, you can always copy the binary into /usr/local/bin manually:
make install
Now you can run aomenc --help | grep "AOMedia" -C 3
to see if lavish installed. If you're getting the same output as above, you may need to copy the aomenc
executable to /opt/local/bin
, /usr/local/bin
, & /opt/homebrew/bin
if you already installed mainline aomenc. Running the version info command again, the correct output should look something like this:
% aomenc --help | grep AOMedia -C 3
Included encoders:
av1 - AOMedia Project AV1 Encoder Psy v3.6.0 (default)
Use --codec to switch to a non-default encoder.
Notice how it says AOMedia Project AV1 Encoder Psy
instead of AOMedia Project AV1 Encoder
. You should be all set after this to start using aom-av1-lavish.
You can download the pre-built versions, which can be found below (Current as of Sept 6, 2023):
https://autumn.revolt.chat/attachments/download/-2EiZW1edcT9anApFZ1PJBEber-pJ6z02NiQBjbr28
Join the AV1 Discord server and head to #community-builds for updated versions, you can opt to compile it yourself with the instructions below.
The Compiling Route:
Full credits to u/Turbulent-Bend-7416 on Reddit for this post on how to compile aomenc.
This guide requires MSYS2, specifically MinGW-W64. Install it if you haven't yet.
First, 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
Now, clone the aom-av1-lavish repo in the Endless_Merging branch and create the folders:
git clone https://github.com/Clybius/aom-av1-lavish -b Endless_Merging
cd aom-av1-lavish && mkdir -p aom_build && cd aom_build
Then we can start compiling with some build optimizations for your CPU:
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"
make -j$(nproc)
The resulting binary will be available within your home folder of the location where you installed MSYS2 (usually C:
), navigate there and the to the aom-av1-lavish folder and it should be there.
Built files should be in the "Debug" folder
Don't share binaries compiled with native CPU optimizations unless the person you're sharing to has the same CPU architecture, as this will lead to missing instructions being used and slowing down encode speeds.
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 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 unfortunately lacks the ability to take advantage of multiple threads, so therefore a tool like Av1an will be needed for parallelization. The parameters shown will be biased towards Av1an and aom-av1-lavish usage, so if you plan on using standalone aomenc then 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-content=psy --tune=ssim --enable-keyframe-filtering=1 --disable-kf --kf-max-dist=9999 --enable-qm=1 --deltaq-mode=0 --aq-mode=0 --quant-b-adapt=1 --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. -
--tune-content=psy --tune=ssim
As the name suggests they are tunes that affect the video output, for the better, and for the worst.
Do not use tune-content=psy
if you encode live action above cq-level=30
.
If you use any of the VMAF tunes, you need to specify --vmaf-model-path=
to where you put VMAF models in.
-
--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
set to 0 b its better -
--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 --quant-b-adapt=1`` Parameters that give you free efficiency boost, ignore it. -
--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
Tips & Tricksâ
- Use
--butteraugli-resize-factor=2
if you use any of the butteraugli-based tunes to speed it up without much losses (lavish, butteraugli) and--butteraugli-intensity-target=250
to match the content light level. - Use
--arnr-maxframes
to set max reference frames that will be used to filter the encode, higher values would make the video blurrier at high fidelity but look better at lower bitrates.