Go2rtc project - help thread

This is perfect! Works like a charm. Between having my iframes working now, and the recent fix to the Nest audio in beta 6, I now have two options for my cameras:

  1. Skip the RTSPtoWeb integration, use built in conversion for Nest cam, and iframes for my Foscams
  2. Use RTSPtoWeb integration, which allows the Foscams to work right off the bat, and use transcoding for Nest Cam.

Gotta love options, thanks again @calisro

In order for this to work without the rewrite, I Believe you would have had to change your ‘basedir’ for the api in the go2rtc config. Revert it and try the rewrite I used instead.

I didn’t have to make any adjustments to ‘basedir’ - the config above that I posted worked with the default go2rtc setup.
I tried your nginx config with the rewrite, it works fine but still doesn’t let me do 2-way audio inside Home Assistant itself :cry: Thanks for the info though!

webrtc integration dont work for me anymore (continues reconnection issues) and i’m trying to move to this project.

can someone make a foolproof tutorial on how to make cards from rtsp? I have read the whole topic but I still do not understand how to do it. I write the steps that I have managed to do so far:

  • I have successfully installed go2rtc
  • I added all rtsp streams as generic camera
  • these cameras have appeared on the go2rtc homepage

now I don’t know how to insert them in the cards, because the only entities that appear to me are the generic ones and not those of go2rtc

There’s nothing more you need to do. your picture glance or camera cars will connect with webrtc. If you experience ‘no audio’ or want to customize it further, then you can using the go2rtc.yaml.

I’ve finally got 2-way audio working via Home Assistant!

I created this go2rtc.html file (that points to my Go2RTC https webrtc page) and stored it under /www in my HA directory. This has the additional option "allow=“microphone *;” which activates the microphone allowing 2-way audio.

<html>
    <head>
    </head>
    <body>
          <iframe src="https://mydomain.org/go2rtc/webrtc.html?src=frontdoor" allow="camera *;microphone *" frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:100%;width:100%;position:absolute;top:0%;left:0px;right:0px;bottom:0px" height="100%" width="100%"></iframe>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    </body>
</html>

I then add that html file as an iframe card in Home Assistant, it now works for 2-way audio when I access my Home Assistant instance over https! :partying_face:

type: iframe
url: https://homeassistant.mydomain.org/local/go2rtc.html
aspect_ratio: 76%
2 Likes

That’s interesting. I never thought to ask but what kind of phone?
I read you were on a Mac. All apple devices? Trying to understand the commonality because all of my devices prompt for microphone permissions.

Android: chrome and companion app
Linux: chrome

Doesn’t your html embed an iframe in an iframe? Fyi that you can copy all the html pages from go2trc GitHub and put them in your www directory and run it directly from there with the "static_dir parameter.

Hey Rob,
I’m using a Samsung S20+ phone, tested with both Chrome & companion app.
For desktop I’m using macOS & Firefox & Edge.

Yeah the html embeds an iframe within an iframe (Inception lol), but for some strange reason it works! Otherwise I haven’t had any success getting the microphone permission prompt!

Good shout about manually copying the html pages, I had considered that but figured the current way I’ve set it up would be easier for future go2rtc updates etc.

I’ve tested things further, I notice that the 2-way audio doesn’t work EVERY time I attempt it; the microphone is active on my device as per the built in OS indicators but no audio comes out of my doorbell. I suspect this is a go2rtc issue however.

One last mention. You can use card_mod to embed iframes manually if you’re using it in a popup or similar. Still inception iframes :slight_smile: but at least you don’t have some extra code in your www directory.

              hold_action:
                action: fire-dom-event
                browser_mod:
                  service: browser_mod.popup
                  data:
                    title: frontdoor_main Live2
                    size: wide
                    content: |
                            <iframe src="https://xxxxx/go2rtc/webrtc.html?src=frontdoor_main" allow="camera *;microphone *" frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:100%;width:100%;position:absolute;top:0%;left:0px;right:0px;bottom:0px" height="100%" width="100%"></iframe>
                            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
1 Like

Are you still getting the “Failed to start WebRTC stream: Timeout handling WebRTC offer” error? I get it somewhat frequently with my Nest cam, which as of beta 6 is going through ffmpeg for audio transcoding (thanks for that btw, huge win for me). I’m not exactly sure if the timeout is set by go2rtc or by the RSTPtoWebRTC integration (my suspicion is it’s the latter).

Yes still get it a lot. I I saw issues in github to better handle retries. I hope that helps.

Hi, sorry I’m not sure if I’ve missed it in this thread or in any documentation on the Go2RTC git but I can’t seem to make WebRTC accessible when off the LAN. Any advice/help is appreciated, I’m sure it’s me but I can’t figure it out!

I have installed the Go2RTC addon. Created go2rtc.yaml and entered:
webrtc:

listen: “:8555” # address of your local server (TCP)
candidates:
- stun:8555
streams:
Camera1: rtsp://[User]:[Password]@[IPAddress]/ch01/1

As I interpret the documentation, it says to port forward ex. 8555 to the HomeAssistant host (done) and if using Dynamic Public IP to use “Stun” as per my config.

My camera is showing in the WebUI and I can load the WebRTC stream but as soon as I’m off the LAN, it stops working - as per WebRTC Camera etc.

If anyone can spot what I’m missing / what I’ve misunderstood, that would be great. Thanks. :slight_smile:

That looks right. I’d guess its either the way you’re connected to the internet or your homeassistant/local setup?

1 Like

Thanks for the quick reply, appreciate it. I can’t figure it out.

