What is AVIF_CODEC_AOM in libavif?

This article explains the purpose and functionality of the AVIF_CODEC_AOM build configuration in libavif, the official library used for encoding and decoding AVIF images. It details how this CMake flag enables the Alliance for Open Media (AOM) reference codec to process AV1-based image files, and outlines when and why developers should enable it during the build process.

Understanding AVIF_CODEC_AOM

libavif is a portable C library used to write and read AVIF (AV1 Image File Format) files. However, libavif does not compress or decompress the underlying AV1 video frames on its own. Instead, it relies on external AV1 codecs to do the heavy lifting.

AVIF_CODEC_AOM is a build configuration option (specifically a CMake variable) that tells libavif to compile with support for libaom, the official AV1 reference codec developed by the Alliance for Open Media.

When you enable AVIF_CODEC_AOM, you instruct the compiler to link libavif with libaom, enabling the library to utilize this specific codec for both compressing (encoding) and decompressing (decoding) AVIF images.

Key Purposes of AVIF_CODEC_AOM

1. Dual Encoding and Decoding Capability

Unlike some codecs that only handle one side of the process (such as dav1d, which is a highly optimized decoder-only library), libaom is a complete encoder and decoder. Enabling AVIF_CODEC_AOM gives your libavif build the ability to both read existing AVIF images and create new ones.

2. Industry Standard Compliance

Because libaom is the reference implementation of the AV1 standard, it is highly compliant with the specification. Using AVIF_CODEC_AOM ensures that the AVIF files you produce are highly compatible across different platforms, web browsers, and image viewers.

3. High Compression Efficiency

The AOM codec is renowned for its advanced compression algorithms. While it can be computationally expensive and slower to encode compared to other options, it yields exceptionally small file sizes with high visual quality.

How to Use AVIF_CODEC_AOM in a Build

To enable the AOM codec when compiling libavif from source, you must pass the appropriate flag to CMake. The configuration values typically include:

CMake Example

A typical build command enabling the AOM codec looks like this:

cmake -S . -B build -DAVIF_CODEC_AOM=SYSTEM
cmake --build build

When Should You Use It?

You should enable AVIF_CODEC_AOM if: * You need to encode (generate) AVIF images, as it is one of the most reliable and widely supported encoders available. * You are building a general-purpose image processing tool that requires robust, standard-compliant AVIF support. * You do not mind slower encoding times in exchange for maximum compression efficiency and compatibility.