.MKV
Matroska video
Introduction
Matroska is an open, royalty-free container format, first released in 2002. A Matroska file can hold any number of video, audio and subtitle tracks in almost any codec, together with chapters, tags and attached files such as fonts. That flexibility makes it a common choice for films with several languages and subtitle tracks.
The same format uses .mkv for video, .mka for audio only,
.mks for subtitles only and .mk3d for stereoscopic video. WebM,
used for video on the web, is a restricted form of Matroska.
Software
- VLC media player (Windows, macOS, Linux, mobile)
- mpv (Windows, macOS, Linux)
- MKVToolNix (Windows, macOS, Linux)
- Kodi (Windows, macOS, Linux, mobile)
- HandBrake (Windows, macOS, Linux)
- FFmpeg (Windows, macOS, Linux)
- DaVinci Resolve (Windows, macOS, Linux)
Structure
Matroska is built on EBML, the Extensible Binary Meta Language, a binary form of XML. Every element is an ID, a size and the data. IDs and sizes are variable-length integers: the number of leading zero bits in the first byte says how many bytes follow, so small values take little space. Elements nest, so the file is a tree.
A file starts with an EBML header, ID 1A 45 DF A3, whose DocType is
matroska or webm. Then comes one Segment holding everything
else: a SeekHead index of the top-level elements, the Info element with the timescale
and duration, the Tracks element describing each track, and Clusters of encoded frames,
each cluster starting with a timestamp. Cues near the end let a player seek quickly.
0EBML header: EBML version and DocTypevaries…Segment holds all the contentvaries…SeekHead where the other top-level elements arevaries…Info timescale, duration and titlevaries…Tracks one entry per track: type, codec, settingsvaries…Cluster a timestamp then blocks of framesrepeated…Cues seek points; also Chapters, Tags, Attachmentsvaries