Skip to content
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

How to stream video II: memory leaks #1091

Open
rodolfoap opened this issue May 7, 2024 · 3 comments
Open

How to stream video II: memory leaks #1091

rodolfoap opened this issue May 7, 2024 · 3 comments

Comments

@rodolfoap
Copy link

rodolfoap commented May 7, 2024

Using the webcam example, I can stream a single RTSP video from a server, to multiple clients in browsers:

player = MediaPlayer("rtsp://myserver:8554/live.sdp") # <- PLAYER IS UNIQUE
relay = MediaRelay()
async def offer(request):
    ...
    peer_connection = RTCPeerConnection()
    ...
    video = relay.subscribe(player.video)
    peer_connection.addTrack(video)
    ...

But I have a problem: a memory leak, which is quite aggressive. With my gaming PC (32Gb RAM, Intel Core i7, Nvidia RTX 2080 with Debian 12), memory leak starts with a 1920x1080 video and only THREE browser windows. Twenty seconds is enough to reach 1Gb, from an initial 500Mb.

User @ZoroLH (thanks!) already observed this behavior (see #1089 (comment)).

Just in case, my code is here. What can I do to address such memory leak?

@rodolfoap
Copy link
Author

rodolfoap commented May 7, 2024

More tests:

  • Memory leaks and performance degrades with a 1920x1080 video opened in three (3) browser tabs.
  • No memory leak and nice performance with a 768x576 video opened in twenty (20) browser tabs. Memory consumption is great (510Mb)!

Seems a performance issue. CPU fan goes max with the third browser tab and frames start to interleave irregularly. I would naively say that the process of the next frame would start before the process of the current frame is finished, that's why some frames are lost and memory occupation keeps growing. I'm probably talking crap, since I don't know too much about video.

@ZoroLH
Copy link

ZoroLH commented May 7, 2024

Looks like this is an issue of pyav.
Relating discussion is #1088 (comment)

@rodolfoap
Copy link
Author

rodolfoap commented May 20, 2024

How-to-reproduce: https://gist.github.com/rodolfoap/20411acc86ecca39d18ebfc2060bb8c5.

Issue remains using either av==11.0.0 (installed by default) or av==12.0.0 (last version). The Dockerfile allows changing the av version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants