Ever rip a Blu-ray and find that the resulting Matroska defaults to the Russian language audio track? You might want to remove the audio track and the corresponding subtitle tracks. The easiest way I’ve found to do this is to remux the Matroska using the
$ pkg install mkvtoolnix
This installs a nice toolchain to work with Matroska files. We’re gonna start out by using
mkvinfo. It prints information about the Matroska files we want to do surgery on.
$ mkvinfo input.mkv
You’re gonna get a bunch of output. Let’s take a closer look at Tracks. It’s a list of tracks that can look something like:
| + Track
The relevant fields for us is
Name. A lot of times you won’t have the language and in that case you’d have to go by name to find the track number you want to omitt or include. We’ll get to that in a bit but first let’s look at a subtitle track.
| + Track
Very similar and the relevant fields are the same.
So how do we remove audio or subtitle tracks from out Matroska? This can be approached in two different ways. Either you specify what tracks you want to include in your new file or you specify what tracks you want to exclude. This can also be done in different ways. Let’s look at the most basic example.
Now, perhaps the default audio track is in Spanish but you only speak English so you want to nuke everything Spanish about this file instead of fiddling with default track flags.
Since we have
Language on both out Spanish tracks we can just exclude them by muxing with the
$ mkvmerge -o output.mkv -a '!spa' -s '!spa' input.mkv
In this case
-o means output,
-a means audio tracks,
'!spa' means exclude tracks with language code
-s means subtitle tracks.
This is a good option if there are audio or subtitle tracks of several languages that you want to keep and you only want to nuke Spanish.
Similarly, if we only want the English tracks we can just include them in particular:
$ mkvmerge -o output.mkv -a 'eng' -s 'eng' input.mkv
This will remove any other tracks.
As I said before, you might not have the language code specified in the track. Say it instead looks like this.
By assumption we got automatically enabled Chinese subtitles. Say we want to get rid of the track completely. This is where the track number comes in handy, as hinted by
(track ID for mkvmerge & mkvextract: 1). Remember to use the number within the parentheses which is going to be one less than the track number.
$ mkvmerge -o output.mkv -s 2 input.mkv
This is going to mux a new Matroska with only subtitle with track number 3 from the input. Since we’re using the
-s flag we’re not touching the audio tracks. If you want to specify multiple tracks you can comma separate them like
An added bonus is that you save space from remuxing away undesired tracks.