How AVIF Uses AV1 Keyframes to Compress Images
The AV1 Image File Format (AVIF) achieves state-of-the-art compression efficiency by repurposing the intra-frame encoding architecture of the AV1 video codec for static pictures. Rather than inventing a distinct algorithm for still photography, AVIF encapsulates a single, self-contained AV1 keyframe within an ISO Base Media File Format (ISOBMFF) container. This article explains how keyframe compression functions within AV1, the specific intra-coding mechanisms that eliminate spatial redundancy, and how this architecture delivers higher visual fidelity at smaller file sizes than legacy formats.
The Concept of Intra-Frames (Keyframes)
In video compression, an intra-frame (often called a keyframe or I-frame) is a frame encoded entirely without reference to any past or future frames. While inter-frames rely on temporal prediction to record only the changes occurring between frames over time, keyframes rely entirely on spatial prediction within the boundaries of that single frame.
AVIF capitalizes on this fundamental design. A static AVIF image is essentially an AV1 video stream consisting of exactly one keyframe. Because video standards demand extreme compression efficiency to stream high-resolution content over limited bandwidth, the intra-frame tools developed for AV1 are significantly more advanced than the decades-old compression methods found in formats like JPEG.
Advanced Partitioning and Superblocks
To compress an image, AV1 begins by dividing the keyframe into large processing units known as Superblocks, which can be up to 128×128 pixels in size.
AV1 utilizes a recursive partitioning tree that divides these Superblocks into smaller sub-blocks ranging from 128×128 down to 4×4 pixels. Unlike older formats that restrict partitioning to rigid, square grids (such as 8×8 or 16×16 blocks), AV1 supports flexible recursive splits, including non-square rectangular partitions (such as 1:2, 2:1, 1:4, and 4:1 ratios).
This flexibility allows the encoder to isolate complex textures and sharp edges into fine, granular blocks while grouping broad, flat areas (such as clear skies or smooth gradients) into massive blocks, drastically reducing the data required to represent uniform regions.
Spatial Intra-Prediction
Once partitioned, the encoder minimizes spatial redundancy by predicting the pixel values of a target block using the reconstructed pixels of immediately adjacent, previously encoded blocks. AV1 keyframe encoding features several sophisticated intra-prediction modes:
- Directional Intra-Prediction: Extends neighboring pixel patterns into the current block across 56 directional angles, allowing precise alignment with edges and contours.
- Smooth and DC Predictors: Generates gradual blending across blocks for smooth surfaces or calculates a simple average value (DC) for flat regions.
- Chroma-from-Luma (CfL): Because human vision is more sensitive to luminance (brightness) than chrominance (color), AV1 models color values directly as a mathematical function of the corresponding luminance pixels. This avoids encoding redundant color data that mirrors existing brightness contours.
Instead of storing raw pixel values, the encoder only records the selected prediction mode and the "residual"—the minor difference between the predicted pattern and the original image.
Transform and Quantization
After prediction, the residual data is converted from the spatial domain into the frequency domain via transform coding. While JPEG relies solely on the Discrete Cosine Transform (DCT), AV1 selects from a variety of transforms for each block:
- Discrete Cosine Transform (DCT)
- Asymmetric Discrete Sine Transform (ADST)
- Identity Transforms (flipping between spatial and frequency processing)
By pairing different horizontal and vertical transforms (for example, a DCT horizontally and an ADST vertically), the encoder efficiently compacts residual energy along directional edges.
The resulting transform coefficients are then quantized. Quantization selectively rounds off high-frequency details that the human visual system struggles to perceive. AV1 features adaptive quantization, allowing the encoder to apply different degrees of compression across varying segments of the image based on visual complexity.
In-Loop Filtering
Quantization at high compression ratios typically causes noticeable artifacts, such as block boundaries or ringing noise around sharp edges. AV1 keyframes counteract this degradation through a sequence of three hardware-accelerated in-loop filters applied directly during the encoding and decoding process:
- Deblocking Filter: Smooths harsh discontinuities along the edges of block partitions.
- Constrained Directional Enhancement Filter (CDEF): Identifies the direction of primary edges within each block and applies directional filtering to eliminate ringing artifacts without blurring structural detail.
- Loop Restoration: Emphasizes overall sharpness using Wiener filters or self-guided restoration, recovering lost contrast and high-frequency textures.
Container Integration
Finally, the fully processed, filtered keyframe bitstream is placed into the ISOBMFF structure. This lightweight wrapper stores image metadata (such as EXIF, XMP, and color profiles), transparency information (via auxiliary alpha channels, which are simply secondary monochromatic keyframes), and instructions for High Dynamic Range (HDR) color spaces with bit depths of 10-bit and 12-bit. By relying directly on the optimized spatial processing of AV1 keyframes, AVIF delivers modern compression performance while retaining full architectural support for modern display standards.