Build libavif Without External AV1 Dependencies
This article explains whether it is possible to build the
libavif library without any external AV1 codec
dependencies. It covers the technical feasibility of compiling the
library in a standalone state, the limitations of a codec-free build,
and how libavif interacts with underlying AV1 encoders and
decoders.
Technically, you can build libavif without any external
AV1 codec dependencies. The compilation process will complete
successfully if you disable all external codecs in the build
configuration. However, the resulting library will have extremely
limited functionality.
How libavif Handles Codecs
The libavif library is not an AV1 codec itself. Instead,
it is a container parser and muxer designed to package AV1 video frames
into the AVIF (AV1 Image File Format) container, which is based on the
ISOBMFF standard.
To actually compress (encode) or decompress (decode) the pixels of an
image, libavif must delegate that work to an external AV1
codec. Common dependencies include: * Decoders:
dav1d, libgav1, or aom *
Encoders: SVT-AV1, libaom, or
rav1e
Building libavif in “Header-Only” or “Container-Only” Mode
If you configure the build system (typically CMake) and turn off all
codec options, libavif will compile. You can achieve this
by setting the following CMake flags to OFF:
cmake -DAVIF_CODEC_AOM=OFF \
-DAVIF_CODEC_DAV1D=OFF \
-DAVIF_CODEC_LIBGAV1=OFF \
-DAVIF_CODEC_RAV1E=OFF \
-DAVIF_CODEC_SVT=OFF ..When built this way, the output library will have zero external AV1 dependencies.
Limitations of a Dependency-Free Build
While the build will succeed, the resulting library cannot perform the primary functions most users expect from an image library:
- No Decoding: If you attempt to read an AVIF file,
libavifcan parse the container metadata (such as width, height, and color profile), but it will fail to decode the actual image pixels. It will return anAVIF_RESULT_NO_CODEC_AVAILABLEerror. - No Encoding: If you attempt to write or compress an image into the AVIF format, the library will fail because it lacks the engine required to compress raw pixels into an AV1 bitstream.
When is a Codec-Free Build Useful?
Building libavif without dependencies is only useful in
niche scenarios. For example, if you are writing a metadata parser, an
image inspector, or a tool that only extracts raw AV1 payloads from
ISOBMFF containers without decompressing them, a dependency-free build
keeps the binary size minimal and simplifies compilation.
For any practical application that needs to display or create AVIF
images, you must bundle at least one decoding dependency (such as
dav1d for fast CPU decoding) and/or one encoding dependency
(such as libaom or SVT-AV1).