Log in

View Full Version : release of used frames


vcmohan
27th April 2006, 03:05
I tried search but could not find. If in a plugin I use a large number of frames initially and calculate statistics or such other frame dependant parameters, then do some work on them together, now as I understand one needs to call GetFrame method repeatedly. For example if whole clip is required to be preprocessed, then GetFrame gets invoked a huge number of times. The memory available will not be enough to hold these. Since after getting the statistic, the frame is not required it can be relinquished. I do not find any call that enables me to release a frame so that I can use that memory again and again. Is there a way already built in ? Or is it possible to supply a pointer to Avisynth and ask it to get frame with that as read pointer? Then I can allot memory and delete as I want.

IanB
27th April 2006, 04:33
PVideoFrame is a smart pointer when you assign a new frame to it the old one gets released. Thusfor (int i=0; i < vi.num_frames; i++) {
PVideoFrame P = child->GetFrame(i, env);
// do some calcs on P ...
}is perfectly okay, apart from trashing the cache.

vcmohan
28th April 2006, 03:15
Thanks for the information

MeteorRain
29th April 2006, 02:06
if you need a whole clip process, how about do 2-pass? that 1st pass write to a temp file, and 2nd pass do real function?

foxyshadis
29th April 2006, 05:32
There's a few filters that do it.

Method one, decombvfr: do the entire first pass the first time you load it, before you show the first frame. (slooooooow, but simple.) A variation on the theme is to put the first pass in a new thread so you can still return frames while the first thread is going, but part of the reason for the first pass is to get the exact final # of frames.

Method two, tivtc: use a pass=1 or 2 argument, where on pass=1 it writes the file but does no processing, and pass=2 it reads matrics from it and processes accordingly.

Fizick
27th October 2008, 17:37
Well, I have a similar question.

If in some filter's (MVTools2) GetFrame function I request some PVideoFrame src=child->Getframe(n), get its data, make some first stage of processing, and do not need in this frame anymore in second stage of processing, can I release this frame explicily by src=0 command?
Will it free some memory usefull for cache, other frames (filters?), creating new videoframes, etc?
(Are single-theading and multitreaded versions differs?)

IanB
28th October 2008, 23:30
Releasing PVideoFrames does not free any memory. The frame in question has it's use count-=1 and if ==0 will be on the LRU chain and the memory available for reuse as another PVideoFrame later.

In filters that handle many PVideoFrames concurrently within the one GetFrame call it can be useful to process the frames serially, using and releasing each before getting the next. All the active PVideoFrames concurrently in use must physically exist, i.e. if you have 10 PVideoFrames in scope concurrently then there must be 10 matching VBF's in existance. If you use and release 10 PVideoFrames serially in sequence then they could all end up using the same VBF, if memory was tight or SetMemoryMax is set very low.

Fizick
29th October 2008, 05:51
But it is quite legal for example to use this:?

PVideoFrame src=child->Getframe(n);
... //some processing with src to filter internal buffer
src=0
dst=NewVideoFrame(vi)
...

IanB
29th October 2008, 09:20
Yes, it make it possible for the VFB used by src to be reused for dst. This is of course a degenerate case when memory is very tight.