Realtime camera streaming without any delay - WebRTC

Trying to start stream means problem between home assistant server and camera. It’s strange because Sonoff camera works well in my case

And the rtsp streams work perfectly in MotionEye as well. Tried both accessing the HA instance through local IP (no SSL) and external domain through NGINX + SSL.

OK. This is what I’ve got:

2021-04-22 13:51:19 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/04/22 13:51:19 Stream Try Connect rtsp://192.168.1.7/ch0_0.h264
2021-04-22 13:51:22 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/04/22 13:51:22 dial tcp 192.168.1.7:554: i/o timeout
2021-04-22 13:51:22 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/04/22 13:51:22 Stream Exit On Demand No Viewer
2021-04-22 13:51:24 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/04/22 13:51:24 Stream Codec Not Found
2021-04-22 13:51:24 DEBUG (webrtc) [custom_components.webrtc.utils] [GIN] 2021/04/22 - 13:51:24 | 200 |  5.032313842s |       127.0.0.1 | POST     "/stream"
2021-04-22 13:51:24 ERROR (MainThread) [custom_components.webrtc] Can't start stream: rtsp://192.168.1.7/ch0_0.h264, because: 0, message='Attempt to decode JSON with unexpected mimetype: ', url=URL('http://localhost:8083/stream')
2021-04-22 13:51:25 ERROR (MainThread) [custom_components.webrtc] Can't start stream: None, because: 'camera'
2021-04-22 13:51:27 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/04/22 13:51:27 Set ICEServers [stun:stun.l.google.com:19302]
2021-04-22 13:51:27 DEBUG (webrtc) [custom_components.webrtc.utils] [GIN] 2021/04/22 - 13:51:27 | 200 |  147.851143ms |       127.0.0.1 | POST     "/stream"

habe the same issue since today :frowning: Opera not supported. i use chrome not opera and i have all cams running well . i ununstalled and added the component again but no success … any solutions here? logs:

2021-04-22 14:46:25 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/04/22 14:46:25 terminated
2021-04-22 14:46:25 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/04/22 14:46:25 Exiting
2021-04-22 14:46:25 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/04/22 14:46:25 Server Start Awaiting Signal

that’s all i see

EDIT: Works with latest version.

Is there any way to hardcode that it opens in fullscreen was watchng the code but didn’t find the right part of the code i fear :frowning: Maybe it’s possible to have a config opetion to start stream in fullscreen?

Thank you @AlexxIT. I have had a Grandstream GDS3710 door station and the lag on video made it very unfriendly. With you project it is working well. Thank you so much.
I am finding since the last update that the card seems to be takign a long time to start.

The card is saying Init connection and if I hit f12. I see the following. The logs seem normal.
‘Uncaught DOMException: Failed to execute ‘define’ on ‘CustomElementRegistry’: the name “webrtc-camera” has already been used with this registry’
Do you have any suggestions.
Thank you again for this amazing project.

Try to find a version when all works fine (reinstall from HACS).

I’m getting the same issue with 1.3: Chrome reports same DOME exception.
Strangely it works for me on android (either in HomeAssistant app or in Chrome for android)

The debug log reports:

2021-04-23 13:46:30 DEBUG (webrtc) [custom_components.webrtc.utils] [GIN] 
2021/04/23 - 13:46:30 | 200 | 63.28649ms | 127.0.0.1 | POST "/stream"

2021-04-23 13:46:30 DEBUG (MainThread) [custom_components.webrtc] New stream to url: rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov

2021-04-23 13:46:34 DEBUG (webrtc) [custom_components.webrtc.utils] 
2021/04/23 13:46:34 Client Not Send ACK (probably the browser is minimized) or tab not active Close client

2021-04-23 13:46:34 DEBUG (webrtc) [custom_components.webrtc.utils] 
2021/04/23 13:46:34 Stream Not Send Video Close

2021-04-23 13:46:34 DEBUG (webrtc) [custom_components.webrtc.utils] 
2021/04/23 13:46:34 WritePacket WebRTC Client Offline

Welcome any thoughts on how to solve this!

This is great! Got it working with the Eufy Indoor 1080 and the 2k; but sadly no sound since they both us AAC for audio.

I haven’t tried rolling back to different versions, but I just tired Edge and the card loads in a few seconds, yet with Chrome it takes around 40 seconds and shows init connection during that time. I would prefer chrome. Any suggestions why Edge works so much faster than Chrome?

I also have this same issue in chrome developer tools.
Also the following in home-assistant.log:

2021-04-26 11:17:54 ERROR (MainThread) [frontend.js.latest.202104073] http://hass.home:8123/lovelace/default_view:0:0 Uncaught

Anyone have a solution?

There is still some problem with the ressource usage when stream is not used with the last version. :slight_smile:
When I restart Home Assistant, my CPU load average is about 3-4%. As soon as I open the tab where my 4 WebRTC lovelace cards are included, my CPU load jumps to 10-15%, which is OK I guess. but then it does not ever go back lower than 10%. I can wait for 5 jours, close my HA tab, close Chrome,…
The only way to get my CPU load average to 3-4% is to restart HA and not open the tab including the WebRTC cards.
It’s not a big issue in my case as my CPU is not overloaded.
What is the expected behaviour ? CPU ressource should be freed when streams are not used for a few minutes for example ?

Hmm suddenly it stopped to work on android Chrome and HA official app via nabu casa with error:

unable to start track, codec is not supported by remote

the same access works OK from PC. Maybe android issue?

Latest master version has a solution

1 Like

Thanks! Latest master seems to have solved my issue. No errors in console and home assistant log anymore and webrtc cards still working in Lovelace GUI.

1 Like

Found the right configuration on the camera itself. Now I have correct ratio.

@RipperChile it’s your issue on GitHub? No need to fix it?

No Alex, it was on the camera configuration. Thanks

Can you please share the configuration, I have a Dahua camera as well

HI, any experience with foscam camera?

regards

In tje camera config, in the video section, look for the 720P video (1280 × 720). It is in the substream 2, I had it disable.