Change audio track order in MKV files

21,035

Solution 1

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).

Solution 2

This can be done with a program called MKVToolNix

MKV Example file with 3 audio streams loaded:

enter image description here

As you can see in this example. I have 3 audio streams. TrueHD, DTS-HD, and AC-3 This would be the same as your English, German Situation.

Simply drag the German Audio stream to the top as so. I'll be moving AC-3 To the top stream as my example.

enter image description here

But all this does is move AC-3 to the top of the audio order... BUT You'll notice TrueHD Atmos is still the default track to be played when the file starts.

In order to make AC-3 (or German in your situation) The default Audio stream, click on the German Track, and on the right side under properties Set Default Track flag as YES

enter image description here

After you're done with all that, press Start Multiplexing. This will create a brand new file with the new adjustments you've made. You can then discard the old file.

Solution 3

Please do NOT use mkvpropedit for ordering the tracks like in the accepted answer. This will NOT order them properly unlike mkvmerge.

If you inspect the video with a tool like MediaInfo, you can see that there's a StreamOrder and ID field.

enter image description here

From my experience (I've learned this the hard way), is that only the track ID will change if you use mkvpropedit. This does not change the StreamOrder, therefore MKVToolnix will also not recognize the tracks as being ordered.

Instead use mkvmerge where you can specify the --track-order, e.g.:

mkvmerge --output "your_file (1).mkv" "(" "your_file.mkv" ")" --track-order 0:0,0:2,0:1

Where 0:0 denotes the video track, 0:2 would then be the German track and 0:1 would be the English track.

Hope this helps future readers.

Solution 4

In Windows, this applies to all MKVs in a folder. It changes the order of tracks by remuxing, i.e. rebuilding the whole file in 1 minute. If necessary, specify the path to the MKV tools.

set path=
for %%A in (*.mkv) do %path%mkvmerge -o "%%~nA_.mkv" "%%A" --track-order 0:0,0:2

If your player can select the audio based on the flag default or forced, rewriting the index takes 1 second.

for %%A in (*.mkv) do %path%mkvpropedit "%%A" -e track:a2 -s flag-forced=1 -s flag-default=1
Share:
21,035

Related videos on Youtube

Martin
Author by

Martin

Updated on September 18, 2022

Comments

  • Martin
    Martin over 1 year

    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?

    • Seth
      Seth almost 5 years
      Do you actually want to change the order or is about which track is played by default on your machine? If you want to change the track order you need to remux those files.
    • Martin
      Martin almost 5 years
      It is about the order of the tracks, because the player app I am using always picks the first track.
    • hmj6jmh
      hmj6jmh over 3 years
      Are you sure it picks the first audio track, as given by mkvmerge --identify "file"? I use VLC Media Player, which automatically plays the 'default' track regardless of order. This can be determined with ffprobe "file" 2>&1 | grep Audio | tr -d '\-\-'. mkvpropedit, which comes with mkvtoolnix, can change the default track to the one I want to play, by modifying the audio track properties in place, without remuxing:mkvpropedit "file" --edit track:a1 --set flag-default=0 --edit track:a2 --set flag-default=1 --edit track:s1 --set flag-default=0 --edit track:s3 --set flag-default=1
    • hmj6jmh
      hmj6jmh over 3 years
      e.g., Stream #0:1(rus): Audio: eac3, 48000 Hz, 5.1(side), fltp, 640 kb/s (default) Stream #0:2(eng): Audio: eac3, 48000 Hz, 5.1(side), fltp, 640 kb/s to Stream #0:1(rus): Audio: eac3, 48000 Hz, 5.1(side), fltp, 640 kb/s Stream #0:2(eng): Audio: eac3, 48000 Hz, 5.1(side), fltp, 640 kb/s (default) This takes about a second on my old Mac.
  • Martin
    Martin almost 5 years
    Is there also a way to do it in bulk for all files of a folder?
  • Nii
    Nii over 4 years
    my only issue with MKVToolNix is that its not really user friendly. if you open multiple files in one tab, their combined info shows on the Tracks, Chapters, and Tags container below - even with just one highlighted item at a time. which is not how i expected it to work. nonetheless, the tool i useful for its purpose
  • Outdated Computer Tech
    Outdated Computer Tech over 4 years
    @niii Complaining about being user friendly when the software is FREE. Is a bit silly, wouldn't you say?
  • CasualDemon
    CasualDemon about 3 years
    I wanted to do similar but just make the second one the default. Also easy: mkvpropedit <input> --edit track:a1 --set flag-default=0 --edit track:a2 --set flag-default=1
  • Community
    Community about 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.