Force the garbage collector to run after decoding the audio with PyAV (#448)

This commit is contained in:
Guillaume Klein
2023-09-01 15:25:13 +02:00
committed by GitHub
parent e87fbf8a49
commit 5871858a5f

View File

@@ -6,6 +6,7 @@ system dependencies. FFmpeg does not need to be installed on the system.
However, the API is quite low-level so we need to manipulate audio frames directly.
"""
import gc
import io
import itertools
@@ -53,6 +54,11 @@ def decode_audio(
dtype = array.dtype
raw_buffer.write(array)
# It appears that some objects related to the resampler are not freed
# unless the garbage collector is manually run.
del resampler
gc.collect()
audio = np.frombuffer(raw_buffer.getbuffer(), dtype=dtype)
# Convert s16 back to f32.