PDA

View Full Version : Subtitle() memory problem


violao
10th December 2004, 12:02
I'm trying to write some strings to a range of frames - subclips - and then concatenate all the subclips together using:

avisource("base_clip.avi")

function write_text(clip c)
{
# calculate some numbers
n1 = ...
n2 = ...
...
# format some strings for writing
s1 = "...."
...
# and then write
subtitle(c, string(n1)).subtitle(string(n2)).subtitle(s1)...
}

function make_clip(clip c, int n)
{
temp = (n > 0) ? make_clip(c, n-1) : write_text (c)
return temp + write_text (c)
}

make_clip(255)

Function make_clip concatenates 255 instances of "base_clip.avi", every instance having some (different) text written on them.
However, this is what I get while playing this script in Virtualdub after some frames are processed:

Avisynth read error:
Avisynth caught an access violation at 0x011ee2c,
attempting to read from 0x0031fa71

While the clip is still playing I notice that the memory consumption constantly rises (in Task Manager - w2k) and just about it hits the maximum Avisynth crashes. This happens on 2 different machines, both w2k sp3, one is Celeron 433, other AthlonXP 1900. I tried several most recent versions (2.5.5 and alpha 2.5.6 241104).

It appears that it isn't a recursion problem, but most certainly Subtitle() because when I comment the Subtitle() line and leave all other variables and calculations intact then the script plays without a problem and the memory consumption is stable. If I include just 1 subtitle() command in write_text function then memory consumtion start to rise and Avisynth eventually crashes.

Is this the problem/bug with Subtitle() or am I doing something wrong?

Thanks
Vioalo

EDIT: There must be definitely something wrong with subtitle() because when I replace subtitle() with a long chain of "ordinary" filters like converttorgb32(), invert(), converttoyuy2(), swapuv(), blur(), etc. memory consumption appears to remain constant. It rises at the start of frame serving and after reaching a certain level (few tenths of megabytes) remains more or less constant until the script stops playing. Only if I insert subtitle() in a chain, or any related filter (like showframenumber(), showsmpte()) I get either Access violation or Virtualdub immediately goes "Out of memory".

violao
13th December 2004, 10:11
OK, I found a workaround. When I moved Subtitle() filter from the recursion that creates-concatenates the clip to another recursive function everything works fine. Now the code looks like this:


avisource("base_clip.avi")
global no_of_frames = framecount()

function make_clip(clip c, int n)
{
temp = (n > 1) ? make_clip(c, n-1) : c
return temp + c
}

function write_clip(clip c, int n)
{
# calculate some numbers for writing
n1 = ...
n2 = ...
...
# calculate first and last frame for subtitling
firstframe = n * no_of_frames
lastframe = firstframe + no_of_frames

# and then recurse
temp = (n > 0) ? write_clip (c, n-1) :
\ subtitle(c, string(n1), x, y, firstframe, lastframe)...

subtitle(temp, string(n1), x, y, firstframe, lastframe)...
}

make_clip(254)
write_clip(254)