Go2rtc project - help thread

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)"
  }
]

I sometimes have issues. I thought it was the loveance card, but even with an Iframe it sometimes stops and won’t restart until I restart the container.

When it works I get the following in the logs:

13:10:01.200 DBG [webrtc] new consumer url=fynn_camera
13:10:01.257 DBG [streams] probe producer url=rtsp://admin:[email protected]:88/videoMain
13:10:01.937 DBG [streams] start producer url=rtsp://admin:[email protected]:88/videoMain
TODO: webrtc ontrack &{mu:{w:{state:0 sema:0} writerSem:0 readerSem:0 readerCount:0 readerWait:0} id:2e1d963c-203a-4cf7-994f-799efdb66eb5 streamID:6Yk3m4hN69YNNYnrs2TMQucn00RLbshXrxgq payloadType:111 kind:1 ssrc:718835236 codec:{RTPCodecCapability:{MimeType:audio/opus ClockRate:48000 Channels:2 SDPFmtpLine:minptime=10;useinbandfec=1 RTCPFeedback:[{Type:transport-cc Parameter:}]} PayloadType:111 statsID:} params:{HeaderExtensions:[{URI:http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 ID:4}] Codecs:[{RTPCodecCapability:{MimeType:audio/opus ClockRate:48000 Channels:2 SDPFmtpLine:minptime=10;useinbandfec=1 RTCPFeedback:[{Type:transport-cc Parameter:}]} PayloadType:111 statsID:}]} rid: receiver:0x400009a2a0 peeked:[144 239 1 224 250 229 74 247 42 216 142 36 190 222 0 1 65 0 1 0 120 11 228 193 54 236 197 141 140 73 70 153 4 197 170 237 146 231 99 74 58 24 152 238 98 203 96 255 108 27 41 0] peekedAttributes:map[0:0x400022ca00]}

So, instantly after the ‘new consumer’ entry it starts the stream. When it doesn’t work I get the following:

13:08:05.835 DBG [webrtc] new consumer url=fynn_camera
TODO: webrtc ontrack &{mu:{w:{state:0 sema:0} writerSem:0 readerSem:0 readerCount:0 readerWait:0} id:68bce349-6d72-4145-9b25-80013bb05a11 streamID:xL3JRwRR1X7GDJSuY49cDhli94jKg2jUOFvC payloadType:111 kind:1 ssrc:1048239277 codec:{RTPCodecCapability:{MimeType:audio/opus ClockRate:48000 Channels:2 SDPFmtpLine:minptime=10;useinbandfec=1 RTCPFeedback:[{Type:transport-cc Parameter:}]} PayloadType:111 statsID:} params:{HeaderExtensions:[{URI:http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 ID:4}] Codecs:[{RTPCodecCapability:{MimeType:audio/opus ClockRate:48000 Channels:2 SDPFmtpLine:minptime=10;useinbandfec=1 RTCPFeedback:[{Type:transport-cc Parameter:}]} PayloadType:111 statsID:}]} rid: receiver:0x400007a960 peeked:[144 239 20 14 109 141 80 4 62 122 220 173 190 222 0 1 65 0 1 0 120 11 228 193 54 236 197 141 140 73 70 153 4 197 170 237 146 231 99 74 58 24 152 238 98 203 96 255 108 27 41 0] peekedAttributes:map[0:0x4000643b80]}

So the stream never starts.

I also got another error:

12:30:54.482 WRN [streams] start error=“parse "\xcb\x00\rK": net/url: invalid control character in URL” url=rtsp://admin:[email protected]:88/videoMain

The reason this is weird, is because it has never changed. I don’t understand why it does this.

Hi guys, I’ve been quite lost with this topic up until now.
And let me tell you, did it help to write this down!
Bear with me as I describe how painful this has been for me :slight_smile:

1. First I started experimenting with this add-on: “RTSPtoWeb - WebRTC”.
And it worked great, I got low-latency streaming, except I didn’t realize at first that this wasn’t going to work outside of my LAN.
So I disabled “RTSPtoWeb - WebRTC” in the integrations page.
Note: I didn’t remove the integration. This will be important later on.

2. Then I installed the add-on “RTSPtoWebRTC” - visiting http://[my HA ip]:8083 returns “No Stream Found (add stream and reload page)” - add stream where exactly?
I’m confused with the tutorial… There seems to be some mix-up between these two add-ons.
The page about this one, shows a video about the first one: RTSPtoWebRTC - Home Assistant

Well, I added the integration “WebRTC Camera”, configured the UDP port range, and added the UDP port forwarding in my router.
Using the ‘custom:webrtc-camera’ does work outside of my LAN, however it’s very unstable. Stream isn’t fluid nor low-latency.

After all this, still no cameras listed here: http://[my HA ip]:8083

I didn’t know where to go from here.

3. Now I’m trying to work with the add-on “go2rtc”.
Visiting http://[my HA ip]:1984, no cameras show up so I really must be missing something, since go2rtc was supposed to “grab” any existing streams.
So I added the streams to the config/go2rtc.yaml file and now they show up under http://[my HA ip]:1984
And I added these streams as “Generic Camera” integrations, the source being something like rtsp://[my HA ip]:8554/[some_camera]
Adding them as picture cards, it all works, but once again this isn’t low-latency.

And then I realize, maybe I had previous configurations messing with my current setup.
So I removed all the “RTSPtoWeb/WebRTC”-related integrations, and re-added the “RTSPtoWebRTC” integration.
This time using the server address http://[my HA ip]:1984
I removed the streams from the config file go2rtc.yaml
Then I re-added the lovelace cards as regular picture cards with “live view”.
And now I do get a dynamic list under http://[my HA ip]:1984; this list changes when I watch the streams in my Dashboard.
However, they take a long time to show up at first. (several seconds; sometimes returning an error and not showing up, and I need to refresh)
And again I lost remote access to the streams.

Now, how do I enable remote access?

#go2rtc.yaml
api:
  listen: "127.0.0.1:1984" # localhost
  listen: "xxx.xxx.xxx.xxx:1984" # vm host

rtsp:
  listen: "127.0.0.1:8554" # localhost

webrtc:
  listen: ":8555" # external TCP port - forward this in your router
  candidates:
    - stun:8555  # if you have dynamic public IP-address

And still not working remotely, I mean, rarely one stream passes through.
So what’s happening?
This pops up a lot in the go2rtc Log:

WRN [webrtc] candidate error="address xxxx:xxx:xxxx:xxxx:xxx:xxxx:xxxx:xxxx:xxxx: too many colons in address"

So I disabled IPv6 under Settings → System → Network
And finally I have remote streaming. :smiley:
But with remote access it’s choppy again. Just 1-2 frames per second.
Do you know how to improve this, or what’s wrong with the way I configured it?

This may be an obvious suggestion, but make sure you’ve forwarded port 8555 in you router to the IP address of your home assistant instance (an RPi 4 in my case).