From c3d6aecffd9d2231f310d0973ce293d5f2e99271 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Tue, 21 Nov 2023 04:00:20 -0800 Subject: [PATCH] Attempt to reduce leak of ffmpeg previews --- cista/preview.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cista/preview.py b/cista/preview.py index e456599..dbb2893 100644 --- a/cista/preview.py +++ b/cista/preview.py @@ -1,4 +1,5 @@ import asyncio +import gc import io import mimetypes import urllib.parse @@ -105,10 +106,13 @@ def process_video(path, *, maxsize, quality): container.seek(container.duration // 8) frame = next(container.decode(stream)) img = frame.to_image() + del frame, stream img.thumbnail((maxsize, maxsize)) imgdata = io.BytesIO() if rotation: img = img.rotate(rotation, expand=True) img.save(imgdata, format="webp", quality=quality, method=4) - return imgdata.getvalue() + ret = imgdata.getvalue() + gc.collect() + return ret