Man Mkvmerge
Man mmg (1): mmg is a wxWindows based GUI for mkvmerge. It offers easy access to all of mkvmerge's options. All settings (e.g. Source files, track options etc) can be saved and restored. Included is a chapter editor that can read OGM style and XML style chapter files. Mmg(1) is a wxWindows(TM) based GUI for mkvmerge(1). It offers easy access to all of mkvmerge(1)'s options. All settings (e.g. Source files, track options etc) can be saved and restored.
Updated: February 2004
Index
NAME
mkvmerge - Merge multimedia streams into a Matroska fileSYNOPSIS
mkvmerge[global options] -o out [
DESCRIPTION
This program takes the input from several media files and joinstheir streams (all of them or just a selection) into a Matroska file.<http://www.matroska.org/>
Global options:
- out'.
- --title <title>
- Sets the general title for the output file, e.g. the movie name.
- --global-tags <file>
- Read global tags from the XML file. See the section about tagsbelow for details.
- --command-line-charset <charset>
- Sets the charset to convert strings given on the command line from. It defaultsto the charset given by system's current locale. This settings applies toarguments of the following options: --title, --track-name and--attachment-description.
Chapter handling: (global options)
- --chapter-charset <charset>
- Sets the charset that is used for the conversion to UTF-8 for simple chapterfiles. Defaults to the current system locale. See the section about chaptersbelow for details.
- --cue-chapter-name-format <format>
- mkvmerge supports reading CUE sheets for audio files as the input forchapters. CUE sheets usually contain the entries PERFORMER andTITLE for each index entry. mkvmerge uses these two stringsin order to construct the chapter name. With this option the format usedfor this name can be set. The following meta characters are supported:
%p is replaced by the current entry's PERFORMER string,
%t is replaced by the current entry's TITLE string,
%n is replaced by the current track number and
%N is replaced by the current track number padded with a leading zero ifit is < 10.
Everything else is copied as-is.
If this option is not given then mkvmerge defaults to theformat '%p - %t' (the performer, followed by a space, a dash,another space and the title). - --chapters <file>
- Read chapter information from the file. See the section about chaptersbelow for details.
General output control (advanced global options):
- n milliseconds of data intoeach cluster. The maximum length for a cluster is 65535ms. Programs willonly be able to seek to clusters, so creating larger clusters may lead toimprecise seeking and/or processing.
- --no-cues
- Tells mkvmerge not to create and write the cue data which can be comparedto an index in an AVI. Matroska files can be played back without the cuedata, but seeking will probably be imprecise and slower. Use this only ifyou're really desperate for space or for testing purposes. See also option--cues which can be specified for each input file.
- --no-clusters-in-meta-seek
- Tells mkvmerge not to create a meta seek element at the end of the filecontaining all clusters. See also the section about MATROSKA FILE LAYOUT.
- --disable-lacing
- Disables lacing for all tracks. This will increase the file's size, especiallyif there are many audio tracks. This option is not intended for everyday use.
- --enable-durations
- Write durations for all blocks. This will increase file size and does notoffer any additional value for players at the moment.
- --enable-timeslices
- Write time slices for all blocks with more than one frame (lacedblocks). This will increase file size and does not offer anyadditional value for players at the moment.
File splitting and linking (more global options):
- n after which thefile should be split.
- --split-max-files <n>
- Create at most n files, even if the last file will be longer or largerthan indicated by --split.
- --link
- Link files to one another when splitting the output file. See thesection FILE LINKING below for details.
- --link-to-previous <UID>
- Links the first output file to the segment with the given UID. See thesection FILE LINKING below for details.
- --link-to-next <UID>
- Links the last output file to the segment with the given UID. See thesection FILE LINKING below for details.
For this splitting mode the output filename is treated differently than forthe normal operation. It may contain a printf like expression '%d' includingan optional field width, e.g. '%02d'. If it does then the current file numberwill 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 beforethe file's extension: '-o output.mkv' would result in 'output-001.mkv' andso on. If there's no extension then '-%03d' will be appended to the name.
Attachment support (more global options):
- -a, --atracks <n,m,...>
- Copy the audio tracks n, m etc. The numbers are track IDs whichcan be obtained with the --identify switch. They're not simplythe track numbers (see section TRACK IDS). Default: copy all audiotracks.
- -d, --vtracks <n,m,...>
- Copy the video tracks n, m etc. The numbers are track IDs whichcan be obtained with the --identify switch (seesection TRACK IDS). They're not simplythe track numbers. Default: copy all video tracks.
- -s, --stracks <n,m,...>
- Copy the subtitle tracks n, m etc. The numbers are track IDs whichcan be obtained with the --identify switch (seesection TRACK IDS). They're not simplythe track numbers. Default: copy all subtitle tracks.
- -A, --noaudio
- Don't copy any audio track from this file.
- -D, --novideo
- Don't copy any video track from this file.
- -S, --nosubs
- Don't copy any subtitle track from this file.
- --no-chapters
- If the source is a Matroska file then don't copy chapters from it.
- --no-attachments
- If the source is a Matroska file then don't copy attachments from it.
- --no-tags
- If the source is a Matroska file then don't copy tags from it.
- -y, --sync <TID:d[,o[/p]]>
- Synchronize manually, delay the audio track with the id TID by dms. The track IDs are the same as the ones given with --identify (seesection TRACK IDS).
d > 0: Pad with silent samples.
d < 0: Remove samples from the beginning.
o/p: adjust the timestamps by o/p to fixlinear drifts. p defaults to 1000 if omitted. Both o andp can be floating point numbers.
Defaults: no manual sync correction (which is the same as d = 0 ando/p = 1.0).
This option can be used multiple times for an input file applying to severaltracks by selecting different track IDs each time. - --cues <TID:none|iframes|all>
- Controls for which tracks cue (index) entries are created for the given track(see section TRACK IDS). none inhibits the creation of cue entries.For iframes only blocks with no backward or forwardreferences ( = I frames in video tracks) are put into the cue sheet. allcauses mkvmerge to create cue entries for all blocks which will makethe file very big.
The default is iframes for video tracks and none for all others.See also option --no-cues which inhibits the creation of cueentries regardless of the --cues options used.
This option can be used multiple times for an input file applying to severaltracks by selecting different track IDs each time. - --default-track <TID>
- Sets the 'default' flag for the given track (see section TRACK IDS).If the user does not explicitly select a track himself then the player shouldprefer the track that has his 'default' flag set. Only one track of each kind(audio, video, subtitles) can have his 'default' flag set.
This option can be used multiple times for an input file applying to severaltracks by selecting different track IDs each time. - --track-name <TID:name>
- Sets the track name for the given track (see section TRACK IDS) toname.
- --language <TID:language>
- Sets the language for the given track (see section TRACK IDS). OnlyISO639-2 codes are allowed. All languages including their ISO639-2 codes can belisted with the --list-languages option.
This option can be used multiple times for an input file applying to severaltracks by selecting different track IDs each time. - -t, --tags <TID:file>
- Read tags for the track with the number TID from the file. Seethe section about tags below for details.
- --aac-is-sbr <TID>
- Tells mkvmerge that the track with the ID TID is SBR AAC (alsoknown as HE-AAC or AAC+). This options is needed if a) the source file is anAAC file (NOT for a Matroska file) and b) the AAC file contains SBR AAC data.The reason for this switch is that it is technically impossible toautomatically tell normal AAC data from SBR AAC data without decoding acomplete AAC frame. As there are several patent issues with AAC decoders Iwon't implement this decoding stage. So for SBR AAC files this switch ismandatory. The resulting file might not play back correctly or even not atall if the switch was omitted.
If the source file is a Matroska file then the CodecID should be enough todetect SBR AAC. However, if the CodecID is wrong then this switch can be usedto correct that. - --timecodes <TID:filename>
- Read the timecodes to be used for the specific track ID from filename.These timecodes forcefully override the timecodes that mkvmergenormally calculates. Read the section about EXTERNAL TIMECODE FILES.
- --track-order <TID1[,TID2,...]>
- This option changes the order in which the tracks for an input file arecreated. If some track IDs are omitted then those tracks are created after theones given with this option have been created.
Options that only apply to video tracks:
- --display-dimensions <TID:widthxheight>
- Matroska files contain two values that set the display properties that aplayer 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 option (see below). These options are mutuallyexclusive. - --aspect-ratio <TID:ar|w/h>
- Matroska files contain two values that set the display properties thata player should scale the image on playback to: display width anddisplay height. With this option mkvmerge will automaticallycalculate the display width and display height based on the image'soriginal width and height and the aspect ratio given with this option.The ratio can be given either as a floating point number or as'width/height', e.g. 16/9.
Another way to specify the values is to use the--aspect-ratio option (see above). These options are mutuallyexclusive.
Options that only apply to text subtitle tracks:
- --compression <TID:method>
- Selects the compression method to be used for the VobSub track. Note that theplayer also has to support this method! Valid values are 'none' and 'zlib'.The default is 'zlib' compression.
Other options:
- 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
USAGE
For each file the user can select which tracks mkvmerge 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.
EXAMPLES
Let's assume you have a file called MyMovie.avi and the audio track in aseparate file, e.g. MyMovie.wav. First you want to encode the audio toOGG:
$ 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 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 and enjoy. If you have multiple audio tracks (or evenvideo tracks) then you can tell mplayer which track to play with the'-vid' and '-aid' parameters. These are 0-based and do notdistinguish between video and audio.
If you need an audio track synchronized you can do that easily. First findout 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 theID 12345 taken from outofsync.ogg.
Some movies start synced correctly but slowly drift out of sync. For thesekind of movies you can specify a delay factor that is applied to alltimestamps - no data is added or removed. So if you make that factor toobig or too small you'll get bad results. An example is that an episodeI transcoded was 0.2 seconds out of sync at the end of the movie whichwas 77340 frames long. At 29.97fps 0.2 seconds correspond to approx. 6frames. 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 (likeSubRipper) or the subrip package found in transcode(1)'ssources (in contrib/subrip). The general process is:
- *
- Ogg/OGM files: The track's ID is its serial number as given in the Ogg streamheader page.
- *
- Matroska files: The track's ID is the track number as reported by mkvinfoor mkvmerge --identify. It is not the track UID.
- *
- Manual audio synchronization for PCM sound (who needs it anyway?)
- NAME
- SYNOPSIS
- DESCRIPTION
- USAGE
- EXAMPLES
- TRACK IDS
- SUBTITLES
- FILE LINKING
- DEFAULT VALUES
- ATTACHMENTS
- CHAPTERS
- TAGS
- MATROSKA FILE LAYOUT
- EXTERNAL TIMECODE FILES
- NOTES
- AUTHOR
- SEE ALSO
- WWW
- --title <title>
- Sets the general title for the output file, e.g. the movie name.
- --global-tags <file>
- Read global tags from the XML file. See the section about tagsbelow for details.
- --command-line-charset <charset>
- Sets the charset to convert strings given on the command line from. It defaultsto the charset given by system's current locale. This settings applies toarguments of the following options: --title, --track-name and--attachment-description.
- --chapter-charset <charset>
- Sets the charset that is used for the conversion to UTF-8 for simple chapterfiles. Defaults to the current system locale. See the section about chaptersbelow for details.
- --cue-chapter-name-format <format>
- mkvmerge supports reading CUE sheets for audio files as the input forchapters. CUE sheets usually contain the entries PERFORMER andTITLE for each index entry. mkvmerge uses these two stringsin order to construct the chapter name. With this option the format usedfor this name can be set. The following meta characters are supported:
%p is replaced by the current entry's PERFORMER string,
%t is replaced by the current entry's TITLE string,
%n is replaced by the current track number and
%N is replaced by the current track number padded with a leading zero ifit is < 10.
Everything else is copied as-is.
If this option is not given then mkvmerge defaults to theformat '%p - %t' (the performer, followed by a space, a dash,another space and the title). - --chapters <file>
- Read chapter information from the file. See the section about chaptersbelow for details.
- --no-cues
- Tells mkvmerge not to create and write the cue data which can be comparedto an index in an AVI. Matroska files can be played back without the cuedata, but seeking will probably be imprecise and slower. Use this only ifyou're really desperate for space or for testing purposes. See also option--cues which can be specified for each input file.
- --no-clusters-in-meta-seek
- Tells mkvmerge not to create a meta seek element at the end of the filecontaining all clusters. See also the section about MATROSKA FILE LAYOUT.
- --disable-lacing
- Disables lacing for all tracks. This will increase the file's size, especiallyif there are many audio tracks. This option is not intended for everyday use.
- --enable-durations
- Write durations for all blocks. This will increase file size and does notoffer any additional value for players at the moment.
- --enable-timeslices
- Write time slices for all blocks with more than one frame (lacedblocks). This will increase file size and does not offer anyadditional value for players at the moment.
- --split-max-files <n>
- Create at most n files, even if the last file will be longer or largerthan indicated by --split.
- --link
- Link files to one another when splitting the output file. See thesection FILE LINKING below for details.
- --link-to-previous <UID>
- Links the first output file to the segment with the given UID. See thesection FILE LINKING below for details.
- --link-to-next <UID>
- Links the last output file to the segment with the given UID. See thesection FILE LINKING below for details.
- -a, --atracks <n,m,...>
- Copy the audio tracks n, m etc. The numbers are track IDs whichcan be obtained with the --identify switch. They're not simplythe track numbers (see section TRACK IDS). Default: copy all audiotracks.
- -d, --vtracks <n,m,...>
- Copy the video tracks n, m etc. The numbers are track IDs whichcan be obtained with the --identify switch (seesection TRACK IDS). They're not simplythe track numbers. Default: copy all video tracks.
- -s, --stracks <n,m,...>
- Copy the subtitle tracks n, m etc. The numbers are track IDs whichcan be obtained with the --identify switch (seesection TRACK IDS). They're not simplythe track numbers. Default: copy all subtitle tracks.
- -A, --noaudio
- Don't copy any audio track from this file.
- -D, --novideo
- Don't copy any video track from this file.
- -S, --nosubs
- Don't copy any subtitle track from this file.
- --no-chapters
- If the source is a Matroska file then don't copy chapters from it.
- --no-attachments
- If the source is a Matroska file then don't copy attachments from it.
- --no-tags
- If the source is a Matroska file then don't copy tags from it.
- -y, --sync <TID:d[,o[/p]]>
- Synchronize manually, delay the audio track with the id TID by dms. The track IDs are the same as the ones given with --identify (seesection TRACK IDS).
d > 0: Pad with silent samples.
d < 0: Remove samples from the beginning.
o/p: adjust the timestamps by o/p to fixlinear drifts. p defaults to 1000 if omitted. Both o andp can be floating point numbers.
Defaults: no manual sync correction (which is the same as d = 0 ando/p = 1.0).
This option can be used multiple times for an input file applying to severaltracks by selecting different track IDs each time. - --cues <TID:none|iframes|all>
- Controls for which tracks cue (index) entries are created for the given track(see section TRACK IDS). none inhibits the creation of cue entries.For iframes only blocks with no backward or forwardreferences ( = I frames in video tracks) are put into the cue sheet. allcauses mkvmerge to create cue entries for all blocks which will makethe file very big.
The default is iframes for video tracks and none for all others.See also option --no-cues which inhibits the creation of cueentries regardless of the --cues options used.
This option can be used multiple times for an input file applying to severaltracks by selecting different track IDs each time. - --default-track <TID>
- Sets the 'default' flag for the given track (see section TRACK IDS).If the user does not explicitly select a track himself then the player shouldprefer the track that has his 'default' flag set. Only one track of each kind(audio, video, subtitles) can have his 'default' flag set.
This option can be used multiple times for an input file applying to severaltracks by selecting different track IDs each time. - --track-name <TID:name>
- Sets the track name for the given track (see section TRACK IDS) toname.
- --language <TID:language>
- Sets the language for the given track (see section TRACK IDS). OnlyISO639-2 codes are allowed. All languages including their ISO639-2 codes can belisted with the --list-languages option.
This option can be used multiple times for an input file applying to severaltracks by selecting different track IDs each time. - -t, --tags <TID:file>
- Read tags for the track with the number TID from the file. Seethe section about tags below for details.
- --aac-is-sbr <TID>
- Tells mkvmerge that the track with the ID TID is SBR AAC (alsoknown as HE-AAC or AAC+). This options is needed if a) the source file is anAAC file (NOT for a Matroska file) and b) the AAC file contains SBR AAC data.The reason for this switch is that it is technically impossible toautomatically tell normal AAC data from SBR AAC data without decoding acomplete AAC frame. As there are several patent issues with AAC decoders Iwon't implement this decoding stage. So for SBR AAC files this switch ismandatory. The resulting file might not play back correctly or even not atall if the switch was omitted.
If the source file is a Matroska file then the CodecID should be enough todetect SBR AAC. However, if the CodecID is wrong then this switch can be usedto correct that. - --timecodes <TID:filename>
- Read the timecodes to be used for the specific track ID from filename.These timecodes forcefully override the timecodes that mkvmergenormally calculates. Read the section about EXTERNAL TIMECODE FILES.
- --track-order <TID1[,TID2,...]>
- This option changes the order in which the tracks for an input file arecreated. If some track IDs are omitted then those tracks are created after theones given with this option have been created.
- --display-dimensions <TID:widthxheight>
- Matroska files contain two values that set the display properties that aplayer 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 option (see below). These options are mutuallyexclusive. - --aspect-ratio <TID:ar|w/h>
- Matroska files contain two values that set the display properties thata player should scale the image on playback to: display width anddisplay height. With this option mkvmerge will automaticallycalculate the display width and display height based on the image'soriginal width and height and the aspect ratio given with this option.The ratio can be given either as a floating point number or as'width/height', e.g. 16/9.
Another way to specify the values is to use the--aspect-ratio option (see above). These options are mutuallyexclusive. - --compression <TID:method>
- Selects the compression method to be used for the VobSub track. Note that theplayer also has to support this method! Valid values are 'none' and 'zlib'.The default is 'zlib' compression.
- *
- Ogg/OGM files: The track's ID is its serial number as given in the Ogg streamheader page.
- *
- Matroska files: The track's ID is the track number as reported by mkvinfoor mkvmerge --identify. It is not the track UID.
- *
- Manual audio synchronization for PCM sound (who needs it anyway?)
- NAME
- SYNOPSIS
- DESCRIPTION
- USAGE
- EXAMPLES
- TRACK IDS
- SUBTITLES
- FILE LINKING
- DEFAULT VALUES
- ATTACHMENTS
- CHAPTERS
- TAGS
- MATROSKA FILE LAYOUT
- EXTERNAL TIMECODE FILES
- NOTES
- AUTHOR
- SEE ALSO
- WWW
$ mkvmerge -o with-lang-codes.mkv --language 2:ger --language 3:dutwithout-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 defaultlanguage. You also have extra subtitles, e.g. in English and French, and wantto 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 specifiedin mkvinfo's output then please read the section about DEFAULTVALUES.
TRACK IDS
Some of the options for mkvmerge need a track ID to specify which trackthey should be applied to. Those track IDs are printed by the readers whendemuxing the current input file, or if mkvmerge is called with the--identify option. Track IDs are assigned like this:
The special track ID '-1' is a wild card and applies the given switch to alltracks that are read from an input file. This was the behaviour of theseswitches prior to version 0.4.4.
The options that use the track IDs are: --atracks, --vtracks,--stracks, --sync, --default-track, --cuesand --language.
SUBTITLES
There are several text subtitle formats that can be embedded into Matroska.At the moment mkvmerge supports only text subtitle formats.These subtitles must be recoded to UTF-8 so that they can be displayedcorrectly by a player.
mkvmerge does this conversion automatically based on the system's currentlocale. If the subtitle charset is not the same asthe system's current charset then the user can use --sub-charsetswitch. If the subtitles are already encoded in UTF-8 then you can use--sub-charset UTF-8.
The following subtitle formats are supported at the moment:
Each segment is identified by a unique 128 bit wide segment UID. This UIDis automatically generated by mkvmerge. The linking is done primarilyvia putting the segment UIDs of the previous/next file into the segmentheader information. mkvinfo(1) prints these UIDs if it finds them.
If a file is split into several smaller ones and linking is used then thetimecodes will not start at 0 again but will continue where the last filehas left off. This way the absolute time is kept even if the previous filesare not available (e.g. when streaming). If no linking is used then thetimecodes should start at 0 for each file. By default mkvmerge does notuse file linking. If you want that you can turn it on with the'-link' option. This option is only useful if splittingis activated as well.
Regardless of whether splitting is active or not the user can tellmkvmerge to link the produced files to specific UIDs. This is achievedwith the options '--link-to-previous' and '--link-to-next'.These options accept a segment UID 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 0xca0xb3 0x93. Alternatively a shorter form can be used: 16 hexadecimal numbersbetween 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 UID given with'--link-to-previous' and the last file is linked to the UID givenwith '--link-to-next'. If splitting is not used then the oneoutput file will be linked to both of the two UIDs.
DEFAULT VALUES
The Matroska specs say that some elements have a default value. Usually anelement is not written to the file if its value is equal to its defaultvalue in order to save space. The elements that the user might miss inmkvinfo's output are the language and the default track flag.The default value for the language is English (eng),and the default value for the default track flag is true. Thereforeif you used --language 0:eng for a track then it will not show upin mkvinfo's output.
ATTACHMENTS
Maybe you also want to keep some photos along with your Matroska file, oryou're using SSA subtitles and need a special TrueType font that's reallyrare. In these cases you can attach those files to the Matroska file. Theywill not be just appended to the file but embedded in it. A player can thenshow those files (the 'photos' case) or use them to render the subtitles(the 'TrueType fonts' case).
Here's an example how to attach a photo and a TrueType font to the outputfile:
$ 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
CHAPTERS
The Matroska chapter system is more powerful than the old known system usedby OGMs. The full specs can be found at<http://cvs.corecodec.org/cgi-bin/viewcvs.cgi/*checkout*/matroska/doc/website/technical/specs/chapters/index.html>

