Security cameras doubt- go2rtc , RTSPtoWeb and what is between

I’ve struggling for sometime to configure HA so i could view my cameras stream on mobile app.
my main issue - not able to view camera stream on mobile.

setup:

Internet connection - fiber (1Gb download ,100 Mb upload).
4 * Dahua camera 4mp - all set to 1080P with AAC 8000 ,bitrate on low-medium .

HA running on docker - latest version
go2rtc - docker , all cameras define there .
HA cameras configure as generic using go2rtc rtsp urls
Chrome as browser through all tests
all test done with picture-glance card
Mobile - samsung S20+

  - platform: generic
    stream_source:  rtsp://192.168.1.113:8554/front_go2rtc
    name: front_camera

Tried below:

“custom-card:webrtc”

very bad performance,
video stream stuttering , disconcertion icon appear most of the time .
also when connecting to HA locally - both from mobile and browser.
Using go2rtc webgui - running smoothly + sound.
http://192.168.1.113:1984/stream.html?src=front_camera_go2rtc

Second:
HA camera configure as generic with go2rtc rtsp urls
On HA - RTSPtoWebRTC integration connecting to go2rtc as rtsp server .
On browser - open HA → working perfectly , except no audio.
On mobile → video is completely stuck (picture freezing)
Same result for webgui - running smoothly + sound.
http://192.168.1.113:1984/stream.html?src=front_camera_go2rtc

Another try:

HA cameras configure as generic with go2rtc rtsp urls
running RTSPToWeb on docker
on HA- RTSPtoWebRTC integration added and connect to RTSPToWeb as rtsp server .

RTSPToWeb - running smoothly , no sound
On browser - HA → video looks good - no audio.
On mobile → video is completely stuck (picture freezing)
from RTSPToWeb log - i see below happening right when using mobile app and trying to view the cameras.
(not sure it’s related)


2022/12/22 22:52:49 Set ICEServers [stun:stun.l.google.com:19302]
2022/12/22 22:52:49 Set ICEServers [stun:stun.l.google.com:19302]
time="2022-12-22T22:53:19Z" level=error msg="WebRTC Client Offline" call=WritePacket channel=0 func=HTTPAPIServerStreamWebRTC module=http_webrtc stream=camera.front_camera
time="2022-12-22T22:53:20Z" level=error msg="WebRTC Client Offline" call=WritePacket channel=0 

Also tried removing WebRTC integration while test RTSPtoWebRTC -->RTSPToWeb
with same result.

Would really appreciate what could be the problem,
and what would be the right approach so i be able to view the cameras from the app.

1 Like

Are you converting your streams with FFMPEG to something your phone will be happy with?

@grandnewbien webrtc is something most browsers should be happy with ,
this all.purpose of both go2rtc and webrtc.

I’ve open the udp ports required for webrtc intergation (using custom webrtc card),
I got pratial improvement, from internal - it’s working from external strange behavior - sometimes it’s working sometimes not .
and I open wide range so I’m not sure why it’s happening.

so current situation:

1.webrtc camera ( using custom: webrtc-card),
working internally,not working externally.

2.RTSPtoWebRTC → go2rtc or RTSPToWeb,
working internally,never working externally.
I’m not sure what can be done further ,
I’m sure it is network issue /configuration,
actually I see othera struggling with same issue with no solution.
unfortunately both intergationa are great especially for non-dockerize setup as well documented ,I’ve it less clear for what exactly required to do when everything ran on Dockers + reverse proxy.

I specifically use Traefik as RP but not sure what exactly required for network part.

You can connect stream from camera to Hass with different ways (has no effect on latency):

  1. RTSP link > Generic Camera Integration
  2. RTSP link > go2rtc Addon > Generic Camera Integration

You can watch stream from Hass into your browser with different ways:

  1. Generic Camera > HLS proto (worst latency)
  2. Generic Camera > RTSPtoWebRTC Inegration > RTSPtoWeb Addon > WebRTC proto
  3. Generic Camera > RTSPtoWebRTC Inegration > go2rtc Addon > WebRTC proto
  4. Generic Camera > WebRTC Camera Inegration > WebRTC + MSE proto
  5. RTSP link > WebRTC Camera Inegration > WebRTC + MSE proto
  6. go2rtc Addon WebUI > WebRTC with 2-way audio + MSE + MP4 + MJPEG proto

Thanks Alext ,
so i did understand it right but still not able to make it work properly .

Test #1.1 - go2rtc

