AV1 Keyframe Placement for Adaptive Bitrate Streaming
This article provides an overview of keyframe placement strategies used in AV1 encoding for adaptive bitrate (ABR) streaming workflows. It explores the technical necessity of aligning keyframes across bitrate ladders, evaluates fixed versus dynamic GOP structures, and examines AV1-specific features—such as Switch Frames (S-frames)—that optimize bandwidth efficiency without sacrificing smooth playback during network fluctuations.
The Role of Keyframes in Adaptive Bitrate Streaming
In adaptive bitrate streaming protocols like HLS and DASH, video streams are split into multi-second segments (typically between 2 to 6 seconds). A client device dynamically switches between high- and low-bandwidth renditions based on changing network conditions.
For seamless switching, every stream rendition in an encoding ladder must contain a keyframe (intra-frame) at the exact same presentation timestamp (PTS). If keyframes are misaligned, switching between bitrates causes playback artifacts, buffering, or decoder crashes because the decoder cannot find the required reference frames.
Fixed-Interval Closed GOPs
The standard approach for ABR streaming is the fixed-interval Closed Group of Pictures (GOP). In this strategy, keyframes are inserted at absolute, non-negotiable intervals matching the streaming segment length.
- Closed GOP Enforcement: Inter-frame prediction (P-frames or B-frames) is strictly prohibited from referencing frames prior to the keyframe. This ensures each segment is completely self-contained and decodable independently.
- Strict Cadence: In encoders like SVT-AV1 or libaom,
the minimum and maximum keyframe intervals (
--min-keyintand--keyint) are set to the identical value (e.g., at 60 fps with 2-second segments, both are set to 120). - Trade-offs: While this approach guarantees predictable segment boundaries and smooth bitrate switching, it sacrifices compression efficiency if a keyframe is forced immediately after a natural scene change.
Scene-Aware Dynamic Keyframe Insertion
Enforcing keyframes only at fixed intervals can degrade visual quality when high-motion scene changes occur between segment boundaries. A dynamic keyframe strategy incorporates scene-cut detection alongside fixed boundaries.
- Primary Boundaries: Keyframes are locked to segment intervals (e.g., every 2 seconds) across all renditions.
- Secondary Intra-Frames: The encoder's lookahead module identifies abrupt scene changes within a segment and inserts an intra-frame. Because intra-frames are computationally heavy, encoders must constrain the minimum distance between them to prevent sudden bitrate spikes.
- Ladder Consistency: If dynamic scene-cut keyframes are utilized, the scene-cut decisions must be applied globally across every rendition in the ABR ladder, typically by using a master pass or shared segmentation map.
AV1 Switch Frames (S-Frames)
AV1 introduces a specialized frame type designed specifically to solve the inefficiencies of traditional ABR keyframe placement: the Switch Frame (S-frame).
In traditional codecs, changing bitrates requires an IDR (Instantaneous Decoder Refresh) frame, which is an intra-coded frame that resets the reference buffer. Intra-frames require significantly more bits than inter-coded frames, causing periodic bitrate spikes at segment boundaries.
AV1 S-frames allow a video stream to switch to a different rendition without requiring a full intra-coded frame.
- An S-frame is predicted from reference frames of the same presentation time within a different bitrate track of the same ladder, provided the tracks are synchronized.
- By allowing inter-frame prediction across tracks at predefined switch points, S-frames reduce the bitrate overhead of segment boundaries by up to 20–30% compared to traditional IDR-based fixed GOPs.
- This mechanism maintains strict decodability for ABR clients while preserving coding efficiency.
Open GOP Configurations in ABR
While Closed GOPs are standard for strict ABR segmentation, Open GOPs allow frames following a keyframe to reference frames that preceded it.
- Compression Advantage: Open GOPs provide better compression efficiency because the frames immediately following a keyframe can reference high-quality data from the previous GOP.
- ABR Constraint: Open GOPs cannot be used at arbitrary segment boundaries if the client switches tracks, as the reference frames from the previous rendition will not match.
- Implementation: When used in ABR, encoders place Open GOP keyframes internally within segments, reserving Closed GOP keyframes (or S-frames) strictly for the segment division points where track-switching occurs.
Best Practices for AV1 ABR Encoders
To maximize streaming stability and bandwidth efficiency in production AV1 workflows:
- Synchronize Segment Lengths: Match
--keyintdirectly to the segment duration (e.g.,--keyint 48for 2-second segments at 24 fps). - Standardize Decisions: If using two-pass encoding with dynamic scene detection, generate a first-pass analysis file and apply it uniformly across all renditions in the ladder to prevent boundary mismatches.
- Leverage S-Frames: When supported by the downstream packager and target client decoders, configure the AV1 encoder to use S-frames at segment switch points instead of full intra-only keyframes.