Skip to content

MKVToolNix

currentMigrated from docs/utilities/MKVToolNix.mdx at 37c3317fd058; modified for Encode Wiki · CC BY-SA 4.0

mbunkus/mkvtoolnix

codeberg.org

Creating and working with Matroska files

Latest tag
release-102.0
Last commit
Stars
98

MKVToolNix, by Moritz Bunkus, is the reference toolkit for Matroska and WebM. It is what most encoders use for the last step of a job: putting the encoded video, audio, subtitles, fonts and chapters together into one .mkv. It never re-encodes anything, so every operation is lossless and fast.

ToolDoes
MKVToolNix GUIFront end for all of the below; most people use its multiplexer and header editor tabs.
mkvmergeMuxes, remuxes, splits and appends files. Reads MKV, MP4, raw streams, IVF, Blu-ray playlists and more.
mkvextractExtracts tracks, attachments, chapters, tags and timestamps.
mkvpropeditEdits titles, track languages, names and flags in place, without remuxing.
mkvinfoShows the element structure of a file.

The downloads page has a Windows installer and portable archive, macOS disk images, an AppImage, and repositories for Debian, Ubuntu, Fedora and other distributions. It is also on Flathub and in most distribution repositories. Releases are frequent; distribution packages may trail by a few versions.

MKVToolNix GUI multiplexer tab

Drag files into the Multiplexer tab, untick the tracks you do not want, set language, name and the default/forced flags for each track, choose the output file and click Start multiplexing. Useful features:

  • Open a Blu-ray playlist (.mpls) or index.bdmv from an unencrypted disc folder to import a title with all its segments.
  • Output → Splitting cuts by duration, size, timestamps, chapters or frame ranges without re-encoding.
  • The Output tab’s “Create WebM compliant file” option restricts the output to WebM.
  • The Header editor tab changes titles, languages and flags in an existing file instantly, without remuxing.
  • The Multiplexer menu can show the equivalent mkvmerge command line, handy for scripting.

List the tracks and their IDs first. mkvmerge numbers tracks from 0 within each file; these IDs are not FFmpeg’s stream indexes.

Terminal window
mkvmerge -i input.mkv
mkvmerge -J input.mkv

-J prints full details as JSON.

Options before a file name apply to that file only. This muxes an encoded video, an Opus track and ASS subtitles with a font:

Terminal window
mkvmerge -o output.mkv video.ivf --language 0:ja audio.opus --language 0:en --track-name 0:"English" subs.ass --attach-file font.ttf

Keep or drop tracks from a source with -d/-a/-s (video/audio/subtitle IDs to keep) or -D/-A/-S (drop all of that type). For example, to keep the video, only audio track 2 and no subtitles:

Terminal window
mkvmerge -o output.mkv -a 2 -S input.mkv

The most-used options:

OptionUse
--language ID:LANGTrack language as a BCP 47 tag (en, ja, pt-BR).
--track-name ID:NAMETrack title shown by players.
--default-track-flag ID:0 / :1Whether players pick this track by default.
--forced-display-flag ID:1Marks a subtitle track as forced (for example, signs and foreign-language dialogue only).
--sync ID:MSDelays (positive) or advances (negative) a track by milliseconds.
--default-duration ID:24000/1001fpsOverrides the frame rate of a raw video stream with no timing of its own.
--attach-file FILEAttaches a file, typically a font used by ASS subtitles.
--chapters FILEAdds chapters from an XML or simple CHAPTER01= text file.
--split ...Splits the output (see below).
--webmProduces a WebM file and rejects codecs WebM does not allow.
--title TEXTSets the file’s title.
Terminal window
mkvmerge -o part.mkv --split duration:00:20:00 input.mkv
mkvmerge -o clip.mkv --split parts:00:01:00-00:02:30 input.mkv
mkvmerge -o episode.mkv --split chapters:all input.mkv
mkvmerge -o joined.mkv part1.mkv + part2.mkv

A split can only happen right before a keyframe, so each cut moves to the first keyframe at or after the point you asked for: clean, but not frame-exact; numbered files (part-001.mkv, …) are created when there is more than one part. A + before a file appends it to the previous one, which requires matching codecs and parameters.

Terminal window
mkvextract input.mkv tracks 0:video.ivf 1:audio.opus 2:subs.ass
mkvextract input.mkv attachments 1:font.ttf
mkvextract input.mkv chapters chapters.xml
mkvextract input.mkv timestamps_v2 0:timestamps.txt

Tracks come out as their raw bitstream; pick an extension that matches the codec. Add --simple to the chapters mode for the plain CHAPTER01= format.

Edits are written into the file in place and take seconds even on large files:

Terminal window
mkvpropedit input.mkv --edit info --set "title=My encode"
mkvpropedit input.mkv --edit track:a1 --set language=ja --set flag-default=1 --edit track:s1 --set flag-forced=1

track:a1 is the first audio track, track:s1 the first subtitle track and track:v1 the first video track; these selectors count from 1 per type, unlike mkvmerge’s IDs. mkvpropedit can also add, replace and delete attachments and chapters. The GUI’s header editor does the same thing interactively.