0

Say you input has 2 english audio tracks, 7.1 and 2.0.

You want to copy the audio track of highest quality (number of channels) to audio.ext

If I use -map 0:m:language:eng it selects all english audio tracks where I thought by default it would only copy the highest channel audio track.

Example:

ffmpeg -i *mkv -map 0:m:language:eng -vn -acodec copy output.flac
1
  • What's your full command? – Gyan Jun 12 '19 at 10:51
2

A map option will select all streams matched by the specification. The 'best' stream is only selected in the absence of any map options.

So, you'll need a two-stage process to do this:

ffmpeg -i in.mkv -map 0:a:m:language:eng -vn -acodec copy -f nut - | ffmpeg -f nut -i - -c copy output.flac

The first ffmpeg process sends all English language audio streams to the 2nd ffmpeg process, which will select only the 'best' among the received streams for output.

If you want to keep metadata, and not worry about the codec of the input file, you can change your output to .mkv

5
  • That's the 'file format' set for the piped data. ffmpeg generally detects the format based on the extension of the output file. There's none specified by - so we have to set one. -f matroska would work as well but nut supports finer timestamps so I prefer that. – Gyan Jun 12 '19 at 12:15
  • nut is not really necessary here, just a habit for me. ffmpeg can't auto-supply extension. – Gyan Jun 12 '19 at 12:30
  • I've added this to your answer so is more relevant to others. Thanks so much! I'll cleanup old comments – Freedo Jun 13 '19 at 8:36
  • Trying to adapt this to subtitles doesn't work. Any idea why? -map 0:s:m:language:eng -vn -scodec copy -f nut - | ffmpeg -f nut -i - -c:s srt "${file%.mkv}".eng.srt – Freedo Dec 28 '19 at 6:43
  • Share full log. – Gyan Dec 28 '19 at 7:10

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.