Realtime camera streaming without any delay - WebRTC

I think that this add on should be added as build in add on from Home Assistant

1 Like

First of all, I want to mention that I like your wonderful contribution Alexey.
I have 8 cameras active; and as far as I can see in the cards, every camera is immediately live and goes to pause after a click. With 8 cameras it becomes restless and slows down.
Is there an option to start with pause and then have to click (per card) to go to live.

@johnvanl you may discuss this feature here. Iā€™m trying to understand why a user would want to look at a camera that doesnā€™t work.

Support my feature request!

1 Like

Thank you for this addon! Is it possible to add on the card option for camera TPZ? On my picture-glance card Iā€™m able to put the options to move my camera and it would be great to do the same on this card. Thank you

Refer below link for ptz config

2 Likes

Terrific, itā€™s working. Thank you very much

Thanks for this. The PTZ works great.

I found that the ptz controls disappear in full screen. Is this normal?

1 Like

@AlexxIT, thank you for this integration! Amazing to see my camera feed on Lovelace with no delay.

In the README.md, it says:
the video will play using MSE. As soon as WebRTC is able to connect - video will play through it, MSE will be stopped.

And in the config, there is an option to disable MSE:
mse: false # disable MSE mode

I disabled MSE mode but when I open Lovelace, the card shows that the camera is still connecting/connects first via MSE (shown by the icon on the upper right) then shifts to WebRTC after ~45 seconds. Is it possible for the connection to go directly to WebRTC?

Iā€™m using a camera with AAC audio codec so sound only works in MSE mode. However, the video is very jumpy in MSE mode so I just want to use WebRTC mode even without audio.

To contribute to the list of working cameras, I can confirm that the Wansview Q6 (PTZ) camera is working with this integration both in WebRTC and MSE mode. Sound is supported in MSE mode only because the camera uses AAC audio codec. I added the camera to HA using the ONVIF integration and then I am able to make the pan and tilt controls work using the following config:

type: 'custom:webrtc-camera'
url: 'rtsp://username:password@cameraipaddress:554/live/ch0' #FHD stream, use ch1 for SD
#entity: camera.your_camera #can also be used instead of url: 'rtsp://username:password@cameraipaddress:554/live/ch0'
ptz:
  service: onvif.ptz
  data_left:
    entity_id: camera.your_camera
    pan: LEFT
    speed: 1
    distance: 0.3
    move_mode: ContinuousMove
  data_right:
    entity_id: camera.your_camera
    pan: RIGHT
    speed: 1
    distance: 0.3
    move_mode: ContinuousMove
  data_up:
    entity_id: camera.your_camera
    tilt: UP
    speed: 1
    distance: 0.3
    move_mode: ContinuousMove
  data_down:
    entity_id: camera.your_camera
    tilt: DOWN
    speed: 1
    distance: 0.3
    move_mode: ContinuousMove

Canā€™t make the zoom controls work. If anyone knows how to configure the zoom controls, please share. :slightly_smiling_face:

Disabling MSE in master version. Not in release yet. Both tech starts simultaneously. Disabling MSE wonā€™t help start video faster

1 Like

This is what i see on my Galaxy S20 with official Home Asistant app in my home network and external. Video stream is broken. On Xiaomi Redmi Note 8 Pro all is ok. Do you have any idea whatā€™s wrong?

What about bunny video. If it works fine?

Yes, works without problems

Hi @AlexxIT
would it be possible to start streaming video on the card only through a ā€œplayā€ button?

I noticed that when the camera is off (I only turn it on when I am away from home), and I view the card on Home Assistant, WebRTC always tries to view the video and tries to reconnect continuously to the webcam, increasing the CPU usage and consumption.

Even when I close Home Assistant, however, the CPU load remains high compared to when I donā€™t see the WebRTC card.

Congratulations for the component, it is the only one that shows the rstp video stream in real time with audio listening.

Thank you

Thanks for the info, @AlexxIT.
Iā€™ll probably just return the Wansview Q6 and just get the Sonoff GK-200 camera since it seems to work in WebRTC mode with audio based on @MikeF9 comment.

Hello Alexey !

WebRTC works fine with my 4 cameras (Hikvision, and Annke flashed with an Hikvision firmware).
However I faced the same issues twice this morning when I tried to access the lovelace tab where my cam streams are displayed from my professional laptop. It uses a corporate VPN, I guess thatā€™s the issue.
WebRTC streams did not load, which is not the issue, I expected this result. The problem is that WebRTC process was stuck at 99% on one core of my CPU, even after changing of lovelace tab. The only solution I found was to restart Home Assistant Core.
It happened twice.
I did not take any log, I just restarted to get everything running back ASAP.
But Iā€™m pretty sure I can easily reproduce it.
What would be the best way to capture relevant logs ?

Thanks,
David

Changing Lovelace tab wonā€™t stop connection retries. Only refresh tab stops.

What CPU loading you have when you at home?

When I start HA my CPU average is about 3-4%. When I open the tab with the 4 WebRTC streams, it goes up to 10-15% average.
With the last versions of WebRTC, whenever I donā€™t use it for some time, it goes down to 7-8% idle.

When I open it from my professional notebook, it increses slowly from 5% to 100%, with WebRTC64 process taking 95% of the CPU.

