Realtime camera streaming without any delay - WebRTC

But I do see the stream zeroconfig occuring in my nest cam on the google hub without any configuration setup for that camera in go2rtc. It works (im using RTSPtoWebRTC with go2rtc). Its just really slow to come up.

go2rtc logs:

16:42:42.096 INF [streams] create new stream url=rtsps://stream-ue1-delta.dropcam.com:443/sdm_live_stream/REMOVED?auth=REMOVED
16:42:42.125 DBG [streams] probe producer url=rtsps://stream-ue1-delta.dropcam.com:443/sdm_live_stream/REMOVED?auth=REMOVED

camera attributes:

model_name: Display
brand: Google Nest
frontend_stream_type: web_rtc

Seems I was wrong. I havenā€™t checked the Nest sources for long time. Current version can get camera RTSP link.

Thanks for all the replies everyone. I did some investigating to see if the problem with my Nest audio was at the go2rtc level or with the RTSPtoWebRTC integration. Seems like itā€™s go2rtc. To test it, I reinstalled the RTSPtoWeb addon by @allenporter, and paired it with the RTSPtoWebRTC integration, and all the audio works well, for the Foscams and the Nest cam. The main reason I donā€™t use the RTSPtoWeb addon is because I need remote access to my cameras, which go2rtc does beautifully.

So it seems the issue with Nest cam audio is with go2rtc. I tried viewing the camera using the addon web interface and audio was also not available. See below the info of the stream when viewed in my Android in case that helps. I also tested it from my desktop using chrome and same behavior.

[{"media:0":"audio, sendonly, 96 MPEG4-GENERIC/16000/2","media:1":"video, sendonly, 97 H264/90000","receive":16995,"remote_addr":"##.##.##.###:###","send":0,"track:0":"97 H264/90000, sinks=1","type":"RTSP client producer","url":"rtsps://stream-uc2-charlie.dropcam.com:443/sdm_live_stream/XXXXXXXXXXXXXXXX"},{"remote_addr":"udp4 host ##.##.##.###:51441","send":16841,"type":"WebRTC server consumer","user_agent":"Mozilla/5.0 (Linux; Android 13; Pixel 6 Build/TP1A.220624.021; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.79 Mobile Safari/537.36 Home Assistant/2022.8.0-2624 (Android 13; Pixel 6)"}]

One thing to add is that this may become a mute point once @AlexxIT incorporates the addon as the back bone of the WebRTC custom component, at which point Iā€™ll be able to use the custom component for my Foscams and leave the Nest Cam alone.

As of now, the WebRTC custom component is very unstable for me, and gives me a ā€œERROR: NotSupportedError: Failed to execute ā€˜addSourceBufferā€™ on ā€˜MediaSourceā€™: The type provided (ā€˜video/mp4; codecs=ā€œavc1.000000ā€ā€™) is unsupported.ā€ error very often, regardless of whether I set up my Foscams using the camera entity or the RTSP url itself.

That makes sense though. Mpeg4 isnā€™t supported through webrtc.

WebRTC technology doesnā€™t support AAC audio (MPEG4-GENERIC). You can hear sound only with HLS technology (default for Hass) or MSE technology (WebRTC Camera custom component).

go2rtc also support MSE, but audio doesnā€™t work well yet.

You can get audio with WebRTC technology with using on the fly transcoding feature.

Unfortunately though thereā€™s really no way to reference the nest integration camera in the go2trc to do this though because the url changes with the authorization. So we canā€™t reference it by rtsp url, hass camera, etc.

Might there be a possibility for another way to reference cameras /streams like this by entity_id or something else?

Interesting, I wonder how the RTSPtoWeb addon is doing it. Because the sound for my Nest Cam does work when I use that with the RTSPtoWebRTC integration.

I put a link above to the core API integrations use to get the url. (Built into core)

If you can hear AAC sound, this means only one - WebRTC donā€™t works and you viewing built-in HLS stream. If you stop the addon - nothing will change.

Yes, Nest uses aac as far as I know.

Interesting, just to make sure weā€™re all on the same page, let me summarize the behavior Iā€™m seeing:

  1. No integrations/addons: Nest cam (yes audio); Foscams (no audio)
  2. RTSPtoWeb addon + RTSPtoWebRTC integration: Nest (yes audio); Foscams (yes audio); only works locally.
  3. go2rtc addon + RTSPtoWebRTC integration: Nest (no audio); Foscams (yes audio); works remotely.

