MKV/Matroska Container Format: The Open-Source Multimedia Powerhouse
Matroska (MKV) is an open-standard multimedia container format that has become the preferred choice for high-quality video archival, Blu-ray rips, and complex multi-track media. Unlike MP4, which prioritizes device compatibility, Matroska prioritizes flexibility — it can hold virtually any codec combination, unlimited tracks, full chapter systems, and advanced subtitle formats. Understanding its architecture reveals why it dominates in enthusiast and professional media contexts.
Origins and Specification
Matroska was created in 2002 by Steve Lhomme as an open alternative to proprietary containers like AVI, ASF, and RealMedia. The name comes from the Russian matryoshka (nesting dolls), reflecting its hierarchical element structure. It is maintained by the Matroska organization and licensed under BSD.
The format uses EBML (Extensible Binary Meta Language) — a binary analog to XML designed for streaming and forward compatibility. Each element has a variable-length ID and size, allowing players to skip unknown elements rather than failing. This design means a player from 2010 can still open a Matroska file using features added in 2024 — it simply ignores the unknown elements.
Related formats:
- MKV (
.mkv): Full Matroska container — video, audio, subtitles, chapters, attachments - MKA (
.mka): Matroska audio only - MKS (
.mks): Matroska subtitles only - WebM (
.webm): Google's restricted subset — VP8/VP9/AV1 video + Vorbis/Opus audio only
EBML Structure
A Matroska file is organized into top-level segments:
EBML Header — EBML version, DocType ("matroska")
Segment
├── SeekHead — index of element positions (enables fast seeking)
├── Info — duration, title, muxing app, creation date
├── Tracks — codec, language, pixel dimensions per track
│ ├── TrackEntry (Video, CodecID: V_MPEG4/ISO/AVC)
│ ├── TrackEntry (Audio, CodecID: A_AAC)
│ ├── TrackEntry (Subtitle, CodecID: S_TEXT/ASS)
│ └── TrackEntry (Attachment: font file)
├── Chapters — full hierarchical chapter system
├── Cluster(s) — blocks of compressed media data
│ └── SimpleBlock / BlockGroup (each frame/sample)
├── Cues — seek table (keyframe positions for fast seeking)
├── Attachments — embedded files (fonts, cover art, etc.)
└── Tags — extensive tagging system
Track Flexibility
Matroska supports virtually any codec through its codec ID system:
| Track Type | Supported Codecs |
|---|---|
| Video | H.264, H.265/HEVC, AV1, VP8, VP9, MPEG-2, Theora, Dirac, FFV1, VC-1, RealVideo |
| Audio | AAC, AC-3, E-AC-3, DTS, DTS-HD, TrueHD, Dolby Atmos, FLAC, MP3, Vorbis, Opus, ALAC, PCM |
| Subtitles | ASS/SSA, SRT (SubRip), WebVTT, PGS (Blu-ray), DVB subtitles, VobSub (DVD), USF |
| Attachments | Fonts (TTF, OTF), cover art, ICC profiles, any binary file |
This codec freedom makes MKV the natural format for:
- Blu-ray remuxes: preserving TrueHD Atmos, DTS-HD MA, and PGS subtitle tracks without conversion
- Anime: ASS subtitles with complex typesetting, multiple audio/subtitle language tracks
- Archival: lossless audio (FLAC, TrueHD) + lossless video (FFV1) in one file
Chapter System
Matroska's chapter system is far more powerful than MP4's:
<!-- Ordered chapters (chapters from different files) -->
<Chapters>
<EditionEntry>
<EditionFlagOrdered>1</EditionFlagOrdered>
<ChapterAtom>
<ChapterTimeStart>00:00:00.000</ChapterTimeStart>
<ChapterTimeEnd>00:02:30.000</ChapterTimeEnd>
<ChapterDisplay>
<ChapterString>Opening</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<!-- ... -->
</EditionEntry>
</Chapters>
Features unique to Matroska chapters:
- Ordered chapters: reference segments from other MKV files (used to avoid duplicating anime OPs/EDs)
- Multiple editions: alternative chapter structures for director's cuts vs. theatrical versions
- Nested chapters: hierarchical chapters within chapters
- Chapter tags: per-chapter metadata (rating, description)
Tags and Metadata
Matroska's tag system is vastly richer than MP4's:
# Apply tags with mkvpropedit
mkvpropedit output.mkv \
--edit info --set "title=My Film" \
--edit track:1 --set "name=English" \
--tags global:tags.xml
Tags can target the entire file, individual tracks, individual chapters, or individual editions. They support arbitrary tag names, allowing full cataloging metadata: DIRECTOR, CINEMATOGRAPHER, IMDB_ID, CONTENT_RATING, ORIGINAL_TITLE, and more.
Working with MKV — Essential Tools
mkvtoolnix (GUI + CLI)
The reference implementation for Matroska:
# Remux Blu-ray streams into MKV without re-encoding
mkvmerge -o output.mkv \
--track-order 0:0,0:1,0:2 \
video.h265 audio_truehd.thd subtitles.sup
# Extract specific tracks
mkvextract tracks input.mkv 0:video.h265 1:audio.flac 2:subtitles.ass
# Edit track properties without remuxing
mkvpropedit input.mkv --edit track:a1 --set language=jpn
# Get full info
mkvinfo input.mkv
ffmpeg with MKV
# Convert MP4 to MKV with stream copy (instant, no quality loss)
ffmpeg -i input.mp4 -c copy output.mkv
# Add external subtitle file to MKV
ffmpeg -i input.mkv -i subtitles.ass \
-c copy -c:s copy \
-metadata:s:s:0 language=eng \
output_with_subs.mkv
# Extract embedded subtitle
ffmpeg -i input.mkv -map 0:s:0 output.ass
# Encode with lossless FFV1 video + FLAC audio for archival
ffmpeg -i input.mkv \
-c:v ffv1 -level 3 -threads 8 -slices 24 \
-c:a flac \
archive.mkv
Seeking Performance and Cue Points
Matroska's Cues element contains a seek table of keyframe positions, enabling instant random access. Without cues (or when they are at the end of the file), a player must linearly scan the file to find a position. The mkvmerge tool always writes cues; some remuxers may not.
For HTTP streaming, Matroska requires the server to support byte-range requests (HTTP Range: header). Since the seek table (Cues) is typically at the end of the file, seeking in a streaming context requires the player to first fetch the Cues element location from SeekHead, then perform a range request. This is less efficient than fMP4 but works correctly with compliant servers.
MKV vs. MP4 — When to Choose Which
| Use Case | Recommended |
|---|---|
| Web streaming (DASH/HLS) | MP4 (fMP4/CMAF) |
| Mobile device playback | MP4 (H.264+AAC) |
| Blu-ray remux (lossless audio/video) | MKV |
| Anime with styled ASS subtitles | MKV |
| Multiple language audio tracks | MKV (simpler tooling) |
| Universal sharing | MP4 |
| Archival (lossless FFV1+FLAC) | MKV |
| Smart TV / media center (Kodi, Plex) | Both (MKV preferred for full features) |
Hardware and Software Support
MKV is not supported natively in most browsers (no <video> tag support) or many mobile devices. However, it plays natively in:
- Desktop: VLC, MPC-HC, mpv, Kodi, Plex (all platforms)
- Windows: Windows Media Player (Win10 1709+ with codec pack), Files app
- macOS: VLC, IINA, Infuse (iTunes wrapper)
- Smart TVs: Most LG/Samsung/Sony TVs natively (2015+)
- Android: MX Player, VLC, Nova Video Player
For broader device support, transcode MKV to MP4: ffmpeg -i input.mkv -c copy output.mp4 (if codecs are MP4-compatible) or with re-encoding if necessary.
Summary
Matroska/MKV is the uncompromising choice when content quality and track flexibility matter more than device compatibility. Its EBML foundation provides forward compatibility, its codec support is virtually unlimited, and its chapter/tag system far surpasses MP4. For media archival, Blu-ray preservation, enthusiast collections, and professional production workflows, MKV is the correct container. For internet distribution and mobile consumption, MP4 remains the right tool.
Related conversions
Common video conversions that pair well with this guide: