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 [global options] {file} [file2] ...

PARAMETERS

--append-mode
    Specifies the append mode. Modes are 'file', 'track', 'uid'.

--split
    Splits the output file after reaching a certain size, duration or number of parts. See documentation for available types.

--global-tags
    Reads global tags from a file for the output file.

--title
    Sets the overall title for the output file.

--track-order
    Specifies the order of tracks in the output file.

-o
    The name of the output Matroska file.

--default-duration
    Sets the default duration for a track to a specified value (e.g., '0:24fps' for 24 frames per second).

--aspect-ratio
    Sets the aspect ratio for a video track (e.g., '0:16/9').

--chapters
    Reads chapter information from a file.

--attachments <'(@)'file_name[:name='']>'
    Attaches files to the Matroska file.

--no-global-tags
    Prevents mkvmerge from writing global tags.

-v
    Verbose mode.

-q
    Quiet mode.

DESCRIPTION

mkvmerge is a powerful command-line tool used to multiplex multimedia streams into a Matroska (MKV) file. It can combine audio, video, subtitles, and other tracks from various sources into a single container. mkvmerge supports a wide variety of input formats. It allows you to adjust track properties like language, name, track name and default flags. You can split files into multiple parts based on size, duration, or timestamps. The tool also offers features for handling attachments, chapters, and metadata. It's a versatile utility for creating, manipulating, and examining Matroska files, offering extensive control over the merging process. mkvmerge doesn't encode or decode any streams; it simply repackages them into an MKV container.

CAVEATS

mkvmerge does not perform encoding or decoding. The input files must already be in a compatible format.
Proper track ordering and handling of overlapping timestamps are crucial for playback compatibility.

EXIT CODES

mkvmerge exits with an exit code of 0 if the operation was successful. An exit code of 1 indicates that at least one warning was issued during the operation. Exit codes of 2 or higher indicate an error.

TRACK IDENTIFICATION

Tracks are identified using a track ID which starts at 0 for the first track in a file and increments with each additional track.

HISTORY

mkvmerge is part of the MKVToolNix suite, initially developed by Moritz Bunkus. It evolved from earlier merging tools and became a prominent utility for creating and manipulating Matroska files, catering to both novice and advanced users.
The Matroska project and mkvmerge gained popularity as a free and open-source alternative to proprietary multimedia container formats.

SEE ALSO

mkvextract(1), mkvinfo(1)

Copied to clipboard