How libavif Relates to the AV1 Video Codec

This article explains the relationship between the libavif library and the AV1 video codec, detailing how they work together to enable the AVIF image format. It covers how libavif serves as the container library that relies on AV1 encoders and decoders to compress and decompress high-quality, lightweight images for the web.

The Connection Between AV1 and AVIF

To understand libavif, you first need to understand the relationship between AV1 and AVIF.

Essentially, an AVIF image is simply a very short AV1 video file containing a single frame.

What is libavif?

libavif is a portable, open-source C library designed to read and write AVIF files. It acts as the bridge between raw image data (like pixels) and the final .avif file.

However, libavif does not actually compress or decompress the image data itself. Because AVIF relies on AV1 compression, libavif requires an external AV1 codec to do the heavy lifting.

How libavif Works with AV1 Codecs

When you use libavif to encode or decode an image, the library coordinates the following workflow:

  1. Packaging (The Container): libavif handles the HEIF container format. It manages metadata (like Exif, XMP, and color profiles) and structures the file so that web browsers and operating systems can read it.
  2. Delegation (The Compression): For the actual pixel compression, libavif passes the raw image data to an AV1 video encoder.
  3. Integration: libavif supports several third-party AV1 codec libraries. It can be compiled to use different codecs depending on the performance requirements:
    • aom (libaom): The reference AV1 encoder/decoder developed by the Alliance for Open Media.
    • dav1d: A highly optimized, fast AV1 decoder.
    • rav1e: An AV1 encoder written in Rust, focused on speed and safety.
    • SVT-AV1: A production-grade AV1 encoder developed by Intel and Netflix, optimized for multi-core processors.

In summary, libavif is the manager of the AVIF file, while an AV1 codec is the engine. Without an AV1 codec, libavif cannot compress or decompress the visual data; without libavif, an AV1 video codec cannot package that data into a standardized image format that web browsers can display.