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
6.78k stars 486 forks source link

RTSP 4K to WebRTC Not Working #1391

Open virtualbitzz opened 1 month ago

virtualbitzz commented 1 month ago

I have a bunch of Reolink cameras that are 1440p and a couple of new ones that are 4K.

The 1440p cameras I have no problem with. I use the addon in Home Assistant, and the WebRTC lovelace card. I'm able to define the sources in the .yaml config file and view the streams via the lovelace card in WebRTC.

The 4K cameras are where I have a problem. If I drop the resolution to 1440p, they come through in WebRTC no problem. However, when I bump the streams up to 4K the streams will only display in MSE, not WebRTC.

For one of the cameras the 1440p stream is fine, however with the RLC-843A if you drop the resolution instead of transcoding it just digitally crops the image! I need the FoV on this camera so cropping / dropping the resolution isn't going to work.

virtualbitzz commented 1 month ago
15:36:24.325 TRC [webrtc] remote candidate="candidate:3624146751 1 udp 1685921535 1.2.3.4 59721 typ srflx raddr 192.168.15.121 rport 59721 generation 0 ufrag 4F0x network-id 2"
15:36:24.325 TRC [api.ws] msg type=webrtc/candidate
15:36:24.325 TRC [webrtc] remote candidate="candidate:4143941418 1 udp 1685987071 1.2.3.4 59720 typ srflx raddr 192.168.15.112 rport 59720 generation 0 ufrag 4F0x network-id 1"
15:36:24.361 TRC [rtsp] client response:
RTSP/1.0 200 OK
Cseq: 2
Date: Fri, Oct 11 2024 22:36:25 GMT
Content-Base: rtsp://192.168.30.27/Preview_01_main/
Content-Type: application/sdp
Content-Length: 880

v=0
o=- 1728684720635403 1 IN IP4 192.168.30.27
s=Session streamed by "preview"
i=reolink rtsp stream
t=0 0
a=tool:BC Streaming Media v202210012022.10.01
a=type:broadcast
a=control:*
a=range:npt=now-
a=x-qt-text-nam:Session streamed by "preview"
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:8192
a=rtpmap:96 H265/90000
a=fmtp:96 profile-space=0;profile-id=1;tier-flag=0;level-id=150;interop-constraints=000000000000;sprop-vps=QAEMAf//AWAAAAMAAAMAAAMAAAMAlqwJ;sprop-sps=QgEBAWAAAAMAAAMAAAMAAAMAlqAB4CACHH+KrTuiS7I=;sprop-pps=RAHAcvCUHjZI
a=recvonly
a=control:track1
m=audio 0 RTP/AVP 97
c=IN IP4 0.0.0.0
b=AS:8192
a=rtpmap:97 MPEG4-GENERIC/16000
a=fmtp:97 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1408
a=recvonly
a=control:track2
m=audio 0 RTP/AVP 0
a=control:track3
a=rtpmap:0 PCMU/8000
a=sendonly
15:36:24.362 TRC [streams] check prod=0 media=video, recvonly, H265
15:36:24.362 TRC [streams] match prod=0 => cons=0
15:36:24.362 TRC [rtsp] client request:
SETUP rtsp://192.168.30.27/Preview_01_main/track1 RTSP/1.0
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
CSeq: 3
Authorization: Digest username="admin", realm="BC Streaming Media", nonce="c78ae772ee70e0891c672cd27fdb8510", uri="rtsp://192.168.30.27/Preview_01_main/track1", response="3c296b5aa324f4052ddb5e31420ea685"

15:36:24.402 TRC [rtsp] client response:
RTSP/1.0 200 OK
Session: AC102710;timeout=65
Cseq: 3
Date: Fri, Oct 11 2024 22:36:25 GMT
Transport: RTP/AVP/TCP;unicast;destination=192.168.10.17;source=192.168.30.27;interleaved=0-1