Input stream:
RTSP link > go2rtc Addon > Generic Camera Integration
HA:
Generic Camera > WebRTC Camera Integration

I set udp port to 50000–>51000 , also open on the router .

On go2trc webgui - working fine
on HA :
Very unstable result : video stream stuttering
On local lan - webrtc icon never shown on video streams , ( the disconnect icon).
No error on HA log or go2rtc.
Note, I map 8554:8554 on go2rtc docker , otherwise the stream will not work on HA.

Test1.2 - go2rtc
(webrtc integration removed)

Input stream:
RTSP link > go2rtc Addon > Generic Camera Integration
On home assistant:
Generic Camera > RTSPtoWebRTC Inegration > go2rtc Addon

go2rtc webui:
links working
from HA - create picture-glance + add camera
getting error:

2022-12-28 23:14:58.025 ERROR (stream_worker) [homeassistant.components.stream.stream.camera.salon_ceiling_camera] Error from stream worker: Error opening stream (ERRORTYPE_111, Connection refused) rtsp://192.168.1.113:8554/salon_ceiling_go2rtc
2022-12-28 23:15:00.900 ERROR (stream_worker) [homeassistant.components.stream.stream.camera.salon_desk_camera] Error from stream worker: Error opening stream (ERRORTYPE_111, Connection refused) rtsp://192.168.1.113:8554/salon_desk_go2rtc
2022-12-28 23:15:01.060 ERROR (stream_worker) [homeassistant.components.stream.
stream.camera.intercom_camera] Error from stream worker: Error opening stream (ERRORTYPE_111, Connection refused) rtsp://192.168.1.113:8554/intercom_go2rtc
2022-12-28 23:15:01.066 ERROR (stream_worker) [homeassistant.components.stream.stream.camera.front_camera] Error from stream worker: Error opening stream (ERRORTYPE_111, Connection refused) rtsp://192.168.1.113:8554/front_go2rtc

No picture shown at all .

Test #2 - RTSPtoWeb

Input stream:
RTSP link > go2rtc Addon > Generic Camera Integration
On home assistant:
Generic Camera > RTSPtoWebRTC Inegration > RTSPtoWeb Addon

webRTC stream not open ,
Log:

time="2022-12-28T20:52:22Z" level=error msg="WebRTC Client Offline" call=WritePacket channel=0 func=HTTPAPIServerStreamWebRTC module=http_webrtc stream=camera.salon_desk_camera

Network:
Traefik playing as RP
I guess i need to do something here - but not sure what is required

Both RTSPtoWeb and go2rtc define in similarly:

networks:
  dockers_inframain:
    external: true

services:
  go2rtc:
    container_name: go2rtc  
    image: alexxit/go2rtc
    networks:
      - dockers_inframain    
    # network_mode: host   
    ports:
      - 1984:1984   
      - 8554:8554 # had to open it otherwise cant play camera stream on HA
    restart: always
    volumes:
      - ./go2rtc.yaml:/config/go2rtc.yaml


rtsp2web

networks:
# Treafik and HA network running in different stack
  dockers_inframain:
    external: true

services:
  go2rtc:
    container_name: rtsp2web
    image: ghcr.io/deepch/rtsptoweb:latest 
    networks:
      - dockers_inframain
    ports:
      - 8083:8083
    restart: always
    volumes:
      - ./config.yaml:/config/config.json

So. You have completely blocked WebRTC for both containers.
It is always better, for all containers and in all cases, to use network_mode: host. And only use the ports option when you know what you’re doing. Very few docker users understand this.

Actually , i tried that as well .
changing back to network_mode: host

Test1 -

Input stream:
RTSP link > go2rtc Addon > Generic Camera Integration
HA:
Generic Camera > WebRTC Camera Integration(udp ports 50000–>51000 , same on router)

  • custom_components.webrtc: debug

local lan :
go2rtc webUi (chrome) - video looks good , currently minor but worth mention the 2 ways audio doesn’t work.
camera(k42) define as following:

  salon_desk_go2rtc: 
    - rtsp://hauser:[email protected]/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif
    - ffmpeg:rtsp://hauser:[email protected]/cam/realmonitor?channel=1&subtype=0#audio=opus

HA (Chrome) - webrtc doesnt work (MSE or disconnection icon)
log:

