Log in

View Full Version : Avisynth and memory


pwolfamv
26th September 2007, 22:57
Ok, here's my problem. I wrote a few functions to help me on a project i'm working on. most of them are pretty small except for one. the problem happens when i have this function running on a lot of clips. Avisynth errors out and thats that. Basically, its running out of memory.

So, the question would be, is there a way to improve memory usage so that this isn't a problem (setmemorymax() wont help, so please don't suggest it, i've tested it already)? And, would writing an external filter be a better course of action or will i be plagued with the same issue?


Pwolf

Terranigma
27th September 2007, 00:48
Basically, its running out of memory.

Yes, get more memory.

--
btw, what are these functions that you're referring to? Whatever it is, it has to be really intense for you just to run out of memory. That, or you have something on the lines of 256 - 512mb of memory (which then you'll be limited to advanced scripting).

IanB
27th September 2007, 01:15
. . . . :script: . . . .

pwolfamv
27th September 2007, 07:22
. . . . :script: . . . .

hehe, was hoping i didn't have to do that, i'm very... self conscious, i guess, of my coding:


function PSetOp(clip c1, int start, int end)
{
return POP(c1,start,end,c1.framecount()).reverse().trim(1,0)
}

function POP(clip c1, int start, int end, int f)
{
frames = c1.framecount() - 1
end = end*1.0
start = start*1.0
f = f*1.0
temp = ((frames-1.0)*((end-start)/((f*1.0)-1.0)))+start
alpha = blankclip(c1,length=1,color=(RGBtoHEX(int(temp),int(temp),int(temp))))
return c1.trim(frames,-1).mask(alpha).subtitle(string(temp+(((end-start)/((f*1.0)-1.0))))) + ((frames > 1) ? POP(c1.trim(0,frames-1),int(start), int(end), int(f)) : c1.mask(alpha).subtitle(String(start)))
}
function RGBtoHEX(int red, int green, int blue)
{
return (65536 * red) + (256 * green) + blue
}


I'm sure there's an easier way to do this. Basically you give it starting and ending value that correspond to how much opacity you want to apply (0-255) and applies it along the entire clip... example would be 0 and 255. the resulting clip will fade in. starting at frame #1 with 0 and the last frame with 255.

the functions work (http://www.pwolfamv.com/videos/AVSRubberbandComp.avi), it's just that they use a lot of memory.

Pwolf

IanB
27th September 2007, 12:41
Ohhhhh! Yeah!!! Big on memory for sure.

Seems to be the week for recursion problems ;)

Animate, ConditionalFilter, FrameEvaluate, ScriptClip and ConditionalReader are the filters to do this sort of thing. Recursing thru frames singley is always going to be painfull.

A little background.

Avisynth compiles your script to build an audio/video processing graph. Recursion happens at compile time. So all the filters and buffers for the graph are ready before you even retrieve frame number 1.

Each BlankClip call allocates a static frame buffer, initialized to the correct shape, size and colour as required by the script. Normally a script allocates just a few and serves 1000's of frames from the single buffers, so this is not a problem.

Your recursive script will be allocating 1 static BlankClip buffer per frame, 720x480 RGB32 frames are 1.3 Mb each. About 1500 of these will fill the 2Gb address space of a windows process.

Filters like Animate allow you to defer this until runtime. Effectively creating 1 BlankClip for rendering the current frame then deleteing it afterwards, so the memory usage never mounts up.

Animate is good for changing filter values based linearly on frame number.

ConditionalReader with FrameEvaluate similarly allows changing filter values but now based on table lookup from a file.

Search this forum, there are 100's of examples of cunning and clever use of these filters.

pwolfamv
27th September 2007, 16:15
I did look at conditionalreader and it didn't seem like it would work for me cause i wanted to be able to just run the one script with no other files, but now that i think of it, it really doesn't matter, lol.

At the moment i'm working on an external filter, but i might give that a try anyway. Thanks for the help.


Pwolf

Terranigma
27th September 2007, 16:32
I did look at conditionalreader and it didn't seem like it would work for me cause i wanted to be able to just run the one script with no other files, but now that i think of it, it really doesn't matter, lol.


You can do this with conditional reader + conditional filter like IanB said. Search or read the conditional documents (conditional filter/Conditonal reader) in avisynth's directory for examples.

Leak
27th September 2007, 21:46
You can do this with conditional reader + conditional filter like IanB said.
He wanted just a single script, with no extra files. What's conditional reader supposed to read, then?

np: Mike Shannon - Miyako (Possible Conclusions To Stories That Never End)

Terranigma
27th September 2007, 22:16
He wanted just a single script, with no extra files. What's conditional reader supposed to read, then?

np: Mike Shannon - Miyako (Possible Conclusions To Stories That Never End)
But at the end, he said that it really doesn't matter. ;)

IanB
27th September 2007, 23:31
Given the script posted Animate is more than adaquate for the task.

temp is linearly dependant on frame number only.

Experiment with this scriptBlankClip(455)
Animate(100, 355, "Foo", 0, -1.0, 255, 1.0)

Function Foo(clip C, int I, float F) {
Return C.Subtitle(String(I)+" "+String(F))
}

pwolfamv
28th September 2007, 03:52
Given the script posted Animate is more than adaquate for the task.

temp is linearly dependant on frame number only.

Experiment with this scriptBlankClip(455)
Animate(100, 355, "Foo", 0, -1.0, 255, 1.0)

Function Foo(clip C, int I, float F) {
Return C.Subtitle(String(I)+" "+String(F))
}

i'll play around with that. I also just finished writing an external plugin, still needs to be test though, but it looks like its working.

I'll test both actually and see how things work. Thanks for the help.

Pwolf

pwolfamv
29th September 2007, 00:48
havn't tested animate yet but my plugin is working great. much better then expected actually. Unfortunately the project i needed it for isn't working the way it's supposed to anymore. I don't think it has anything to do with my plugin though.


Pwolf