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.
- AV1 (AOMedia Video 1) is an open-source, royalty-free video compression format designed for transmitting video over the internet. It offers superior compression efficiency compared to older formats like H.264 and VP9.
- AVIF (AV1 Image File Format) is a still-image format. Instead of inventing a completely new compression algorithm for images, the creators of AVIF decided to wrap a single frame (or a short sequence of frames for animations) compressed with the AV1 video codec inside a standard HEIF (High Efficiency Image File) container.
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:
- Packaging (The Container):
libavifhandles 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. - Delegation (The Compression): For the actual pixel
compression,
libavifpasses the raw image data to an AV1 video encoder. - Integration:
libavifsupports 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.