How EBML Structure Works in MKV Files

This article explains how the Extensible Binary Meta Language (EBML) structure functions within Matroska (MKV) files. It covers the fundamental components of EBML, its structural hierarchy, and how this binary, XML-like format enables the MKV container to flexibly store and organize various video, audio, and subtitle streams.

What is EBML?

Extensible Binary Meta Language (EBML) is a generalized binary container format designed to store data in a structured, hierarchical manner. Often described as a binary equivalent to XML, EBML uses tag-like elements to organize data. Instead of using text tags like <video>, EBML uses binary identifiers (IDs) to define data types and structures. The Matroska format (MKV) is the most prominent implementation of EBML.

The Anatomy of an EBML Element

Every piece of data within an MKV file is wrapped in an EBML element. Each element consists of three distinct parts:

  1. Element ID: A variable-length binary identifier that specifies what the element is (e.g., track information, audio data, or metadata).
  2. Data Size: A Variable-Size Integer (VINT) that indicates the length of the upcoming data payload in bytes.
  3. Data Payload: The actual content, which can be an integer, a float, a text string, raw binary data (like a video frame), or container elements that hold other sub-elements.

By using Variable-Size Integers (VINTs) for IDs and sizes, EBML saves significant storage space. If an element’s data payload is small, the size descriptor only uses one byte instead of forcing a fixed 4-byte or 8-byte integer.

The Hierarchical Structure of an MKV File

At its core, an MKV file is a single, nested EBML document. A standard MKV file is structured into several nested levels:

Within the Segment Element, the data is organized into level-1 sub-elements:

Why EBML Benefits MKV

Because EBML is structurally modular, it provides MKV with two major advantages: extensibility and backward compatibility. If a new video codec or metadata tag is introduced, a new EBML ID is defined for it. Older media players that do not recognize the new ID can simply read the “Data Size” descriptor, skip over that specific payload, and continue playing the rest of the file without crashing.