Description
This program extracts specific parts from a Matroska(TM) file to other useful formats. The first argument is the name of the source file which must be a Matroska(TM) file.
Calls the mkvmerge command on the input video(s), splitting it at the passed timecodes, where each scene is written in sequence from 001. Parameters: inputvideopaths ( List str ) – List of strings to the input video path(s). Simple answer and solution is to convert to another format. In this post we will cover how to convert using the command line with mkvmerge and MKVToolNix. Mkvmerge is part of MKVToolNix tools, MKVToolNix is a set of tools to create, alter and inspect Matroska files under Linux, other Unix and Windows.
All other arguments either switch to a certain extraction mode, change options for the currently active mode or specify what to extract into which file. Multiple modes can be used in the same invocation of mkvextract allowing the extraction of multiple things in a single pass. Most options can only be used in certain modes with a few options applying to all modes.
Currently supported is the extraction of tracks, tags, attachments, chapters, CUE sheets, timestamps and cues.
Common options
The following options are available in all modes and only described once in this section.
Sets the parse mode to 'full'. The default mode does not parse the whole file but uses the meta seek elements for locating the required elements of a source file. In 99% of all cases this is enough. But for files that do not contain meta seek elements or which are damaged the user might have to use this mode. A full scan of a file can take a couple of minutes while a fast scan only takes seconds.
Sets the character set to convert strings given on the command line from. It defaults to the character set given by system's current locale.
Sets the character set to which strings are converted that are to be output. It defaults to the character set given by system's current locale.
Writes all messages to the file file-name instead of to the console. While this can be done easily with output redirection there are cases in which this option is needed: when the terminal reinterprets the output before writing it to a file. The character set set with --output-charset is honored.
Tells the program to flush all data cached in memory to storage when closing files opened for writing. This can be used to prevent data loss on power outages or to circumvent certain problems in the operating system or drivers. The downside is that multiplexing will take longer as mkvmerge will wait until all data has been written to the storage before exiting. See issues #2469 and #2480 on the MKVToolNix bug tracker for in-depth discussions on the pros and cons.
Forces the translations for the language code to be used (e.g. 'de_DE' for the German translations). Entering 'list' as the code will cause the program to output a list of available translations.
Tells the program to abort after the first warning is emitted. The program's exit code will be 1.
Turn on debugging for a specific feature. This option is only useful for developers.
Turn on experimental features. A list of available features can be requested with mkvextract --engage list. These features are not meant to be used in normal situations.
Turns on GUI mode. In this mode specially-formatted lines may be output that can tell a controlling GUI what's happening. These messages follow the format '#GUI#message'. The message may be followed by key/value pairs as in '#GUI#message#key1=value1#key2=value2...'. Neither the messages nor the keys are ever translated and always output in English.
Be verbose and show all the important Matroska(TM) elements as they're read.
Show usage information and exit.
Mkvmerge Commands List
Mkvmerge Commands Cheat
Show version information and exit.
Reads additional command line arguments from the file options-file. For a full explanation on the supported formats for such files see the section called 'Option files' in the mkvmerge(1) man page.
Track extraction mode
Syntax: mkvextractsource-filenametracks [options] TID1:dest-filename1[TID2:dest-filename2 ...]
The following command line options are available for each track in the 'tracks' extraction mode. They have to appear in front of the track specification (see below) they should be applied to.
Sets the character set to convert the next text subtitle track to. Only valid if the next track ID targets a text subtitle track. It defaults to UTF-8.
Keep only the BlockAdditions up to this level. The default is to keep all levels. This option only affects certain kinds of codecs like WAVPACK4.
Causes mkvextract(1) to extract a CUE sheet from the chapter information and tag data for the following track into a file whose name is the track's output name with '.cue' appended to it.
Extracts the raw data into a file without any container data around it. Unlike the --fullraw flag this flag does not cause the contents of the CodecPrivate element to be written to the file. This mode works with all CodecIDs, even the ones that mkvextract(1) doesn't support otherwise, but the resulting files might not be usable.
Extracts the raw data into a file without any container data around it. The contents of the CodecPrivate element will be written to the file first if the track contains such a header element. This mode works with all CodecIDs, even the ones that mkvextract(1) doesn't support otherwise, but the resulting files might not be usable.
Causes extraction of the track with the ID TID into the file outname if such a track exists in the source file. This option can be given multiple times. The track IDs are the same as the ones output by mkvmerge(1)'s --identify option.
Mkvmerge Command Line Examples
Each output name should be used only once. The exception are RealAudio and RealVideo tracks. If you use the same name for different tracks then those tracks will be saved in the same file. Example:
Attachments extraction mode
Syntax: mkvextractsource-filenameattachments [options] AID1:outname1[AID2:outname2 ...]
Causes extraction of the attachment with the ID AID into the file outname if such an attachment exists in the source file. If the outname is left empty then the name of the attachment inside the source Matroska(TM) file is used instead. This option can be given multiple times. The attachment IDs are the same as the ones output by mkvmerge(1)'s --identify option.
Chapters extraction mode
Syntax: mkvextractsource-filenamechapters [options] output-filename.xml
Exports the chapter information in the simple format used in the OGM tools (CHAPTER01=..., CHAPTER01NAME=...). In this mode some information has to be discarded. Default is to output the chapters in XML format.
If the simple format is enabled then mkvextract(1) will only output a single entry for each chapter atom encountered even if a chapter atom contains more than one chapter name. By default mkvextract(1) will use the first chapter name found for each atom regardless of its language.
Using this option allows the user to determine which chapter names are output if atoms contain more than one chapter name. The language parameter must be an ISO 639-1 or ISO 639-2 code.
The chapters are written to specified output file. By default the XML format understood by mkvmerge(1) is used. If no chapters are found in the file, the output file is not created.
Tags extraction mode
Syntax: mkvextractsource-filenametags [options] output-filename.xml
The tags are written to specified output file in the XML format understood by mkvmerge(1). If no tags are found in the file, the output file is not created.
Cue sheet extraction mode
Syntax: mkvextractsource-filenamecuesheet [options] output-filename.cue
The cue sheet is written to specified output file. If no chapters or tags are found in the file, the output file is not created.
Timestamp extraction mode
Syntax: mkvextractsource-filenametimestamps_v2 [options] TID1:dest-filename1[TID2:dest-filename2 ...]
Causes extraction of the timestamps for the track with the ID TID into the file outname if such a track exists in the source file. This option can be given multiple times. The track IDs are the same as the ones output by mkvmerge(1)'s --identify option.
Example:
Cues extraction mode
Syntax: mkvextractsource-filenamecues [options] TID1:dest-filename1[TID2:dest-filename2 ...]
Causes extraction of the cues for the track with the ID TID into the file outname if such a track exists in the source file. This option can be given multiple times. The track IDs are the same as the ones output by mkvmerge(1)'s --identify option and not the numbers contained in the CueTrack element.
The format output is a simple text format: one line per CuePoint element with key=value pairs. If an optional element is not present in a CuePoint (e.g. CueDuration) then a dash will be output as the value.
Example:
The possible keys are:
The cue point's timestamp with nanosecond precision. The format is HH:MM:SS.nnnnnnnnn. This element is always set.
The cue point's duration with nanosecond precision. The format is HH:MM:SS.nnnnnnnnn.
The absolute position in bytes inside the Matroska(TM) file where the cluster containing the referenced element starts.
Note
Inside the Matroska(TM) file the CueClusterPosition is relative to the segment's data start offset. The value output by mkvextract(1)'s cue extraction mode, however, contains that offset already and is an absolute offset from the beginning of the file.
The relative position in bytes inside the cluster where the BlockGroup or SimpleBlock element the cue point refers to starts.
Note
Inside the Matroska(TM) file the CueRelativePosition is relative to the cluster's data start offset. The value output by mkvextract(1)'s cue extraction mode, however, is relative to the cluster's ID. The absolute position inside the file can be calculated by adding cluster_position and relative_position.
Example: