Log in

View Full Version : Animate() avs equivalents for vapoursynth ?


poisondeathray
5th March 2020, 17:54
Can someone give some Animate() examples for vapoursynth? Maybe something to do with core.std.FrameEval ?
http://www.vapoursynth.com/doc/functions/frameeval.html

e.g avisynth Animate overlay position (x,y) between frame range (t0,t1)


red = blankclip(color=color_red)
green = blankclip(width=320, height=240, color=color_lime)

Animate(0,120, "MoveOverlay",red,green,0,0, red,green,320,240)

function MoveOverlay(clip bg, clip fg, int x, int y)
{
Overlay(bg, fg, x, y)
}



How would I do something similar in vapoursynth ?

I'm guessing you have to define a wrapper function.

How would you structure it so ,the variables are easily changed/controllable? Such as over what frame range, x,y position

Also how would you change the "keyframe" interpolation from linear to something else ?


I think I'm having problems structuring the def, including control over the frame range


import havsfunc as haf
import functools

red = core.std.BlankClip(color=[255, 0, 0])
green = core.std.BlankClip(width=320, height=240, color=[0, 255, 0])

def MoveOverlay(red, green, x, y):
return haf.Overlay(red, green, x, y)

ani = core.std.FrameEval(red, functools.partial(MoveOverlay(red,green 320,240), clip=red))

ani.set_output()




Thanks

Myrsloik
5th March 2020, 22:18
import vapoursynth as vs
import havsfunc as haf
import functools

red = vs.core.std.BlankClip(color=[255, 0, 0])
green = vs.core.std.BlankClip(width=320, height=240, color=[0, 255, 0])

def MoveOverlay(n, red, green, fromx, tox, fromy, toy, startframe, endframe):
if n < startframe:
return haf.Overlay(red, green, fromx, fromy)
elif n > endframe:
return haf.Overlay(red, green, tox, toy)
else:
return haf.Overlay(red, green, round(fromx + (tox - fromx)/(endframe - startframe) * (n - startframe)), round(fromy + (toy - fromy)/(endframe - startframe) * (n - startframe)))

ani = vs.core.std.FrameEval(red, functools.partial(MoveOverlay, red=red,green=green, fromx=0, tox=320, fromy=0, toy=240, startframe=20, endframe=100))

ani.set_output()

Note that you can cache the before and after range clips to increase performance and avoid having to recreate them every frame. Simply insert your favorite interpolation function.

poisondeathray
5th March 2020, 22:53
Note that you can cache the before and after range clips to increase performance and avoid having to recreate them every frame.


How would I cache it ?

Is that referring to something like this ?
http://www.vapoursynth.com/doc/functions/cache.html
https://forum.doom9.org/showthread.php?p=1827484#post1827484


clip = clip.std.Cache(size = 100, fixed=False, make_linear=True)




Simply insert your favorite interpolation function.

How would I do that ?

eg. Common motion animation curves
ease in, ease out, accelerate, decelerate, logarithmic, exponential, etc...



Thanks for the example.

_Al_
6th March 2020, 02:03
I guess it is like simply creating that clip beforehand, that would cache it.
red = vs.core.std.BlankClip(color=[255, 0, 0])
green = vs.core.std.BlankClip(width=320, height=240, color=[0, 255, 0])
fromx=0
tox=320
fromy=0
toy=240
before = haf.Overlay(red, green, fromx, fromy)
after = haf.Overlay(red, green, tox, toy)

def MoveOverlay(n, red, green, fromx, tox, fromy, toy, startframe, endframe):
if n < startframe:
return before
elif n > endframe:
return after
else:
return haf.Overlay(red, green, round(fromx + (tox - fromx)/(endframe - startframe) * (n - startframe)), round(fromy + (toy - fromy)/(endframe - startframe) * (n - startframe)))

ani = vs.core.std.FrameEval(red, functools.partial(MoveOverlay, red=red,green=green, fromx=fromx, tox=tox, fromy=fromy, toy=toy, startframe=20, endframe=100))

ani.set_output()

Myrsloik
6th March 2020, 11:06
You're correct about the caching bit.

You see where the linear interpolation function is now. Simply write down similar ones for whatever motion you need. Use your favorite polynomials and so on.

Here's x^2 movement for some acceleration.
return haf.Overlay(red, green, round(fromx + (tox - fromx)/((endframe - startframe) ** 2) * ((n - startframe) ** 2)), round(fromy + (toy - fromy)/((endframe - startframe) ** 2) * ((n - startframe) ** 2)))