View Single Post
Old 20th March 2014, 08:43   #4  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,373
@poisondeathray, good idea, but I have some refinements: variable transparency and a little decay time to cut down on flickering.
Code:
LoadPlugin("MinMaxAudio\Release\MinMaxAudio.dll")

A1=WavSource("a1.wav") ## uncompressed audio is a lot faster due to runtime analysis!
A2=WavSource("a2.wav")
#A3=...

AviSource("v.avi")

debug=true ## set to true for adjusting the mask windows

overlay_1 = Subtitle("VOICE ONE", x=24, y=32, size=56)
AudioLevelOverlay(A1, overlay_1, 
\  16, 26, 512, 80, showmask=debug)

overlay_2 = Subtitle("VOICE TWO", x=Width-524, y=32, size=56)
AudioLevelOverlay(A2, overlay_2, 
\  Width-532, 26, 512, 80, showmask=debug)

#overlay_3 = ...

#AudioDub(final_audio_mix)
return Last

##################################
### show overlay clip only when there is audio
### http://forum.doom9.org/showthread.php?p=1674312#post1674312
##
## @ C - base clip
## @ A - audio 
## @ O - overlay 
## @ x, y, wid, hgt - position & size of mask window
## @ boost - overall level boost (fudge factor) (default 18)
## @ gate - ignore audio under (-gate+boost) dB; (default 20)
##   NOTE "boost" and "gate" are shared among all instances of
##   this function (thanks Gavino). 
##   * if the overlay does not get fully opaque, increase boost;
##   * if the overlay shows up when it shouldn't, increase gate.
##   For example, I used boost=24, gate=12 on a muddy source.
## @ showmask - for setting window size & position
##
function AudioLevelOverlay(clip C, clip A, clip O, 
\            int x, int y, int wid, int hgt,
\            int "boost", int "gate", bool "showmask", string "mode")
{
    Assert(O.Width==C.Width && O.Height==C.Height, 
    \  "AudioLevelOverlay: overlay must be same size as base clip")
    global boost = Min(Max( 0, Default(boost, 18)), 24)
    global gate  = Min(Max(0, Default(gate,  20)), 60)
    showmask = Default(showmask, false)
    mode = Default(mode, "blend")

    AudioDub(C, A.AmplifyDB(-6).AudioEcho.Normalize(1))

    S = ScriptClip(Last.Crop(0, 0, wid, hgt), """
        x = Min(Max(0, Round(AudioRMS(0))+gate+boost), 255)*255/gate 
        return Last.BlankClip(color=to_rgb(x))""")
    M = Overlay(C.BlankClip, S, x=x, y=y).ConvertToY8

    return (showmask) 
    \ ? C.Overlay(M, opacity=0.5, mode="add")
    \ : C.Overlay(O, mask=M, mode=mode)
}

function AudioEcho(clip A, float "delay", float "mix") {
    delay = Min(Max(0.01, Float(Default(delay, 0.33))), 5.0)
    mix = Min(Max(0.0, Float(Default(mix, 0.33))), 1.0)
    return A.MixAudio(A.AudioTrim(0, delay)+A, (1.0-mix), mix)
}

function to_rgb(int r, int "g", int "b") {
    r = Min(Max(0, r), 255) ## thanks Gavino
    g = Min(Max(0, Default(g, r)), 255)
    b = Min(Max(0, Default(b, r)), 255)
    return (r*65536) + (g*256) + b 
}

Last edited by raffriff42; 22nd March 2014 at 05:11. Reason: changes in blue
raffriff42 is offline   Reply With Quote