Log in

View Full Version : Overlay and ApplyRange with recursion


damichi
20th January 2008, 23:39
Hallo.

I try to move an image overlay over a clip.
The image should move every frame, based on different coordinates, which are stored in an array.
I tried to use a recursive function to apply the overlay on every single frame, but there's no overlay in the output video.
When I write 6 ApplyRange statements instead of the recursive function call, the overlay is visible.
Could anyone please help me and tell me, why it doesn't work?

LoadLibrary("avslib", CONFIG_AVSLIB_ARRAYS)
global XKoordinaten = ArrayCreate(100, 200, 300, 400, 500, 600)
global YKoordinaten = ArrayCreate(150, 150, 150, 150, 150, 150)
global myVideo = AviSource("D:\vid\myVideo.avi")
global myOverlayImage = ImageSource("D:\vid\myOverlayImage.bmp")

function myOverlay(clip myVideo, clip myOverlayImage, int z)
{
Overlay(myVideo, myOverlayImage, x=ArrayGet(XKoordinaten, z), y=ArrayGet(YKoordinaten, z), opacity=0.5)
}

function doTheJob(int d)
{
myVideo
ApplyRange(last, d, d, "myOverlay", myOverlayImage, d)
(d < 5) ? doTheJob((d+1)) : ApplyRange(last, d, d, "myOverlay", myOverlayImage, (d-1))
}

doTheJob(0)


Thanks in advance.
damichi

stickboy
21st January 2008, 09:55
I haven't looked at your code, but it sounds like you really just want to use Animate in conjunction with Overlay, which should be a lot simpler.

sh0dan
21st January 2008, 10:37
If you do not use Animate, but use the conditional variables and conditionalreader, it will be many times faster and use much less memory. The last example in the Overlay Documentation (http://avisynth.org/mediawiki/Overlay) does exactly that.