ayufan / camera-streamer

High-performance low-latency camera streamer for Raspberry PI's
291 stars 46 forks source link

Advice on a reliable Pi Zero stream? #102

Open apbarratt opened 10 months ago

apbarratt commented 10 months ago

Apologies for opening this as an issue, I couldn't see a discussion page or link to similar, forgive me if I missed a pointer to a more appropriate forum.

I have a Pi Zero w with one of these 160° ZeroCam cameras. Whilst it was my understanding that the ZeroCam is based on official Pi Camera tech, it looks like it's the same as the larger Chinese cameras with the wide angle lens options. It's an OV5647.

Anyway, I'm attempting to keep a steady and reliable stream open, but ever method I use seems to crash eventually, whether that just be a cronjob taking photos using lib camera-jpeg or now camera-streamer, which I'd figured I'd give a go after seeing the high praise its received from Gina at Octoprint.

Now I expect my real challenge for you is the Pi hardware. The Pi Zero w is a slow and unpowerful beastie and I know it, but I figured there must be some set of settings that would keep a stream going without eventually falling over or resulting in non-stop buffering over the LAN for devices accessing it.

The command I'm using is this:

camera-streamer \
  --camera-path=/base/soc/i2c0mux/i2c@1/ov5647@36 \
  --camera-type=libcamera \
  --camera-format=YUYV \
  --camera-width=2592 --camera-height=1944 \
  --camera-fps=15 \
  --camera-nbufs=3 \
  --camera-snapshot.height=1944 \
  --camera-video.height=480 \
  --camera-stream.height=480 \
  --camera-options=brightness=0 \
  --http-listen=0.0.0.0 \
  --http-port=8080 \
  --rtsp-port

I seem to get a stream from this on the /video endpoint, but it only ever seems to last a few seconds before freezing up. I can refresh the page and this will usually bring it back to life but sometimes I'll just be faced with a loading spinner in whatever browser and nothing more. The /stream endpoint seems to be a little better, though I have seen it freeze up too but not necessarily after just a few seconds like with /video, and I understand it's meant to be more resource intensive, which is something I'd like to avoid.

I was hoping to rely on an RTSP stream for use with HomeAssistant's generic camera integration, which runs it through a proxy, making it accessible elsewhere etc, sadly it seems this is not an option with the mjpeg stream :/

I'd wondered if perhaps there's a simple option for telling the h264 stuff to decrease its quality? I've seen stuff about bitrates, but I don't know what is a high bitrate compared to a low one etc. I also find the --camera-list_options a little frustrating as it doesn't seem to reveal what the default values of each option are. This would be rather helpful to know if there's some way of finding it.

I have also tried running sudo v4l2-ctl -d /base/soc/i2c0mux/i2c@1/ov5647@36 --list-formats-ext to see if I could experiment with other formats (the suggested YUV412, or whatever it was seemed to just produce a corrupted image) but it seems I get no answer with the device being a libcamera one. Is there any way to find this information for libcamera device paths?

What settings have others tried and found reliable on these super low-end Pis? I'm running Raspberry Pi OS lite, Bullseye

JoelBecker1998 commented 9 months ago

I use a very similar setup in a couple of places and it works fine. I do use an imx708 (Camera Module 3) with the following setup:

--camera-format=YUYV 
--camera-fps=30 
--camera-path=/base/soc/i2c0mux/i2c@1/imx708@1a 
--http-port=8081 
--rtsp-port=8555 
--camera-width=2304 
--camera-height=1296 
--camera-video.height=720
--camera-nbufs=4

This is sometimes a bit laggy, but doesn't crash. Do you have the zero configured as an ethernet gadget and do LAN via USB or do you connect wireless?