AV1 in WebM: Audio-Video Encapsulation Requirements
This article provides an overview of the technical specifications and
encapsulation requirements for muxing AV1 video and compatible audio
streams into the WebM container format. Standardized as a restricted
subset of the Matroska (MKV) specification, WebM defines strict rules
regarding container headers, video track parameters using the
V_AV1 identifier, allowed audio codecs (predominantly
Opus), and stream packetization behavior to ensure broad cross-platform
interoperability.
Container-Level Specifications
WebM files carrying AV1 streams must strictly follow the EBML (Extensible Binary Meta Language) structure defined for WebM, rather than full-featured Matroska:
- DocType: The EBML
DocTypeelement must be set towebm. - DocTypeVersion: Must be set to
4(or at least2depending on feature usage, though version4is standard for modern implementations). - Track Types: The container should only contain video tracks, audio tracks, and WebVTT subtitle tracks. Menu systems, attachments, and arbitrary metadata tags present in standard Matroska are not allowed.
AV1 Video Track Requirements
When encapsulating AV1 video within WebM, the following track settings and payload structures are mandatory:
- CodecID: The
CodecIDstring must beV_AV1. - CodecPrivate: The
CodecPrivateelement must contain theAV1CodecConfigurationRecord(defined in the AV1 ISOBMFF binding specification, commonly known asav1C). This record communicates critical sequence information, such as the AV1 profile, level, tier, color bit depth, chroma subsampling format, and initial Sequence Header Open Bitstream Units (OBUs). - Block Packetization:
- AV1 bitstreams must be stored as Open Bitstream Units (OBUs).
- Each Matroska
SimpleBlockorBlockelement must correspond to a complete Temporal Unit (TU) or a frame. - Temporal Delimiter OBUs should generally be omitted to avoid unnecessary container bloat, as the container's block structure natively defines frame boundaries.
- Keyframes must contain a Sequence Header OBU and an intra-frame,
flagged accordingly in the
SimpleBlockheader flags.
Supported Audio Streams
WebM strictly limits the audio codecs permitted within the container. When paired with AV1 video, audio must adhere to one of the following formats:
- Opus (Recommended):
- CodecID:
A_OPUS - CodecPrivate: Must contain the mandatory
OpusHeadheader packet defining the channel count, pre-skip samples, and input sample rate. - Packetization: Each audio block must contain an exact Opus packet.
- CodecID:
- Vorbis:
- CodecID:
A_VORBIS - CodecPrivate: Must contain the three Vorbis initialization headers (Identification, Comments, and Setup) wrapped using Matroska Vorbis lacing.
- CodecID:
No other audio codecs (such as AAC or MP3) are valid within the WebM specification.
Timestamping and Synchronization
- TimecodeScale: Must be defined in the Segment
Information header (commonly set to
1,000,000nanoseconds, representing a 1-millisecond resolution). - Timestamps: Every
BlockorSimpleBlockspecifies a relative timecode that, combined with the track's timecode scale and the cluster's base timestamp, yields the presentation time (PTS) of the frame. - SimpleBlock Usage: Video and audio streams should
use
SimpleBlockstructures instead of standardBlockstructures unless non-default block duration elements are required.SimpleBlockprovides native one-byte flags for marking keyframes and discardable frames, minimizing container overhead.