go2rtc icon indicating copy to clipboard operation
go2rtc copied to clipboard

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

Open tonysprenk opened this issue 1 year ago • 14 comments
trafficstars

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?

tonysprenk avatar Sep 11 '24 16:09 tonysprenk

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

AlexxIT avatar Sep 11 '24 17:09 AlexxIT

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.

tonysprenk avatar Sep 11 '24 17:09 tonysprenk

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.

AlexxIT avatar Sep 11 '24 17:09 AlexxIT

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.

tonysprenk avatar Sep 11 '24 20:09 tonysprenk

You should setup transcoding

AlexxIT avatar Sep 12 '24 03:09 AlexxIT

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.

tonysprenk avatar Sep 15 '24 20:09 tonysprenk

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

AlexxIT avatar Sep 16 '24 09:09 AlexxIT

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

tonysprenk avatar Sep 16 '24 12:09 tonysprenk

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.

AlexxIT avatar Sep 16 '24 13:09 AlexxIT

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?

tonysprenk avatar Sep 19 '24 19:09 tonysprenk

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

AlexxIT avatar Sep 20 '24 14:09 AlexxIT

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 :)

xxgmxx avatar Nov 01 '24 08:11 xxgmxx

have the same x40, have you managed?

incline02 avatar Dec 03 '24 13:12 incline02

No

tonysprenk avatar Dec 03 '24 13:12 tonysprenk

Guys, give this a try:

  • https://github.com/felipecrs/hass-expose-camera-stream-source/issues/53

felipecrs avatar May 23 '25 23:05 felipecrs