Difference between revisions of "Mkvtoolnix"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
(header removal compression bug)
m (remove a subtitle track from a Matroska .avi file)
 
(14 intermediate revisions by one user not shown)
Line 2: Line 2:
  
 
A CRITICAL consideration when hoping to edit [[Matroska]] video files is that Matroska is a CONTAINER and not a VIDEO itself.  If it helps, a lose example is to consider how a zip archive can contain several files within.  A mkv (or Matroska) file contains files within, such as a video stream, one or more audio streams, one or more subtitle files, etc.  In order to edit the video, everything needs to be taken out of the Matroska container and dealt with individually.  Mkvtoolnix is a wonderful set of utilities for doing just that, and additionally, performing many common editing tasks.  Mkvtoolnix can also be used to inspect and verify Matroska files.
 
A CRITICAL consideration when hoping to edit [[Matroska]] video files is that Matroska is a CONTAINER and not a VIDEO itself.  If it helps, a lose example is to consider how a zip archive can contain several files within.  A mkv (or Matroska) file contains files within, such as a video stream, one or more audio streams, one or more subtitle files, etc.  In order to edit the video, everything needs to be taken out of the Matroska container and dealt with individually.  Mkvtoolnix is a wonderful set of utilities for doing just that, and additionally, performing many common editing tasks.  Mkvtoolnix can also be used to inspect and verify Matroska files.
 +
 +
== installation ==
 +
=== linux ===
 +
Many Linux distributions are directly supported.  There are packages for Debian and Ubuntu, Mint users should try the Ubuntu package first.
 +
 +
Successfully installed on Mint Linux 18.3, Sylvian based on Ubuntu Xenial 16.04 with the following commands:
 +
sudo apt install mkvtoolnix mkvtoolnix-gui
 +
 +
Flatpak Method Broken:
 +
 +
There are also Linux Flatpak images which work across the distributions if you have flatpak.  I wouldnt count on this method.
 +
$ flatpak install flathub org.bunkus.mkvtoolnix-gui flatpak run org.bunkus.mkvtoolnix-gui
 +
Required runtime for org.bunkus.mkvtoolnix-gui/x86_64/stable (org.kde.Platform/x86_64/6.2) is not installed, searching...
 +
Found in remote flathub, do you want to install it? [y/n]: y
 +
error: Invalid id flatpak: Names must contain at least 2 periods
 +
 +
And that's what you get.
 +
 +
