3

I want to mux (combine) two files into one mkv file. The first one is an mkv file that contains a video and an audio stream in German. The second one is an English audio stream in dts format.I want one mkv file that contains both audio channels, the English one being the first and default audio stream.

Here's the ffmpeg command I'm using so far:

ffmpeg -i movie.mkv -i audio.dts -map 0:v:0 -map 1:a:0
-map 0:a:0 -c copy movie_combined.mkv

This produces acceptable results. I get an mkv file that has two audio channels, the first one English, the second one German. However, there's two problems. The second (German) audio stream is still the default stream (VLC media player uses it by default and according to MediaInfo, there's a default flag on the stream). Also, the English stream doesn't show up as English, according to MediaInfo there's no language information for that stream.

How do I flag the English audio stream as the default one? And how do I add the language information for that stream (so that, for example, it shows up as English in the audio track selection of VLC media player)?

  • For language, add -metadata:s:a:0 language=eng. FFmpeg doesn't set or alter track dispositions in MKV. Use mkvpropedit. – Gyan Oct 22 '16 at 16:20
  • @Mulvya Thanks, the metadata tag works. Can you explain what it does / how that parameter takes it's input? And do you know what command I need to use with mkvpropedit to set the default audio stream flag? Feel free to post that as an answer so I can accept it – MoritzLost Oct 22 '16 at 16:51
3

For language, add -metadata:s:a:0 language=eng.

FFmpeg doesn't set or alter track dispositions in MKV. Use mkvpropedit.

To set the default flag for the first audio track and remove it from the second one, use this command:

mkvpropedit movie.mkv --edit track:a1 --set flag-default=1 --edit track:a2 --set flag-default=0

As mentioned in the docs, the app "does not set the 'default track flag' of other tracks to '0' if it is set to '1' for a different track automatically." This is salient because FFmpeg sets default flags for all tracks to 1 unless the input has it different.

6

Based on this answer on stackoverflow, it seems that changing the disposition is now possible with ffmpeg (though it still seems to be not documented in the manpage).

I think that the command that you would need, so that the final file had English as the default audio stream is:

ffmpeg -i movie.mkv -i audio.dts -map 0:v:0 -map 1:a:0 -map 0:a:0 -c copy -disposition:a:0 default -disposition:a:1 none movie_combined.mkv

The addition is -disposition:a:0 default -disposition:a:1 none. The numbering of the streams is for the output.

In my testing, -disposition:a:1 none was necessary to remove the disposition from the second stream — it might not be required in some cases. (Note: the none option might be non-standard — I used it by analogy with the use of none in other situations in ffmpeg, but I haven't seen it documented in this context.)

To add metadata/language information, see the other answer.

  • Have you tested this? At the time of my answer, -disposition was added but didn't work with MKVs. – Gyan May 10 '17 at 5:10
  • Yes, I have tested this (using ffmpeg on Ubuntu 16.04) with MKVs and it did work. The changed disposition was recognised by both ffmpeg itself (ffmpeg -i previous_output_file.mkv) and a mediaplayer. – aplaice May 10 '17 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.