The order of command line options is important. Please read the section "Option order" if you're new to the program.
Global options:
-v, --verbose
-q, --quiet
-o, --output file-name
-w, --webm
--title title
--tags file-name
--default-language language-code
Segment info handling: (global options)
--segmentinfo filename.xml
--segment-uid SID1,SID2,...
Each file created contains one segment, and each segment has one segment UID. If more segment UIDs are specified than segments are created then the surplus UIDs are ignored. If fewer UIDs are specified than segments are created then random UIDs will be created for them.
Chapter and tag handling: (global options)
--chapter-language language-code
This option can be used both for simple chapter files and for source files that contain chapters but no information about the chapters' language, e.g. MP4 and OGM files.
--chapter-charset character-set
This switch does also apply to chapters that are copied from certain container types, e.g. Ogg/OGM and MP4 files. See the section about chapters below for details.
--cue-chapter-name-format format
mkvmerge(1) supports reading CUE sheets for audio files as the input for chapters. CUE sheets usually contain the entries PERFORMER and TITLE for each index entry. mkvmerge(1) uses these two strings in order to construct the chapter name. With this option the format used for this name can be set.
If this option is not given then mkvmerge(1) defaults to the format '%p - %t' (the performer, followed by a space, a dash, another space and the title).
If the format is given then everything except the following meta characters is copied as-is, and the meta characters are replaced like this:
--chapters file-name
--global-tags file-name
General output control (advanced global options):
--track-order FID1:TID1,FID2:TID2,...
--cluster-length spec
If no unit is used then mkvmerge(1) will put at most n data blocks into each cluster. The maximum number of blocks is 65535.
If the number d is postfixed with 'ms' then mkvmerge(1) puts at most d milliseconds of data into each cluster. The minimum for d is '100ms', and the maximum is '32000ms'.
mkvmerge(1) defaults to putting at most 65535 data blocks and 5000ms of data into a cluster.
Programs trying to find a certain frame can only seek directly to a cluster and have to read the whole cluster afterwards. Therefore creating larger clusters may lead to imprecise or slow seeking.
--no-cues
--clusters-in-meta-seek
--disable-lacing
--enable-durations
--timecode-scale factor
Normally mkvmerge(1) will use a value of 1000000 which means that timecodes and durations will have a precision of 1ms. For files that will not contain a video track but at least one audio track mkvmerge(1) will automatically chose a timecode scale factor so that all timecodes and durations have a precision of one audio sample. This causes bigger overhead but allows precise seeking and extraction.
If the special value -1 is used then mkvmerge(1) will use sample precision even if a video track is present.
File splitting, linking and appending (more global options):
--split specification
At the moment mkvmerge(1) supports three different modes.
Syntax: --split [size:]d[k|m|g]
Examples: --split size:700m or --split 150000000
The parameter d may end with 'k', 'm' or 'g' to indicate that the size is in KB, MB or GB respectively. Otherwise a size in Bytes is assumed. After the current output file has reached this size limit a new one will be started.
The 'size:' prefix may be omitted for compatibility reasons.
Syntax: --split [duration:]HH:MM:SS.nnnnnnnnn|ds
Examples: --split duration:00:60:00.000 or --split 3600s
The parameter must either have the form HH:MM:SS.nnnnnnnnn for specifying the duration in up to nano-second precision or be a number d followed by the letter 's' for the duration in seconds. HH is the number of hours, MM the number of minutes, SS the number of seconds and nnnnnnnnn the number of nanoseconds. Both the number of hours and the number of nanoseconds can be omitted. There can be up to nine digits after the decimal point. After the duration of the contents in the current output has reached this limit a new output file will be started.
The 'duration:' prefix may be omitted for compatibility reasons.
Syntax: --split timecodes:A[,B[,C...]]
Example: --split timecodes:00:45:00.000,01:20:00.250,6300s
The parameters A, B, C etc must all have the same format as the ones used for the duration (see above). The list of timecodes is separated by commas. After the input stream has reached the current split point's timecode a new file is created. Then the next split point given in this list is used.
The 'timecodes:' prefix must not be omitted.
For this splitting mode the output filename is treated differently than for the normal operation. It may contain a printf like expression '%d' including an optional field width, e.g. '%02d'. If it does then the current file number will be formatted appropriately and inserted at that point in the filename. If there is no such pattern then a pattern of '-%03d' is assumed right before the file's extension: '-o output.mkv' would result in 'output-001.mkv' and so on. If there's no extension then '-%03d' will be appended to the name.
--link
--link-to-previous segment-UID
--link-to-next segment-UID
--append-mode mode
When mkvmerge appends a track (called 'track2_1' from now on) from a second file (called 'file2') to a track (called 'track1_1') from the first file (called 'file1') then it has to offset all timecodes for 'track2_1' by an amount. For 'file' mode this amount is the highest timecode encountered in 'file1' even if that timecode was from a different track than 'track1_1'. In track mode the offset is the highest timecode of 'track1_1'.
Unfortunately mkvmerge cannot detect which mode to use reliably. Therefore it defaults to 'file' mode. 'file' mode usually works better for files that have been created independently of each other; e.g. when appending AVI or MP4 files. 'track' mode may work better for sources that are essentially just parts of one big file, e.g. for VOB and EVO files.
Subtitle tracks are always treated as if 'file' mode were active even if 'track' mode actually is.
--append-to SFID1:STID1:DFID1:DTID1[,...]
If this option has been omitted then a standard mapping is used. This standard mapping appends each track from the current file to a track from the previous file with the same track ID. This allows for easy appending if a movie has been split into two parts and both file have the same number of tracks and track IDs with the command mkvmerge -o output.mkv part1.mkv +part2.mkv.
+
$ mkvmerge -o full.mkv file1.mkv + file2.mkv
$ mkvmerge -o full.mkv file1.mkv +file2.mkv
=
The '=' can also be put in front of the next file name. Therefore the following two commands are equivalent:
$ mkvmerge -o full.mkv = file1.mkv
$ mkvmerge -o full.mkv =file1.mkv
Attachment support (more global options):
--attachment-description description
--attachment-mime-type MIME type
MIME type of the following attachment. Applies to the next --attach-file or --attach-file-once option. A list of officially recognized MIME types can be found e.g. at m[blue]the IANA homepagem[][2]. The MIME type is mandatory for an attachment.
--attachment-name name
--attach-file file-name, --attach-file-once file-name
mkvextract(1) can be used to extract attached files from a Matroska(TM) file.
Options that can be used for each input file:
-a, --audio-tracks n,m,...
-d, --video-tracks n,m,...
-s, --subtitle-tracks n,m,...
-b, --button-tracks n,m,...
--track-tags n,m,...
-m, --attachments n[:all|first],m[:all|first],...
The default is to copy all attachments to all output files.
-A, --no-audio
-D, --no-video
-S, --no-subtitles
-B, --no-buttons
-T, --no-track-tags
--no-chapters
-M, --no-attachments
--no-global-tags
--chapter-charset character-set
--chapter-language language-code
-y, --sync TID:d[,o[/p]]
o/p: adjust the timestamps by o/p to fix linear drifts. p defaults to 1 if omitted. Both o and p can be floating point numbers.
Defaults: no manual sync correction (which is the same as d = 0 and o/p = 1.0).
This option can be used multiple times for an input file applying to several tracks by selecting different track IDs each time.
--cues TID:none|iframes|all
The default is 'iframes' for video tracks and 'none' for all others. See also option --no-cues which inhibits the creation of cue entries regardless of the --cues options used.
This option can be used multiple times for an input file applying to several tracks by selecting different track IDs each time.
--default-track TID[:bool]
This option can be used multiple times for an input file applying to several tracks by selecting different track IDs each time.
--forced-track TID[:bool]
This option can be used multiple times for an input file applying to several tracks by selecting different track IDs each time.
--blockadd TID:level
--track-name TID:name
--language TID:language
This option can be used multiple times for an input file applying to several tracks by selecting different track IDs each time.
-t, --tags TID:file-name
--aac-is-sbr TID[:0|1]
If the source file is a Matroska(TM) file then the CodecID should be enough to detect SBR AAC. However, if the CodecID is wrong then this switch can be used to correct that.
If mkvmerge wrongfully detects that an AAC file is SBR then you can add ':0' to the track ID.
--timecodes TID:file-name
--default-duration TID:x
If the default duration is not forced then mkvmerge will try to derive the track's default duration from the container and/or codec used. One case in which this option is of use is when adding AVC/h.264 elementary streams because these do not contain information about their number of frames or a default duration for each frame. For such files mkvmerge(1) will assume a default duration of '25fps' unless overridden.
This option can also be used to change the FPS of video tracks without having to use an external timecode file.
--nalu-size-length TID:n
--compression TID:n
The compression method 'mpeg4_p2'/'mpeg4p2' is a special compression method called 'header removal' that is only available for MPEG4 part 2 video tracks.
The default for some subtitle tracks is 'zlib' compression. This compression method is also the one that most if not all playback applications support. Support for other compression methods other than 'none' is not assured.
Options that only apply to video tracks:
-f, --fourcc TID:FourCC
--display-dimensions TID:widthxheight
Matroska(TM) files contain two values that set the display properties that a player should scale the image on playback to: display width and display height. These values can be set with this option, e.g. '1:640x480'.
Another way to specify the values is to use the --aspect-ratio or the --aspect-ratio-factor option (see below). These options are mutually exclusive.
--aspect-ratio TID:ratio|width/height
Matroska(TM) files contain two values that set the display properties that a player should scale the image on playback to: display width and display height. With this option mkvmerge(1) will automatically calculate the display width and display height based on the image's original width and height and the aspect ratio given with this option. The ratio can be given either as a floating point number ratio or as a fraction 'width/height', e.g. '16/9'.
Another way to specify the values is to use the --aspect-ratio-factor or --display-dimensions options (see above and below). These options are mutually exclusive.
--aspect-ratio-factor TID:factor|n/d
Another way to specify the values is to use the --aspect-ratio or --display-dimensions options (see above). These options are mutually exclusive.
--cropping TID:left,top,right,bottom
--stereo-mode TID:n|keyword
'mono', 'side_by_side_left_first', 'top_bottom_right_first', 'top_bottom_left_first', 'checkboard_right_first', 'checkboard_left_first', 'row_interleaved_right_first', 'row_interleaved_left_first', 'column_interleaved_right_first', 'column_interleaved_left_first', 'anaglyph', 'side_by_side_right_first'.
Options that only apply to text subtitle tracks:
--sub-charset TID:character-set
This option can be used multiple times for an input file applying to several tracks by selecting different track IDs each time.
Other options:
-i, --identify file-name
-I, --identify-verbose file-name
This option causes mkvmerge(1) to output additional information about the container and each track within. The extra information is surronded by square brackets. It consists of space-saparated key/value pairs where keys and values are separated by a colon.
Each value is escaped according to the rules described in the section about escaping special characters in text.
-l, --list-types
--list-languages
--priority priority
--command-line-charset character-set
--output-charset character-set
-r, --redirect-output file-name
--ui-language code
@options-file
Several chars can be escaped, e.g. if you need to start a non-comment line with '#'. The rules are described in the section about escaping text.
The command line 'mkvmerge -o "my file.mkv" -A "a movie.avi" sound.ogg' could be converted into the following option file:
# Write to the file "my file.mkv".
-o
my file.mkv
# Only take the video from "a movie.avi".
-A
a movie.avi
sound.ogg
--capabilities
-h, --help
-V, --version
--check-for-updates
Afterwards the program exists with an exit code of 0 if no newer release is available, with 1 if a newer release is available and with 2 if an error occured (e.g. if the update information could not be retrieved).
This option is only available if the program was built with support for libcurl.
For each file the user can select which tracks mkvmerge(1) should take. They are all put into the file specified with -o. A list of known (and supported) source formats can be obtained with the -l option.
The order of command line options is important. Please read the section "Option order" if you're new to the program.
The order in which options are entered is important for some options. Options fall into two categories:
The options are processed from left to right. If an option appears multiple times within the same scope then the last occurence will be used. Therefore the title will be set to "Something else" in the following example:
$ mkvmerge -o output.mkv --title 'This and that' input.avi --title 'Something else'
The following example shows that using the --language option twice is OK because they're used in different scopes. Even though they apply to the same track ID they apply to different input files and therefore have different scopes:
$ mkvmerge -o output.mkv --language 0:fre français.ogg --language 0:deu deutsch.ogg
Let's assume you have a file called MyMovie.avi and the audio track in a separate file, e.g. 'MyMovie.wav'. First you want to encode the audio to OggVorbis(TM):
$ oggenc -q4 -oMyMovie.ogg MyMovie.wav
After a couple of minutes you can join video and audio:
$ mkvmerge -o MyMovie-with-sound.mkv MyMovie.avi MyMovie.ogg
If your AVI already contains an audio track then it will be copied as well (if mkvmerge(1) supports the audio format). To avoid that simply do
$ mkvmerge -o MyMovie-with-sound.mkv -A MyMovie.avi MyMovie.ogg
After some minutes of consideration you rip another audio track, e.g. the director's comments or another language to 'MyMovie-add-audio.wav'. Encode it again and join it up with the other file:
$ oggenc -q4 -oMyMovie-add-audio.ogg MyMovie-add-audio.wav $ mkvmerge -o MM-complete.mkv MyMovie-with-sound.mkv MyMovie-add-audio.ogg
The same result can be achieved with
$ mkvmerge -o MM-complete.mkv -A MyMovie.avi MyMovie.ogg MyMovie-add-audio.ogg
Now fire up mplayer(TM) and enjoy. If you have multiple audio tracks (or even video tracks) then you can tell mplayer(TM) which track to play with the '-vid' and '-aid' options. These are 0-based and do not distinguish between video and audio.
If you need an audio track synchronized you can do that easily. First find out which track ID the Vorbis track has with
$ mkvmerge --identify outofsync.ogg
Now you can use that ID in the following command line:
$ mkvmerge -o goodsync.mkv -A source.avi -y 12345:200 outofsync.ogg
This would add 200ms of silence at the beginning of the audio track with the ID 12345 taken from 'outofsync.ogg'.
Some movies start synced correctly but slowly drift out of sync. For these kind of movies you can specify a delay factor that is applied to all timestamps -- no data is added or removed. So if you make that factor too big or too small you'll get bad results. An example is that an episode I transcoded was 0.2 seconds out of sync at the end of the movie which was 77340 frames long. At 29.97fps 0.2 seconds correspond to approx. 6 frames. So I did
$ mkvmerge -o goodsync.mkv -y 23456:0,77346/77340 outofsync.mkv
The result was fine.
The sync options can also be used for subtitles in the same manner.
For text subtitles you can either use some Windows software (like SubRipper(TM)) or the subrip(TM) package found in transcode(1)'s sources in the 'contrib/subrip' directory. The general process is:
$ tccat -i /path/to/copied/dvd/ -T 1 -L | tcextract -x ps1 -t vob -a 0x20 | subtitle2pgm -o mymovie
$ pgm2txt mymovie
$ ispell -d american *txt
$ srttool -s -w -i mymovie.srtx -o mymovie.srt
The resulting file can be used as another input file for mkvmerge(1):
$ mkvmerge -o mymovie.mkv mymovie.avi mymovie.srt
If you want to specify the language for a given track then this is easily done. First find out the ISO639-2 code for your language. mkvmerge(1) can list all of those codes for you:
$ mkvmerge --list-languages
Search the list for the languages you need. Let's assume you have put two audio tracks into a Matroska(TM) file and want to set their language codes and that their track IDs are 2 and 3. This can be done with
$ mkvmerge -o with-lang-codes.mkv --language 2:ger --language 3:dut without-lang-codes.mkv
As you can see you can use the --language switch multiple times.
Maybe you'd also like to have the player use the Dutch language as the default language. You also have extra subtitles, e.g. in English and French, and want to have the player display the French ones by default. This can be done with
$ mkvmerge -o with-lang-codes.mkv --language 2:ger --language 3:dut --default-track 3 without-lang-codes.mkv --language 0:eng english.srt --default-track 0 --language 0:fre french.srt
If you do not see the language or default track flags that you've specified in mkvinfo(1)'s output then please read the section about default values.
Turn off the compression for an input file.
$ mkvmerge -o no-compression.mkv --compression -1:none MyMovie.avi --compression -1:none mymovie.srt
Some of the options for mkvmerge(1) need a track ID to specify which track they should be applied to. Those track IDs are printed by the readers when demuxing the current input file, or if mkvmerge(1) is called with the --identify option. An example for such output:
$ mkvmerge -i v.mkv File 'v.mkv': container: Matroska(TM) Track ID 1: video (V_MS/VFW/FOURCC, DIV3) Track ID 2: audio (A_MPEG/L3)
Do not confuse the track IDs that are assigned to the tracks that are placed in the output MKV file with the track IDs of the input files. Only the input file track IDs are used for options needing these values.
Also note that each input file has its own set of track IDs. Therefore the track IDs for file 'file1.ext' as reported by 'mkvmerge --identify' do not change no matter how many other input files are there or in which position 'file1.ext' is used.
Track IDs are assigned like this:
AVI files: The video track has the ID 0. The audio tracks get IDs in ascending order starting at 1.
MP4 files: As output from x264, the video track has the ID 1.
AAC, AC3, MP3, SRT and WAV files: The one 'track' in that file gets the ID 0.
Matroska(TM) files: The track's ID is the track number as reported by mkvinfo(1). It is not the track UID.
The special track ID '-1' is a wild card and applies the given switch to all tracks that are read from an input file.
The options that use the track IDs are the ones whose description contains 'TID'. The following options use track IDs as well: --atracks, --vtracks, --stracks and --btracks.
This section applies to all programs in MKVToolNix even if it only mentions mkvmerge(1).
All text in a Matroska(TM) file is encoded in UTF-8. This means that mkvmerge(1) has to convert every text file it reads as well as every text given on the command line from one character set into UTF-8. In return this also means that mkvmerge(1)'s output has to be converted back to that character set from UTF-8, e.g. if a non-English translation is used with --ui-language or for text originating from a Matroska(TM) file.
mkvmerge(1) does this conversion automatically based on the presence of a byte order marker (short: BOM) or the system's current locale. How the character set is inferred from the locale depends on the operating system that mkvmerge(1) is run on.
Text files that start with a BOM are already encoded in one representation of UTF. mkvmerge(1) supports the following five modes: UTF-8, UTF-16 Little and Big Endian, UTF-32 Little and Big Endian. Text files with a BOM are automatically converted to UTF-8. Any of the parameters that would otherwise set the character set for such a file (e.g. --sub-charset) is silently ignored.
On Unix-like systems mkvmerge(1) uses the setlocale(3) system call which in turn uses the environment variables LANG, LC_ALL and LC_CYPE. The resulting character set is often one of UTF-8 or the ISO-8859-* family and is used for all text file operations and for encoding strings on the command line and for output to the console.
On Windows there are actually two different character sets that mkvmerge(1) uses due to the way the Windows shell program cmd.exe is implemented. The first character set is determined by a call to the GetCP() system call. This character set is used as the default for text file conversions and for all elements displayed by the GUI programs in the MKVToolNix package. cmd.exe uses another character set which is determined by a call to the GetACP() system call. This is the default character set for all strings read from the command line and for all strings output to the console.
The following options exist that allow specifying the character sets:
--sub-charset for text subtitle files and for text subtitle tracks stored in container formats for which the character set cannot be determined unambiguously (e.g. Ogg files),
--chapter-charset for chapter text files and for chapters and file titles stored in container formats for which the character set cannot be determined unambiguously (e.g. Ogg files for chapter information, track and file titles etc; MP4 files for chapter information),
--command-line-charset for all strings on the command line,
--output-charset for all strings written to the console or to a file if the output has been redirected with the --redirect-output option.
There are a few places in which special characters in text must or should be escaped. The rules for escaping are simple: each character that needs escaping is replaced with a backslash followed by another character.
The rules are: ' ' becomes '\s', '"' becomes '\2', ':' becomes '\c', '#' becomes '\h' and '\' itself becomes '\\'.
There are several text subtitle formats that can be embedded into Matroska(TM). At the moment mkvmerge(1) supports only text, VobSub and Kate subtitle formats. Text subtitles must be recoded to UTF-8 so that they can be displayed correctly by a player (see the section about text files and character sets for an explanation how mkvmerge(1) converts between character sets). Kate subtitles are already encoded in UTF-8 and do not have to be re-encoded.
The following subtitle formats are supported at the moment:
Matroska(TM) supports file linking which simply says that a specific file is the predecessor or successor of the current file. To be precise, it's not really the files that are linked but the Matroska(TM) segments. As most files will probably only contain one Matroska(TM) segment the following explanations use the term 'file linking' although 'segment linking' would be more appropriate.
Each segment is identified by a unique 128 bit wide segment UID. This UID is automatically generated by mkvmerge(1). The linking is done primarily via putting the segment UIDs (short: SID) of the previous/next file into the segment header information. mkvinfo(1) prints these SIDs if it finds them.
If a file is split into several smaller ones and linking is used then the timecodes will not start at 0 again but will continue where the last file has left off. This way the absolute time is kept even if the previous files are not available (e.g. when streaming). If no linking is used then the timecodes should start at 0 for each file. By default mkvmerge(1) does not use file linking. If you want that you can turn it on with the --link option. This option is only useful if splitting is activated as well.
Regardless of whether splitting is active or not the user can tell mkvmerge(1) to link the produced files to specific SIDs. This is achieved with the options --link-to-previous and --link-to-next. These options accept a segment SID in the format that mkvinfo(1) outputs: 16 hexadecimal numbers between 0x00 and 0xff prefixed with '0x' each, e.g. '0x41 0xda 0x73 0x66 0xd9 0xcf 0xb2 0x1e 0xae 0x78 0xeb 0xb4 0x5e 0xca 0xb3 0x93'. Alternatively a shorter form can be used: 16 hexadecimal numbers between 0x00 and 0xff without the '0x' prefixes and without the spaces, e.g. '41da7366d9cfb21eae78ebb45ecab393'.
If splitting is used then the first file is linked to the SID given with --link-to-previous and the last file is linked to the SID given with --link-to-next. If splitting is not used then the one output file will be linked to both of the two SIDs.
The Matroska(TM) specification states that some elements have a default value. Usually an element is not written to the file if its value is equal to its default value in order to save space. The elements that the user might miss in mkvinfo(1)'s output are the language and the default track flag elements. The default value for the language is English ('eng'), and the default value for the default track flag is true. Therefore if you used --language 0:eng for a track then it will not show up in mkvinfo(1)'s output.
Maybe you also want to keep some photos along with your Matroska(TM) file, or you're using SSA subtitles and need a special TrueType(TM) font that's really rare. In these cases you can attach those files to the Matroska(TM) file. They will not be just appended to the file but embedded in it. A player can then show those files (the 'photos' case) or use them to render the subtitles (the 'TrueType(TM) fonts' case).
Here's an example how to attach a photo and a TrueType(TM) font to the output file:
$ mkvmerge -o output.mkv -A video.avi sound.ogg --attachment-description "Me and the band behind the stage in a small get-together" --attachment-mime-type image/jpeg --attach-file me_and_the_band.jpg --attachment-description "The real rare and unbelievably good looking font" --attachment-type application/octet-stream --attach-file really_cool_font.ttf
If a Matroska(TM) containing attachments file is used as an input file then mkvmerge(1) will copy the attachments into the new file. The selection which attachments are copied and which are not can be changed with the options --attachments and --no-attachments.
The Matroska(TM) chapter system is more powerful than the old known system used by OGM files. The full specifications can be found at m[blue]the Matroska(TM) websitem[][1].
mkvmerge(1) supports two kinds of chapter files as its input. The first format, called 'simple chapter format', is the same format that the OGM tools expect. The second format is a XML based chapter format which supports all of Matroska(TM)'s chapter functionality.
This formmat consists of pairs of lines that start with 'CHAPTERxx=' and 'CHAPTERxxNAME=' respectively. The first one contains the start timecode while the second one contains the title. Here's an example:
CHAPTER01=00:00:00.000 CHAPTER01NAME=Intro CHAPTER02=00:02:30.000 CHAPTER02NAME=Baby prepares to rock CHAPTER03=00:02:42.300 CHAPTER03NAME=Baby rocks the house
mkvmerge(1) will transform every pair or lines into one Matroska(TM) ChapterAtom. It does not set any ChapterTrackNumber which means that the chapters all apply to all tracks in the file.
As this is a text file character set conversion may need to be done. See the section about text files and character sets for an explanation how mkvmerge(1) converts between character sets.
The XML based chapter format looks like this example:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Chapters SYSTEM "matroskachapters.dtd">
<Chapters>
<EditionEntry>
<ChapterAtom>
<ChapterTimeStart>00:00:30.000</ChapterTimeStart>
<ChapterTimeEnd>00:01:20.000</ChapterTimeEnd>
<ChapterDisplay>
<ChapterString>A short chapter</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
<ChapterAtom>
<ChapterTimeStart>00:00:46.000</ChapterTimeStart>
<ChapterTimeEnd>00:01:10.000</ChapterTimeEnd>
<ChapterDisplay>
<ChapterString>A part of that short chapter</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
</ChapterAtom>
</EditionEntry>
</Chapters>
With this format three things are possible that are not possible with the simple chapter format:
The mkvtoolnix distribution contains some sample files in the doc subdirectory which can be used as a basis.
When splitting files mkvmerge(1) will correctly adjust the chapters as well. This means that each file only includes the chapter entries that apply to it, and that the timecodes will be offset to match the new timecodes of each output file.
mkvmerge(1) is able to copy chapters from Matroska(TM) source files unless this is explicitly disabled with the --no-chapters option. The chapters from all sources (Matroska(TM) files, Ogg files, MP4 files, chapter text files) are usually not merged but end up in separate ChapterEditions. Only if chapters are read from several Matroska(TM) or XML files that share the same edition UIDs will chapters be merged into a single ChapterEdition. If such a merge is desired in other situations as well then the user has to extract the chapters from all sources with mkvextract(1) first, merge the XML files manually and mux them afterwards.
Matroska(TM) supports an extensive set of tags that is deprecated and a new, simpler system like it is is used in most other containers: KEY=VALUE. However, in Matroska(TM) these tags can also be nested, and both the KEY and the VALUE are elements of their own. The example file example-tags-2.xml shows how to use this new system.
Matroska(TM) tags do not automatically apply to the complete file. They can, but they also may apply to different parts of the file: to one or more tracks, to one or more chapters, or even to a combination of both. The m[blue]the Matroska(TM) specificationm[][3] gives more details about this fact.
One important fact is that tags are linked to tracks or chapters with the Targets Matroska(TM) tag element, and that the UIDs used for this linking are not the track IDs mkvmerge(1) uses everywhere. Instead the numbers used are the UIDs which mkvmerge(1) calculates automatically (if the track is taken from a file format other than Matroska(TM)) or which are copied from the source file if the track's source file is a Matroska(TM) file. Therefore it is difficult to know which UIDs to use in the tag file before the file is handed over to mkvmerge(1).
mkvmerge(1) knows two options with which you can add tags to Matroska(TM) files: The --global-tags and the --tags options. The difference is that the former option, --global-tags, will make the tags apply to the complete file by removing any of those Targets elements mentioned above. The latter option, --tags, automatically inserts the UID that mkvmerge(1) generates for the tag specified with the TID part of the --tags option.
Let's say that you want to add tags to a video track read from an AVI. mkvmerge --identify file.avi tells you that the video track's ID (do not mix this ID with the UID!) is 0. So you create your tag file, leave out all Targets elements and call mkvmerge(1):
$ mkvmerge -o file.mkv --tags 0:tags.xml file.avi
mkvmerge(1) supports a XML based tag file format. The format is very closely modeled after m[blue]the Matroska(TM) specificationm[][3]. Both the binary and the source distributions of MKVToolNix come with a sample file called example-tags-2.xml which simply lists all known tags and which can be used as a basis for real life tag files.
The basics are:
The new Matroska(TM) tagging system only knows two data types, a UTF-8 string and a binary type. The first is used for the tag's name and the <String> element while the binary type is used for the <Binary> element.
As binary data itself would not fit into a XML file mkvmerge(1) supports two other methods of storing binary data. If the contents of a XML tag starts with '@' then the following text is treated as a file name. The corresponding file's content is copied into the Matroska(TM) element.
Otherwise the data is expected to be Base64 encoded. This is an encoding that transforms binary data into a limited set of ASCII characters and is used e.g. in email programs. mkvextract(1) will output Base64 encoded data for binary elements.
The deprecated tagging system knows some more data types which can be found in the official Matroska(TM) tag specs. As mkvmerge(1) does not support this system anymore these types aren't described here.
The Matroska(TM) file layout is quite flexible. mkvmerge(1) will render a file in a predefined way. The resulting file looks like this:
[EBML head] [segment {meta seek #1} [segment information] [track information] {attachments} {chapters} [cluster 1] {cluster 2} ... {cluster n} {cues} {meta seek #2} {tags}]
The elements in curly braces are optional and depend on the contents and options used. A couple of notes:
The shortest possible Matroska file would look like this:
[EBML head] [segment [segment information] [track information] [cluster 1]]
This might be the case for audio-only files.
mkvmerge(1) allows the user to chose the timecodes for a specific track himself. This can be used in order to create files with variable frame rate video or include gaps in audio. A frame in this case is the unit that mkvmerge(1) creates separately per Matroska(TM) block. For video this is exactly one frame, for audio this is one packet of the specific audio type. E.g. for AC3 this would be a packet containing 1536 samples.
Timecode files that are used when tracks are appended to each other must only be specified for the first part in a chain of tracks. For example if you append two files, v1.avi and v2.avi, and want to use timecodes then your command line must look something like this:
mkvmerge ... --timecodes 0:my_timecodes.txt v1.avi +v2.avi
There are four formats that are recognized by mkvmerge(1). The first line always contains the version number. Empty lines, lines containing only whitespace and lines beginning with '#' are ignored.
This format starts with the version line. The second line declares the default number of frames per second. All following lines contain three numbers separated by commas: the start frame (0 is the first frame), the end frame and the number of frames in this range. The FPS is a floating point number with the dot '.' as the decimal point. The ranges can contain gaps for which the default FPS is used. An example:
# timecode format v1 assume 27.930 800,1000,25 1500,1700,30
In this format each line contains a timecode for the corresponding frame. This timecode must be given in millisecond precision. It can be a floating point number, but it doesn't have to be. You have to give at least as many timecode lines as there are frames in the track. The timecodes in this file must be sorted. Example for 25fps:
# timecode format v2 0 40 80
In this format each line contains a duration in seconds followed by an optional number of frames per second. Both can be floating point numbers. If the number of frames per second is not present the default one is used. For audio you should let the codec calculate the frame timecodes itself. For that you should be using 0.0 as the number of frames per second. You can also create gaps in the stream by using the 'gap' keyword followed by the duration of the gap. Example for an audio file:
# timecode format v3 assume 0.0 25.325 7.530,38.236 gap, 10.050 2.000,38.236
This format is identical to the v2 format. The only difference is that the timecodes do not have to be sorted. This format should almost never be used.
mkvmerge(1) exits with one of three exit codes:
0 -- This exit codes means that muxing has completed successfully.
1 -- In this case mkvmerge(1) has output at least one warning, but muxing did continue. A warning is prefixed with the text 'Warning:'. Depending on the issues involved the resulting file might be ok or not. The user is urged to check both the warning and the resulting file.
2 -- This exit code is used after an error occurred. mkvmerge(1) aborts right after outputting the error message. Error messages range from wrong command line arguments over read/write errors to broken files.
mkvinfo(1), mkvextract(1), mkvpropedit(1), mmg(1)
The latest version can always be found at m[blue]the MKVToolNix homepagem[][4].
Moritz Bunkus <moritz@bunkus.org>