WebM Container¶
Overview¶
WebM is an open media container based on a restricted profile of Matroska. It is designed for web video delivery and is commonly used with open codecs such as VP8, VP9, Vorbis, and Opus.
A WebM file stores compressed audio and video streams together with timing information and container metadata needed for synchronized playback. WebM is most often used for browser playback, HTML5 video delivery, and open media workflows.
WebM is a container, not a codec. The container defines how streams are packaged and synchronized; the codecs define how the audio and video streams are compressed.
Container Structure¶
WebM files are organized as EBML elements. A WebM file typically contains a segment with track metadata, clusters of media data, cue points, and optional metadata.
Important WebM / Matroska elements include:
EBML header - identifies the file as an EBML-based document and declares the document type
Segment - the top-level container for media data and metadata
Info - contains segment-level information such as duration and timestamp scale
Tracks - describes each audio or video stream
Cluster - stores groups of encoded media blocks with timing information
Block / SimpleBlock - stores encoded audio or video samples
Cues - provides seek points for efficient random access
During demuxing, the reader parses the EBML hierarchy, identifies the available tracks, reads clusters, extracts encoded blocks, and reconstructs timestamps for each output stream.
Common Streams¶
WebM commonly stores:
Video - VP8 or VP9
Audio - Vorbis or Opus
These codec restrictions are part of what separates WebM from general Matroska files. A Matroska .mkv file can contain many codec types; a WebM .webm file is intended to use the smaller WebM codec set for predictable web playback.
Muxing and Demuxing¶
Muxing creates a WebM file by writing track metadata, codec identifiers, timestamps, and encoded audio/video blocks into WebM clusters. The muxer is responsible for generating a valid EBML structure that WebM-compatible players can parse.
Demuxing reads the WebM EBML structure, selects tracks, and extracts compressed stream samples. Demuxing does not inherently decode the VP8, VP9, Vorbis, or Opus streams; it separates the streams unless the workflow also includes decoding or transcoding.
Key features of WebM include:
Open web media format - Designed for royalty-free web video workflows
Common codec pairings - Typically VP8 or VP9 video with Vorbis or Opus audio
Browser support - Used in HTML5 video and web delivery scenarios
Matroska-based structure - Uses a flexible container model for media tracks and timing
Streaming-friendly layout - Clusters and cues support sequential playback and seeking
AVBlocks provides support for WebM container workflows, allowing you to:
Mux encoded audio and video streams into a WebM file
Demux streams from a WebM file into separate output files
Work with common WebM codec combinations such as VP8/Vorbis
WebM Muxing¶
Mux Audio and Video Into WebM - Mux Vorbis audio and VP8 video streams into a WebM file using Transcoder::run
WebM Demuxing¶
Demux Audio and Video From WebM - Extract the first audio and video streams from a WebM file using Transcoder::run