Log in

View Full Version : reporting audio level in conditional environment


Mug Funky
22nd August 2013, 03:07
is there an undocumented (or documented, but not found by me) way to get the current frame's audio level? peak or rms or whichever...

i've written a horribly kludge that sort of works (it gives correct numbers for multiples of 6dB, but incorrect for multiples of 10, just due to the precision of the crap i'm doing to pull the number out).


function getlevel (clip c)
{
c.converttoyv12().converttomono()
audiodub(blankclip(last,width=256,height=1024),last).histogram(mode="audiolevels")
pointresize(64,last.height,90,0,2,0).vtoy()
global audio_peak=mt_lut(expr="x 127 > 0 255 ?").lanczosresize(8,256)
global audio_rms=mt_lut(expr="x 64 > 0 255 ?").lanczosresize(8,256)
scriptclip(c,""" subtitle(string( (audio_peak.averageluma-255)/255 * 96 )) """ )
}


background: i'm trying to write a function that lists possible chapter or layer break candidates in a text file. i have a black detection script that works already, but anywhere that has low motion and very low audio is a potential place as not all programmes dip to black between segments.

raffriff42
22nd August 2013, 04:50
>or documented, but not found by me
Waddyaknow, there is (your question piqued my curiosity, and searching around I stumbled on this solution) :D
http://wilbertdijkhof.com/ MinMaxAudio: Computes the root mean square, maximal or minimal value over all samples in all channels, or just over all samples in channel, and outputs the value (in decibels) as a string.
It's a conditional audio filter, so the computation is done framewise.
(discussion)
http://forum.doom9.org/showthread.php?t=127530 Syntax:
AudioMax(channel) # maximal volume in channel (framewise)
AudioMin(channel) # minimal volume in channel (framewise)
AudioRMS(channel) # root mean square volume in channel (framewise)
# channel = 0 means that the max/min/rms is taken over all samples in all channels (framewise)

return ScriptClip(C, """ Subtitle(LeftStr(String(C.AudioMax(1)), 5) ) """ )