Realtime camera streaming without any delay - WebRTC

waaw… we will wait for the coming release with many thanksss.

@fuatakgun I’m trying to do the same thing. Any chance you could share conditional card logic? How do you know when camera is streaming?

I read the docs you shared and it was suggesting to key off a binary sensor for the camera, but I don’t seem to have one. I’m using MQTT with Ring.

Would appreciate any tips.

@anon63427907 Update: I noticed there was a switch I could key off of (I missed it in the docs).

Unfortunately, I’m noticing a quirk: When I turn the switch off (to stop streaming), it flips back to the static image, but then a few seconds later resumes streaming. I’m assuming there is some delay between the MTQQ/Ring switch and the WebRTC card still trying to stream, which has it bouncing back and forth. Did you run into similar issues?

type: grid
square: false
cards:
  - type: conditional
    conditions:
      - entity: switch.my_camera_name_stream
        state: 'off'
    card:
      type: picture-entity
      entity: camera.my_camera_name_snapshot
      tap_action:
        action: call-service
        service: switch.turn_on
        target:
          entity_id: switch.my_camera_name_stream
  - type: conditional
    conditions:
      - entity: switch.my_camera_name_stream
        state: 'on'
    card:
      type: vertical-stack
      cards:
        - type: custom:webrtc-camera
          entity: camera.my_camera_name_video_feed
        - type: button
          name: Stop Streaming
          show_state: false
          show_icon: false
          tap_action:
            action: call-service
            service: switch.turn_off
            target:
              entity_id: switch.my_camera_name_stream
columns: 1

@AlexxIT - any thoughts on using your card/component in this way? Any better solution you can think of? My hope is to avoid streaming my cameras by default, and require a click/tap on the image to trigger the live feed. [BTW: This WebRTC implementation is soooo fast. Thanks for your contributions!]

This is amazing, thanks all for everyone who’s contributed. It works wonderfully… however, Fully (android) crashes after a couple hours. Anyone else experienced this?

hey all - what what a thread - apologies if ive missed a post above on this. Im trying to get this to work through a nginx and docker setup thats NOT in network_mode: host.

Yes i know the docs say not to do this… but hey im a network dude and i like the pain.

The first step in getting any protocol to work is to understand the packet flow… and its here i noticed some crazy-weird behaviour. First i had a lot of trouble even finding my source / test host trying to load the stream… i think i figured it out though… i think the hass webrtc-camera card code seems to be instructing clients to try connect to ALL addresses that it can pick up on the hass host.

In my case, its a docker container, with

  • A forward facing NIC (172.20.1.x which points upto NGINX) and
  • A downward facing nic (172.20.3.x which points down to the DB layer)

… both of which are useless to tell say an iPhone to connect to - they are internal docker addresses - non routable.

But then curiously it seems to ALSO want to try and connect to my ISP public IP address (no idea how it knows that).

so @AlexxIT - heres the question - whats your code doing here? Seems it might be a bit inefficient to spray prospective clients - telling them to connect in to many IPs addresses to bring up the streams. Is there a chance you could have your code tell clients to connect to just the base FQDN, not all the IP addresses (and let the client resolve what that means). In my case (and i suspect a lot of peoples) that would work on the LAN and remote

I can raise an issue, but i did notice there was 117 open so hopeful for the good people in here to comment before i head there.

