Set the English audio stream on output provided that it exists on video

Questions involving a Windows version of FFmpeg.
Post Reply
parsasaei
Posts: 4
Joined: Sat Nov 05, 2016 11:19 am

Set the English audio stream on output provided that it exists on video

Post by parsasaei » Tue May 16, 2017 11:07 am

How can I have the english audio stream on output file where it exists on video? and If not exists, set all streams on output.
Is there anyway for do that at one command? I'm using this code:

Code: Select all

 ffmpeg -i input.mkv -f mp4 -map m:language:eng? -map v -c:v copy -c:a copy output.mp4
In my code when english audio not exists, there aren't any audio tracks on output file, I want to set all audio tracks on output when can't find the audio with language which I choosed.
please help me.

PieCaptain
Posts: 7
Joined: Thu Oct 13, 2016 9:46 am

Re: Set the English audio stream on output provided that it exists on video

Post by PieCaptain » Sun Jun 25, 2017 12:15 pm

Not sure about in one command, but you could use mkvpropedit.exe (part of mkvtoolnix https://mkvtoolnix.download/) and Media Info (https://mediaarea.net/en/MediaInfo)

Something like this in powershell:

Code: Select all

$AudioCount = &mediainfo.exe --Language=raw --Full input.mkv --Inform="General;%AudioCount%"
for ($i=0; $i –le ($AudioCount -1); $i++){
                       $TrackLanguage = &FFprobe.exe -v error -select_streams a:$i -show_entries stream_tags=language -of default=nw=1:nk=1 input.mkv
                        IF($TrackLanguage -like "und" - OR $TrackLanguage -e ""){
                                                                &mkvpropedit.exe input.mkv --edit track:a$i --set language=en
                                                                             }
                                                             }

That uses Mediainfo to get the number of audiostreams
Then goes through each audiostream (from 0 to the number of streams less one - because they are numbered from 0)to get the language using FFProbe (faster than mediainfo) then if it's unknown or blank, sets it to English using mkvpropedit.

mkvpropedit is good as it can edit the tracks directly and doesn't need to re-encode to a new file

Hope that helps!

Paul

Post Reply