What is an Alt-Ref Frame in libvpx?
This article explains the function and utility of alternate reference (alt-ref) frames in the libvpx video codec library, which encodes VP8 and VP9 video formats. You will learn how these hidden, high-quality frames are constructed, how they differ from standard reference frames, and how they significantly improve video compression efficiency and visual quality.
The Core Function of Alt-Ref Frames
In video compression, reference frames are previously decoded frames used to predict the appearance of future frames, saving data by only encoding the differences between them. While standard codecs use past and future displayed frames for this purpose, libvpx introduces a unique type of frame called the alternate reference (alt-ref) frame.
The primary function of an alt-ref frame is to serve as a high-quality, non-displayed predictor. Unlike traditional video frames, an alt-ref frame is encoded into the video bitstream but is not directly shown to the viewer. Instead, it sits in the decoder’s buffer, allowing subsequent visible frames to reference it to reconstruct their own images.
How Alt-Ref Frames Improve Compression
Alt-ref frames improve compression efficiency through a process called temporal filtering.
- Temporal Filtering (Noise Reduction): To create an alt-ref frame, the libvpx encoder looks ahead at a group of future frames. It applies a temporal filter that averages these frames together. This process effectively removes random sensor noise and transient details while preserving static background elements.
- High-Quality Reference: Because the noise is filtered out, the resulting alt-ref frame is highly clean and requires fewer bits to encode. It acts as a “golden” representation of the scene.
- Efficient Prediction: Subsequent visible frames can reference this clean alt-ref frame. Because the background noise has been stripped away, the encoder only needs to compress the actual motion and changes, drastically reducing the overall bitrate required for the video sequence.
Alt-Ref Frames vs. Traditional B-Frames
In other codecs like H.264 or HEVC, bi-directional prediction is achieved using B-frames. B-frames target compression by referencing both past and future displayed frames, but they must eventually be displayed themselves.
Libvpx’s alt-ref frames offer a more flexible alternative. Because an alt-ref frame is invisible, the encoder is not constrained by having to make it look perfect to the human eye at a specific timestamp. It can be a highly customized, mathematically optimized blend of multiple frames designed purely to help other frames compress better.
Additionally, when the video sequence naturally progresses to the point in time represented by the alt-ref frame, the encoder can use a “show-existing-frame” flag. This instantly displays the cached alt-ref frame to the user without needing to re-transmit the image data, saving massive amounts of data at scene transitions or keyframes.