Can libavif Use aom for Both Encoding and Decoding
Yes, libavif can be compiled to use the Alliance for
Open Media (aom) library as both its AV1 encoder and
decoder. This article explains how to configure the build process using
CMake flags to enable aom for both tasks, providing a
unified setup for handling AVIF images without needing auxiliary
libraries like dav1d or rav1e.
To achieve this, you must configure the libavif build
system using specific CMake variables. The aom library is
the reference software for the AV1 video format, and it contains robust
pipelines for both compressing (encoding) and decompressing (decoding)
image data.
CMake Configuration Flags
When compiling libavif from source, you need to pass the
following flags to the CMake command to ensure aom is
utilized for both operations:
-DAVIF_CODEC_AOM=ON: This enables the AOM codec wrapper withinlibavif.-DAVIF_CODEC_AOM_DECODE=ON: This explicitly instructslibavifto useaomfor decoding AVIF images.-DAVIF_CODEC_AOM_ENCODE=ON: This explicitly instructslibavifto useaomfor encoding AVIF images.
Compilation Steps
To compile libavif with these settings, follow these
steps:
Install the AOM Library: Ensure the
aomdevelopment headers and libraries are installed on your system.Prepare the Build Directory: Navigate to your cloned
libavifrepository and create a build directory.mkdir build && cd buildConfigure with CMake: Run CMake with the required flags.
cmake .. -G Ninja -DAVIF_CODEC_AOM=ON -DAVIF_CODEC_AOM_DECODE=ON -DAVIF_CODEC_AOM_ENCODE=ONBuild the Project: Run the build command.
ninja
Why Use AOM for Both?
Using aom for both encoding and decoding simplifies your
dependency chain. Instead of linking dav1d for fast
decoding and svt-av1 or rav1e for encoding,
you only need to manage a single external dependency
(libaom).
While dav1d is generally faster for decoding AV1/AVIF
than aom, using aom for decoding is highly
compatible and sufficient for many server-side processing or
command-line tool workflows.