Open geextahslex opened 8 months ago
Hi,
I am no expert, and I don't have access to a Windows machine for the time being, I can not test a full bat script easily... But I will do my best. I don't think you can make ffmpeg tell whether you have a stereo or a 5.1 audio track, but you can ask ffprobe (which should be shipped alongside the ffmpeg executable) for the amount of audio channels in a track (which i think is 6 for a 5.1 versus 2 for stereo).
For example:
ffprobe -i "inputFile.ext" -show_entries stream=channels -select_streams a:0 -of compact=p=0:nk=1 -v 0
-i "inputFile.ext"
: input file to query about-show_entries stream=channels
to tell which "entries" we want to query about the input file, here we use channels
-select_streams a:0
to indicate a specific track to query in the input file, here the first audio track.-of compact=p=0:nk=1
sets the output formatting to show only the query value. I.E. without it, you would get [STREAM]channels=2[/STREAM]
instead of just 2
for a stereo channel.-v 0
disables ffprobe's verbosity aside from fatal errors (so that you don't get the usual ton of informational text from ffprobe).I guess you could format your script like this:
for /f %%a in ('ffprobe -i %~1 -show_entries stream=channels -select_streams a:0 -of compact=p=0:nk=1 -v 0') do set channels=%%a
if %channels% LEQ 2 (
REM Run ffmpeg job for <= 2 channels
) else (
REM Run ffmpeg job for > 2 channels
)
Basically, store ffprobe's query in a variable. And run the appropriate ffmpeg command depending on whether ffprobe found a value <=2.
You might need to use trickeries to correctly parse the ffprobe command in the for loop. I can't test it now, but you can check the "alternative to escaping" part in this post answer.
Let me know how it goes.
Okay thank you. I think I would need something like
ffprobe -i %~1 -v error -select_streams a -of csv=p=0 -show_entries stream=channels,index:stream_tags=language
to check all audio tracks and language tags, to distinct between them
ffprobe -i spider.mkv -show_entries stream=channels,index:stream_tags=language -select_streams a -of compact=p=0:nk=1 -v 0
output of the first one:
1,6,ger
2,6,eng
output of the 2nd:
1|6|ger
2|6|eng
I don't know if this makes any difference
Hi I have a .bat file to convert and change channel volume (with ffmpeg) from 5.1 Audio to Stereo, and a different .bat for Stereo/Mono Audio that doesn't change loudness. Now I have to manually look if a movie is 5.1 or Mono/Stereo and decide which .bat to run. I would like to make one .bat with a condition so it looks what the channel layout is and then decide which profile to run. I hope this makes sense. It has to check also the language tag, because sometimes (in my case) german is 2.0 but English is 5.1 or vice versa.
Thank you for any advice
5.1
2.0/Mono
This is the whole .bat