MKVToolNix
37c3317fd058; modified for Encode Wiki · CC BY-SA 4.0Creating and working with Matroska files
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.
| Tool | Does |
|---|---|
| MKVToolNix GUI | Front end for all of the below; most people use its multiplexer and header editor tabs. |
mkvmerge | Muxes, remuxes, splits and appends files. Reads MKV, MP4, raw streams, IVF, Blu-ray playlists and more. |
mkvextract | Extracts tracks, attachments, chapters, tags and timestamps. |
mkvpropedit | Edits titles, track languages, names and flags in place, without remuxing. |
mkvinfo | Shows the element structure of a file. |
Install it
Section titled “Install it”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.
Using the GUI
Section titled “Using the GUI”
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) orindex.bdmvfrom 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
mkvmergecommand line, handy for scripting.
mkvmerge
Section titled “mkvmerge”List the tracks and their IDs first. mkvmerge numbers tracks from 0 within each file; these IDs are not FFmpeg’s stream indexes.
mkvmerge -i input.mkvmkvmerge -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:
mkvmerge -o output.mkv video.ivf --language 0:ja audio.opus --language 0:en --track-name 0:"English" subs.ass --attach-file font.ttfKeep 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:
mkvmerge -o output.mkv -a 2 -S input.mkvThe most-used options:
| Option | Use |
|---|---|
--language ID:LANG | Track language as a BCP 47 tag (en, ja, pt-BR). |
--track-name ID:NAME | Track title shown by players. |
--default-track-flag ID:0 / :1 | Whether players pick this track by default. |
--forced-display-flag ID:1 | Marks a subtitle track as forced (for example, signs and foreign-language dialogue only). |
--sync ID:MS | Delays (positive) or advances (negative) a track by milliseconds. |
--default-duration ID:24000/1001fps | Overrides the frame rate of a raw video stream with no timing of its own. |
--attach-file FILE | Attaches a file, typically a font used by ASS subtitles. |
--chapters FILE | Adds chapters from an XML or simple CHAPTER01= text file. |
--split ... | Splits the output (see below). |
--webm | Produces a WebM file and rejects codecs WebM does not allow. |
--title TEXT | Sets the file’s title. |
Split and join
Section titled “Split and join”mkvmerge -o part.mkv --split duration:00:20:00 input.mkvmkvmerge -o clip.mkv --split parts:00:01:00-00:02:30 input.mkvmkvmerge -o episode.mkv --split chapters:all input.mkvmkvmerge -o joined.mkv part1.mkv + part2.mkvA 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.
mkvextract
Section titled “mkvextract”mkvextract input.mkv tracks 0:video.ivf 1:audio.opus 2:subs.assmkvextract input.mkv attachments 1:font.ttfmkvextract input.mkv chapters chapters.xmlmkvextract input.mkv timestamps_v2 0:timestamps.txtTracks come out as their raw bitstream; pick an extension that matches the codec. Add --simple to the chapters mode for the plain CHAPTER01= format.
mkvpropedit
Section titled “mkvpropedit”Edits are written into the file in place and take seconds even on large files:
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=1track: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.
Related pages
Section titled “Related pages”- Matroska and WebM
- FFmpeg, MP4Box for MP4
- Handle audio and subtitles