Change audio track order in MKV files

matroskavideovideo conversionvideo editing

I have a bunch of MKV files, that were all made the same way:

  • one video track
  • audio track 1 is english
  • audio track 2 is german

Now I want to change the audio track order, so that german is track 1 and english is track 2. How can I achieve this for all MKV files in a folder?

Best Answer

I found the solution and build the following script with mkvmerge from the mkvtoolnix package:

#!/bin/bash

for f in *.mkv
do 
    mkvpropedit -v "$f" --edit track:2 --set track-number=3 --edit track:3 --set track-number=2
done

This loops over all mkv files in the folder (assuming they were all built the same way and need to be edited the same way). Since the first track is normally the video track, it changes the second track to third (--edit track:2 --set track-number=3) and the third to second (--edit track:3 --set track-number=2).

Related Question