I am struggling to get my webcam (Logitech C270) working in Mainsail. I got the latest versions of Klipper, Moonraker, Mainsail and Crowsnest running on a RPi 4. Everything is working great except the webcam (this setup has previously worked great in OctoPi). I am using the camera-streamer backend, the WebRTC service and the /webcam/webrtc
streming URL. The video is really choppy and unreliable with these settings so I took a look at the camera-streamer github page. This is where it gets quite interesting. First of all, access camera-streamer directly from the http://your-ip:8080/
URL. Great index page with links to the different streams. I try the http://your-ip:8080/webrtc
stream and it is quite choppy, not as bad as in Mainsail but not smooth at all. I then try the http://your-ip:8080/video
stream, it automatically redirects to http://your-ip:8080/video.mp4
(I am using Firefox) and it is buttery smooth!
Great, I thought I found a solution to my problem and tried to use /webcam/video
as the streaming URL in Mainsails webcam setting. But this doesn’t work! The webcam widget is stuck with a circular progress-bar and the text “connecting”. The same for the /webcam/video.mp4
and direct http://your-ip:8080/video
and http://your-ip:8080/video.mp4
streaming URLs. These URLs all work if I access them directly from Firefox. So why is Mainsail webcam widgets stuck with a circular progress-bar and the text “connecting” when these URLs works perfectly from a browser?
I found a workaround (for now). I changed service settings to “IP Camera” instead of “WebRTC”. I can then use the URLs /webcam/video
for stream and /webcam/snapshot
for snapshot and it seems to work with Mainsail. This is still somewhat integrated with Crowsnest. I guess the Crowsnest service is running camera-streamer so restarting the Crowsnest service restarts camera-streamer). It might be better to install camera-streamer as its own service but I guess I then have to manually restart the service if it stops streaming. I don’t know how the Crowsnest service is integrated with the Mainsail Service Control
menu? If it is only managing the crowsnest.service
would I then be able to make an alias to the standalone camera-streamer.service
?
I spoke too soon. Using service setting “IP Camera” instead of “WebRTC” works for a while until the webcam widget in Mainsail Dashboard freezes up. Swapping to the Webcam view shows the live stream and swapping back to Dashboard shows the live stream again but just for a while until it freezes again. Opening Webcam Settings (Edit Webcam) shows a live stream again in the preview windows but not always. Seems like the webcam view freezes after a while and switching between view might trigger an update showing the live stream (but not always). It is a pity because I really enjoy Klipper and Mainsail but I have not managed to get webcam to work in Mainsail. Can someone confirm that they got a stable webcam feed in Mainsail with Crowsnest? If so please submit versions of Mainsail and Crowsnest, camera used and if using a RPi or not. Thanks in advance…
Use go2rtc for ip camera , good work for me
Thanks for the tip Creo2005, I have played around with it for the last couple of days and it seems like a solid streamer. Unfortunate, It doesn’t solve my problems but it enabled me to troubleshoot my setup. I first had to install ffmpeg to be able to capture streams from my Logitech C270 (YUYV 4:2:2 and MJPEG), i.e.
streams:
h264: ffmpeg:device?video=/dev/video0&input_format=yuyv422&video_size=640x480#video=h264#hardware
mjpeg: ffmpeg:device?video=/dev/video0&input_format=mjpeg&video_size=640x480
The h264 without hardware acceleration bumped the CPU load on my RPi4 to 10% but stayed below 2% with hardware acceleration enabled (640x480).
I was able to use the h264 stream in Mainsail using IP Camera as service and with the streaming URL set to http://my-ip:1984/api/stream.mp4?src=h264
. It works but it is kind of flaky, the go2rtc stream seems to work but the webcam widget in Mainsail stops working at times (and I also get some errors in the go2rtc trace log).
I never managed to get a solid WebRTC stream. It could be a Firefox problem, a problem with the webcam widget in Mainsail or a combination of both.
MJPEG streaming is rock solid using the UV4L-MJPEG service with a streaming URL like http://my-ip:1984/api/stream.mjpeg?src=mjpeg
and a snapshot URL like http://my-ip:1984/api/frame.jpeg?src=mjpeg
. But MJPEG streaming is pretty solid if I use Crowsnest with the UV4L-MJPEG service too.
The good thing with go2rtc is how easy it is to reconfigure the streams and change log level from the built in web UI, e.g. to change the MJPEG stream to 800x600 with 5 frames per second and trace as log level:
streams:
mjpeg: ffmpeg:device?video=/dev/video0&input_format=mjpeg&framerate=5&video_size=800x600
log:
format: ""
level: "trace"
I wrote a simple systemd service file for it and I will keep it running instead of Crowsnest until I find a better solution…