2022-12-29 12:10:17.789 DEBUG (webrtc) [custom_components.webrtc.utils] [GIN] 2022/12/29 - 12:10:17 | 200 | 22.560231402s |       127.0.0.1 | GET      "/ws?url=rtsp://192.168.1.113:8554/salon_desk_go2rtc"
2022-12-29 12:10:22.738 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:10:22 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-29 12:10:22.738 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:10:22 Set UDP ports to 50000 .. 51000
2022-12-29 12:10:22.740 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:10:22 WebRTC Ignore Audio Track codec not supported WebRTC support only PCM_ALAW or PCM_MULAW
2022-12-29 12:10:24.107 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:10:24 muxerWebRTC.WritePacket WebRTC Client Offline
2022-12-29 12:10:25.058 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:10:25 websocket.JSON.Receive EOF
2022-12-29 12:10:25.058 DEBUG (webrtc) [custom_components.webrtc.utils] [GIN] 2022/12/29 - 12:10:25 | 200 |  2.471960666s |       127.0.0.1 | GET      "/ws?url=rtsp://192.168.1.113:8554/salon_desk_go2rtc"
2022-12-29 12:10:25.675 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:10:25 muxerWebRTC.WritePacket WebRTC Client Offline
2022-12-29 12:10:27.967 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:10:27 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-29 12:10:27.967 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:10:27 Set UDP ports to 50000 .. 51000
2022-12-29 12:10:27.970 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:10:27 WebRTC Ignore Audio Track codec not supported WebRTC support only PCM_ALAW or PCM_MULAW

outside network
via HA mobile - webrtc doesn’t work .
HA log show repeated print as following:


022-12-29 12:22:09.352 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:22:09 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-29 12:22:09.353 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:22:09 Set UDP ports to 50000 .. 51000
2022-12-29 12:22:09.355 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:22:09 WebRTC Ignore Audio Track codec not supported WebRTC support only PCM_ALAW or PCM_MULAW
2022-12-29 12:22:21.146 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:22:21 muxerWebRTC.WritePacket WebRTC Client Offline
2022-12-29 12:22:24.775 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:22:24 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-29 12:22:24.776 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:22:24 Set UDP ports to 50000 .. 51000
2022-12-29 12:22:24.779 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/29 12:22:24 WebRTC Ignore Audio Track codec not supported WebRTC support only PCM_ALAW or PCM_MULAW