mkvmerge supports two kinds of chapter files as its input. The firstformat, called 'simple chapter format', is the same format that the OGM toolsexpect. The second format is a XML based chapter format which supports allof Matroska's chapter functionality.
The simple chapter format
It looks basically like this:
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 will transform every pair or lines (CHAPTERxx and CHAPTERxxNAME)into one Matroska ChapterAtom. It does not set anyChapterTrackNumber which means that the chapters all apply to alltracks in the file.
The charset used in the file is assumed to be the same charset that thecurrent system's locale returns. If this is not the case then the swith--chapter-charset should be used. If the file contains a validBOM (byte order marker) then all UTF styles are converted automatically.In this case --chapter-charset is simply ignored. You can usemkvinfo or mkvextract to verify that the chapter names havebeen converted properly.
The XML based chapter format
The XML based chapter format looks like this:
<?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 thesimple chapter format: 1) The timestamp for the end of the chapter can beset, 2) chapters can be nested, 3) the language and country can be set.
The mkvtoolnix distribution contains some sample files in the docsubdirectory which can be used as a basis.
General notes
When splitting files mkvmerge will correctly adjust the chapters aswell. This means that each file only includes the chapter entries thatapply to it, and that the timecodes will be offset to match the new timecodesof each output file.
mkvmerge is able to copy chapters from Matroska source files unless thisis explicitely disabled with the --no-chapters option. At themoment mkvmerge is limited to one 'buch of chapters' globally. This meansthat only the first chapter section found in all source files is used. Ifthe user specified chapters on the command line then these take precedenceover any chapters found in source files. mkvmerge does not mergechapters. This must be done manually by using mkvextract to extractthe chapter information and editing the resulting files.
One shortcoming is that mkvmerge cannot parse chapter information foundin OGM files.
TAGS
Introduction
Matroska supports an extensive set of tags that is deprecated and anew, simpler system like it is is used in most other containers:KEY=VALUE. However, in Matroska these tags can also be nested,and both the KEY and the VALUE are elements of theirown. The exaple file example-tags-2.xml show how to use this newsystem.
Scope of the tags
Matroska 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 moretracks, to one or more chapters, or even to a combination of both. Theaforementioned URL gives more details about this fact.
One important fact is that tags are linked to tracks or chapters withthe Targets Matroska tag element, and that the UIDs used forthis linking are NOT the track IDs mkvmerge useseverywhere. Instead the numbers used are the UIDs which mkvmergecalculates automatically (if the track is taken from a file formatother than Matroska) or which are copied from the source file if thetrack's source file is a Matroska file. Therefore it is difficult toknow which UIDs to use in the tag file before the file is handedover to mkvmerge.
mkvmerge knows two options with which you can add tags toMatroska files: The --global-tags and the --tagsoptions. The difference is that the former option,--global-tags, will make the tags apply to the complete fileby removing any of those Targets elements mentioned above. Thelatter option, --tags, automatically inserts the UID thatmkvmerge generates for the tag specified with the TID partof the --tags option.
Example
Let's say that you want to add tags to a video track read froman AVI. mkvmerge -i 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 any Targets element and call mkvmerge:
$ mkvmerge -o file.mkv --tags 0:tags.xml file.avi
Tag file format
mkvmerge supports a XML based tag file format. The format isvery easy and closely connected to the Matroska tag specs found at theURL mentioned above. Both the binary and the source mkvtoolnixdistributions come with a sample file called xample-tags-2.xmlwhich simply lists all known tags and which can be used as a basis forreal life tag files.
The basics are:
- <String>element while the binary type is used for the <Binary> type.
As binary data itself would not fit into a XML file mkvmergesupports two other methods of storing binary data. If the contents ofa XML tag starts with '@' then the following text is treated as afile name. The corresponding file's content is copied into theMatroska element.
Otherwise the data is expected to be Base64 encoded. This is anencoding that transforms binary data into a limited set of ASCIIcharacters and is used e.g. in email programs. mkvtoolnix comeswith a utility, base64tool, that can be used to encode to anddecode from Base64. mkvextract will output Base64 encoded datafor binary elements.
The deprecated tagging system knows some more data types which can befound in the official Matroska tag specs. The following two paragraphs onlyapply to the deprecated tags (an example file is still available and calledexample-tags-deprecated.xml):
The types integer, unsigned integer, float, stringand UTF-8 string look just like you expect them to: 4254,-2, 5.0, hello world and hello world.
The date format used by both mkvmerge when reading XML tag filesand by mkvextract when outputting XML tag data is the ISO-8601format. It has the following structure:YYYY-MM-DDTHH:MM:SS+TZTZ.YYYY is the year (four digist long), MM the month (two digitslong starting with 01), DD the day of the month (two digits longstarting with 01), HH the hour of the day (two digits long, range00 - 23), MM the minute (two digits long, range 00 - 59), SSthe seconds (two digits long, range 00 - 59). +TZTZ is the time zone,e.g. +0100 or -0200. An example would be 2003-07-30T19:10:16+0200.
MATROSKA FILE LAYOUT
The Matroska file layout is quite flexible. mkvmerge will render a filein a predefined way. The resulting file looks like this:
[EBML head] [segment {meta seek #1} {attachments} {chapters}[segment information] [track information] [cluster 1] {cluster 2} ...{cluster n} {cues} {meta seek #2} {tags}]
The elements in curly braces are optional and depend on the contents andoptions used. Some notes:
Timecode file format v1
This format starts with this line:
# timecode format v1
The second line gives the default number of frames per second:
assume 27.930
All following lines contain three numbers separated by commas: thestart frame (0 is the first frame), the end frame and the number offrames in this range. The FPS is a floating point number with the dotdefault FPS is used. Example:
800,1000,25
1500,1700,30
Timecode file format v2
In this format each line contains a timecode for the next frame. Thistimecode must be given in ms precision. It can be a floating point number,but it doesn't have to be. You must give at least as many timecodelines as there are frames in the track. Example for 25fps:
# timecode format v2
0
40
80
etc.
NOTES
What works:
AUTHOR
mkvmergewas written by Moritz Bunkus <moritzAATTbunkus.org>.SEE ALSO
mkvinfo(1),mkvextract(1),mmg(1)WWW
The newest version can always be found at<http://www.bunkus.org/videotools/mkvtoolnix/>Index
Section: User Commands (1)
Setting Up Mkvmerge GUI
Updated: February 2004Index
NAME

SYNOPSIS
mkvmerge[global options] -o out [options1] <file1> [[options2] <file2> ...] [@optionsfile]DESCRIPTION
This program takes the input from several media files and joinstheir streams (all of them or just a selection) into a Matroska file.<http://www.matroska.org/>
Global options:
- out'.
Chapter handling: (global options)
General output control (advanced global options):
- n milliseconds of data intoeach cluster. The maximum length for a cluster is 65535ms. Programs willonly be able to seek to clusters, so creating larger clusters may lead toimprecise seeking and/or processing.
File splitting and linking (more global options):
- n after which thefile should be split.
For this splitting mode the output filename is treated differently than forthe normal operation. It may contain a printf like expression '%d' includingan optional field width, e.g. '%02d'. If it does then the current file numberwill 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 beforethe file's extension: '-o output.mkv' would result in 'output-001.mkv' andso on. If there's no extension then '-%03d' will be appended to the name.
Attachment support (more global options):
Options that only apply to video tracks:
Options that only apply to text subtitle tracks:
Other options:
- 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
USAGE
For each file the user can select which tracks mkvmerge 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.
EXAMPLES
Let's assume you have a file called MyMovie.avi and the audio track in aseparate file, e.g. MyMovie.wav. First you want to encode the audio toOGG:
$ 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 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 and enjoy. If you have multiple audio tracks (or evenvideo tracks) then you can tell mplayer which track to play with the'-vid' and '-aid' parameters. These are 0-based and do notdistinguish between video and audio.
If you need an audio track synchronized you can do that easily. First findout 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 theID 12345 taken from outofsync.ogg.
Some movies start synced correctly but slowly drift out of sync. For thesekind of movies you can specify a delay factor that is applied to alltimestamps - no data is added or removed. So if you make that factor toobig or too small you'll get bad results. An example is that an episodeI transcoded was 0.2 seconds out of sync at the end of the movie whichwas 77340 frames long. At 29.97fps 0.2 seconds correspond to approx. 6frames. 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 (likeSubRipper) or the subrip package found in transcode(1)'ssources (in contrib/subrip). The general process is:
$ mkvmerge -o with-lang-codes.mkv --language 2:ger --language 3:dutwithout-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 defaultlanguage. You also have extra subtitles, e.g. in English and French, and wantto 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 specifiedin mkvinfo's output then please read the section about DEFAULTVALUES.
TRACK IDS
Some of the options for mkvmerge need a track ID to specify which trackthey should be applied to. Those track IDs are printed by the readers whendemuxing the current input file, or if mkvmerge is called with the--identify option. Track IDs are assigned like this:
The special track ID '-1' is a wild card and applies the given switch to alltracks that are read from an input file. This was the behaviour of theseswitches prior to version 0.4.4.
The options that use the track IDs are: --atracks, --vtracks,--stracks, --sync, --default-track, --cuesand --language.
SUBTITLES
There are several text subtitle formats that can be embedded into Matroska.At the moment mkvmerge supports only text subtitle formats.These subtitles must be recoded to UTF-8 so that they can be displayedcorrectly by a player.
mkvmerge does this conversion automatically based on the system's currentlocale. If the subtitle charset is not the same asthe system's current charset then the user can use --sub-charsetswitch. If the subtitles are already encoded in UTF-8 then you can use--sub-charset UTF-8.
The following subtitle formats are supported at the moment:
Each segment is identified by a unique 128 bit wide segment UID. This UIDis automatically generated by mkvmerge. The linking is done primarilyvia putting the segment UIDs of the previous/next file into the segmentheader information. mkvinfo(1) prints these UIDs if it finds them.
If a file is split into several smaller ones and linking is used then thetimecodes will not start at 0 again but will continue where the last filehas left off. This way the absolute time is kept even if the previous filesare not available (e.g. when streaming). If no linking is used then thetimecodes should start at 0 for each file. By default mkvmerge does notuse file linking. If you want that you can turn it on with the'-link' option. This option is only useful if splittingis activated as well.
Regardless of whether splitting is active or not the user can tellmkvmerge to link the produced files to specific UIDs. This is achievedwith the options '--link-to-previous' and '--link-to-next'.These options accept a segment UID 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 0xca0xb3 0x93. Alternatively a shorter form can be used: 16 hexadecimal numbersbetween 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 UID given with'--link-to-previous' and the last file is linked to the UID givenwith '--link-to-next'. If splitting is not used then the oneoutput file will be linked to both of the two UIDs.
DEFAULT VALUES
The Matroska specs say that some elements have a default value. Usually anelement is not written to the file if its value is equal to its defaultvalue in order to save space. The elements that the user might miss inmkvinfo's output are the language and the default track flag.The default value for the language is English (eng),and the default value for the default track flag is true. Thereforeif you used --language 0:eng for a track then it will not show upin mkvinfo's output.
ATTACHMENTS
See Full List On Priede.bf.lu.lv
Maybe you also want to keep some photos along with your Matroska file, oryou're using SSA subtitles and need a special TrueType font that's reallyrare. In these cases you can attach those files to the Matroska file. Theywill not be just appended to the file but embedded in it. A player can thenshow those files (the 'photos' case) or use them to render the subtitles(the 'TrueType fonts' case).
Here's an example how to attach a photo and a TrueType font to the outputfile:
$ 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
CHAPTERS
The Matroska chapter system is more powerful than the old known system usedby OGMs. The full specs can be found at<http://cvs.corecodec.org/cgi-bin/viewcvs.cgi/*checkout*/matroska/doc/website/technical/specs/chapters/index.html>
mkvmerge supports two kinds of chapter files as its input. The firstformat, called 'simple chapter format', is the same format that the OGM toolsexpect. The second format is a XML based chapter format which supports allof Matroska's chapter functionality.
The simple chapter format
It looks basically like this:
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 will transform every pair or lines (CHAPTERxx and CHAPTERxxNAME)into one Matroska ChapterAtom. It does not set anyChapterTrackNumber which means that the chapters all apply to alltracks in the file.
The charset used in the file is assumed to be the same charset that thecurrent system's locale returns. If this is not the case then the swith--chapter-charset should be used. If the file contains a validBOM (byte order marker) then all UTF styles are converted automatically.In this case --chapter-charset is simply ignored. You can usemkvinfo or mkvextract to verify that the chapter names havebeen converted properly.
The XML based chapter format
The XML based chapter format looks like this:
<?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 thesimple chapter format: 1) The timestamp for the end of the chapter can beset, 2) chapters can be nested, 3) the language and country can be set.
The mkvtoolnix distribution contains some sample files in the docsubdirectory which can be used as a basis.
General notes
When splitting files mkvmerge will correctly adjust the chapters aswell. This means that each file only includes the chapter entries thatapply to it, and that the timecodes will be offset to match the new timecodesof each output file.
mkvmerge is able to copy chapters from Matroska source files unless thisis explicitely disabled with the --no-chapters option. At themoment mkvmerge is limited to one 'buch of chapters' globally. This meansthat only the first chapter section found in all source files is used. Ifthe user specified chapters on the command line then these take precedenceover any chapters found in source files. mkvmerge does not mergechapters. This must be done manually by using mkvextract to extractthe chapter information and editing the resulting files.

