Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Matroska

From ReverseEngineering.wiki
Format
Developer Matroska project (IETF CELLAR specification)
Magic 1A 45 DF A3 (EBML header)
Extensions .mkv, .mka, .mks, .mk3d, .webm
Endianness big
Website https://www.matroska.org/
On this wiki Facts · Code · Notes · Topics

The EBML-based container of .mkv, .mka, .mks and WebM: a file starts with the EBML header (1A 45 DF A3, DocType 'matroska' or 'webm'), then a Segment (18 53 80 67) holding SeekHead, Info, Tracks, Clusters with SimpleBlock/BlockGroup frames, Cues and Tags.

EBML basics

EBML (Extensible Binary Meta Language) is a binary XML-like format. Each element is ID + size + data. Both ID and size are variable-length integers whose length is given by the number of leading zero bits of the first byte: 1xxxxxxx is 1 byte, 01xxxxxx 2 bytes, 001xxxxx 3 bytes, 0001xxxx 4 bytes (sizes go up to 8 bytes). An ID keeps its marker bit (so the 4-byte ID is written 1A 45 DF A3), a size drops it. A size with all value bits set means unknown size (live streams; used for Segment and Cluster). RFC 8794 sections 4.1-4.3 and 6.2 (text read at https://www.rfc-editor.org/rfc/rfc8794.txt) agree: the width is the count of leading 0 bits plus the marker bit 1, the data bits follow (7 bits for 1 octet, 14 for 2, 21 for 3), and an Element Data Size with all data bits set to one means unknown size, allowed only for Master Elements.

Header

The file starts with the EBML header element 0x1A45DFA3 containing EBMLVersion 0x4286, EBMLReadVersion 0x42F7, EBMLMaxIDLength 0x42F2, EBMLMaxSizeLength 0x42F3, DocType 0x4282 (the string matroska or webm), DocTypeVersion 0x4287 and DocTypeReadVersion 0x4285. Global elements usable anywhere: Void 0xEC (padding) and CRC-32 0xBF (ids from FFmpeg libavformat/matroska.h).

Top-level elements

ID Element
0x18538067 Segment (the root of all data)
0x114D9B74 SeekHead (positions of other top-level elements, relative to the Segment data start)
0x1549A966 Info (TimestampScale 0x2AD7B1 default 1000000 ns, Duration 0x4489, Title 0x7BA9, MuxingApp 0x4D80, WritingApp 0x5741, DateUTC 0x4461, SegmentUID 0x73A4)
0x1654AE6B Tracks
0x1F43B675 Cluster
0x1C53BB6B Cues (seek index)
0x1941A469 Attachments (fonts, covers)
0x1043A770 Chapters
0x1254C367 Tags

Tracks

Each TrackEntry 0xAE holds TrackNumber 0xD7, TrackUID 0x73C5, TrackType 0x83 (1 video, 2 audio, 3 complex, 0x10 logo, 0x11 subtitle, 0x12 buttons, 0x20 control, 0x21 metadata), CodecID 0x86 (a string such as V_MPEG4/ISO/AVC, V_VP9, A_OPUS, A_VORBIS, A_FLAC, A_AAC, S_TEXT/UTF8, S_TEXT/ASS), CodecPrivate 0x63A2 (the codec's out-of-band headers, for example the Vorbis three headers or the Opus OpusHead of Format:Ogg), CodecDelay 0x56AA and SeekPreRoll 0x56BB (Opus), TrackLanguage 0x22B59C, DefaultDuration 0x23E383, ContentEncodings 0x6D80 (compression or encryption of the frames), Video 0xE0 (PixelWidth 0xB0, PixelHeight 0xBA, DisplayWidth 0x54B0) and Audio 0xE1.

Clusters and blocks

A Cluster holds Timestamp 0xE7 and frames as SimpleBlock 0xA3 or BlockGroup 0xA0 > Block 0xA1 (plus BlockDuration 0x9B, BlockReference 0xFB, BlockAdditions 0x75A1). A block body is: track number as a vint, a signed 16-bit timestamp relative to the cluster timestamp, a flags byte, then the frame data. In SimpleBlock the flags are: bit 0x80 keyframe, 0x08 invisible, bits 0x06 lacing (00 none, 01 Xiph, 11 EBML, 10 fixed-size), 0x01 discardable (specification cellar-matroska/notes.md). Lacing packs several small frames (often audio) into one block; with lacing the frame count minus one and the lace sizes follow the flags byte.

WebM

WebM is a restricted Matroska profile: DocType webm, video VP8/VP9/AV1 and audio Vorbis/Opus only, no chapters, tags only through a small subset. It is the same bytes otherwise, so a Matroska parser reads it unchanged.

Reversing notes

  • Identify by the first four bytes, then read DocType. Game cutscenes in WebM are common in engines using Chromium Embedded Framework or libvpx.
  • Frames are located through Cluster walk or Cues; there is no sample table. For codecs with out-of-band headers, rebuild them from CodecPrivate.
  • ContentEncodings may declare header stripping (the common leading bytes removed from every frame; they live in the track's ContentCompSettings) or encryption: recognise it, do not assume the frames are raw.

Code & repositories

See the linked IETF CELLAR specification repository (ebml_matroska.xml is the machine-readable element list) and Library:FFmpeg (libavformat/matroska.h).

  • https://github.com/ietf-wg-cellar/matroska-specification @ 1a943ead9bb4c67b02b966cebafe51c8c074e703 · license: CC-BY-4.0 OR BSD-3-Clause (declared by the contributor; GitHub's detector did not recognize LICENSE.md)
    The Matroska specification source: ebml_matroska.xml (every element with id, type, path), cellar-matroska/notes.md (block and lacing structure), codec mapping documents.
    Tested on: source read, not run: Read cellar-matroska/notes.md block structure and ebml_matroska.xml header at this commit. · checked 2026-10-18
  • https://github.com/FFmpeg/FFmpeg @ 7045cc9b8020ebaae156f4947baa752625056f90 · license: LGPL-2.1-or-later (declared by the contributor; GitHub's detector did not recognize LICENSE.md)
    FFmpeg libavformat demuxers: riff.c (wFormatTag and FourCC tables), wavdec.c, avidec.c/avi.h, matroska.h (element ids), id3v2.h, isom.h/mov.c.
    Tested on: source read, not run: Read riff.c tag table, wavdec.c probe, avi.h, matroska.h and id3v2.h at this commit (sparse checkout). Not built. · checked 2026-10-18