heres the TCPDUMP’ing i was doing proving what im saying if anyone is interested (i ended up finding the flows by grep’ing for 528 (which i configured the port range to be 52800 → 52850)

Hi. I am glad to introduce to you my new project:

It’s in very early stage and can be super unstable. But it already can:

  • be a Home Assistant Add-on or be a standalone application
  • has integration with Hass built-in lovelace camera card
  • has a stable solution for external access to webrtc
  • has integration with FFmpeg for transcoding, MJPEG, HLS and other nice things
  • has 2-way audio support for cameras with ONVIF Profile T

There are more very cool features coming in the near future…

7 Likes

So, if i understand correct, this addon supports h265 codec? All my cameras are lately h265 so i’ve had problems showing picture in HA…

H265 supported almost nowhere in the web.

Theoretically it may be supported on Safari, but with additional development from my side.

But H265 can be transcoded to H264 on the fly with ffmpeg integration. Check examples in the docs. This should still work in near real time delay.

Yeah, i feared so…
thanks, i’ll try to play with ffmpeg then.

@keiran.harris I can try to limit listeners on docker interfaces in new go2rtc project.

2 Likes

Hello guys. I am wondering if it possible to combine webrtc-camera card with the picture glance. In other words i would like to have a live feed from sd sream but when i click inside the picture i would like to see the hd stream at bigger window. Thanks.

PS, i am using the tapo integration. My card is looking like this at the moment:

type: custom:stack-in-card
cards:
  - type: custom:webrtc-camera
    url: rtsp://lXXXXX:[email protected]:554/stream2
    camera_view: live
    entities:
      - entity: camera.tapo_camera_sd
        icon: mdi:arrow-left-drop-circle-outline
        tap_action:
          action: call-service
          service: tapo_control.ptz
          service_data:
            entity_id: camera.tapo_camera_sd
            pan: LEFT
      - entity: camera.tapo_camera_sd
        icon: mdi:arrow-up-drop-circle-outline
        tap_action:
          action: call-service
          service: tapo_control.ptz
          service_data:
            entity_id: camera.tapo_camera_sd
            tilt: UP
      - entity: camera.tapo_camera_sd
        icon: mdi:arrow-down-drop-circle-outline
        tap_action:
          action: call-service
          service: tapo_control.ptz
          service_data:
            entity_id: camera.tapo_camera_sd
            tilt: DOWN
      - entity: camera.tapo_camera_sd
        icon: mdi:arrow-right-drop-circle-outline
        tap_action:
          action: call-service
          service: tapo_control.ptz
          service_data:
            entity_id: camera.tapo_camera_sd
            pan: RIGHT
  - type: glance
    show_icon: true
    show_name: false
    show_state: false
    style: |
      ha-card.type-glance .entities, 
      ha-card.type-glance .entity {
        padding: 0px;
        margin: 0px;
      }
      ha-card.type-glance {
        margin-bottom: 0px;
      }
    entities:
      - entity: camera.tapo_camera_hd
        icon: mdi:cctv
        tap_action:
          action: call-service
          service: tapo_control.set_motion_detection_mode
          service_data:
            entity_id: camera.tapo_camera_hd
            motion_detection_mode: low
      - entity: camera.tapo_camera_sd
        icon: mdi:cctv-off
        tap_action:
          action: call-service
          service: tapo_control.set_motion_detection_mode
          service_data:
            entity_id: camera.tapo_camera_hd
            motion_detection_mode: 'off'
      - entity: camera.tapo_camera_sd
        icon: mdi:weather-sunny
        tap_action:
          action: call-service
          service: tapo_control.set_day_night_mode
          service_data:
            entity_id: camera.tapo_camera_sd
            day_night_mode: 'off'
      - entity: camera.tapo_camera_sd
        icon: mdi:weather-night
        tap_action:
          action: call-service
          service: tapo_control.set_day_night_mode
          service_data:
            entity_id: camera.tapo_camera_sd
            day_night_mode: 'on'
  - type: entities
    entities:
      - entity: binary_sensor.tapo_motion_detection
        name: Motion Sensor
    style: |
      ha-card.type-entities {
        margin-right: 14px;
      }
      ha-card.type-entities #states {
        padding-top: 10px;
      }
1 Like

go2rtc compatible with default picture glance card

Thanks @AlexxIT - wow go2rtc looks really promising! Thanks for all you dev!!

Thinking about my issue more (and anyone with their setup using docker and non-host-mode networking) … i think the feature request may simply be - allow the user to configure what IP address HASS is known on the local network (not the inside docker network). For instance inside my hass docker instance is 172.x.x.x…… but on my real LAN, its 10.1.3.50 (which then of course maps out to an external IP on the internet thru NAT for access outside the house).

So an ability to hard code the IP that the hass streaming source is on - not auto discovery of it - which in this case doesnt work.

go2rtc support hardcode IP list. Check docs.

I’m trying to decide which networks to ignore. Maybe all networks 172.xxx.xxx.xxx

Nice @AlexxIT ! I plan to look deeper at your new project on the weekend so will read the docs fully then. I suspect you will need to allow the user to configure what ranges they should ignore - as docker people may like to fiddle with non standard ranges. Did you want me to move this chat to a new github issue (how do you find the time mate?!!! Very appreciative of your dev. Ill buy you a coffee when im up and running).

Range of networks is very complicated for middle user. I don’t like having options like this.

Unfortunately, you can’t send me a coffee after february 2022…

New feature for go2rtc - support stream from local USB cameras to RTSP and WebRTC.
Tested cameras from Windows, macOS, HassIO installations.

1 Like

I am using 172.16.3.x as my local net …might not be the best option :slight_smile:

To close this tangent off here… ive just spun up your go2rtc project, and early signs are very promising (for anyone following the IP address problem of hass inside of docker running behind nginx - i believe it will be solved via this new project - by virtue of the fact that the webRTC server in the new project runs as its own container - which you can place on a more accessible part of your docker network, NOT behind nginx where your HASS probably lives - which gets around the random UDP port thing that webRTC uses).

I do have some early questions… so have spawned off a new thread so as to not bug these good people on this already mega-thread.

For those interested in @AlexxIT wonderful new go2rtc project, lets continue the chat over here —> Go2rtc project - help thread

I have been using WebRTC player on my frontend for some time now, it was working great up until recently. I’m now getting an error: “ERROR: WebRTC server not available”, after some time it tries to restart the stream and it get’s the same error again.

When I hit F12 in my browser I see the following:

image

When I try to open the RTSP stream on my system it works great (through VLC player) for both the bunny.mp4 and my camera.

I honestly don’t know what has changed, but something must have changed.

Where can I start to troubleshoot.