Stream Homekit cameras outside of home network

Hi everyone,
TL:DR : I am having trouble when sharing a camera through the homekit bridge integration.
While I am inside my networki, I can correctly see the cameras in my Home app, I can stream the videos and see the still images.
However when I am outside my network (i.e. with iphone connected to cellular network) I can only see the still images but the streaming does not seem to work.

Longer part:
I have dug a bit more in dept into this issue but I have reached a point in which I don’t know anymore what to look for.
My setup is as follows:

  • Camera: Reolink E1 Zoom
  • Router: Fritz!Box 3490
  • Home Assistant Core 0.112.1:
    • running on Docker official images
    • running on Raspberri Pi4 connected by ethernet cable to the router
    • running on host network
  • Apple TV 4K to act as Homekit Hub connected by ethernet cable to the router

The camera can be added to HA in three ways:

The result does not change depending on which platform is used to add the Camera to HA.
Current configuration of the yaml file below [1]

When I stream through Home app and I am connected to the Wifi network I notice that HA spawns an FFMPEG process with the following commandline

ffmpeg -i rtsp://[username]:[password][email protected]:554/h264Preview_01_sub -map 0:v:0 -an -c:v copy -tune zerolatency -pix_fmt yuv420p -r 30 -b:v 299k -bufsize 1196k -maxrate 299k -payload_type 99 -ssrc 5589354 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params g7b9hIFZOfsd6MPnzmlH4MCDyLDow+3IkTN4gneE srtp://192.168.178.24:53448?rtcpport=53448&localrtcpport=53448&pkt_size=1316

When I stream outside the Wifi (cellular) I see:

ffmpeg -i rtsp://[username]:[password][email protected]:554/h264Preview_01_sub -map 0:v:0 -an -c:v copy -tune zerolatency -pix_fmt yuv420p -r 15 -b:v 132k -bufsize 528k -maxrate 132k -payload_type 99 -ssrc 5906845 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params WO/cpvA8zfkvlwjlG1IAXTtnC25gvLBpKTq1iHq+ srtp://192.168.178.33:65304?rtcpport=65304&localrtcpport=65304&pkt_size=1316

Where:

  • 192.168.178.25 - Camera IP address
  • 192.168.178.24 - Iphone IP address while inside the wifi network
  • 192.168.178.33 - Apple TV IP address inside the wifi network

So I assume that the Apple TV is acting as a relay and is supposed to forward the stream to my device.
Even though it should not be needed I have tried enabling uPnP port forwarding on the router for the Apple TV without any real change, looks like it is not even trying opening ports.

Is there anything I can do to diagnose further?
Thanks!

[1] yaml configuration

camera:
- platform: reolink_dev
  host: 192.168.178.25
  username: !secret reolink_username
  password: !secret reolink_password 
  name: reolink_e1
  stream: sub #using the sub stream with the custom component in order to avoid bandwidth problems while streaming remotely
  protocol: rtsp
  scan_interval: 20
homekit:
  name: Home Assistant Bridge
  filter:
    include_entities:
      - camera.reolink_e1_profile000_mainstream #camera added by the ONVIF integration, full resolution stream
      - camera.reolink_e1_profile001_substream #camera added by the ONVIF integration, full resolution stream
      - camera.reolink_e1 #camera added by the Reolink custom component
  entity_config:
    camera.reolink_e1_profile000_mainstream:
      name: Reolink clear
      support_audio: True
      video_codec: copy
      audio_codec: copy
    camera.reolink_e1_profile001_substream:
      name: Reolink fast
      support_audio: True
      video_codec: copy
      audio_codec: copy
    camera.reolink_e1:
      name: Reolink test
      #support_audio: True
      video_codec: copy
      #audio_codec: copy

A couple of additions.

  1. when I try to stream from cellular netwok I can indeed see traffic flowing outside my router:


    but the image on the Home app is still stuck with a spinning wheel

  2. If I use a VPN (wireguard) and log into lovelace I can correctly stream the camera using the “sub” stream, thus it doesn’t seems to be a bandwidth problem

Yeah. I have the same problem here.
Thing is, something must be missing on the implementation as we’re getting the local IPs, which will obviously not be accessible outside our networks.

I’m guessing you’ll need to forward the port to the camera and create a static link that is accessible externally instead of the local IP.

I had this issue initially as well. I believe prefixing my stream_source for each camera with "-rtsp_transport tcp -re -i " under homekit: entity_config fixed it:

homekit:

  entity_config:
    camera.mycamera:
       video_codec: copy
       support_audio: True
       stream_source: "-rtsp_transport tcp -re -i rtsp://..."

Hi,
I tried and it worked for, like, one time and with very low latency.
Then it hanged: I tried to restart the camera, home assistant, docker container… no result…

After I added that prefix the ffmpeg command becomes:

ffmpeg -rtsp_transport tcp -re -i rtsp://[username:password]@192.168.178.25:554/h264Preview_01_sub -map 0:v:0 -an -c:v copy -tune zerolatency -pix_fmt yuv420p -r 30 -b:v 299k -bufsize 1196k -maxrate 299k -payload_type 99 -ssrc 7057143 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params XQvZ0oH1/Q4OkKn69q2Git/2QMHn6mtYtklGml2U srtp://192.168.178.33:59076?rtcpport=59076&localrtcpport=59076&pkt_size=1316 -map 0:a:0 -vn -c:a copy -ac 1 -ar 16k -b:a 24k -bufsize 96k -payload_type 110 -ssrc 2871594 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params rCCjwG192nOZIUrgt0k5lbcVO8GcQHkhtULMuUtB srtp://192.168.178.33:58888?rtcpport=58888&localrtcpport=58888&pkt_size=188

does your solution also work for subsequent attempt to stram via the Home app on iOS?