I recently helped someone on OctoPrint's Discord server to get a wyze cam v3 to work with OctoPrint. Thanks to previous work by @Chudsaviet to get integrated HLS support it's fairly easy to transcode rtsp using restreamer. As of this posting the following steps worked to get this integration.
SSH to Pi using putty, run these commands
sudo apt update
sudo apt upgrade
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo groupadd docker
sudo usermod -aG docker $USER
sudo systemctl disable webcamd
sudo systemctl disable ffmpeg_hls
sudo service webcamd stop
sudo service ffmpeg_hls stop
log back in to SSH, run this command. I'd recommend reading restreamer's documentation for optimizing the system to your needs. Make sure to replace the username and password from the default ones listed in the example command line below.
docker run -d --restart always \
--name restreamer \
-e "RS_USERNAME=admin" -e "RS_PASSWORD=datarhei" \
-e "RS_SNAPSHOT_INTERVAL=10" \
-p 8080:8080 -v /mnt/restreamer/db:/restreamer/db \
--tmpfs /tmp/hls \
open browser to http://<your pi's ip>:8080/ and login with username password specified in docker run command above.
add your rtsp stream url in restreamer, set options accordingly and start.
in octoprint's webcam & timelapse settings set the stream url to
http://<your pi's ip>:8080/hls/live.stream.m3u8 and snapshot url to
http://<your pi's ip>:8080/images/live.jpg
Example rtsp test stream of BigBuckBunny...
Actually, you don’t need restreamer - ffmpeg can pickup RTSP stream directly.
Also /tmp is on SD card in RaspberryPi OS, not in RAM. Use /var/run instead.
Thanks for the tip on RAM pathing.
Thanks for the tips!
I notice a 8-12second delay on restreamer. I can't seem to figure out how to remove (well, drastically reduce) this delay. a couple seconds is fine.
That is the drawback of this approach. The streaming technology requires to create a buffer in order to stream, so doubt you'll ever get any lower.
I'm noticing that... well, back to USB camera
Thank you for the response!
Anyone coming here, I can strongly recommend rtsp2mjpg docker image for this purpose. I have tried all kind of solutions, until I found rtsp2mjpg . It works straight forward and is exactly what you need to use a RTSP camera in Octoprint.
The only drawback to that solution is the final stream is MJPG. Although this works great with OctoPrint, it still is not as network friendly as HLS or with a future release of OctoPrint webrtc and will consume bandwidth very quickly.
It also seemed I was too early with my comment. After trying it out some more. It seems the still image will not work with rtsp2mjpg. Octoprint says it cant capture the still image, while it does show the image when I press the Test button.
My solution now is using Motioneye, which also has an option to restream an rtsp stream. And with motioneye the timelapse does work correctly.
What is that webrtc? Will that allow Octoprint to consume rtsp stream natively?
You would still need something to convert the RTSP stream to something that WebRTC can work with. A quick google gave me this: deepch/RTSPtoWeb: RTSP Stream to WebBrowser (github.com).
The WebRTC handshake protocol has not been fully finalized & documented in OctoPrint just yet - there's still some ongoing discussion, so the above project may not just work.
Can confirm, I tried Restreamer first and not sure why but it wouldn't load in OctoPrint although the URLs seemed to work fine elsewhere, and did show up when I tried the Test button in Webcam settings.
After switching to rtsp2mjpg it worked right away, the setup is actually much simpler, there's no storage needed, and the video and snapshots have much less latency. Highly recommend as well!