marcolivierarsenault / moonraker-home-assistant

Home Assistant integration for Moonraker, Klipper and Mainsail
https://moonraker-home-assistant.readthedocs.io
MIT License
227 stars 25 forks source link

WebRTC/RTSP camera support (crowsnest) #225

Open spikeygg opened 9 months ago

spikeygg commented 9 months ago

I've recently learned about crowsnest (https://github.com/mainsail-crew/crowsnest) which supports alternative methods for serving up the cameras attached to a printer. It allows for webrtc cameras via camera-streamer. After upgrading my printer to use this package I noticed that the camera entities from the moonraker integration in Home Assistant no longer worked correctly - broken icon instead of the camera's image.

I swapped my configuration back to using ustreamer with the /webcam/?action=stream URL and deleted and reloaded the integration for moonraker and that made the camera entities work again.

The URL can be several different variations based on the source. The default for webcamd works in crowsnest if you don't change away from ustream:

####    Port 8080 equals /webcam/?action=[stream/snapshot]      #####
####    Port 8081 equals /webcam2/?action=[stream/snapshot]     #####
####    Port 8082 equals /webcam3/?action=[stream/snapshot]     #####
####    Port 8083 equals /webcam4/?action=[stream/snapshot]     #####

but you can also use camera-streamer and enable rtsp. The URLs are: /webcam/webrtc for the camera-streamer #### rtsp://<ip>:<rtsp_port>/stream.h264 #####

Describe your setup

I have a Voron 2.4 with Klipper, Moonraker, Fluidd and Mainsail running from a Raspberry Pi 4 and Octopus controller.

Describe the solution you'd like

Ideally, the camera entities served into Home Assistant would support all technologies served by the software.

WayneManion commented 8 months ago

I don't use Crowsnest. I have PoE IP cameras connected over Ethernet to keep an eye on my printers. I have the camera details set up in moonraker.conf. The camera is automatically populated in the fluidd UI when I visit any of my printers via fluidd, but the camera does not work in Home Assistant.

The [webcam] section in one of my printers' moonraker.conf looks like this (the printer is named Kevin):

[webcam kevinRakerCam] location: outside enabled: True service: hlsstream target_fps: 15 target_fps_idle: 5 stream_url: http://[NUMERIC_IP_ADDR]:8083/stream/kevin/channel/0/hlsll/live/index.m3u8 snapshot_url: http://[NUMERIC_IP_ADDR]:8083/stream/kevin/channel/0/hlsll/live/index.m3u8 flip_horizontal: False flip_vertical: False rotation: 0 aspect_ratio: 16:9

I have the cameras piped into RTSP2WebRTC running on another Linux box and then I stream them from there in Moonraker. Right now I use the Generic camera integration to 'catch' the feed from RTSP2WebRTC, but it would be cool if if the Home Assistant integration could 'figure out' that my camera stream is not MJPEG and just automatically work.

marcolivierarsenault commented 8 months ago

This is a good idea, but it's really tricky for us to implement since we don't have this hardware.

that being said if someone would implement it, we will happily merge that into the integration

Codel1417 commented 8 months ago

There are multiple options. https://github.com/ayufan/camera-streamer/blob/main/docs/streaming.md

I had success with the /video endpoint but there is a delay. Using the RTSP url would return connection timed out in home assistant

WayneManion commented 8 months ago

This is a good idea, but it's really tricky for us to implement since we don't have this hardware.

that being said if someone would implement it, we will happily merge that into the integration

I don't think one would necessarily have to have this hardware to be able to implement this feature. I could very well be wrong, I'm not a Python expert.

class MoonrakerCamera(MjpegCamera): It appears that the Moonraker integration currently assumes all video cameras are MJPEG, which is not necessarily true.

One could test by transcoding an MJPEG camer into another format supported by Moonraker/Fluidd/Mainsail (HLS, WebRTC, etc).

Codel1417 commented 8 months ago

If it assumes mjpeg, Camera-Streamer has a mjpeg stream http://:8080/stream

WayneManion commented 8 months ago

The Creality camera for my K1 finally arrived. The integrated camera in my K1 works automatically in the HA integration, but the IP camera that is defined in my moonraker.conf file does not work in the integration.

I believe this is supporting evidence to the notion that the HA integration assumes all cameras defined in moonraker.conf are mjpeg cameras.

marcolivierarsenault commented 8 months ago

The integration only supports mjpeg cameras

TheManoeuvre commented 8 months ago

Im using a Creality K1, rooted and the camera is set up and working in Fluidd in the UI as mjpeg adaptive however the HA integration shows it as a camera but it consistently idle. Do these need to be in the moonraker.conf file to work?

EyalRotem commented 6 months ago

I saw the last update added a way to configure camera links, any info about how to use it and in which cases? does it support webrtc/rtsp?