From 0de8b99c025e3ac690b064eddd95bd018f3f1d3f Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Thu, 14 Aug 2025 15:41:15 -0700 Subject: [PATCH] Try to leak less memory. --- cista/preview.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cista/preview.py b/cista/preview.py index bc65f2a..d8de724 100644 --- a/cista/preview.py +++ b/cista/preview.py @@ -99,14 +99,15 @@ def process_pdf(path, *, maxsize, maxzoom, quality, page_number=0): def process_video(path, *, maxsize, quality): frame = None imgdata = io.BytesIO() + istream = ostream = icontainer = ocontainer = icc = occ = frame = None with ( - av.open(str(path)) as container, + av.open(str(path)) as icontainer, av.open(imgdata, "w", format="avif") as ocontainer, ): - istream = container.streams.video[0] + istream = icontainer.streams.video[0] istream.codec_context.skip_frame = "NONKEY" - container.seek((container.duration or 0) // 8) - for frame in container.decode(istream): + icontainer.seek((icontainer.duration or 0) // 8) + for frame in icontainer.decode(istream): if frame.dts is not None: break else: @@ -136,6 +137,6 @@ def process_video(path, *, maxsize, quality): ocontainer.mux(ostream.encode(None)) # Flush the stream ret = imgdata.getvalue() - del imgdata + del imgdata, istream, ostream, icc, occ, frame gc.collect() return ret