Example of WebRTC logs at debug level when my CPU goes up to 100% in a few minutes :

2021-05-11 12:52:51 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:52:51 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43980: i/o timeout
2021-05-11 12:53:00 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:00 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:01 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:01 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43986: i/o timeout
2021-05-11 12:53:15 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:15 Stream Try Connect rtsp://HomeAssistant:[email protected]:554/Streaming/Channels/2
2021-05-11 12:53:16 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:16 Stream Try Connect rtsp://HomeAssistant:[email protected]:554/Streaming/Channels/2
2021-05-11 12:53:22 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:22 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:22 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:22 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:22 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:22 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:22 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:22 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:22 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:22 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:23 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:23 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43980: i/o timeout
2021-05-11 12:53:24 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:24 Stream Try Connect rtsp://HomeAssistant:[email protected]:554/Streaming/Channels/2
2021-05-11 12:53:25 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:25 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:26 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:26 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43980: i/o timeout
2021-05-11 12:53:27 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:27 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:27 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:27 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43976: i/o timeout
2021-05-11 12:53:27 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:27 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43986: i/o timeout
2021-05-11 12:53:33 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:33 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57858: i/o timeout
2021-05-11 12:53:33 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:33 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57894: i/o timeout
2021-05-11 12:53:47 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:47 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:47 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:47 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:47 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:47 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:47 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:47 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:47 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:47 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:47 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:47 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:48 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:48 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43976: i/o timeout
2021-05-11 12:53:48 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:48 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43986: i/o timeout
2021-05-11 12:53:50 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:50 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:53:51 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:51 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43976: i/o timeout
2021-05-11 12:53:52 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:52 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57858: i/o timeout
2021-05-11 12:53:52 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:52 muxerWebRTC.WritePacket WebRTC Client Offline
2021-05-11 12:53:52 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:52 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43980: i/o timeout
2021-05-11 12:53:52 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:52 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57894: i/o timeout
2021-05-11 12:53:52 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:52 muxerWebRTC.WritePacket WebRTC Client Offline
2021-05-11 12:53:55 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:55 Stream Exit On Demand No Viewer
2021-05-11 12:53:55 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:55 Stream Exit On Demand No Viewer
2021-05-11 12:53:56 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:56 Stream Exit On Demand No Viewer
2021-05-11 12:53:56 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:56 Stream Exit On Demand No Viewer
2021-05-11 12:53:57 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:53:57 muxerWebRTC.WritePacket WebRTC Client Offline
2021-05-11 12:54:07 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:07 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:07 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:07 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:07 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:07 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:07 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:07 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:07 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:07 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:07 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:07 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:08 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:08 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57894: i/o timeout
2021-05-11 12:54:10 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:10 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:10 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:10 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:11 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:11 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:11 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:11 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57858: i/o timeout
2021-05-11 12:54:11 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:11 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57894: i/o timeout
2021-05-11 12:54:11 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:11 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43980: i/o timeout
2021-05-11 12:54:12 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:12 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57858: i/o timeout
2021-05-11 12:54:12 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:12 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43980: i/o timeout
2021-05-11 12:54:12 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:12 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43986: i/o timeout
2021-05-11 12:54:12 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:12 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43976: i/o timeout
2021-05-11 12:54:18 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:18 muxerWebRTC.WritePacket WebRTC Client Offline
2021-05-11 12:54:25 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:25 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:25 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:25 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:25 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:25 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:26 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:26 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:26 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:26 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:26 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:26 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43986: i/o timeout
2021-05-11 12:54:26 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:26 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:26 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:26 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57858: i/o timeout
2021-05-11 12:54:26 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:26 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57894: i/o timeout
2021-05-11 12:54:26 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:26 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43980: i/o timeout
2021-05-11 12:54:30 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:30 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43976: i/o timeout
2021-05-11 12:54:38 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:38 muxerWebRTC.WritePacket WebRTC Client Offline
2021-05-11 12:54:42 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:42 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:42 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:42 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:42 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:42 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:42 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:42 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:42 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:42 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:42 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:42 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:43 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:43 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57858: i/o timeout
2021-05-11 12:54:43 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:43 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43980: i/o timeout
2021-05-11 12:54:43 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:43 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43986: i/o timeout
2021-05-11 12:54:43 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:43 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57894: i/o timeout
2021-05-11 12:54:43 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:43 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43976: i/o timeout
2021-05-11 12:54:46 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:46 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:54:55 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:54:55 muxerWebRTC.WritePacket WebRTC Client Offline
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57858: i/o timeout
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:57894: i/o timeout
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43976: i/o timeout
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43986: i/o timeout
2021-05-11 12:55:06 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:06 websocket.JSON.Send write tcp 127.0.0.1:8083->127.0.0.1:43980: i/o timeout
2021-05-11 12:55:07 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:07 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:55:09 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:09 Set ICEServers [stun:stun.l.google.com:19302]
2021-05-11 12:55:09 DEBUG (webrtc) [custom_components.webrtc.utils] 2021/05/11 12:55:09 Set ICEServers [stun:stun.l.google.com:19302]

Thatā€™s a lot of timeouts. Might be the issue.

Note : this test was made using configuration ā€˜mse: falseā€™ as a test

Amazing work! I really enjoy this addon.