LinuxCommandLibrary

mkvmerge

Combine multiple multimedia streams into one file

TLDR

Display information about a Matroska file

$ mkvmerge --identify [path/to/file.mkv]
copy

Extract the audio from track 1 of a specific file
$ mkvextract tracks [path/to/file.mkv] [1]:[path/to/output.webm]
copy

Extract the subtitle from track 3 of a specific file
$ mkvextract tracks [path/to/file.mkv] [3]:[path/to/subs.srt]
copy

Add a subtitle track to a file
$ mkvmerge --output [path/to/output.mkv] [path/to/file.mkv] [path/to/subs.srt]
copy

SYNOPSIS

mkvmerge [options] <input-files>...

PARAMETERS

-o, --output <file>
    Sets the name of the output Matroska file.

-d, --video-tracks <TID>[,TID]...
    Selects specific video tracks from an input file to be included.

-a, --audio-tracks <TID>[,TID]...
    Selects specific audio tracks from an input file to be included.

-s, --subtitle-tracks <TID>[,TID]...
    Selects specific subtitle tracks from an input file to be included.

-A, --no-audio
    Disables inclusion of all audio tracks from all input files.

-D, --no-video
    Disables inclusion of all video tracks from all input files.

-S, --no-subtitles
    Disables inclusion of all subtitle tracks from all input files.

--no-global-tags
    Disables inclusion of global tags from input files.

--no-attachments
    Disables inclusion of attachments from input files.

--default-track <TID>:[0|1]
    Sets the 'default track' flag for a specific track (0=no, 1=yes). Only one default track per type is allowed.

--forced-track <TID>:[0|1]
    Sets the 'forced track' flag for a specific track (0=no, 1=yes).

--track-name <TID>:<name>
    Sets a user-defined name for a specific track (e.g., 'Director's Commentary').

--language <TID>:<lang>
    Sets the language code for a specific track (e.g., 'eng' for English, 'jpn' for Japanese).

--chapters <file>
    Adds chapter information from an XML or OGM style chapter file.

--tags <TID>:<file>
    Adds tags for a specific track from an XML tags file.

--global-tags <file>
    Adds global tags for the entire movie from an XML tags file.

--attach-file <file>
    Attaches a file to the Matroska file (e.g., cover art, fonts).

--attach-file-mime-type <type>
    Sets the MIME type for the last attached file (e.g., 'image/jpeg', 'font/ttf').

--split <method>
    Splits the output file into multiple segments. Methods include size:<size>, duration:<duration>, chapters:<count>, etc.

--title <title>
    Sets the main title for the Matroska file (movie title).

-i, --identify <file>
    Prints detailed track information from an input file without muxing, useful for identifying track IDs.

-v, --verbose
    Increases verbosity, showing more information about the muxing process.

-q, --quiet
    Suppresses all messages except for errors and warnings.

-h, --help
    Shows the help message with a list of all available options.

-V, --version
    Shows version information for mkvmerge.

DESCRIPTION

mkvmerge is a powerful command-line tool part of the mkvtoolnix suite designed for creating, modifying, and examining Matroska (MKV) files. It allows users to combine multiple audio, video, and subtitle tracks into a single MKV container. Beyond simple muxing, mkvmerge provides extensive control over the resulting file, including options for setting default tracks, specifying track languages, adding chapter information, embedding tags, attaching files, and splitting output into multiple segments based on size, duration, or number of files. It supports a wide array of input formats and allows for flexible track selection and manipulation, making it an indispensable tool for multimedia enthusiasts and professionals working with MKV files. It does not edit the content of the tracks themselves but rather re-packages them into the Matroska container.

CAVEATS

mkvmerge is primarily a muxer, not a stream editor. It combines existing audio, video, and subtitle streams into a new Matroska file but does not modify the actual content of these streams (e.g., cutting, re-encoding). Any content modification requires external tools and re-muxing. Also, track IDs assigned to streams by mkvmerge during the muxing process can differ from their original IDs in the input files. Always use --identify or mkvinfo to confirm track IDs for subsequent operations.

TRACK IDENTIFICATION

When working with mkvmerge, understanding track IDs is crucial for selecting specific streams. Use
mkvinfo <input_file>
or
mkvmerge -i <input_file>
to list all tracks and their corresponding IDs within an input file. These IDs are then used with options like --audio-tracks, --video-tracks, --language, etc.

DEFAULT FLAGS AND LANGUAGES

For optimal playback compatibility and user experience, it's highly recommended to set default track flags (using --default-track) and language codes (using --language) for all relevant tracks. This helps media players automatically select the preferred audio or subtitle tracks.

SPLITTING LARGE FILES

mkvmerge offers sophisticated splitting capabilities, allowing users to divide large output files into smaller segments based on criteria such as size, duration, or a specific number of output files. This feature is particularly useful for managing storage, burning to optical discs, or preparing files for streaming.

HISTORY

mkvmerge is a core component of the mkvtoolnix software suite, which was initially developed by Moritz Bunkus. The project began in the early 2000s, coinciding with the rise of the Matroska multimedia container format. mkvtoolnix aimed to provide robust command-line tools for working with Matroska files on various operating systems, including Linux, macOS, and Windows. mkvmerge quickly became a de-facto standard for creating and manipulating MKV files due to its extensive feature set, flexibility, and active development, ensuring continuous support for new Matroska features and codecs.

SEE ALSO

mkvinfo(1), mkvextract(1), mkvpropedit(1)

Copied to clipboard