Try to leak less memory.
This commit is contained in:
parent
7d55a43119
commit
0de8b99c02
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user