By adding the following into go2rtc.yaml:
log:
level: info # default level
api: debug
rtsp: debug
streams: debug
webrtc: debug

I notice I’m getting this error, prompted when opening the WebRTC stream via the WebUI:

16:14:53.037 WRN [webrtc] candidate error=“address 2a02:c7e:1b8c:b00:47bb:275a:73bc:2f4b:8555: too many colons in address”
16:14:57.243 ERR [api.ws] readJSON error=“websocket: close 1000 (normal)”

Not sure if that’s relevant or not?.. That was opened on the Home Assistant Host i.e. on LAN. My access to Home Assistant external is via Nabu Casa so I’ve done little setup there.

Once I have the camera in go2rtc, what address do I use to connect the WebRTC stream to a lovelace card i.e. WebRTC Camera Card or Picture Entity, is it an address to use or should I see an Entity for the camera in go2rtc?

That looks like a IPV6 address. Not sure. Do you have IPV6 enabled in HA or something? Is your internet address IPV6? Can’t help too much here…

You can use (like the documentation says) a picture glance or camera card or add it as a generic camera.

Its here:

1 Like

That looks like a IPV6 address. Not sure. Do you have IPV6 enabled in HA or something? Is your internet address IPV6? Can’t help too much here…

You’re right, it’s the IPV6 address of my HA; Took me a second to realize but I’ve disabled IPV6 in HA now - to clear the waters a bit. Should’ve been IPV4, strange that WebRTC would default to v6.

No change in disabling it though. Ok, no worries. I’ll keep tinkering and update my comments if/when I figure it out. :slight_smile:

You can use (like the documentation says) a picture glance or camera card or add it as a generic camera.

Ok, I’ve not managed to get any Camera entities to show from the RTSPtoWebRTC integration however at least I was on the right track, I’ll cross that bridge when I get to it… Thank you.

Thanks again :+1:

After doing that, you restarted HA? The port forward from your router is to your IPV4:8555 address of HA? After that, you should be able to use the addons UI page to view your cameras remotely. You should test from the go2rtc UI remotely to begin with.

Yeah, restarted HA and that’s when the error disappeared from go2rtc. Port forward is 8555 to IPV4 (192.168.X.X) address.

I can’t get the addons UI page to work remotely though. I can get to it, but no streams open. Unlike on the HA host machine, it opens fine. Feels as if port forwarding isn’t working.

I don’t use nabucasa but I don’t think that should matter. The stun should detect your external IP and webrtc should negotiate directly.

Not sure if this is useful feedback but thought I’d share in case it points to a deeper issue. As I’ve mentioned, I have 3 Foscams ( two R2Cs and one R4), and a Nest Cam (via a Nest Hub max). Beta 6 fixed my Nest Cam audio issue by adding audio transcoding to the go2rtc.yaml:

"camera.nest_cam": ffmpeg:{input}#video=copy#audio=opus"

I thought the Foscams were working well without any additional settings, but in reality only the R4 has constant motion, so that’s the only one I was sure looked good. I later realized when I tested the R2Cs with motion, that their video actually looked quite choppy, when displayed using a picture-elements card, the info tab of the entity, but also via the addon WebUI. I then added similar transcoding settings for the Foscams as the one above for my Nest cam, and that finally fixed the video. Here is the info for one of the R2Cs when it’s working (top) and when it’s not (bottom). The main difference I see is without the transcoding settings, the audio codec is PCMU instead of OPUS (obviously), and the RTSP stream is listed as client producer, rather then server producer. Maybe one way taxes the cameras more than the other? The R2Cs are older than the R4, so maybe that’s why the R4 works well regardless of the transcoding settings.

Thought I’d share in case it helps improve something. Again, all 4 cameras work well by defining all 4 streams in the go2rtc.yaml using similar settings as for the Nest cam above, with lag-free video and audio.

[
  {
    "media:0": "video, sendonly, 96 H264/90000",
    "media:1": "audio, sendonly, 97 OPUS/48000/2",
    "receive": 3249353,
    "remote_addr": "[::1]:52732",
    "send": 0,
    "track:0": "97 OPUS/48000/2, sinks=1",
    "type": "RTSP server producer",
    "url": "rtsp://localhost:8554/7dbc29519ce96b1d0468ab61323562e9",
    "user_agent": "Lavf59.16.100"
  },
  {
    "remote_addr": "udp4 host 192.168.0.210:54225",
    "send": 423092,
    "type": "WebRTC server consumer",
    "user_agent": "Mozilla/5.0 (Linux; Android 13; Pixel 6 Build/TP1A.220905.004; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.136 Mobile Safari/537.36 Home Assistant/2022.9.1-2700 (Android 13; Pixel 6)"
  }
]

[
  {
    "media:0": "video, sendonly, 96 H264/90000",
    "media:1": "audio, sendonly, 0 PCMU/8000",
    "receive": 667299,
    "remote_addr": "192.168.0.191:39761",
    "send": 0,
    "track:0": "0 PCMU/8000, sinks=1",
    "type": "RTSP client producer",
    "url": "rtsp://192.168.0.191:65534/videoMain/"
  },
  {
    "remote_addr": "udp4 host 192.168.0.210:39873",
    "send": 369381,
    "type": "WebRTC server consumer",
    "user_agent": "Mozilla/5.0 (Linux; Android 13; Pixel 6 Build/TP1A.220905.004; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.136 Mobile Safari/537.36 Home Assistant/2022.9.1-2700 (Android 13; Pixel 6)"
  }
]