question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webcam example plays back very slowly

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jlainecommented, Oct 12, 2018

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 down

  • with 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:

  • to see if there are some settings I can tweak in the vpx encoder to try and speed things up
  • implementing some kind of safety mechanism to drop frames if encoding really isn’t keeping up

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

0reactions
varunkumarcommented, Sep 17, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Stop Your Webcam From Lagging
If your video signal lags, the webcam itself is likely not the problem. Possible causes include a slow Internet connection, poor lighting and...
Read more >
Webcam recording in slow motion on media
I will record videos without any issue but then when I play them back my voice has a significantly lower tone and everything...
Read more >
Windows 10 UI lags horribly when streaming webcam video
My system has recently started to lag when streaming video from my webcam. This manifests as: all UI windows are very slow to...
Read more >
NORMAL VIEWING SPEED TO SUPER SLOW WITHOUT ...
Too many gadgetry not needed in the now models - it is a waste. ... the system you're using to edit on -...
Read more >
Questions & Answers for: webcam slow motion - Fixya
Slow motion playback of video Can you change the format to play back the video in Media Player or ... Logitech webcam is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found