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
- The first part before the colon is the input ID. Since we only have one input, it's
- The second part is the ID of the input stream.
0 will probably be the video track, 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.
-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.