5

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?

7
  • 2
    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.
    – Seth
    Commented May 24, 2019 at 7:35
  • It is about the order of the tracks, because the player app I am using always picks the first track.
    – Martin
    Commented May 26, 2019 at 12:42
  • 2
    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
    Commented Dec 14, 2020 at 15:45
  • 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.
    – hmj6jmh
    Commented Dec 14, 2020 at 15:47
  • @hmj6jmh I don't understand what you do with s1 and s3 but I think the general notion of setting an audio track (a1) as default should be an answer (and the right one).
    – bomben
    Commented Jun 17, 2022 at 18:47

7 Answers 7

8

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.

3
  • Thanks! It seems to me that with mkvpropedit actually the "stream order" IS changed, but the ID:s are NOT. The result is confusing, anyway.
    – Lorents
    Commented Jun 30, 2023 at 23:38
  • @Lorents That generally should not be the case, as the documentation states if you use the track:n option with mkvpropedit, it will use mkvmerge --identify under the hood, which returns the track IDs. Also just tested it with a random file using track:n and it still changes the ID without changing the StreamOrder. I'm curious how you managed to achieve this, but I don't think this is the place to discuss this further.
    – YTZ
    Commented Jul 1, 2023 at 15:34
  • Okay, my bad. There's some confusion in identifying streams/tracks when the "order" and "ID" don't match. For example mkvpropedit --add-track-statistics-tags writes the stream sizes to the wrong tracks.
    – Lorents
    Commented Jul 3, 2023 at 14:44
7

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

2
  • 1
    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 Commented Apr 21, 2021 at 21:41
  • This answer messes things up terribly. In VLC, the shown audio track order remains the same, but the titles become switched. This seems to have to do with "track ID":s, see YTZ:s answer.
    – Lorents
    Commented Jun 30, 2023 at 23:40
5

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.

3
  • Is there also a way to do it in bulk for all files of a folder?
    – Martin
    Commented May 26, 2019 at 12:42
  • 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
    – Nii
    Commented Dec 21, 2019 at 0:38
  • @niii Complaining about being user friendly when the software is FREE. Is a bit silly, wouldn't you say? Commented Dec 21, 2019 at 19:34
1

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
0

You cannot reorder tracks inside an mkv file without remerging the tracks into a new file. I have encountered exactly the same issue recently and found a solution. I created a batch file to reorder audio tracks that processes all mkv files in a chosen folder and outputs the new mkv files of the same name with reordered audio tracks into a new location. It uses mkvmerge.exe of MKVToolNix kit (latest version) for Windows. And, sure enough, remerging tracks takes some time compared to changing flags and properties using mkvproedit. Let me know if you are still interested.

0

I know I'm late, but I'd like to share a simple solution - Shutter Encoder, a GUI based on ffmpeg. It can batch rewrap and rearrange audio tracks at ease without reencoding. A drawback is it doesn't preserve subtitles well and ruins all fonts format in my ASS subtitles.

Hope it helps.

1
  • 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.
    – Community Bot
    Commented Feb 5, 2022 at 6:34
0

user1221013 it appears that you might have an answer to my dilemma below Can you share the script you mentioned? I have tried using CitrusPollo's mkv-batch-set-flag script, but it makes all tracks flagged as default.

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

But in my case, how can I remux moving audio/subtitle to track 1 and make it the default. If you see the pic, all are the default and I want Japanese Audio default/1 and English Default. Basically, I want Japanese audio with English subs to play automatically. The English audio/Signs subs second, and I can delete the other tracks for all I care. MKVtoolnix is great, but I have to do this to over 500 files so Batch is a must. mkv file info in MKVtoolnix

2
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 4, 2023 at 15:03
  • 1
    If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Commented May 4, 2023 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .