MKV (Matroska) in Practice | EBML, Multi-Subtitle & FFmpeg Remux

MKV (Matroska) in Practice | EBML, Multi-Subtitle & FFmpeg Remux

이 글의 핵심

MKV is the flexible general Matroska profile—EBML, tracks, chapters, and FFmpeg patterns for real archives.

Introduction

MKV (Matroska Video) is an open-specification container built on EBML (Extensible Binary Meta Language)—strong at multiple audio tracks, subtitles, chapters, and attachments in one meaningful package. Ripping, podcast archives, multilingual lecture capture, and subtitle workflows often prefer MKV over MP4 for expressiveness.

For default OS players and web standards, MP4/fMP4 often passes more conservatively, so teams commonly use MKV for masters and editing, then transmux for release. This article walks structure → FFmpeg track handling → release strategy.

After reading this post

  • Explain EBML, Segment, and Cluster roles
  • Map multiple audio, subtitles, and metadata with FFmpeg snippets
  • Choose MKV vs MP4/WebM on a flexibility vs compatibility axis
  • Triage common player failures

Table of contents

  1. Container overview
  2. Internal structure
  3. Hands-on usage
  4. Performance comparison
  5. Real-world use cases
  6. Optimization tips
  7. Common problems
  8. Wrap-up

Container overview

History and background

Matroska was designed in the 2000s as an open container to improve on predecessors like MCF. EBML encodes an extensible element tree. MKV is video-centric; MKA audio; MKS subtitle-centric—always verify contents with ffprobe.

Technical characteristics

  • Track model: Separate video, audio, subtitle tracks with language, title, and default flags.
  • Chapters and tags: Edition, Chapter, Tag elements support DVD/BD-like navigation.
  • Attachments: Fonts and cover images for subtitle rendering.
  • Codecs: H.264/HEVC/AV1, FLAC, AC3, ASS, and more—players must decode each codec.

Extensions

ExtensionTypical use
.mkvGeneral video container
.mkaAudio-only
.mksSubtitle-focused

Internal structure

EBML and Matroska elements

EBML uses variable-length integers (VINT) for element IDs and sizes so the tree can be scanned sequentially from the front. Segment is the top-level payload root for content.

Segment, Cluster, Track

  • Segment: Main body—header (Tracks, Tags, …) and Clusters.
  • Tracks: Track types, codec IDs, private codec data.
  • Cluster: Time-ordered groupsSimpleBlock carries frames/packets. Seeking and keyframe policy depend heavily on encode and mux settings.

WebM relationship

WebM is a subset of Matroska limited to VP8/VP9/AV1 + Vorbis/Opus. MKV is the general archive profile without that restriction.

Metadata

  • Tags: ARTIST, TITLE, DATE, …
  • Chapters: Editions and chapters for extras and navigation.

Structure (conceptual)

flowchart TB
  EBMLHdr[EBML header]
  Seg[Segment]
  Info[Info: timecode scale, etc.]
  Tracks[Tracks: video, audio, subs]
  Tags[Tags: metadata]
  Chapters[Chapters]
  ClA[Cluster: time block A]
  ClB[Cluster: time block B]
  EBMLHdr --> Seg
  Seg --> Info
  Seg --> Tracks
  Seg --> Tags
  Seg --> Chapters
  Seg --> ClA
  Seg --> ClB

Hands-on usage

Inspect tracks and chapters

ffprobe -hide_banner -show_format -show_streams -show_entries chapter=metadata input.mkv

Lossless remux

ffmpeg -i input.mkv -c copy remuxed.mkv

Merge from multiple inputs (multi-audio + subtitle)

ffmpeg -i video.mp4 -i commentary.m4a -i subs.ass \
  -map 0:v:0 -map 0:a:0 -map 1:a:0 -map 2:s:0 \
  -c:v copy -c:a copy -c:s copy \
  -metadata:s:a:1 title="Director commentary" -metadata:s:s:0 language=kor package.mkv

Extract a subtitle track

ffmpeg -i package.mkv -map 0:s:0 -c:s copy subs-track0.srt

If the codec is ASS, match extension and -c:s.

MKV → MP4 for web (when codecs allow)

ffmpeg -i package.mkv -c:v copy -c:a aac -b:a 192k \
  -map 0:v:0 -map 0:a:0 -movflags +faststart for_web.mp4

Burning subs into MP4 is constrained—external VTT is common.

Simple metadata edit

ffmpeg -i input.mkv -c copy -metadata title="Series title" -metadata date="2026-03-30" tagged.mkv

For precise chapters/tags, mkvtoolnix (mkvpropedit, …) is often better.


Performance comparison

Overhead

Flexible indexes and tags can slightly increase header share on metadata-heavy files—usually small vs video bitrate.

Streaming fit

AspectMKV
HTTP single fileWorks locally, but fMP4 is more standardized for industry streaming
HLS/DASHUsually package to segmented MP4, not raw MKV
Local high-quality playbackVLC, mpv, … excel

Compatibility

  • Desktop: generally strong.
  • Mobile: OS and player may limit HEVC or subtitle tracks.
  • Web: do not rely on native MKV in browsers.

Real-world use cases

Streaming (HLS, DASH)

  • Keep masters in MKV, transpackage to fMP4 in the factory—good for many languages and subtitle tracks in one object.

Web

  • Prefer MP4/WebM + VTT or a streaming protocol over direct MKV upload for simpler operations.

Mobile

  • ExoPlayer can play MKV, but maintain a codec × device matrix for licensing and decoders.

Archiving

  • Multiple dubs, subs, chapters, covers in one file—pair with checksums and catalog DBs for long-term storage.

Optimization tips

Streaming

If the end goal is web streaming, design around fMP4/TS + master playlists; use MKV as intermediate or master.

Smaller files

Remove duplicate tracks and heavy attachments:

ffmpeg -i heavy.mkv -map 0:v:0 -map 0:a:0 -c copy slim.mkv

Compatibility

Test on target hardware before release; if needed, remux or transcode to H.264 + AAC as a lowest common denominator.


Common problems

Browser won’t play MKV

  • HTML5 video does not standardize MKV—use MP4/WebM for web.

Metadata lost

  • Tag key support varies by tool—mirror important data in external JSON or MAM.

Codec issues

  • TrueHD/DTS and similar tracks may need license-capable decoders—often transcode to AAC or AC3 for distribution.

Wrap-up

Summary

  • MKV on EBML/Matroska is flexible for multi-track, chapters, tags, and attachments.
  • FFmpeg remux and track selection automation simplify internal workflows.
  • Wide final distribution still often favors MP4/fMP4split roles by stage.

When to choose MKV

  • Multilingual masters, heavy subtitle/chapter content, ripping, intermediate editorial outputs. For CDN streaming and mobile web, pair with the MP4 guide and WebM guide.