Removing subtitles:
mkvmerge -o output.mkv input.mkv -S # remove all subtitle tracks
mkvmerge -o output.mkv input.mkv -s 3,4 # remove tracks 3 and 4
mkvmerge -o output.mkv input.mkv -s '!3' # remove all subtitle tracks except 3
mkvmerge -i input.mkv # show track numbers
Adding subtitles:
mkvmerge -o output.mkv input.mkv subs.srt
mkvmerge -o output.mkv input.mkv --language 0:ger --track-name 0:German subs.srt
Extracting subtitles:
mkvextract tracks input.mkv 3:subs.srt
for f in *.mkv; do
sub=$(mkvmerge -i "$f" | awk '$4=="subtitles"{print;exit}')
[[ $sub ]] || continue
[[ $sub =~ S_TEXT/ASS ]] && ext=ass || ext=srt
track=$(awk -F '[ :]' '{print $3}' <<< "$sub")
mkvextract tracks "$f" "$track:${f%mkv}$ext"
done
mkvmerge and mkvextract can be installed with brew install mkvtoolnix
.
Note that the above commands for adding subtitles also set the subtitles as “enabled by default” when playing the file. (This flag can be confirmed using the MKVMerge GUI.) To avoid this, use
--default-track '0:0'
. – Mathias Bynens – 2016-05-05T20:45:25.360The
-s 3,4
now does the opposite, it preserves the tracks3
and4
.$ mkvmerge.exe --version
mkvmerge v43.0.0 ('The Quartermaster') 64-bit
– Det – 2020-02-20T15:47:41.830Actually looks like it's been that way all this time https://superuser.com/posts/98401/revisions . Would've been weird to break default functionality.
– Det – 2020-02-20T15:57:56.5802MKVMerge GUI is already available on Mac OS X, but nevertheless, it's a good how to for console fans. – Bora – 2013-06-18T23:35:58.757