lunacam icon indicating copy to clipboard operation
lunacam copied to clipboard

Intermittent webstream stuttering

Open fafnir1 opened this issue 5 years ago • 5 comments

Per our message on reddit, I am having the occasional stuttering issue. It sounds like you have looked into it a bit and determined it is not related to the load on the pi's CPU.

My initial thought was that there was too much data for my wireless network so I was going to decrease the size/resolution of the video and see if that had an impact on this issue.

fafnir1 avatar Jan 05 '20 18:01 fafnir1

Agreed! If reducing the stream resolution causes the stuttering to go away, that's probably a good indication that some part of the system isn't keeping up.

Stream resolution is currently hard-coded in src/stream.rs (search for "-video_size"). To test, you'll need to change this value, then cross-compile a new lunacam binary (with tools/scripts/cross-compile.ps1), place it in /usr/bin, and restart the lunacam service.

reynoldsbd avatar Jan 05 '20 20:01 reynoldsbd

Given that it is the weekend, I am having some additional time to look into this. Right now my camera is in a state where there is only about 9 seconds of video in the buffer and it is not recording any new video. I likely didn't notice this fact when this occurred a few days ago and I mentioned it as an issue on reddit. When I re-load the webpage with the camera stream on another computer I see the same 9 seconds of video and then the video freezes.

Hardware: Raspberry Pi Zero W, Raspberry Pi Camera V2. Software: LuncaCam Image Version 1.01, used image file: lunacam-1.0.1.zip

Steps taken to duplicate the issue: :

  1. Boot raspberry pi with the camera attached
  2. Open browser on another computer and monitor video stream
  3. Note that after a period of time the stream has frozen and I am seeing a spinning / loading indicator.
  4. Click on refresh in my web browser and the page reloads showing that there is 9 seconds available in the video stream.
  5. Click play and the 9 seconds of video plays and then the stream is frozen with the spining / loading indicator again.

SSH into the raspberry pi, TOP shows about 15% CPU utilization and about the same for memory utilization. Rebooting results in normal functionality restored.

I have rebooted and I will see how long it takes before becoming non-functional again. Is there a log file I could pull which may give some indication as to what may have occurred?

fafnir1 avatar Jan 05 '20 22:01 fafnir1

In this case we probably want the ffmpeg output, which is currently piped to /dev/null because it's ridiculously verbose. Quickest way to get those logs would be to comment out ffmpeg's stdout/stderr redirects and tail the lunacam service's logs (journalctl -u lunacam -f). You may also want to change ffmpeg's log level.

reynoldsbd avatar Jan 05 '20 22:01 reynoldsbd

Also of interest would be the contents of /dev/shm/lunacam/hls. This directory contains the actual video buffer, stored as a sequence of video snippets and a "manifest" file (stream.m3u8). These files are constantly updated by ffmpeg as new video is recorded, but if there's some issue causing latency, then I would expect to see that latency reflected in the timestamps/contents of the files in this directory.

reynoldsbd avatar Jan 05 '20 22:01 reynoldsbd

In this case we probably want the ffmpeg output, which is currently piped to /dev/null because it's ridiculously verbose. Quickest way to get those logs would be to comment out ffmpeg's stdout/stderr redirects and tail the lunacam service's logs (journalctl -u lunacam -f). You may also want to change ffmpeg's log level.

OK, that makes sense, I am not set up yet to compile this project. I will have to get that working first. May be some time though.

fafnir1 avatar Jan 05 '20 22:01 fafnir1