-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in if mp4 container not explicitely closed #1117
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
No stale |
hi @hmaarrfk Have you found any other solution besides explicitly closing containers and streams? This is my current code that encodes and decodes from the list of numpy array images ( with io.BytesIO() as buf:
with av.open(buf, "w", format=container_string) as container:
stream = container.add_stream(codec, rate=rate, options=options)
stream.height = imgs[0].shape[0]
stream.width = imgs[0].shape[1]
stream.pix_fmt = pixel_fmt
for img in imgs_padded:
frame = av.VideoFrame.from_ndarray(img, format="rgb24")
frame.pict_type = "NONE"
for packet in stream.encode(frame):
container.mux(packet)
# Flush stream
for packet in stream.encode():
container.mux(packet)
stream.close()
outputs = []
with av.open(buf, "r", format=container_string) as video:
for i, frame in enumerate(video.decode(video=0)):
if sequence_length <= i < sequence_length * 2:
outputs.append(frame.to_rgb().to_ndarray().astype(np.uint8))
if i >= sequence_length * 2:
break
video.streams.video[0].close() |
no, i just explicitly call close. |
Ok, thanks. I later found out the memory leak only occurs if I use the |
I can also reproduce this, without It seems to happen when I process the frames in a different process, and stream.close causes everything to hang if I use more than 1 processes. Multiple bugs bundled into one 😅 |
hi, @meakbiyik |
Hey @RoyaltyLJW, I still use |
@meakbiyik Thanks a lot. It fix my deadlock issue |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale |
I also experienced the same issue - when deployed in Docker, not closing the stream causes memory instability. @hmaarrfk you saved my life with this extremely niche bug report. |
Overview
I think there is a memory leak that occurs if you don't explicitly close a container or stream.
I'm still trying to drill the problem down, but I think I have a minimum reproducing example that I think is worthwhile to share at this stage.
It seems that
__dealloc__
isn't called as expected maybe??? https://github.com/PyAV-Org/PyAV/blob/main/av/container/input.pyx#L88Expected behavior
That the memory be cleared. If I add the
![image](https://user-images.githubusercontent.com/90008/228960278-92c91a36-5cd1-47e9-92a8-8f9fcaefddcf.png)
close
calls to the loop I get.Versions
My PyAV builds include the patch in #1061 those in master. I really don't think it is related, but if you want, I'll run my plotting code again.
Research
I have done the following:
Additional context
Maybe related to:
OutputContainer.__del__
is never called. #427The text was updated successfully, but these errors were encountered: