CMake Flags to Enable libavif Codec Backends

This article provides a direct guide on the CMake configuration flags required to enable specific AV1 encoder and decoder backends when building libavif. You will learn how to configure support for popular codecs like AOM, dav1d, rav1e, SVT-AV1, and libgav1 to customize your AVIF image compilation.

To compile libavif with support for specific AV1 codecs, you must pass specific boolean flags to CMake during configuration. You can also instruct CMake to build these dependencies from the library’s local ext/ subdirectory if you do not want to use system-installed libraries.

AOM (Alliance for Open Media)

AOM is the reference encoder and decoder for AV1. It is highly compatible and supports both encoding and decoding. * Enable AOM: -DAVIF_CODEC_AOM=ON (or SYSTEM to force system library search) * Build from ext/ subdirectory: -DAVIF_LOCAL_AOM=ON

dav1d

dav1d is an extremely fast, highly optimized AV1 decoder developed by VideoLAN. It is the recommended choice for decoding in libavif. * Enable dav1d: -DAVIF_CODEC_DAV1D=ON (or SYSTEM) * Build from ext/ subdirectory: -DAVIF_LOCAL_DAV1D=ON

SVT-AV1

SVT-AV1 is a high-performance, multi-threaded AV1 encoder developed by Intel and Netflix, ideal for fast encoding. * Enable SVT-AV1: -DAVIF_CODEC_SVT=ON (or SYSTEM) * Build from ext/ subdirectory: -DAVIF_LOCAL_SVT=ON

rav1e

rav1e is an AV1 encoder written in Rust. It is designed to be safe, efficient, and fast. * Enable rav1e: -DAVIF_CODEC_RAV1E=ON (or SYSTEM) * Build from ext/ subdirectory: -DAVIF_LOCAL_RAV1E=ON

libgav1

libgav1 is a lightweight AV1 decoder developed by Google, often utilized in mobile environments. * Enable libgav1: -DAVIF_CODEC_GAV1=ON (or SYSTEM) * Build from ext/ subdirectory: -DAVIF_LOCAL_LIBGAV1=ON

Example Build Command

To build libavif with the fast dav1d decoder and the SVT-AV1 encoder using locally downloaded sources, use the following CMake configuration:

cmake -B build \
  -DAVIF_CODEC_DAV1D=ON -DAVIF_LOCAL_DAV1D=ON \
  -DAVIF_CODEC_SVT=ON -DAVIF_LOCAL_SVT=ON
cmake --build build