So my questions are:

  1. Does the RTSPtoWeb addon use the built-in HLS stream of the Nest cams instead of WebRTC? If not, Iā€™m not sure how it is that the audio works for both the Foscams and the Nest cam when Iā€™m using it.
  2. If the only fix for the Nest cam audio to work with go2rtc is to exclude it from the using WebRTC, any chance we could add a setting to either enable the on-the-fly setup of streams? This way, I could set up only my Foscams to work via go2rtc, and let the Nest cam use the built-in integration.

Thanks again to all of you for making these great addons happen, really appreciate it.

The two main issues here are:

  1. you canā€™t reference that camera easily in go2rtc so that you can add audio to the webrtc feed by transcoding.
  2. you canā€™t exclude cameras from automatically being pulled into the RTSPtoWebRTC/go2rtc feeds.

@nprez83 you do have options though.

  1. You can add all your foscam cameras to the go2rtc.yaml
  2. You can then add each of those cameras as generic cameras in HA using the go2trc URL (rtsp://127.0.0.1:8554/-go2trc_entry-).
  3. remove the RTSPtoWebRTC integration
  4. you now have all your cameras that you want webrtc for managed and the ones you donā€™t want excluded.

You still do not have webrtc for the nest camera using the above. That will still use HLS because of issue #1 above. THereā€™s no way in the go2rtc to reference that camera to transcode audio to something like opus/pcm.

IMO, Home Assistant should be giving us rtsp URLs for cameras like they do for its still images in the cameras properties.

I donā€™t know why RTSPtoWeb addon may donā€™t work for your Nest cameras.

For now you may use go2rtc for transcodings audio to AAC format for your Foscams. And donā€™t use WebRTC at all for all your cameras. So you get audio for all of them.

Iā€™ll think how to add transcoding for zero-setup cameras.

Thanks for your help @calisro. I tried this, but I must be doing something wrong, because I still canā€™t get the audio to work with my Foscams in lovelace. Hereā€™s what Iā€™ve done. Iā€™ve set up the streams for my 3 Foscams in the go2rtc.yaml file. The sound works well when I open the webrtc option via the go2rtc addon webui. I then created the 3 generic camera entries as you described, for example one of them is rtsp://127.0.0.1:8554/baby_cam_1. Iā€™ve removed the RTSPtoWebRTC integration altogether.

Unfortunately, when I add the generic camera to my lovelace the audio doesnā€™t work. Should I be specifying the audio codec in the rtsp url?
Iā€™ve tried the following:
rtsp://127.0.0.1:8554/baby_cam_1?video&audio=opus
rtsp://127.0.0.1:8554/baby_cam_1?video&audio=pcmu
rtsp://127.0.0.1:8554/baby_cam_1?video&audio=pcma

I just canā€™t seem to get the sound to work in lovelace with either google chrome or the home assistant Android companion app. Again, sound works when the Foscamā€™s viewed using the go2rtc addon webui in both chrome and the companion app.

Thatā€™s not how it works. When you get RTSP from go2rtc, you can filter tracks with codecs. As you do. But this tracks should be already in stream. So you need to config streams with ffmpeg source type and transcoding options.

streams:
  baby: ffmpeg:rtsp://...#video=copy#audio=aac

rtsp://localhost:8554/baby

You can also do this:

streams:
  baby:
  - rtsp://...
  - ffmpeg:rtsp://...#audio=aac
  - ffmpeg:rtsp://...#audio=opus
  - ffmpeg:rtsp://...#audio=pcmu
  - ffmpeg:rtsp://...#audio=pcma

Now you have stream with all audio codecs. Now filters can be useful

rtsp://localhost:8554/baby?video&audio=aac

1 Like

Hereā€™s one example entry from a reolink camera.

  backyard_main:
    - rtsp://xxxx:[email protected]/h264Preview_01_main
    - ffmpeg:rtsp://xxxx:[email protected]/h264Preview_01_main#audio=opus

That will pass the existing stream AND a new stream with JUST audio in opus codec to teh client. The client will pick from the 2 streams any codecs that match. That will give you video from the first entry and audio from the second on browsers/clients that donā€™t support the audio stream from the first one.

Then I added that cameras to generic with URL:

snapshot: existing snapshot URL from the reolink camera.  This is used by the glance cards, for example, to see intermittant image changes
rtsp: rtsp://127.0.0.1:8554/backyard_main

EDIT: didnā€™t see Alexā€™s examples. :slight_smile: now you have two sets.

Alright guys, at this point I feel Iā€™m just being plain dumb, so I deeply apologize but I still canā€™t get the audio to work. Hereā€™s my go2rtc.yaml config:

streams:
  baby_cam_1: 
    - rtsp://xxxx:[email protected]:39761/videoMain
    - ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=aac
    - ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=opus
    - ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=pcmu
    - ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=pcma

rtsp:
  listen: ":8554"

ffmpeg:
  bin: ffmpeg

Unfortunately I get the following error in the addonā€™s log:

16:00:28.060 ERR [api.ws] readJSON error="websocket: close 1000 (normal)"
16:00:33.102 WRN [streams] stop empty producer url=ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=aac
16:00:33.102 WRN [streams] stop empty producer url=ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=opus
16:00:33.103 WRN [streams] stop empty producer url=ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=pcmu
16:00:33.103 WRN [streams] stop empty producer url=ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=pcma

I feel like somethingā€™s going on with my ffmpeg setup up, just not sure what it is. Iā€™m running hass os in an RPI 4 btw, and have go2rtc installed as an addon.

  1. You can remove this. I donā€™t think itā€™s causing you issues though.
ffmpeg:
  bin: ffmpeg
  1. Change to this for now:
streams:
  baby_cam_1: 
    - rtsp://xxxx:[email protected]:39761/videoMain
    - ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=opus
  1. Add these so you can see more info in the logs:
log:
  level: debug
  api: debug
  rtsp: debug
  streams: debug
  webrtc: debug
  mse: debug
  hass: debug
  homekit: debug
  1. Open the go2rtc UI and make sure audio/video comes through when clicking the ā€˜webrtcā€™ link.

  2. Create a generic camera in HA pointing to this URL:
    rtsp://127.0.0.1:8554/baby_cam_1

  3. Add a lovelace glance card pointing to the generic camera you just created or even you can just open the ā€˜more infoā€™ on the entity itself.

  4. See if audio comes through.

EDIT:

Although I just read this part of what you said:

That tells me go2rtc is setup properly. Meaning you can probably start at step 5 aboveā€¦ How do you have your generic camera and your lovelace setup?

Alright, I followed all of your steps, and hereā€™s what I got.

  1. Hereā€™s the logs result if I declare the generic camera without any filters as rtsp://127.0.0.1:8554/baby_cam_1
s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
13:28:12.660 DBG [app] arch=arm64 conf_size=1655 cwd=/config os=linux
13:28:12.662 INF [rtsp] listen addr=:8554
13:28:12.665 INF [hass] load stream url="hass:Baby Cam 1"
13:28:12.666 INF [api] listen addr=:1984
13:28:12.667 INF [webrtc] listen addr=:39760
13:28:12.668 INF [srtp] listen addr=:8443
13:28:27.765 DBG [rtsp] new consumer stream=baby_cam_1
13:28:27.765 DBG [streams] probe producer url=rtsp://xxxx:[email protected]:39761/videoMain
13:28:27.805 DBG [streams] start producer url=rtsp://xxxx:[email protected]:39761/videoMain

This doesnā€™t seem to be even attempt to pull the ffmpeg stream.

  1. On the other hand, this is the log output when I declare the generic camera with the opus filter as rtsp://127.0.0.1:8554/baby_cam_1?video&audio=opus
s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
13:30:36.926 DBG [app] arch=arm64 conf_size=1655 cwd=/config os=linux
13:30:36.928 INF [rtsp] listen addr=:8554
13:30:36.931 INF [hass] load stream url="hass:Baby Cam 1"
13:30:36.932 INF [api] listen addr=:1984
13:30:36.933 INF [webrtc] listen addr=:39760
13:30:36.934 INF [srtp] listen addr=:8443
13:30:44.072 DBG [rtsp] new consumer stream=baby_cam_1
13:30:44.073 DBG [streams] probe producer url=rtsp://xxxx:[email protected]:39761/videoMain
13:30:44.107 DBG [streams] probe producer url=ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=opus
13:30:44.109 DBG [exec] run url="exec:ffmpeg -hide_banner -allowed_media_types audio -fflags nobuffer -flags low_delay -rtsp_transport tcp -i rtsp://xxxx:[email protected]:39761/videoMain -codec:a libopus -ar 48000 -ac 2 -vn -rtsp_transport tcp -f rtsp rtsp://localhost:8554/0676cff6569a2412ad729598d290affe"
13:30:44.370 DBG [exec] run launch=260.907518ms
13:30:44.370 DBG [streams] start producer url=rtsp://xxxx:[email protected]:39761/videoMain
13:30:44.371 DBG [streams] start producer url=ffmpeg:rtsp://xxxx:[email protected]:39761/videoMain#audio=opus
13:31:01.955 DBG [rtsp] new consumer stream=baby_cam_1
13:31:02.044 WRN [stream] can't get track

This way of declaring the camera at least seems to attempt to pull the opus track, even though in the end it fails.

Iā€™m using picture glance cards to test right now, although I ultimately use picture elements cards to incorporate PTZ controls.

I tested from Chrome and the Android app. Any thoughts?