I want to overlay multiple images on my video at different times. I have user function defined as
function myFunction(clip c, int coordinateX, int from, int to) {
c = c.trim(0, from-1) + c.trim(from, to).Overlay(myImage, x=coordinateX, y=667, mask=myImageMask, opacity=1) + c.trim(to+1, 0)
return c
}
which essentially takes myImage
image and place it on specific part of the clip.
I call my function as
video = video.myFunction(320, 1, 187)
and I have bunch of those like this (I'm trying to make some sort of animation with multiple images)
video = video.myFunction(320, 1, 187)
video = video.myFunction(480, 1, 187)
video = video.myFunction(640, 1, 187)
video = video.myFunction(320, 187, 374)
video = video.myFunction(480, 187, 374)
video = video.myFunction(640, 187, 374)
video = video.myFunction(319, 374, 561)
and everything works fine if there is less than ~400 of those calls. If I exceed that limit, "Out of Memory" occurs (I'm using VirtualDub).
I suppose it's because AviSynth must process all the calls to figure out the output (although only ~3 of those 100s of calls are related to specific single frame). If I however remove video =
at the beginning of the line, I could have 10000 of those and there is no "Out of Memory" error but of course I don't have video out.
Is there a fix to this? Hundreds/thousands of image overlays at different times on the video clip?
Try to play with SetMemoryMax() function. But make sure that you have enough of free memory.
Also note if you are working in 32-bit environment, max memory volume will be 2 GB.
Try to convert the video and all images to YUY2 colorspace before overlaying with "ConvertToYUY2()", this might probably decrease the amount of reconversions on every call as explained here - http://avisynth.nl/index.php/Overlay#Repeated_overlays_on_RGB_base_clip That's assuming your video and images are in RGB. You can probably try to use also YV12 colorspace, maybe it will save even more memory. Note that it will cause slight quality decrease since color channels have reduced resolution in formats other than YV24 plus there are conversion errors too.
来源:https://stackoverflow.com/questions/18720919/avisynth-out-of-memory-error-100s-of-image-overlays