15:36:24.402 TRC [streams] check prod=0 media=video, recvonly, H265
15:36:24.402 TRC [streams] check prod=0 media=audio, recvonly, MPEG4-GENERIC/16000
15:36:24.402 TRC [streams] check prod=0 media=audio, sendonly, PCMU/8000
15:36:24.402 TRC [streams] check cons=1 media=audio, sendonly, OPUS/48000/2, RED/48000/2, G722/8000, PCMU/8000, PCMA/8000, CN/8000, TELEPHONE-EVENT/48000, TELEPHONE-EVENT/8000, L16
15:36:24.402 TRC [streams] check prod=0 media=video, recvonly, H265
15:36:24.402 TRC [streams] check prod=0 media=audio, recvonly, MPEG4-GENERIC/16000
15:36:24.402 TRC [streams] check prod=0 media=audio, sendonly, PCMU/8000
15:36:24.402 DBG [webrtc] add consumer error=PCMU
15:36:24.402 TRC [streams] check cons=0 media=audio, sendonly, MPEG4-GENERIC, PCMA, PCMU, L16, OPUS
15:36:24.402 TRC [streams] check prod=0 media=video, recvonly, H265
15:36:24.402 TRC [streams] check prod=0 media=audio, recvonly, MPEG4-GENERIC/16000
15:36:24.402 TRC [streams] match prod=0 => cons=0
15:36:24.402 TRC [rtsp] client request:
SETUP rtsp://192.168.30.27/Preview_01_main/track2 RTSP/1.0
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
CSeq: 4
Authorization: Digest username="admin", realm="BC Streaming Media", nonce="c78ae772ee70e0891c672cd27fdb8510", uri="rtsp://192.168.30.27/Preview_01_main/track2", response="4acc00a30c8accff5e6206e453153c64"
Session: AC102710

15:36:24.407 TRC [rtsp] client response:
RTSP/1.0 200 OK
Transport: RTP/AVP/TCP;unicast;destination=192.168.10.17;source=192.168.30.27;interleaved=2-3
Session: AC102710;timeout=65
Cseq: 4
Date: Fri, Oct 11 2024 22:36:25 GMT

15:36:24.407 DBG [streams] start producer url=rtsp://admin:password@miccam07.domain.net:554/h265Preview_01_main
15:36:24.407 TRC [rtsp] client request:
PLAY rtsp://192.168.30.27/Preview_01_main/ RTSP/1.0
CSeq: 5
Authorization: Digest username="admin", realm="BC Streaming Media", nonce="c78ae772ee70e0891c672cd27fdb8510", uri="rtsp://192.168.30.27/Preview_01_main/", response="186921abbdece512d7411652439d2dd4"
Session: AC102710

15:36:24.455 TRC [rtsp] client response:
RTSP/1.0 200 OK
Cseq: 5
Date: Fri, Oct 11 2024 22:36:25 GMT
Range: npt=0.000-
Session: AC102710
Rtp-Info: url=rtsp://192.168.30.27/Preview_01_main/track1;seq=52077;rtptime=107816884,url=rtsp://192.168.30.27/Preview_01_main/track2;seq=26019;rtptime=2378866631,url=rtsp://192.168.30.27/Preview_01_main/track3;seq=0;rtptime=0
virtualbitzz commented 1 month ago

Can go2rtc route an RTSP H265 stream to WebRTC? This camera's main stream can't product H264 at the full resolution, which I need for the FoV

maynardpha commented 11 hours ago

I've got the same issue with the Reolink RCL843A camera, but I was able to find a possible work around for you for the time being. First, my setup: HA is running in as a VirtualBox 7.0.16 guest on Kubuntu 24.04 - so there's no hardware accel available in HA. go2rtc is running as a docker container on the same host as HA, using the hardware accel version of go2rtc docker run config: (you can't use docker compose with Virtualbox running)

docker run -d \ --name go2rtc \ --network host \ --restart unless-stopped \ -e TZ=America/Vancouver \ -e PUID=1000 \ -e PGID=1000 \ -e GIDLIST=44,992 \ -v ~/Go2rtc:/config \ --device /dev/dri/renderD128:/dev/dri/renderD128 \ --device /dev/dri:/dev/dri/card0 \ --device /dev/kfd:/dev/kfd \ alexxit/go2rtc:latest-hardware

(not sure if the --device entries are need for this container - I needed those for another GPU container I'm running, so I added them to this one as well, and the GIDLIST is for the video & render groups to allow access to those devices)

I found that by using ffmpeg with mjpeg & hardware, I was able to view the "clear" aka "main" video stream in go2rtc and in HA using the custom:webrtc-camera card URL used in HA is:

ffmpeg:rtsp://{userid}:{password}@{camera ip}/Preview_01_main#video=mjpeg#hardware

Hope this works as a work around for you. Note: it's not perfect, (it flashes once in a while), but in my opinion, it's better than the low res "sub" view for this camera.

AlexxIT commented 3 hours ago

There can be many reasons for this problem:

PS: