mkvmerge − Merge multimedia streams into a Matroska file |
mkvmerge [global options] −o out [options] <file1> [[options] <file2> ...] [@optionsfile] |
This program takes the input from several media files and joins their streams (all of them or just a selection) into a Matroska file. Global options: |
−v, −−verbose |
Increase verbosity. |
−q, −−quiet |
Suppress status output. |
−o, −−output out |
Write to the file ’out’. |
−−cluster−length n[ms] |
Put at most n data blocks into each cluster. If the number is postfixed with ’ms’ then put at most n milliseconds of data into each cluster. The maximum length for a cluster is 65535ms. Programs will only be able to seek to clusters, so creating larger clusters may lead to imprecise seeking and/or processing. |
−−no−cues |
Tells mkvmerge not to create and write the cue data which can be compared to an index in an AVI. Matroska files can be played back without the cue data, but seeking will probably be imprecise and slower. Use this only if you’re really desparate for space or for testing purposes. See also option −−cues which can be specified for each input file. |
−−no−meta−seek |
The meta seek information is stored along with the headers at the beginning of the file and points to the cue entries (the index). This allows a player to quickly find the index and uses very little space. It should be left on and only disabled for testing purposes. At the moment −−no−cues implies −−no−meta−seek. |
−−meta−seek−size d |
Reserve d bytes for the meta seek information (see −−no−meta−seek). Default value is 100 bytes which should be enough. mkvmerge will abort with an appropriate warning message if the space is not enough and also provide the optimal size to use with this option. This option is normally not needed. |
−−no−lacing |
Disable lacing for all tracks. This will increase the file’s size, especially if there are many audio tracks. This option is not intended for everyday use. |
Options that can be used for each input file: |
−a, −−atracks <n,m,...> |
Copy the audio tracks n, m etc. Default: copy all audio tracks. |
−d, −−vtracks <n,m,...> |
Copy the video tracks n, m etc. Default: copy all video tracks. |
−s, −−stracks <n,m,...> |
Copy the subtitle tracks n, m etc. 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. |
−T, −−nosubs |
Don’t copy any subtitle track from this file. |
−y, −−sync <d[,o[/p]]> |
Synchronize manually, delay the audio track by d
ms. |
−−cues <none|iframes|all> |
Controls for which tracks cue (index) entries are
created. none inhibits the creation of cue entries
for all tracks contained in the following source files. For
iframes only blocks with no backward or forward
references ( = I frames in video tracks) are put into the
cue sheet. all causes mkvmerge to create cue
entries for all blocks which will make the file very
big. |
−−default−track |
Sets the ’default’ flag for all tracks read from this file. If the user does not explicitly select a track himself then the player should prefer the track that has his ’default’ flag set. Only one track of each kind (audio, video, subttiles) can have his ’default’ flag set. |
−−language <language> |
Sets the language for all tracks read from this file. Only ISO639-2 codes are allowed. All languages including their ISO639-2 codes can be listed with the −−list−languages option. |
Options that only apply to video tracks: |
−f, −−fourcc <FourCC> |
Forces the FourCC to the specified value. Works only for video tracks. |
−−aspect−ratio <ar|w/h> |
Sets the aspect ratio for the track. The ratio can be given either as a floating point number or as ’widht/height’, e.g. 16/9. |
Options that only apply to subtitle tracks: |
−−sub−charset |
Sets the charset for the conversion to UTF-8 for UTF-8 subtitles. If not specified the charset will be derived from the current locale settings. |
Other options: |
−l, −−list−types |
Lists supported input file types. |
−−list−languages |
Lists all languages and their ISO639-2 code which can be used with the −−language option. |
−h, −−help |
Show usage information. |
−V, −−version |
Show version information. |
@optionsfile |
Reads additional command line arguments from the file
optionsfile. Lines whose first non-whitespace
character is a hash mark (#) are treated as comments and
ignored. Whitespaces at the start and end of a line will be
stripped. If a space is encountered and the line starts with
’−’ then the line will be split into
exactly two arguments - the string before the space and the
string after it. There is no meta character escaping. |
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. |
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 OGG: $ 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 aswell (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 The same result can be achieved with $ mkvmerge -o MM-complete.mkv -A MyMovie.avi
MyMovie.ogg \ Now fire up mplayer and enjoy. If you have multiple audio tracks (or even video tracks) then you can tell mplayer which track to play with the ’-vid’ and ’-aid’ parameters. These are 0-based and do not distinguish between video and audio. If you need an audio track synchronized you can do that easily with $ mkvmerge -o goodsync.mkv -A source.avi -s 200 outofsync.ogg This would add 200ms of silence at the beginning of the audio tracks taken from outofsync.ogg. And -s always applies to all audio tracks in a source file. If you want to apply -s only to a specific track then take the same source file more than once and add -a and -s accordingly. 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 -s 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) or the subrip package found in transcode(1)’s sources (in contrib/subrip). The general process is: |
1. |
extract a raw subtitle stream from the source: |
$ tccat -i /path/to/copied/dvd/ -T 1 -L | \ |
2. |
convert the resulting PGM images to text with gocr: |
$ pgm2txt mymovie |
3. |
spell-check the resulting text files: |
$ ispell -d american *txt |
4. |
convert the text files to a SRT file: |
$ srttool -s -w -i mymovie.srtx -o mymovie.srt |
The resulting file can be used as another input file for mkvmerge: $ mkvmerge -o mymovie.mkv mymovie.avi mymovie.srt |
There are several text subtitle formats that can be embedded into Matroska. At the moment mkvmerge supports only one simple text subtitle formats: SRT (Subtitle Ripper). These subtitles should normally be recoded to UTF-8 so that they can be displayed correctly by a player. For recoded subtitles Matroska specifies S_TEXT/UTF8 as the codec ID. There’s also S_TEXT/ASCII which assumes that no conversion is necessary. mkvmerge does this conversion automatically based on the system’s current locale. If the user does not want that conversion then he has to use the −−sub−type ascii switch. If the subtitle charset is not the same as the system’s current charset then the user can use −−sub−charset switch. If the subtitles are already encoded in UTF-8 then you can use −−sub−charset UTF−8. |
What works: |
* |
AVI as the video and audio source (only raw PCM, MP3 and AC3 audio tracks at the moment) |
||
* |
OGG as the source for video, audio (Vorbis, raw PCM, MP3 and AC3 audio) and text streams (subtitles). |
||
* |
WAV as the audio source |
||
* |
MP3 audio files |
||
* |
AC3 audio files |
||
* |
Track selection |
||
* |
Manual audio synchronization by adding silence/removing packets for Vorbis audio and for text streams by adjusting the starting point and duration. |
||
* |
Manual audio synchronization for AC3 and MP3 audio by duplicating/removing packets at the beginning. |
||
* |
Text subtitles can be read from SRT (SubRipper / subrip) files or taken from other OGM files. |
What not works: |
* |
Manual audio synchronization for PCM sound (who needs it anyway?) |
Planned functionality: |
* |
support for other subtitle formats |
||
* |
chapter information |
||
* |
a lot of other stuff, like tags, user information etc. |
mkvmerge was written by Moritz Bunkus <moritz@bunkus.org>. |
mkvinfo(1) |
The newest version can always be found at <http://www.bunkus.org/videotools/mkvtoolnix/> |