Force the garbage collector to run after decoding the audio with PyAV (#448)
This commit is contained in:
@@ -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.
|
However, the API is quite low-level so we need to manipulate audio frames directly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import gc
|
||||||
import io
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
@@ -53,6 +54,11 @@ def decode_audio(
|
|||||||
dtype = array.dtype
|
dtype = array.dtype
|
||||||
raw_buffer.write(array)
|
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)
|
audio = np.frombuffer(raw_buffer.getbuffer(), dtype=dtype)
|
||||||
|
|
||||||
# Convert s16 back to f32.
|
# Convert s16 back to f32.
|
||||||
|
|||||||
Reference in New Issue
Block a user