Log in

View Full Version : turning off frame caching


njahnke
25th January 2007, 18:35
hi,

working with avisynth making very large (dimensions wise) clips and i need to turn off the caching feature that stores several adjacent frames in ram. what i mean by this is that when i open the clip in vdub etc, i get maybe 1 gb ram usage, which is fine, but then when i start to export the clip to image sequence i get rapidly increasing usage until i run out of ram and then get an access violation. the reason i think it's the caching that's to blame is that i can step forward one frame and it takes maybe ten seconds to draw, then step back and step forward again and it takes no time at all. any other way to (automatically!) save one frame at a time would be cool as well.

thanks.

Boulder
25th January 2007, 18:52
Use SetMemoryMax in your script? I don't know if it affects caching though.

njahnke
25th January 2007, 18:59
yeah, it doesn't seem to work. i've set it as low as 64 meg and memory usage seems to be the same regardless. the script is this kind of thing:

setmemorymax(64)

global fromend1=75
global fromend2=fromend1 + fromend1
global fromend3=fromend2 + fromend1
global fromend4=fromend3 + fromend1

makegrid("c:\zwei\AlienVsPredator_Predator_1952_HQ.avi",\
"c:\zwei\BatmanAndRobin_5623.avi",\
"c:\zwei\Doom_UV_e4m6_138.avi",\
"c:\zwei\HalfLife2_13657_HQ.avi")

function makegrid(clip1,clip2,clip3,clip4) {

avisource(clip1).bilinearresize(320,240).changefps(59.94)
a11=randtrim(fromend4)
a1=trim(a11,0,fromend1)
a2=trim(a11,fromend1,fromend2)
a3=trim(a11,fromend2,fromend3)
a4=trim(a11,fromend3,0)

avisource(clip2).bilinearresize(320,240).changefps(59.94)
a11=randtrim(fromend4)
b1=trim(a11,0,fromend1)
b2=trim(a11,fromend1,fromend2)
b3=trim(a11,fromend2,fromend3)
b4=trim(a11,fromend3,0)

avisource(clip3).bilinearresize(320,240).changefps(59.94)
a11=randtrim(fromend4)
c1=trim(a11,0,fromend1)
c2=trim(a11,fromend1,fromend2)
c3=trim(a11,fromend2,fromend3)
c4=trim(a11,fromend3,0)

avisource(clip4).bilinearresize(320,240).changefps(59.94)
a11=randtrim(fromend4)
d1=trim(a11,0,fromend1)
d2=trim(a11,fromend1,fromend2)
d3=trim(a11,fromend2,fromend3)
d4=trim(a11,fromend3,0)


blankclip(length=fromend1,fps=59.94,width=640,height=480)
animate(last,0,fromend1,"overlay", a1,0,0, a1,320,0 )
animate(last,0,fromend1,"overlay", b1,320,0, b1,320,240 )
animate(last,0,fromend1,"overlay", c1,320,240, c1,0,240 )
animate(last,0,fromend1,"overlay", d1,0,240, d1,0,0 )
w1=last

blankclip(length=fromend1,fps=59.94,width=640,height=480)
animate(last,0,fromend1,"overlay", d2,0,0, d2,320,0 )
animate(last,0,fromend1,"overlay", a2,320,0, a2,320,240 )
animate(last,0,fromend1,"overlay", b2,320,240, b2,0,240 )
animate(last,0,fromend1,"overlay", c2,0,240, c2,0,0 )
x1=last

blankclip(length=fromend1,fps=59.94,width=640,height=480)
animate(last,0,fromend1,"overlay", c3,0,0, c3,320,0 )
animate(last,0,fromend1,"overlay", d3,320,0, d3,320,240 )
animate(last,0,fromend1,"overlay", a3,320,240, a3,0,240 )
animate(last,0,fromend1,"overlay", b3,0,240, b3,0,0 )
y1=last

blankclip(length=fromend1,fps=59.94,width=640,height=480)
animate(last,0,fromend1,"overlay", b4,0,0, b4,320,0 )
animate(last,0,fromend1,"overlay", c4,320,0, c4,320,240 )
animate(last,0,fromend1,"overlay", d4,320,240, d4,0,240 )
animate(last,0,fromend1,"overlay", a4,0,240, a4,0,0 )
z1=last

w1++x1++y1++z1

function randtrim(last,fromend) {
firstone=rand(last.framecount-fromend,seed=true)
secondone=(firstone+fromend)
return last.trim(firstone,secondone)
}
}

foxyshadis
25th January 2007, 19:16
Sounds like you're running into the allocations of individual functions, and you'd be better off fixing up your script. I bet it's the animate() doing the sucking up, and I'll have to consider whether there's a more efficient way of doing what you're doing. For starters, you might need to do the four blocks in separate scripts.

njahnke
25th January 2007, 19:26
Sounds like you're running into the allocations of individual functions, and you'd be better off fixing up your script. I bet it's the animate() doing the sucking up, and I'll have to consider whether there's a more efficient way of doing what you're doing.

thanks for the reply. one thing i was thinking of was putting down one set of four clips per grid at a time, so saving that result, then opening that as the source for the next overlay. (edit: great minds think alike i suppose :P)

however i don't think that will solve the problem because even opening a much simpler script producing a final clip with such large dimensions will cause the "memory use escalates on export" problem. this is very frustrating because there is no problem with opening the script, just with saving it in an automated fashion (i could, if it weren't stupid, step through frame by frame saving each one as an image). therefore i think disabling the frame cache, which i believe is causing the memory usage, to be the best method of attack.

gzarkadas
25th January 2007, 21:58
...therefore i think disabling the frame cache, which i believe is causing the memory usage, to be the best method of attack.

The memory usage is caused by Animate + Overlay. See the explanation by IanB at the thread Photo scripting: crash @ 2GB (http://forum.doom9.org/showthread.php?t=101669). Disabling the frame cache will be no use (the memory will be allocated anyway).

Therefore, you must either break your script in many subscripts, or try to use a different approach: ScriptClip()

For the later you may find of use the thread Repeated use of function with global vars (http://forum.doom9.org/showthread.php?t=104090)