Realtime camera streaming without any delay - WebRTC

your config directory. Same directory as your configuration.yaml

After weeks of frustration because of very unstable connections of my Tapo cams, with ‘no connection/no video’ messages which occurred very randomly but often,; I finally seem to have found a solution for this!

There is an option called ‘rtsp passthrough’ which you can find at WAN > nat passthrough. (Asus router) Since I Disabled (!) this option, all connection seems to wake up and stream seamlessly.

Maybe this is common knowledge, (because tbh I don’t know what it in fact should be doing) but I always thought it sounds like it should be enabled because you want your rtsp streams to pass through right?? :sweat_smile:

Anyway Hopefully this will help some of you guys - with an Asus router (?)

I have it enabled in mine but mine is also a hybrid firmware from Merlin. Mine is actually set to ‘enabled + nat helper’. All works.

But frankly, you don’t need it enabled so I also disabled it.

1 Like

Hi there.

I have installed this via HACS and added it as an integration but it has not created the custom lovelace card.

How can i get the card installed??

Thanks.

Hi all looking for some help, I basically am running into the issue where some camera’s live stream isn’t consistently starting. I have about 12 cameras and any time I open my Lovelace view using the custom card anywhere from 2-5 camera’s fail to start the live stream. Usually I have refresh the page a few times for them to come online. I had a look at the logs and here is what I am seeing.

Anyone have any possible solutions?

I also opened a github issue here with some more info.

2022-12-19 11:21:59.643 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:21:59 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37314: i/o timeout

2022-12-19 11:21:59.647 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:21:59 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:21:59.676 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:21:59 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37346: i/o timeout

2022-12-19 11:22:14.030 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:14.081 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37312: i/o timeout

2022-12-19 11:22:14.372 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:14.373 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:14.407 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37326: i/o timeout

2022-12-19 11:22:14.409 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37356: i/o timeout

2022-12-19 11:22:14.578 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:14.612 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37310: i/o timeout

2022-12-19 11:22:14.701 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:14.755 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37342: i/o timeout

2022-12-19 11:22:14.763 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:14.789 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:14.796 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37314: i/o timeout

2022-12-19 11:22:14.819 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:14 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37346: i/o timeout

2022-12-19 11:22:29.193 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:29.228 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37312: i/o timeout

2022-12-19 11:22:29.532 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:29.533 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:29.573 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37356: i/o timeout

2022-12-19 11:22:29.585 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37326: i/o timeout

2022-12-19 11:22:29.798 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:29.842 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37310: i/o timeout

2022-12-19 11:22:29.912 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:29.921 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:29.952 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:29.959 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37342: i/o timeout

2022-12-19 11:22:29.973 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37314: i/o timeout

2022-12-19 11:22:29.986 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:29 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37346: i/o timeout

2022-12-19 11:22:44.336 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:44 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:44.374 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:44 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37312: i/o timeout

2022-12-19 11:22:44.694 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:44 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:44.695 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:44 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:44.747 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:44 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37356: i/o timeout

2022-12-19 11:22:44.749 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:44 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37326: i/o timeout

2022-12-19 11:22:44.966 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:44 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:45.019 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:45 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:37310: i/o timeout

2022-12-19 11:22:45.032 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:45 Set ICEServers [stun:stun.l.google.com:19302]

2022-12-19 11:22:45.033 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/19 11:22:45 Set ICEServers [stun:stun.l.google.com:19302]

The card should automatically be added when you add downloaded the HACS integration. Have you cleared browser cache and restart Home Assistant to double check? Is the resource listed in your dashboard resources?

having same issue , watching the camera on chrome even when i’m on same network.
What can be done in order to improve it ?
When im watching the cameras through DMSS for example there’s no issue at all which prove no issue with camera stream - and this when connecting outside the house.

You are trying to compare an average browser and standalone software that can be written in any programming language and use any libraries.

The browser has only three ways to retrieve data from the server. This component uses two of them (by default, HA uses the third one).

In addition, when using DMSS, the connection can pass through the cloud servers of the manufacturer of your camera. Because you paid for them when you bought the camera.

When you use a regular browser, no one will give you a free server through which you can connect to your camera.

So you just need to carefully read the component documentation on setting up external access. You can set up fast external access in any case. But in some complex cases, you may need extensive IT skills


