AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
5.32k stars 414 forks source link

Help needed: how to transcode home assistant camera entity (series of images) to h264. #1348

Open tonysprenk opened 1 month ago

tonysprenk commented 1 month ago

I thought I could just do:

streams: 
 camera.x40_ultra_complete_map: ffmpeg:{output}#video=h264

But then I get an error. What am I doing wrong?

AlexxIT commented 1 month ago

If you talking about mjpeg camera - it's not supported. Because it doesn't have a stream.

tonysprenk commented 1 month ago

I want to add the map from my robot vacuum cleaner to HomeKit. The map in home assistant is a camera component. When I add it to HomeKit with the HomeKit integration the preview image works but the stream does not. In home assistant I have an error saying that there is no stream.

I was hoping that go2rtc could transcode the vacuum cleaner map camera component to h264.

AlexxIT commented 1 month ago

You repeated what I said. MJPEG camera in Hass is not a stream. You can get a MJPEG link from Hass, add a long live token to it, and use that as a source for go2rtc. You can find the link in the browser debug menu or ask around on the Hass forums.

tonysprenk commented 1 month ago

Ok I have done that but the h264 stream is not working. This my config:

streams: 
 camera.x40_ultra_complete_map: "http://homeassistant.local:8123/api/camera_proxy_stream/camera.x40_ultra_complete_map#header=Authorization: Bearer xxxx"

I get this error when streaming h264:

Webrtc/offer: streams: codec not matched: JPEG => h264, ......

Thank you for the help so far and any further insights.

AlexxIT commented 1 month ago

You should setup transcoding

tonysprenk commented 1 month ago

With this config:

streams:
 Map: 
  - "http://homeassistant.local:8123/api/camera_proxy_stream/camera.x40_ultra_complet_map#header=Authorization: Beare xxx"
  -  ffmpeg:Map#video=h264

I get the following error:

10:02:31.664 PM error   undefined error=streams: exec/rtsp
[out#0/rtsp @ 0x7f8d2f4f00] Output file does not contain any stream
Error opening output file rtsp://127.0.0.1:8554/ab29e4cbf5edb947487550b7caf09bdf.
Error opening output files: Invalid argument
caller=github.com/AlexxIT/go2rtc/internal/hls/ws.go:28

Any suggestions? thanks for the help so far.

AlexxIT commented 1 month ago

Are you sure this stream is currently running in MJPEG format?

tonysprenk commented 1 month ago

I assume so because I'm accessing it through the home assistant API camera proxy. And opening the original stream in go2rtc works fine. Where it says MJPEG as the source. image

AlexxIT commented 1 month ago

Go to go2rtc WebUI > links page for your stream. Try to open RTSP for this stream for example in VLC.

Also you can copy MJPEG stream link and use it as input for ffmpeg source. Because by default it will try to use RTSP as input.

tonysprenk commented 1 month ago

I have come to find out that the source is a series of images (as you mentioned before) in the PNG format. This FFMPEG command works in terminal:

ffmpeg -re -loop 1 -headers "Authorization: Bearer long_lived_access_token" -i "http://homeassistant.local:8123/api/camera_proxy/camera.x40_ultra_complete_map" -vf "fps=1" -vcodec libx264 -r 15 -pix_fmt yuv420p output.mp4

How can I use it in go2rtc?

AlexxIT commented 1 month ago

https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#source-exec

xxgmxx commented 1 week ago

Hi :) Did you mange to make it work? I have integrated my 3D printer and I would love to transcode the camera entity too. It looks similar to your request :)