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
7.08k stars 504 forks source link

Re-using homekit URL from HomeAssistant results in ffmpeg initialization error #1082

Open visigoth opened 6 months ago

visigoth commented 6 months ago

I am using Frigate's builtin go2rtc running in a docker instance. I have a HomeAssistant docker instance on the same box. The config path for HomeAssistant is mapped into the Frigate docker instance at /hass_config.

I have go2rtc configured like this inside the frigate configuration, and the frigate configuration is below that


go2rtc:
  rtsp:
    username: "camera"
    password: "XXXXXXXXX"
  hass:
    config: "/hass_config"
  streams:
    doorbell:
      - homekit://192.168.0.71:49152?client_id=...&client_private=...&device_id=...&device_public=...

cameras:
  doorbell:
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
        - path: rtsp://127.0.0.1:8554/doorbell
          input_args: preset-rtsp-stream
          roles:
            - detect
            - record
      hwaccel_args: preset-intel-qsv-h264

note i have a number of other plain PoE RTSP cameras that are working fine with go2rtc + frigate doing both detection and recording. the above snippet just shows the one HomeKit camera i have for the doorbell. also note that i tried hass:camera.doorbell as well for the URL but i kept getting no entity_id and 404 errors in the log. i manually formatted the homekit:// URL as above.

when i start things up, i get Could not find codec parameters for stream 0 (Video: h264, 1 reference frame, none): unspecified size

i tried increasing the analyzeduration and probesize values as suggested, but that didn't work either.

the information ffmpeg is able to get out of go2rtc is:

[tcp @ 0x557adb5cd580] Successfully connected to 127.0.0.1 port 8554
[rtsp @ 0x557adb5ca540] SDP:
v=0
o=- 1 1 IN IP4 0.0.0.0
s=go2rtc/1.8.4
c=IN IP4 0.0.0.0
t=0 0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=4D001F
a=control:trackID=0
AlexxIT commented 6 months ago

Is the Frigate container running with the network host setting?

visigoth commented 6 months ago

apologies for taking a while to respond, but i don't get a lot of time to look into home networking issues.

for my case, i am running frigate along with other containers on a MAC VLAN network - i.e. each container has its own virtual NIC that shows up on the physical network.

AlexxIT commented 6 months ago

Go2rtc should run in the host network to get the HomeKit protocol working

visigoth commented 4 months ago

got it; i would rather not move to the host networking mode. having each container be a separate endpoint on the network makes traffic shaping and firewall rules easier to manage.

fwiw, the doorbell camera is routable for the HomeAssistant docker container as i have used HA as the HomeKit controller for it. also, the Frigate container can talk to the HomeAssistant container since i have camera entities in HomeAssistant for the go2rtc-reflected RTSP cameras.

i suppose i could host another go2rtc instance just to reflect the doorbell camera as an RTSP stream that Frigate can consume, but that seems convoluted.

given that the containers are routable to each other, and HA can talk to the doorbell camera, and the containers are under the same traffic shaping rules, what is it about the HomeKit protocol that requires host-mode networking?

AlexxIT commented 4 months ago

Additional inbound ports for this protocol to work. mDNS and SRTP. They are static. Many streaming protocols use random inbound ports. Maybe some additional docker configuring of the docker container will be enough to make everything work. I don't know. I have no plans to test and support modes other than network host. It would take a lot of effort to support an issue (like this one) that shouldn't have come up.

visigoth commented 2 weeks ago

i've made a bit of progress on this. my physical device is paired with HomeAssistant, so i setup the hass module to point at the HA config.

i've used the go2rtc web UI to enumerate the available streams. i've tried the homekit URL from the HomeAssistant section of the web UI (which has the client_private secret). when i use this URL, i get "ffmpeg.doorbell.detect ERROR : [rtsp @ 0x55cf23d086c0] method SETUP failed: 461 Unsupported transport" in the frigate logs. i put the log level for go2rtc to debug and got the following:

2024-11-08 00:14:08.107713721  00:14:08.107 DBG [rtsp] new consumer stream=doorbell
2024-11-08 00:14:09.285753715  00:14:09.285 DBG [streams] start producer url=hass:Circle View Doorbell LFV8
2024-11-08 00:14:14.417223572  00:14:14.417 DBG [streams] retry=0 to url=hass:Circle View Doorbell LFV8
2024-11-08 00:14:16.305956681  [INFO] Starting go2rtc healthcheck service...
2024-11-08 00:14:20.749099608  00:14:20.749 DBG [streams] retry=0 to url=hass:Circle View Doorbell LFV8
2024-11-08 00:14:27.169481182  00:14:27.169 DBG [streams] retry=0 to url=hass:Circle View Doorbell LFV8
2024-11-08 00:14:33.607964698  00:14:33.607 DBG [streams] retry=0 to url=hass:Circle View Doorbell LFV8
2024-11-08 00:14:38.128588921  00:14:38.128 DBG [rtsp] handle=EOF
2024-11-08 00:14:38.128684719  00:14:38.128 DBG [streams] stop producer url=hass:Circle View Doorbell LFV8
2024-11-08 00:14:38.128755673  00:14:38.128 DBG [rtsp] disconnect stream=doorbell

because this is a macvlan, the container is sitting on the main network. it has its own IP address and is able to communicate over any port. go2rtc is able to enumerate homekit camera devices on the network just fine as evidenced in the web UI.

running go2rtc locally on my macbook on the same network with the same URL. however, i get a black stream and i don't get the handle=EOF error as in the logs above.