AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
4.28k stars 351 forks source link

Support SRTP for UniFi RTSPS cameras #81

Open saxopwn opened 1 year ago

saxopwn commented 1 year ago

Added a number of UniFi cameras via yaml as below:

streams:
 front: rtspx://192.168.1.1:7441/E1oZmxXGX4dAzBsz?enableSrtp

When I open go2rtc to view the stream, I either get: 07:42:38.656 WRN [streams] start error="rtcp: invalid packet version" url=rtspx://192.168.1.1:7441/E1oZmxXGX4dAzBsz?enableSrtp or 07:43:30.654 WRN [streams] start error="rtcp: packet too short" url=rtspx://192.168.1.1:7441/E1oZmxXGX4dAzBsz?enableSrtp

Doesn't matter if I use rtsps or rtspx

AlexxIT commented 1 year ago

You need to increase logs level. Maybe there will be something useful there.

saxopwn commented 1 year ago

09:52:14.746 TRC [rtsp] client request:
PLAY rtsps://192.168.1.1:7441/E1oZmxXGX4dAzBsz?enableSrtp/ RTSP/1.0
Session: vBTZ55qE
CSeq: 4

09:52:14.747 TRC [rtsp] client response:
RTSP/1.0 200 OK
Range: npt=now-
Session: vBTZ55qE
Cache-Control: no-store
Date: Fri, 21 Oct 2022 09:52:14 UTC
Pragma: no-cache
Rtp-Info: url=rtsps://192.168.1.1:7441/E1oZmxXGX4dAzBsz?enableSrtp/trackID=1;seq=51883;rtptime=0,url=rtsps://192.168.1.1:7441/E1oZmxXGX4dAzBsz?enableSrtp/trackID=2;seq=34745;rtptime=0
Server: EvoStream Media Server (www.evostream.com)
Cseq: 4
Expires: Fri, 21 Oct 2022 09:52:14 UTC

09:52:14.747 TRC [webrtc] local candidate="candidate:3928457368 1 udp 2130706431 192.168.1.160 60312 typ host"
09:52:14.802 TRC [webrtc] local candidate="candidate:2838228210 1 udp 1694498815 76.249.129.230 48395 typ srflx raddr 0.0.0.0 rport 48395"
09:52:14.802 TRC [webrtc] answer
v=0
o=- 5397660643515131343 1666345934 IN IP4 0.0.0.0
s=-
t=0 0
a=fingerprint:sha-256 F2:8D:99:17:B0:4A:D2:FE:A9:DE:A5:61:F3:F5:90:25:E2:E9:3C:0C:D5:43:E7:FC:D2:80:A7:25:33:22:ED:FF
a=extmap-allow-mixed
a=group:BUNDLE 0 1
m=video 9 UDP/TLS/RTP/SAVPF 102 125 123
c=IN IP4 0.0.0.0
a=setup:active
a=mid:0
a=ice-ufrag:XSJWPEMlYJRajKih
a=ice-pwd:XZlmpIbxKHdcGumhEfugsuxcbYeINUcm
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:102 H264/90000
a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
a=rtcp-fb:102 goog-remb 
a=rtcp-fb:102 transport-cc 
a=rtcp-fb:102 ccm fir
a=rtcp-fb:102 nack 
a=rtcp-fb:102 nack pli
a=rtpmap:125 H264/90000
a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtcp-fb:125 goog-remb 
a=rtcp-fb:125 transport-cc 
a=rtcp-fb:125 ccm fir
a=rtcp-fb:125 nack 
a=rtcp-fb:125 nack pli
a=rtpmap:123 H264/90000
a=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f
a=rtcp-fb:123 goog-remb 
a=rtcp-fb:123 transport-cc 
a=rtcp-fb:123 ccm fir
a=rtcp-fb:123 nack 
a=rtcp-fb:123 nack pli
a=extmap:4 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=ssrc:3662871118 cname:go2rtc
a=ssrc:3662871118 msid:go2rtc video
a=ssrc:3662871118 mslabel:go2rtc
a=ssrc:3662871118 label:video
a=msid:go2rtc video
a=sendonly
a=candidate:3928457368 1 udp 2130706431 192.168.1.160 60312 typ host
a=candidate:3928457368 2 udp 2130706431 192.168.1.160 60312 typ host
a=candidate:2838228210 1 udp 1694498815 76.249.129.230 48395 typ srflx raddr 0.0.0.0 rport 48395
a=candidate:2838228210 2 udp 1694498815 76.249.129.230 48395 typ srflx raddr 0.0.0.0 rport 48395
a=end-of-candidates
m=audio 9 UDP/TLS/RTP/SAVPF 111 0 8
c=IN IP4 0.0.0.0
a=setup:active
a=mid:1
a=ice-ufrag:XSJWPEMlYJRajKih
a=ice-pwd:XZlmpIbxKHdcGumhEfugsuxcbYeINUcm
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:111 opus/48000/2
a=fmtp:111 minptime=10;useinbandfec=1
a=rtcp-fb:111 transport-cc 
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=extmap:4 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=ssrc:3363078967 cname:go2rtc
a=ssrc:3363078967 msid:go2rtc audio
a=ssrc:3363078967 mslabel:go2rtc
a=ssrc:3363078967 label:audio
a=msid:go2rtc audio
a=sendonly
09:52:14.802 TRC [webrtc] remote candidate="candidate:215036887 1 udp 2113937151 814ff855-a712-48c0-9dbd-140d70865e30.local 62774 typ host generation 0 ufrag gHjR network-cost 999"
09:52:14.802 TRC [webrtc] remote candidate="candidate:215036887 1 udp 2113937151 814ff855-a712-48c0-9dbd-140d70865e30.local 62776 typ host generation 0 ufrag gHjR network-cost 999"
09:52:14.802 TRC [webrtc] remote candidate="candidate:842163049 1 udp 1677729535 76.249.129.230 62774 typ srflx raddr 0.0.0.0 rport 0 generation 0 ufrag gHjR network-cost 999"
09:52:14.802 TRC [webrtc] remote candidate="candidate:842163049 1 udp 1677729535 76.249.129.230 62776 typ srflx raddr 0.0.0.0 rport 0 generation 0 ufrag gHjR network-cost 999"
09:52:15.772 WRN [streams] start error="rtcp: invalid packet version" url=rtspx://192.168.1.1:7441/E1oZmxXGX4dAzBsz?enableSrtp```
AlexxIT commented 1 year ago

