LiveZilla Live Chat Software

0429 091 360

Changing default audio on mkv files

I recently, er… acquired  🙂  two seasons of the Walking Dead (four and five). However it was only after I (cough) acquired them did I realize that they were all in French.

Major bummer. I didn’t want to “acquire” them again so I checked to see if there was anything I could do. As it happens there was.

I had installed on my PC a set of freeware tools called MKVToolNix (download it here). From this I was able to run the MKVMerge GUI tool. I dragged and dropped one of the MVK files I had “acquired” unto the tool and it then told me everything I needed to know about that file. Most importantly it told me this file had an English Secondary track.

Different audio tracks on mkv file

This tool can also remove the parts of the file and “remux” it into a new one. That was cool but I just wanted to change the default track. I also wanted to do this to about 36 files and I didn’t want to do it one at a time.

Fortunately there are command line tools with this program which I could then put through PowerShell to automate the whole lot. Here is a sample of the code I wrote.


So what does this do? Simple really.

The first part of the code sets some variables. The first sets the default directory that is housing the files I want to change (you can of course paramatise all this but for the sake of simplicity I will hard code them in).


$files = Get-ChildItem $directory -Filter "*.mkv" | Sort Name $files

This code loops through the folder and adds only the file name to the variable $files. I have then placed the $files variable on a separate line so that I could see it had got everything (this is optional).

The variable $mkvinputfile simply uses the directory path and concatenates the $ element from the for loop.

Now the tricky bit

& "C:\Program Files\MKVToolNix\mkvpropedit.exe" "$mkvinputfile" `-`-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`=0

Because we are calling on an executable you need the put the & symbol at the front. This tells Powershell this is not a commandlet but commandline executable. next we need to pass the switches with the variables. Because these switches use the hyphen (-) which is a special character in Powershell we need to use an escape character to tell Powershell to just read it as is. This is done using the carrat key () e.g. -`-edit

The next bit simply tells mkvpropedit.exe to to edit the track labled a1 and set the default flag to 0 (i.e. false) and then to set the track labled a2 to 1 (i.e. True). it also sets the default for the subtitles to false.


of course it would have been easier to “acquire” the correct language in the first place. 🙂

Facebooktwittergoogle_plusby feather
Facebookby feather