```

Are you sure you have public IP address for your home network? Forward port on router won’t help for private IP.

can u clarify the question please?
On go2rtc i’m using local camera ip (192.168.1xx)
for connecting from outside i’m using my own domain .

my preference is to be able to work
with Generic Camera > RTSPtoWebRTC Inegration > go2rtc
instead of webrtc camera integration .
Unfortunately , at current both are not working .
I suspect both for same reason…but maybe I wrong.

current focus is make webrtc camera integration working ,
but i’m getting(both inside the network or externally):

2022-12-30 00:42:56.068 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/30 00:42:56 muxerWebRTC.WritePacket WebRTC Client Offline
2022-12-30 00:42:57.879 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/30 00:42:57 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-30 00:42:57.879 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/30 00:42:57 Set UDP ports to 50000 .. 51000
2022-12-30 00:42:57.881 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/30 00:42:57 WebRTC Ignore Audio Track codec not supported WebRTC support only PCM_ALAW or PCM_MULAW
2022-12-30 00:42:59.102 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/30 00:42:59 websocket.JSON.Receive EOF
2022-12-30 00:42:59.102 DEBUG (webrtc) [custom_components.webrtc.utils] [GIN] 2022/12/30 - 00:42:59 | 200 |  1.357078167s |       127.0.0.1 | GET      "/ws?url=rtsp://192.168.1.113:8554/salon_ceiling_go2rtc"
2022-12-30 00:43:00.146 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/30 00:43:00 muxerWebRTC.WritePacket WebRTC Client Offline

I confirm both IP coming from router by checking https://www.whatismyip.com/
are the same ,
more ever , confirm only 1 hop when running tracert to my ip.
so looks i’m not behind NAT

tracert 6.5.43.210
Tracing route to 6.5.43.210 over a maximum of 30 hops

  1     1 ms    <1 ms    <1 ms  6.5.43.210 

Trace complete.

And you setup WebRTC TCP port in go2rtc yaml and forward this port on your router?

of course:

api:
  listen: ":1984"

rtsp:
  listen: ":8554"

webrtc:
  listen: ":8555"  # address of your local server (TCP)
  candidates:
    - stun:8555  # if you have dynamic public IP-address

also open router port:

In addition , i saw ur comment on main thread
and i added stun server on RTSPWebtoRTC integration
image

Strange both WebRTC camera and also RTSPWebtoRTC doesnt work :frowning:
keep getting:

2022-12-31 14:17:37.514 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 14:17:37 muxerWebRTC.WritePacket WebRTC Client Offline
2022-12-31 14:17:40.717 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 14:17:40 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-31 14:17:40.735 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 14:17:40 Set UDP ports to 50000 .. 50400
2022-12-31 14:17:40.773 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 14:17:40 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-31 14:17:40.778 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 14:17:40 Set UDP ports to 50000 .. 50400
2022-12-31 14:17:46.988 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 14:17:46 muxerWebRTC.WritePacket WebRTC Client Offline

Your logs from WebRTC Camera integration. They not related to go2rtc WebRTC TCP port. They are different software.

Yes Alex im aware of the log related to WebRTC Camera integration .

Got some progress -i reset everything and also stop raid scrubbing which found overloading the cpu(not sure if it’s related).

TLNR:
WebRTC Camera integration - working internally partially (only from wifi), externally never.
go2rtc - some progress , not sure if the stream is webrtc

details:

1.WEBRTC Camera integration
Now the situation little bit strange - while with my phone connect to the AP (Wifi) ,
Using HA app - WebRTC icon popups immediately and show smooth streaming

logs approve it:


2022-12-31 22:39:11.407 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 22:39:11 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-31 22:39:11.408 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 22:39:11 Set UDP ports to 50000 .. 50400
2022-12-31 22:39:14.157 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 22:39:14 websocket.JSON.Receive EOF
2022-12-31 22:39:14.158 DEBUG (webrtc) [custom_components.webrtc.utils] [GIN] 2022/12/31 - 22:39:14 | 200 |  3.205108571s |       127.0.0.1 | GET      "/ws?url=rtsp://192.168.1.113:8554/intercom_go2rtc"

When connect on LAN from my PC using chrome and open HA

2-12-31 22:40:22.100 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 22:40:22 Stream Try Connect rtsp://192.168.1.113:8554/intercom_go2rtc
2022-12-31 22:40:22.316 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 22:40:22 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-31 22:40:22.317 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 22:40:22 Set UDP ports to 50000 .. 50400
2022-12-31 22:40:37.790 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 22:40:37 Set ICEServers [stun:stun.l.google.com:19302]
2022-12-31 22:40:37.792 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 22:40:37 Set UDP ports to 50000 .. 50400
2022-12-31 22:40:52.577 DEBUG (webrtc) [custom_components.webrtc.utils] 2022/12/31 22:40:52 muxerWebRTC.WritePacket WebRTC Client Offline

External access also blocked - log look the same .

2.RTSPtoWebRTC Integration > go2rtc docker

Local PC → chrome → glance card
looks it’s working from both internal and external but not sure it’s webrtc as video is not really smooth and if there’s a movement it’s getting little stuttering,
I suspect this webrtc as on camera with AAC there’s no audio.


2023-01-01 10:51:51.556 DEBUG (MainThread) [rtsp_to_webrtc.web_client] request[post] http://192.168.1.113:1984/stream/camera.front_camera/add
2023-01-01 10:51:51.560 DEBUG (MainThread) [rtsp_to_webrtc.web_client] response <ClientResponse(http://192.168.1.113:1984/stream/camera.front_camera/add) [200 OK]>
<CIMultiDictProxy('Content-Type': 'application/json', 'Date': 'Sun, 01 Jan 2023 08:51:51 GMT', 'Content-Length': '25')>

2023-01-01 10:51:51.560 DEBUG (MainThread) [rtsp_to_webrtc.web_client] request[post] http://192.168.1.113:1984/stream/camera.front_camera/channel/0/webrtc
2023-01-01 10:51:51.653 DEBUG (MainThread) [rtsp_to_webrtc.web_client] response <ClientResponse(http://192.168.1.113:1984/stream/camera.front_camera/channel/0/webrtc) [200 OK]>


2023-01-01 10:52:34.228 ERROR (stream_worker) [homeassistant.components.stream.stream.camera.front_camera] Error from stream worker: Error demuxing stream: [Errno 110] Operation timed out: 'rtsp://192.168.1.113:8554/front_go2rtc'

Hi, I have been using dahua ipcams and NVR with RTSPtoWeb and go2rtc and have the same issues too. Have there been any progress?