Log in

View Full Version : Avisynth getting slower and slower


sscheidegger
7th November 2012, 15:06
Hi all

I have the following problem: I programmed an OFX plug-in to use Avisynth scripts in NLEs with the OFX interface. I used the Avisynth MT 64bit version in order to get it to work with 64bit NLEs. This works very well with simple scripts. Unfortunately I encountered problems with a more complex script. When rendering, avisynth is getting slower and slower! While it starts rendering at about 10 - 15 fps, after half an hour it's down at about 1 fps. I was hoping that it wouldn't get even slower, but after two days it was down at about 1/60 fps!

I started from the following motion compensation script, which I can render with no problems:

OFXsource(0)

LoadPlugin("mvtools2.dll")
ConvertToYV12()

super = MSuper()
vectors = MAnalyse(super, isb = false, truemotion = true)
compensation = MFlow(super,vectors)

return ConvertToRGB32(compensation)


Then I changed the script and the problem started:

OFXsource(0)

LoadPlugin("mvtools2.dll")
ConvertToYV12()

super = MSuper()
vectors = MAnalyse(super, isb = false, truemotion = true)
vectorsb = MAnalyse(super, isb = true, truemotion = true)
compensation = MFlow(super,vectors)
compensationb = MFlow(super,vectorsb)
average = Overlay(compensation, compensationb, mode="blend", opacity=0.5)

return ConvertToRGB32(average)


If I replace OFXsource() by Avisource() and render with 64bit VirtualDub, I don't get any problems. But when I use it in my OFX plug-in, it gets slower and slower.

Anyone any idea what could be the reason for this issue?

Chirico
7th November 2012, 19:33
Have you checked its memory usage while running? Memory leaks, or just extreme memory usage, can lead to page thrashing which would significantly slow things down.

sscheidegger
8th November 2012, 14:12
I think memory usage problems are a good hint!

With 64bit VirtualDub, rendering of the problematic script uses 620 MB RAM (size of the VirtualDub process). When rendering in my NLE (Sony Vegas Pro 11), the size of the Vegas process grows up to 1500 MB RAM!

If I add SetMemoryMax(128) at the beginning of the script, VirtualDub needs only 227 MB RAM, Vegas 460 MB. But even with this configuration, VirtualDub renders fast, Vegas gets slower and slower!

Also interesting is the effect when I try to run the script on a 32bit machine: VirtualDub runs it again no problem. In Vegas the process keeps growing until it crashes at around 1400MB! SetMemoryMax(128) doesn't seem to have any effect there.

Before I tested with this script, I thought I had solved all the memory leaks (with help of this forum, see http://forum.doom9.org/archive/index.php/t-165883.html). But apparently there are still memory issues!

I don't understand why SetMemoryMax() doesn't work in my OFX plugin! Could it be that avisynth has problems with the cache, when it is run as part of another process, which uses a lot of memory itself?

Thanks a lot for more hints!

Warperus
16th November 2012, 14:23
I think it's not avisynth issue. Example of ofx plugin makes me believe you have to delete some objects you get from OFX environment.
For example, compare image requesting in OFX plugin example
BasicPlugin::setupAndProcess(ImageScalerBase &processor, const OFX::RenderArguments &args)
{
// get a dst image
std::auto_ptr<OFX::Image> dst(dstClip_->fetchImage(args.time));
OFX::BitDepthEnum dstBitDepth = dst->getPixelDepth();
OFX::PixelComponentEnum dstComponents = dst->getPixelComponents();

// fetch main input image
std::auto_ptr<OFX::Image> src(srcClip_->fetchImage(args.time));


and your own image requesting line:

PVideoFrame __stdcall SimpleSample::GetFrame(int n, IScriptEnvironment* env) {

double field = bpInstance->getTime()-floor(bpInstance->getTime()+0.2);
OFX::Image* src(bpInstance->getSrcClip()->fetchImage(((double)n)+field));

Auto_ptr deletes image in example, but your src is not deleted anywhere.

sscheidegger
20th November 2012, 14:02
Warperus, that's it, you found it! Now that you told me it seems so obvious!!!

I changed the line using an auto_ptr like in the example plug-in. Then I rendered some one hour footage with the complex avisynth script. Everything works like a charm!

Thank you very, very much for your help!

tin3tin
21st November 2012, 10:15
Wow, running OFX plug-ins in Avisynth. I would love to test it. Will you release a 32-bit version?

[After reading you post more carefully I realise that it's the other way around avisynth running as a OFX plugin. That sounds interesting too. :-)]