Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using plex. Plex seems to ignore the default audio stream (on Roku) and instead just use the first audio stream. This is per my testing using mkvpropedit.

Since Plex does not currently support the changing of audio sources on clients outside of the LAN, I'd like to change a few of my files so the current second audio source is the first?

What's the best way to swap audio streams in an MKV on a Linux based system such as Ubuntu?

share|improve this question
up vote 6 down vote accepted

With FFmpeg, this should be rather simple. Make sure you download a static build from their download page and don't use the Ubuntu repository version, which is quite old.

Here's the command:

ffmpeg -i input.mkv -map 0:0 -map 0:2 -map 0:1 -c copy output.mkv

Here's what -map does:

  • The first part before the colon is the input ID. Since we only have one input, it's 0.
  • The second part is the ID of the input stream. 0 will probably be the video track, and 1 and 2 will be your audio tracks.
  • The order of the -map options determines the order of the streams in the output file.

This means we'll leave the video bitstream as the first stream, then take the second audio stream, and then the first—in essence, we're swapping the audio streams.

Using the -c copy option ensures that the bitstreams are copied and not re-encoded.

A few examples on how to use the -map option can be found on the FFmpeg wiki.

share|improve this answer
tested and worked. thanks! – user191723 Jan 22 '13 at 0:48

Just use mkvtool to avoid, repack, re-encode ... wasting time.

mkvpropedit -v movie.mkv -v --edit track:2 --set track-number=3 --edit track:3 --set track-number=2

this should be enough to swap stream.

share|improve this answer

You must log in to answer this question.

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