12

Change Default Language/Subtitles in MKV Files

Posted (Updated ) in Linux

Tonight I discovered I had an entire folder of dual audio MKV files with the wrong default language and wrong default subtitle track. I could have used mkvpropedit to manually change each file but that’s such a hassle. Instead, here’s a handy one-liner to do them all at once:

1
find . -name "*.mkv" -exec mkvpropedit {} --edit track:a1 --set flag-default=0 --edit track:a2 --set flag-default=1 --edit track:s1 --set flag-default=0 --edit track:s2 --set flag-default=1 \;

 

Explanation

At first glance they may look a bit complicated, but let’s break it down a bit:

Find all .mkv files and execute an operation on them:

1
find . -name "*.mkv" -exec ... \;

Do an mkvpropedit on the current matched file:

1
mkvpropedit {}

Set the first audio track to not be default, the second audio track to be default, and do the same with the subtitle tracks:

1
2
3
4
--edit track:a1 --set flag-default=0
--edit track:a2 --set flag-default=1
--edit track:s1 --set flag-default=0
--edit track:s2 --set flag-default=1

 

You’ll need mkvtoolnix installed for the mkvpropedit command. To determine what the various tracks contain, do a

1
mkvinfo /path/to/file.mkv

or mkvinfo -g for you GUI users 🙂 This can be a bit tricky to read though so I tend to just open the file in VLC and look at the audio and video tracks that way.

As an added bonus, here’s the Windows equivalent of the above script:

1
2
3
4
5
6
7
8
9
@echo off
FOR /f "tokens=*" %%G IN ('dir /a-d /b') DO (
	mkvpropedit.exe "%%G" --edit track:2 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:3 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:4 --set flag-default=1
	mkvpropedit.exe "%%G" --edit track:5 --set flag-default=0
	echo.
)
pause

I’ve been told the Windows version works but haven’t tested personally.

Happy viewing!