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):
|
def process_video(path, *, maxsize, quality):
|
||||||
frame = None
|
frame = None
|
||||||
imgdata = io.BytesIO()
|
imgdata = io.BytesIO()
|
||||||
|
istream = ostream = icontainer = ocontainer = icc = occ = frame = None
|
||||||
with (
|
with (
|
||||||
av.open(str(path)) as container,
|
av.open(str(path)) as icontainer,
|
||||||
av.open(imgdata, "w", format="avif") as ocontainer,
|
av.open(imgdata, "w", format="avif") as ocontainer,
|
||||||
):
|
):
|
||||||
istream = container.streams.video[0]
|
istream = icontainer.streams.video[0]
|
||||||
istream.codec_context.skip_frame = "NONKEY"
|
istream.codec_context.skip_frame = "NONKEY"
|
||||||
container.seek((container.duration or 0) // 8)
|
icontainer.seek((icontainer.duration or 0) // 8)
|
||||||
for frame in container.decode(istream):
|
for frame in icontainer.decode(istream):
|
||||||
if frame.dts is not None:
|
if frame.dts is not None:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -136,6 +137,6 @@ def process_video(path, *, maxsize, quality):
|
|||||||
ocontainer.mux(ostream.encode(None)) # Flush the stream
|
ocontainer.mux(ostream.encode(None)) # Flush the stream
|
||||||
|
|
||||||
ret = imgdata.getvalue()
|
ret = imgdata.getvalue()
|
||||||
del imgdata
|
del imgdata, istream, ostream, icc, occ, frame
|
||||||
gc.collect()
|
gc.collect()
|
||||||
return ret
|
return ret
|
||||||
|
Loading…
x
Reference in New Issue
Block a user