Webcam example plays back very slowly
See original GitHub issueI am playing around with the webcam example and it appears to play back any type of input media in the browser very slowly (maybe dropping frames, timecodes are wrong? – not sure exactly what the problem is).
I’ve tried several different input media including just a regular mp4 example mp4 file. My ultimate goal is to feed in mpeg-ts/udp and then distribute via webrtc. I’ve made some progress on that by modifying the webcam example like:
player = MediaPlayer("udp://127.0.0.1:9001", format="mpegts")
and then streaming mpeg-ts via:
ffmpeg -re -i https://ll-streams.s3.amazonaws.com/colorbars.mp4 -c copy -f mpegts udp://127.0.0.1:9001
this seems to work but exhibits the slow playback problem. also webcam.py spams the console with these error messages:
non-existing PPS 0 referenced
non-existing PPS 0 referenced
decode_slice_header error
no frame!
non-existing PPS 0 referenced
non-existing PPS 0 referenced
decode_slice_header error
no frame!
any information to point me in the right direction would be really appreciated. this project is awesome btw thanks a lot for it! I hope to contribute some day
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (3 by maintainers)
I ran some additional tests:
the (unmodified) server example for two hours -> memory usage seems stable
a minute program reading a .mp4 in a tight loop with PyAV -> I don’t see leaks per se, but maybe sprinkling an occasional
gc.collect()
would keep memory usage downwith the webcam example : if I slow down encoding a bit by introducing some “sleep()” calls, video playback falls behind and memory usage grows indefinitely. This is probably what you are seeing!
Seeing how I coded MediaPlayer, this isn’t that surprising as you basically have one thread capturing frames and pushing them into a queue, and another thread which handles the vp8 encoding… so if vp8 encoding is lagging, the queue grows, and grows…
I’ll try:
In the meantime if you are willing to sacrifice some video quality, can you try modifying aiortc/codecs/vpx.py and changing:
self.cfg.rc_target_bitrate = 500
to something like:
self.cfg.rc_target_bitrate = 200
I am facing the slowness with webcam feeds. The process is ever hungry for CPU and sucking too much of memory. I tried the work around of setting lower bit rates but that didn’t help either.