Hello,

I am a new comer in the fantastic world of HA since some weeks, I was unhappy with camera on HA until I discovered WebRTC custom integration, works perfectly when viewing from Android app internal or external, anyway on desktop browser (Chrome) it work half of the time, looking at the debugger, there are different error :

/OFFTOPIC BEGIN

e318687c.js:2 Uncaught (in promise) Error: Map container is already initialized.
    at i._initContainer (e318687c.js:2:37860)
    at i.initialize (e318687c.js:2:26233)
    at new i (e318687c.js:2:2911)
    at Object.ee [as map] (e318687c.js:2:46362)
    at ha-entity-marker.ts:6:1
    at async c.value (ha-entity-marker.ts:6:1)

or

Uncaught (in promise) DOMException: Failed to execute 'setRemoteDescription' on 'RTCPeerConnection': Failed to set remote answer sdp: Called in wrong state: stable

Depending on the error the card size change from black square, grey rectangle, working video, three cases, it may be a browser bug or something wrong in WebRTC

And sometime it works flawlessly, so I refresh F5, times to times
 I would hapilly try to grab some more information and try to debug if I got some time.

Anyway this is offtopic but I wanted to let you know @AlexxIT , just in case
/OFFTOPIC END

So I have a question, there is WebRTC (custom integration) wich works nearly perfectly, but I learned on this thread that there is also now go2RTC (external service/docker) and rstpToWebRTC (external service/docker)

I am a bit confuse/lost on how they integrate in what they perform differently, and when one should go for WebRTC, go2RTC, rstpToWebRTC ?

Which one would you recommend to go for ? or maybe my question is irrelevant ?

I use the docker installation for HA, would you recommend to install the Docker version of go2rtc to improve the custom component WebRTC ? is it easy to link it to HA (when unable to use addon as it is the Docker installation of HA) and what rtspToWebRTC is finally for ?

To say it more simply, what your setup recommendation to build an automation with camera on a raspberry pi and the docker version of HA ?

@joaopedros2 - did u find a way solving it?
Based on AlexxIT reply this is expected for MSE but is there any way improving it?

Ok after some time of reading and testing I can answer my own question !

The way to go is to use go2rtc as a service (Docker in my case)
Configure HA intégration RTSPtoWebRTC to use the go2rtc service using by default URL http://xx.xx.xx.xx:1984
Use Generic camera in HA

It is a lot more reliable than WebRTC (WebRTC was working perfect on phone, but it was a disaster on PC, tested with Chrome and Edge, lot of JS error in console & Network, and lot of black video when changing page, or changing window size, or anything else, not reliable in my experience)

Using “Generic camĂ©ra/RTSPTOWebRTC/go2rtc” combo works like a charm !! great job @AlexxIT no need of WebRTC any more, and a lot more reliable, no flickering, no/ (or few) disconnection, a bit more lantency (not much 1 or 2 secondes)

Now my question is what about camera configuration protocole TCP/UDP/Multicast-UDP/HTTP ? I would suppose UDP is the best but does this configuration is really used by go2rtc @AlexxIT ?

1 Like

The only thing missing now is a dedicated HA cards, the WebRTC one was prettier.

outside question: is anyone able to call Ranger 2C Ovif PTZ ???

The built in default camera card works though right? You’re just looking for extra features in the standard card?

Is a Imou camera right? Please have a look at the cloud integration. Ptz works like a charm.

The built in default camera card works though right? You’re just looking for extra features in the standard card?

Yes it works very well (I got just some trouble on remote access, it does not work all the time, I wonder why), about the layout it is just that the WebRTC cards looks better IMO : like standard camera control on overlay

I tried but got an error on creating App on Imou life platform and cant go further, also I am not a big fan of propriotary cloud
 I would prefer it workd with the Onvif integration

Remote access can be configured with a stun server from the integration options, though i haven’t tried it with go2rtc it works with RTSPtoWeb and probably works in go2rtc too.

The regular onvif works fine too for me, 2012.12 however had a memory leak and made me move to the cloud integration. I got an Rex. But we’re getting off topic. So my cents; it should work. Good luck

go2rtc only uses the RTSP TCP protocol. It has less problems and is more stable for general users.

Ok so I believe their is no need to forward any other ports than HA HTTP, as video goes through it too via Web socket ?