One shortcoming is that mkvmerge cannot parse chapter information foundin OGM files.
TAGS
Introduction
Matroska supports an extensive set of tags that is deprecated and anew, simpler system like it is is used in most other containers:KEY=VALUE. However, in Matroska these tags can also be nested,and both the KEY and the VALUE are elements of theirown. The exaple file example-tags-2.xml show how to use this newsystem.
Scope of the tags
Matroska 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 moretracks, to one or more chapters, or even to a combination of both. Theaforementioned URL gives more details about this fact.
One important fact is that tags are linked to tracks or chapters withthe Targets Matroska tag element, and that the UIDs used forthis linking are NOT the track IDs mkvmerge useseverywhere. Instead the numbers used are the UIDs which mkvmergecalculates automatically (if the track is taken from a file formatother than Matroska) or which are copied from the source file if thetrack's source file is a Matroska file. Therefore it is difficult toknow which UIDs to use in the tag file before the file is handedover to mkvmerge.
mkvmerge knows two options with which you can add tags toMatroska files: The --global-tags and the --tagsoptions. The difference is that the former option,--global-tags, will make the tags apply to the complete fileby removing any of those Targets elements mentioned above. Thelatter option, --tags, automatically inserts the UID thatmkvmerge generates for the tag specified with the TID partof the --tags option.
Example
Let's say that you want to add tags to a video track read froman AVI. mkvmerge -i 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 any Targets element and call mkvmerge:
$ mkvmerge -o file.mkv --tags 0:tags.xml file.avi
Tag file format
mkvmerge supports a XML based tag file format. The format isvery easy and closely connected to the Matroska tag specs found at theURL mentioned above. Both the binary and the source mkvtoolnixdistributions come with a sample file called xample-tags-2.xmlwhich simply lists all known tags and which can be used as a basis forreal life tag files.
The basics are:
- <String>element while the binary type is used for the <Binary> type.
As binary data itself would not fit into a XML file mkvmergesupports two other methods of storing binary data. If the contents ofa XML tag starts with '@' then the following text is treated as afile name. The corresponding file's content is copied into theMatroska element.
Otherwise the data is expected to be Base64 encoded. This is anencoding that transforms binary data into a limited set of ASCIIcharacters and is used e.g. in email programs. mkvtoolnix comeswith a utility, base64tool, that can be used to encode to anddecode from Base64. mkvextract will output Base64 encoded datafor binary elements.
The deprecated tagging system knows some more data types which can befound in the official Matroska tag specs. The following two paragraphs onlyapply to the deprecated tags (an example file is still available and calledexample-tags-deprecated.xml):
The types integer, unsigned integer, float, stringand UTF-8 string look just like you expect them to: 4254,-2, 5.0, hello world and hello world.
The date format used by both mkvmerge when reading XML tag filesand by mkvextract when outputting XML tag data is the ISO-8601format. It has the following structure:YYYY-MM-DDTHH:MM:SS+TZTZ.YYYY is the year (four digist long), MM the month (two digitslong starting with 01), DD the day of the month (two digits longstarting with 01), HH the hour of the day (two digits long, range00 - 23), MM the minute (two digits long, range 00 - 59), SSthe seconds (two digits long, range 00 - 59). +TZTZ is the time zone,e.g. +0100 or -0200. An example would be 2003-07-30T19:10:16+0200.
MATROSKA FILE LAYOUT
The Matroska file layout is quite flexible. mkvmerge will render a filein a predefined way. The resulting file looks like this:
[EBML head] [segment {meta seek #1} {attachments} {chapters}[segment information] [track information] [cluster 1] {cluster 2} ...{cluster n} {cues} {meta seek #2} {tags}]
The elements in curly braces are optional and depend on the contents andoptions used. Some notes:
Timecode file format v1
This format starts with this line:
# timecode format v1
The second line gives the default number of frames per second:
assume 27.930
All following lines contain three numbers separated by commas: thestart frame (0 is the first frame), the end frame and the number offrames in this range. The FPS is a floating point number with the dotdefault FPS is used. Example:
800,1000,25
1500,1700,30
Timecode file format v2
In this format each line contains a timecode for the next frame. Thistimecode must be given in ms precision. It can be a floating point number,but it doesn't have to be. You must give at least as many timecodelines as there are frames in the track. Example for 25fps:
# timecode format v2
0
40
80
etc.
NOTES
What works:

AUTHOR
mkvmergewas written by Moritz Bunkus <moritzAATTbunkus.org>.SEE ALSO
mkvinfo(1),mkvextract(1),mmg(1)WWW
The newest version can always be found at<http://www.bunkus.org/videotools/mkvtoolnix/>Index
