I need to detect the average volume of the left and right channels of an MP3, considered separately (e.g., to detect when one channel is louder than the other).
The ffmpeg volumedetect filter really, really wants to work on both channels at once. I thought maybe something like this would work, but it is still averaging the two of them, and producing the same output twice:
ffmpeg -hide_banner -i IN.mp3 -filter_complex 'channelsplit=channel_layout=stereo; [0:0:0]volumedetect; [0:0:1]volumedetect' -f null /dev/null
Any suggestions?
I can do it by writing a temporary file with each channel and then examining them again, but that's a lot slower because these are really big files. So I'd rather do it in one pass.
Like this?
kamloops$ sox ./babo21Jun.wav ./jnkout.wav stats [0/727]
Overall Left Right
DC offset -0.014594 -0.009413 -0.014594
Min level -0.655884 -0.655884 -0.343994
Max level 0.621765 0.621765 0.324219
Pk lev dB -3.66 -3.66 -9.27
RMS lev dB -24.55 -22.82 -27.46
RMS Pk dB -12.72 -12.72 -18.85
RMS Tr dB -45.61 -45.54 -45.61
Crest factor - 9.08 8.12
Flat factor 0.00 0.00 0.00
Pk count 2 2 2
Bit-depth 16/16 16/16 15/16
Num samples 1.32M
Length s 30.000
Scale max 1.000000
Window s 0.050
sox is like 10x slower than ffmpeg, so it's almost always the wrong answer.
Disclaimer: this is only based on reading the documentation as I can't check it against a live file right now. Given my previous experience with ffmpeg it might not do what I describe below at all.
It looks like there is another filter that will do what you need: astats. I can't get to the site right now but looking at it in the Google cache is promising. Unfortunately it doesn't have an option to do the whole file but you can set it to do stats on a 10 second chunk of the audio, then spit it out as metadata with auto reset of statistics every 10 seconds. Processing that output seems like a lot of work compared to just having volumedetect show you a value for each channel. But hey, at least you won't have to patch ffmpeg and compile it just for this feature.
Never mind - the window is the integration period.
It should just spit out stats for the audio file which you can digest as metadata. If it works as described that looks like it will get you what you need per channel.
Looks like that will work. Thanks!
Split to named pipes and analyze separately? Separate analysis processes would seem to be supported based on the "Works" part of this bug: https://trac.ffmpeg.org/ticket/1663
SoX (available in fink) can gather the stats for all channels in a single pass.
>time sox in.mp3 -n stats
Overall Left Right
DC offset -0.000000 -0.000000 -0.000000
Min level -0.700772 -0.700772 -0.609887
Max level 0.608675 0.608675 0.583612
Pk lev dB -3.09 -3.09 -4.30
RMS lev dB -30.26 -29.93 -30.60
RMS Pk dB -14.11 -14.11 -14.41
RMS Tr dB -147.93 -146.78 -147.93
Crest factor - 21.99 20.68
Flat factor 0.00 0.00 0.00
Pk count 2 2 2
Bit-depth 29/29 29/29 29/29
Num samples 284M
Length s 6450.260
Scale max 1.000000
Window s 0.050
real 1m27.562s
user 1m27.243s
sys 0m0.241s
Time gathered on a late 2012 Mac mini.
do your own homework, you bidet-humping cockstrangler
Wow. Somebody must have been called an idiot by jwz, in his own inimitable way, and gotten mad enough to keep registering bullshit aliases to yell at jwz.
Which is particularly funny, as jwz only calls out those idiots who've really earned it.
I think he's angry because he couldn't figure out how to buy tickets on DNA.
best answer
do your own homework, you bidet-humping cockstrangler
come again?
Do you really want him to put that up a 3rd time? ;)