ajp_anton
14th January 2011, 07:20
This is my script for syncing audio from captures. You give it multiple sync points in a string:
lda("0,.1,1000,.5,5000,-1.2")
and it will delay the audio at frames 0, 1000 and 5000 by .1, .5 and -1.2 seconds.
##lda = linear delayaudio
function lda(clip v,string pd){v
## find the 4 first values (2 points, 2 delays)
c1=findstr(pd,",")
c2=findstr(midstr(pd,c1+1),",")+c1
c3=findstr(midstr(pd,c2+1),",")+c2
c4=findstr(midstr(pd,c3+1),",")+c3
c4=(c4==c3?strlen(pd)+1:c4)
## extract those 4 values
p1=int(value(leftstr(pd,c1-1)))
d1=value(midstr(pd,c1+1,c2-c1-1))
p2=int(value(midstr(pd,c2+1,c3-c2-1)))
d2=value(midstr(pd,c3+1,c4-c3-1))
## sync the whole clip according to those points
timestretch(rate=100-100.0*framerate*(d2-d1)/(p2-p1))
delayaudio((d1*p2-d2*p1)/(p2-p1))
## trim only the relevant section. If more points, call the function again.
c4-1==strlen(pd)?trim(p1,0):trim(p1,p2-1)+lda(v,midstr(pd,c2+1))
}
Now, I'd like to add some info text that tells me the stretch and delay for each frame, to more easily add more sync points.
The stretch part is easy, since it's constant in each segment:
subtitle(string(100-100.0*framerate*(d2-d1)/(p2-p1)))
But how to display the delay?
I can only think of calculating it in scriptclip:
scriptclip("""subtitle(string(d1+(d2-d1)*(current_frame-p1)/(p2-p1)))""")
But it doesn't recognize the variables p1,p2,d1,d2. Making them global doesn't help because scriptclip will only use them from the last time the function calls itself.
lda("0,.1,1000,.5,5000,-1.2")
and it will delay the audio at frames 0, 1000 and 5000 by .1, .5 and -1.2 seconds.
##lda = linear delayaudio
function lda(clip v,string pd){v
## find the 4 first values (2 points, 2 delays)
c1=findstr(pd,",")
c2=findstr(midstr(pd,c1+1),",")+c1
c3=findstr(midstr(pd,c2+1),",")+c2
c4=findstr(midstr(pd,c3+1),",")+c3
c4=(c4==c3?strlen(pd)+1:c4)
## extract those 4 values
p1=int(value(leftstr(pd,c1-1)))
d1=value(midstr(pd,c1+1,c2-c1-1))
p2=int(value(midstr(pd,c2+1,c3-c2-1)))
d2=value(midstr(pd,c3+1,c4-c3-1))
## sync the whole clip according to those points
timestretch(rate=100-100.0*framerate*(d2-d1)/(p2-p1))
delayaudio((d1*p2-d2*p1)/(p2-p1))
## trim only the relevant section. If more points, call the function again.
c4-1==strlen(pd)?trim(p1,0):trim(p1,p2-1)+lda(v,midstr(pd,c2+1))
}
Now, I'd like to add some info text that tells me the stretch and delay for each frame, to more easily add more sync points.
The stretch part is easy, since it's constant in each segment:
subtitle(string(100-100.0*framerate*(d2-d1)/(p2-p1)))
But how to display the delay?
I can only think of calculating it in scriptclip:
scriptclip("""subtitle(string(d1+(d2-d1)*(current_frame-p1)/(p2-p1)))""")
But it doesn't recognize the variables p1,p2,d1,d2. Making them global doesn't help because scriptclip will only use them from the last time the function calls itself.