Log in

View Full Version : Some guidelines on Vapoursynth memory management


Cary Knoop
11th August 2020, 18:44
I just finished a very large script with VideoNodes being put into lists. Even running this with a single list entry the script runs about 60GB. Now, I have plenty of memory and the script runs fine but I suspect nodes are deep copied on certain operations.

VideoNodes are never assigned to new variables however they are returned by functions and added to lists using the append() function.

Any recommendations handling clips in lists and clips being returned from functions and other general considerations?

_Al_
11th August 2020, 19:21
I do not know Python to the last bit as others but something:
using ModifyFrame, FrameEval as much as possible,
clips you need locally and it is a tool, just use in a function, then it should be garbage collected,
like clips that are needed to assemble other clips and if not in function, then deleting them,
making clips only if they are needed using generator, so yield could be used in functions instead of return (but I never actually tried this),inspiration from here (https://towardsdatascience.com/reduce-memory-usage-and-make-your-python-code-faster-using-generators-bd79dbfeb4c?gi=b7bde53a29c3),
so quick attempt:

def make_clip(colors):
index = 0
while index<3:
yield core.std.BlankClip(format=vs.RGB24, color=colors[index])
index +=1
clips = make_clip([(255,0,0), (0,255,0), (0,0,255)])
clip1 = next(clips)
#do something else
del clip1
clip2 = next(clips)
#do something else
clip3 = next(clips)
#do something else
del clip3

Myrsloik
11th August 2020, 19:28
What _Al_ said. You can also try the audio test builds since they have a more aggressive cache clearing strategy which most likely will improve things.

If you post the script or at least the general idea we can suggest better strategies.