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 DocType element must be set to webm.
  • DocTypeVersion: Must be set to 4 (or at least 2 depending on feature usage, though version 4 is 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 CodecID string must be V_AV1.
  • CodecPrivate: The CodecPrivate element must contain the AV1CodecConfigurationRecord (defined in the AV1 ISOBMFF binding specification, commonly known as av1C). 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 SimpleBlock or Block element 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 SimpleBlock header 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 OpusHead header packet defining the channel count, pre-skip samples, and input sample rate.
    • Packetization: Each audio block must contain an exact Opus packet.
  • Vorbis:
    • CodecID: A_VORBIS
    • CodecPrivate: Must contain the three Vorbis initialization headers (Identification, Comments, and Setup) wrapped using Matroska Vorbis lacing.

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,000 nanoseconds, representing a 1-millisecond resolution).
  • Timestamps: Every Block or SimpleBlock specifies 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 SimpleBlock structures instead of standard Block structures unless non-default block duration elements are required. SimpleBlock provides native one-byte flags for marking keyframes and discardable frames, minimizing container overhead.