as an example: I have 2 MKV videos with 3 audio streams (English, French and Mandarin) 2 subtitle streams (English and Mandarin)

The streams can appear in any order. like on the first video, Mandarin is the first audio stream but on the 2nd it's using French. Same situation with subtitle.

what I want to auto-select the Mandarin audio and English subtitle without having to specify the stream number (like using -map perhaps?).

Is this possible? If yes, how?



This can't be done at present with a single command. However, there's a workaround with multiple commands.

ffmpeg -i in.mkv -map 0:m:language=chi? -c copy chi.mkv

ffmpeg -i in.mkv -map 0:m:language=eng? -map -0:v -c copy eng.mkv

ffmpeg -i in.mkv -i chi.mkv -i eng.mkv -map 0:v -map 1:a? -map 2:s? -c copy final.mkv

The first command extracts all Chinese language streams, if any, into a temporary MKV.

The second command extracts all English language streams, if any, except the video into a temporary MKV.

The final command maps the video from the original file, the audio from the Chinese-language temp file, and the subtitle from the English-language temp file.

  • I tried your 2nd command on the MKV I have on my laptop. This video has english subtitle as default (stream 0:2) and others. As a test, I decided to extract the Italian subtitles (0:6). If I use -map 0:m:language=ita?, no subtitles in the output video. If I use -map 0:s:language=ita? (also tried without the ?), I get English. If I use -map 0:6, I get the Italian subtitles. Any more ideas? Thanks a lot! edit: using ffmpeg 3.3.x – mrjayviper Nov 18 '17 at 0:30
  • Add -report. and run. Share the report. – Gyan Nov 18 '17 at 4:58

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.