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:

Compilation Steps

To compile libavif with these settings, follow these steps:

  1. Install the AOM Library: Ensure the aom development headers and libraries are installed on your system.

  2. Prepare the Build Directory: Navigate to your cloned libavif repository and create a build directory.

    mkdir build && cd build
  3. Configure with CMake: Run CMake with the required flags.

    cmake .. -G Ninja -DAVIF_CODEC_AOM=ON -DAVIF_CODEC_AOM_DECODE=ON -DAVIF_CODEC_AOM_ENCODE=ON
  4. Build 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.