Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping streams by language in FFmpeg

I have lots of files with multiple audio and subtitle languages, however the track numbers aren't consistent (the English audio stream isn't always the first) so using a command such as:

ffmpeg -i "input.mkv" -map 0 -map -0:a:1 -c:v copy -c:a copy "output.mkv"

doesn't yield expected results. After searching around I discovered it was possible to map streams based on language with this command:

ffmpeg -i "input.mkv" -map 0 -map -0:m:language:eng -c:v copy -c:a copy "output.mkv"

However -map -0:m:language:eng will remove all tracks with the English language flag. To keep the subtitle tracks you can use -map 0:s this is a good solution however, I want to know if it's possible to only map audio streams based on language. I.e.,

I want to remove English audio while retaining all other streams without using stream IDs.

like image 688
ffmpeg123 Avatar asked Nov 28 '22 06:11

ffmpeg123


1 Answers

-0:m:language:eng will remove english audio tracks and keep all others.

to keep only english audio tracks and remove all others, remove the dash at the beginning: 0:m:language:eng the dash at the beginning creates a negative mapping, which tells ffmpeg "remove this and only things that match this"

i know this is 8 months later, but i thought it would be helpful for those who end up here off of google searches like i did.

like image 168
jeff Avatar answered Feb 11 '23 05:02

jeff