Oh. SRTP not supported. You shouldn't enable it.

There is no need to enable SRTP if you have an RTSPS with a TCP stream. It is already encrypted.

saxopwn commented 1 year ago

Easy fix, thanks! FYI- the latest build of UniFi Protect automatically includes the "?enableSrtp" when you copy the RTSP address but seems to work fine after deleting it.

AlexxIT commented 1 year ago

SRTP is useful for RTSPS+UDP. But go2rtc support only TCP for now.

dw0rak commented 1 year ago

@saxopwn Did your fix involve only removing from url "?enableSrtp"? I tried changing URL using generic camera integration configuration, but with no luck. Could you please share your config? Thank you

AlexxIT commented 1 year ago

Use rtspx for disable certificate check.

rcjkierkels commented 1 year ago

Use rtspx for disable certificate check.

How do I use rtspx and where should I disable the certificate check? I only have rtsps and rtsp as far as I can see?

NickM-27 commented 1 year ago

@rcjkierkels see https://github.com/AlexxIT/go2rtc/issues/15#issuecomment-1226713334

ViViDboarder commented 9 months ago

I managed to get my UniFi cameras to show stream removing the parameter and using rtspx and manually configuring a stream, however this seems impossible to resolve using the Home Assistant Integration. It appears that whenever I start a stream it overrides my configured value and adds ?enableSrtp back in.

Am I missing a way to get my configuration to persist or maybe a way to tell go2rtc to remove this?

AlexxIT commented 9 months ago

@ViViDboarder I don't understand what you talking about

ViViDboarder commented 9 months ago

Hmm. Sorry. I think I left off some important context while in a debugging rabbit hole.

I tried using go2rtc and configuring it with the Home Assistant RTSP2WebRTC integration. In this integration it seems to pull the RTSP URLs from the entities in Home Assistant. Those URLs look like the ones shown here, with RSTPS and this parameter.

I tried to override it by storing the updated URL in the configuration file using the same entity id, but that didn’t seem to work.