* [ [https://mkvtoolnix.download/downloads.html installation guides for various distributions] ]
 +
 +
=== windows ===
 +
Version v69.0.0 is available as an installer and as a portable 7zip archive.  Supported Windows versions are Windows 10/Windows Server 2012 and newer.
 +
 +
* [ [https://mkvtoolnix.download/downloads.html download] ]
 +
 +
=== mac ===
 +
Newer versions of MKVToolNix require newer versions of macOS to run due to Apple supporting certain required libraries only with certain macOS versions.
 +
 +
* [ [https://mkvtoolnix.download/downloads.html download] ]
  
 
== mkvmerge ==
 
== mkvmerge ==
Line 26: Line 55:
  
 
source: [http://forum.videohelp.com/threads/339823-Remove-subtitles-etc-from-MKV-files aedipuss on videohelp.com]
 
source: [http://forum.videohelp.com/threads/339823-Remove-subtitles-etc-from-MKV-files aedipuss on videohelp.com]
 +
 +
''see also below: mkvextract''
  
 
=== crop off part of the matroska video (edit/split) ===
 
=== crop off part of the matroska video (edit/split) ===
Line 60: Line 91:
 
# Set Forced track flag to YES
 
# Set Forced track flag to YES
  
Technically, the Default track flag would not necessarily have to be set to YES, but can be.  This is explained best in the section about subtitles ([Mkvtoolnix#subtitles]).
+
Technically, the Default track flag would not necessarily have to be set to YES, but can be.  This is explained best in the section about subtitles ([[Mkvtoolnix#subtitles]]).
  
 
== support ==
 
== support ==
Line 77: Line 108:
 
* click extra options tab
 
* click extra options tab
 
* change "compression" to none
 
* change "compression" to none
 +
 +
=== track cue (index) entries ===
 +
 +
In mkvmerge GUI v6.0.0 look under the tab "Extra options" and the Cues drop down.  The option is also set via command line parameter.  The option applies individually for each track.
 +
 +
--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 forward references ( = I frames in video tracks) are put into the cue sheet.
 +
'all' causes mkvmerge(1) to create cue entries for all blocks which will make the 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 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.
 +
 +
Remux with mkvmerge sometimes results in out that [[VideoLAN Player]] has problems playing back, namely, when the user clicks forward in the video.  changing the cues sometimes resolves. 
 +
 +
=== remux after added subtitles vlc hangs on scan ===
 +
 +
''"I added subtitles to some mkv files using MKVMerge, however now when I scan through the files with VLC, it takes 15 seconds before it starts playing again. I can skip to any part of the original mkv files and VLC plays without any lag."''  [http://forum.videohelp.com/threads/352097-After-remux-with-MKVMerge-to-add-subs-scanning-is-slow source]
 +
 +
You can add this parameters :
 +
 +
--clusters-in-meta-seek --engage no_cue_duration --engage no_cue_relative_position
 +
 +
It will fix the problem of seeking after remuxing.  This is a [https://trac.bunkus.org/wiki/FAQ%3APlaybackDoesNotWorkVLCCannotSeekMkvmerge590 bug in mkvtoolnix / mkvmerge]. 
 +
 +
Now, how you do this :<BR>
 +
In the menu bar go to Muxing->add command line option
 +
 +
In the new window jsut past in the bottom field (command line options) :
 +
 +
--clusters-in-meta-seek --engage no_cue_duration --engage no_cue_relative_position
 +
 +
Remux and you are done.
 +
 +
Note that those options need to be pasted EACH time you open MKVToolNIX : they are not persistent.
 +
 +
But before doing so, if you don't want to remux, there is a workaround in VLC. I just quote a passage of the page i linked to you at the begining of the post:
 +
 +
Turning on "Dummy elements" fixes this immediately; now seeking works as it has before. You can do that in VLC here ​: Tools -> Preferences -> "Show settings: all" at the bottom left; In the tree on the left side: Input/Codecs -> Matroska; make sure "Dummy elements" is turned on.
 +
 +
credit to: Namoi of vcdhelp.com (Namoi should read "[[your is not a contraction]]" to benefit credibility)
 +
 +
== Additional Related Tools ==
 +
There are a number of related tools some to be installed individually. 
 +
 +
(maybe a partial list)
 +
*mkvextract
 +
*mkvinfo
 +
*mkvmerge
 +
*mkvpropedit
 +
*mkvtoolnix-gui
 +
 +
There are additional GUI interface tools such as MKVExtractGUI which has too many dependency requirements unless you don't mind.
 +
 +
Example 1:  mkvextract - To extract subtitles from the mkv.  You can use mkvinfo to output all tracks to console however I recommend using mkvtoolnix as a visual reference.  Tracks count starts at zero.  In this example two subtitle tracks will be extracted. 
 +
mkvextract tracks movie.mkv 2:subtitles0.srt
 +
mkvextract tracks movie.mkv 3:subtitles1.srt
 +
 +
  
 
&nbsp;
 
&nbsp;

Latest revision as of 07:37, 20 July 2023

Free open source cross platform set of tools and utilities for working with mkv container files. These tools are ideal for working with H.264 video in an mkv container.

A CRITICAL consideration when hoping to edit Matroska video files is that Matroska is a CONTAINER and not a VIDEO itself. If it helps, a lose example is to consider how a zip archive can contain several files within. A mkv (or Matroska) file contains files within, such as a video stream, one or more audio streams, one or more subtitle files, etc. In order to edit the video, everything needs to be taken out of the Matroska container and dealt with individually. Mkvtoolnix is a wonderful set of utilities for doing just that, and additionally, performing many common editing tasks. Mkvtoolnix can also be used to inspect and verify Matroska files.

installation

linux

Many Linux distributions are directly supported. There are packages for Debian and Ubuntu, Mint users should try the Ubuntu package first.

Successfully installed on Mint Linux 18.3, Sylvian based on Ubuntu Xenial 16.04 with the following commands:

sudo apt install mkvtoolnix mkvtoolnix-gui

Flatpak Method Broken:

There are also Linux Flatpak images which work across the distributions if you have flatpak. I wouldnt count on this method.

$ flatpak install flathub org.bunkus.mkvtoolnix-gui flatpak run org.bunkus.mkvtoolnix-gui
Required runtime for org.bunkus.mkvtoolnix-gui/x86_64/stable (org.kde.Platform/x86_64/6.2) is not installed, searching...
Found in remote flathub, do you want to install it? [y/n]: y
error: Invalid id flatpak: Names must contain at least 2 periods

And that's what you get.

windows

Version v69.0.0 is available as an installer and as a portable 7zip archive. Supported Windows versions are Windows 10/Windows Server 2012 and newer.

mac

Newer versions of MKVToolNix require newer versions of macOS to run due to Apple supporting certain required libraries only with certain macOS versions.

mkvmerge

subtitles

The Default track flag will determine the default track to be played. The Forced track flag comes into play if you need to force a particular audio or subtitle file to play always. For instance in a movie with foreign dialog there would be a subtitle stream specifically for this portion of the movie. This subtitle stream should be set to forced, otherwise there would be no subtitles during this portion of the movie, leaving the audience scratching their heads.

Leaving a flag (no matter which flag) on the "default" settings means the decision whether or not it should be set is up to mkvmerge. mkvmerge usually takes the information provided by the source container into account. For some flag types (especially the "default track" flag) there are other considerations as well. Setting a flag to "no" will force mkvmerge not to set that flag, no matter what those other considerations would have done and no matter what the source container provided for that flag.

As a lot of users don't want subtitles shown by default they tell mkvmerge not to set the "default track" flag for any subtitle track.

Now on to the "forced display" flag, in short "forced". If this is set to "on" then this track must be played/shown no matter what the user selected for his preferences or what the player would normally chose to show/play. This is used seldom, e.g. only for a subtitle track that only contains the English translation whenever a foreign language character is talking.

"Forced" has nothing to do with "default track". If "forced" is set the player must play that track no matter what "default track" is set to. In fact normally a track that has "forced" set does not have "default track" set, though it is neither invalid nor undefined behavior.

Uses

remove a subtitle track from a Matroska .avi file

note: It is recommended that you disable "header removal compression."

Run mmg.exe which is a GUI front end for the tools. open your mkv with it. uncheck whatever you don't want and then give it an output folder and name. click merge.

source: aedipuss on videohelp.com

see also below: mkvextract

crop off part of the matroska video (edit/split)

You can split a large MKV file in to multiple parts and in a user specified size. This is easy to do and explained well in a guide on TechFleece. Ref: How To Split MKV files using MKVToolnix

In this specific example, we want to remove the first few seconds of a matroska video (the first 27 seconds of the video and audio). Our particular video is 1:38:24 long. The individual distributing the video, a movie, decided to add his own custom logo sequence at the beginning (he goes by the handle TiCTaC). Cute as it may be, the logo sequence, which features his handle orbiting the earth to the tune of the Un1versal studio theme, causes the entire mkv movie to fail to play properly in VideoLAN Player and Windows Media Player. His logo sequence is encoded differently than the rest of the video stream. Many (most) video players get confused and therefore do not render any video after the initial custom logo sequence (video goes black at 27 seconds when the actual movie starts.) In short, TiCTaC breaks the video by prepending his logo sequence. We fix the video by cutting out the first 27 seconds, getting rid of the TiCTaC logo sequence incompatibility, thus allowing VideoLAN (VLC) and other players to play the entire video correctly. We also remove unneeded global tags. Follow these steps.

  1. Load and run 'mmg.exe'
  2. On the INPUT tab click 'add' and choose the mkv video file.
  3. Under 'Tracks, chapters and tags:' uncheck the checkbox in front of the global tags.
  4. Click on the GLOBAL tab
  5. In the 'Splitting' section check 'Enable splitting...'
  6. Click the '...after this duration:' radio button and enter '00:00:27'
  7. For 'max. number of files:' enter '2'. (This is a VERY important step!)
  8. Choose an 'Output file name' on the bottom of the interface and click 'Start muxing.'

By choosing 'max. number of files:' you prevent mkvmerge from creating thousands of tiny 27 second video files. We are basically splitting the video into 2 unequal sized files, the first being the 27 second logo sequence we can later discard, and the entire rest of the movie.

If you ever come into possession of a video or movie that will not play after the first few seconds, and has a custom logo sequence, you will likely resolve the problem by elimination of that first part of the video file.

combine mp4 and srt into mkv container

  1. open mkvmerge
  2. input, add, select the mp4 file
  3. input, add, select the srt file
  4. Tracks, chapters, and tags, look to make sure everything you want is checked (audio, video, subtitles)
  5. General Track Options, set the Default track flag, and Forced track flag for the streams. For forced subtitles see below
  6. Start Muxing

Forced Subtitles

  1. under Tracks, chapters, and tags make sure to highlight the subtitles track for the forced subtitles
  2. Set Default track flag to YES
  3. Set Forced track flag to YES

Technically, the Default track flag would not necessarily have to be set to YES, but can be. This is explained best in the section about subtitles (Mkvtoolnix#subtitles).

support

header removal compression bug

Starting with v4.1.0 Mosu, the developer of mkvtoolnix, implemented “header removal compression”. Several hardware/software players don’t support header compression in mkvs. The benefit from header compression is minimal at best, it is best not to use header compression at all for compatibility purposes.

source: MKV Mania: Header Compression And The Side Effects by Damian

Version 5.8.0 allows you to set a default -
Run mmg.exe and open file options and put a check in disable header removal compression. Close mmg and then restart.

Version 6.0.0 you will have to set it manually each time -

  • load video, highlight video stream
  • click extra options tab
  • change "compression" to none

track cue (index) entries

In mkvmerge GUI v6.0.0 look under the tab "Extra options" and the Cues drop down. The option is also set via command line parameter. The option applies individually for each track.

--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 forward references ( = I frames in video tracks) are put into the cue sheet. 
'all' causes mkvmerge(1) to create cue entries for all blocks which will make the 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 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. 

Remux with mkvmerge sometimes results in out that VideoLAN Player has problems playing back, namely, when the user clicks forward in the video. changing the cues sometimes resolves.

remux after added subtitles vlc hangs on scan

"I added subtitles to some mkv files using MKVMerge, however now when I scan through the files with VLC, it takes 15 seconds before it starts playing again. I can skip to any part of the original mkv files and VLC plays without any lag." source

You can add this parameters :

--clusters-in-meta-seek --engage no_cue_duration --engage no_cue_relative_position

It will fix the problem of seeking after remuxing. This is a bug in mkvtoolnix / mkvmerge.

Now, how you do this :
In the menu bar go to Muxing->add command line option

In the new window jsut past in the bottom field (command line options) :

--clusters-in-meta-seek --engage no_cue_duration --engage no_cue_relative_position

Remux and you are done.

Note that those options need to be pasted EACH time you open MKVToolNIX : they are not persistent.

But before doing so, if you don't want to remux, there is a workaround in VLC. I just quote a passage of the page i linked to you at the begining of the post:

Turning on "Dummy elements" fixes this immediately; now seeking works as it has before. You can do that in VLC here ​: Tools -> Preferences -> "Show settings: all" at the bottom left; In the tree on the left side: Input/Codecs -> Matroska; make sure "Dummy elements" is turned on.

credit to: Namoi of vcdhelp.com (Namoi should read "your is not a contraction" to benefit credibility)

Additional Related Tools

There are a number of related tools some to be installed individually.

(maybe a partial list)

  • mkvextract
  • mkvinfo
  • mkvmerge
  • mkvpropedit
  • mkvtoolnix-gui

There are additional GUI interface tools such as MKVExtractGUI which has too many dependency requirements unless you don't mind.

Example 1: mkvextract - To extract subtitles from the mkv. You can use mkvinfo to output all tracks to console however I recommend using mkvtoolnix as a visual reference. Tracks count starts at zero. In this example two subtitle tracks will be extracted.

mkvextract tracks movie.mkv 2:subtitles0.srt
mkvextract tracks movie.mkv 3:subtitles1.srt