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.95k stars 497 forks source link

API to get stream in WebRTC format (WHEP) delay in response #1392

Open n1mda opened 1 month ago

n1mda commented 1 month ago

Hi!

I'm using the REST API to send an SDP offer to Get stream in WebRTC format (WHEP). It takes about 5 seconds before I get a response from the endpoint.

What is consuming all this time to create an SDP answer?

My go2rtc configuration is empty, I have not specified any ice_servers or candidates

AlexxIT commented 1 month ago

Empty? You should have a one stream at least. POST /api/webrtc should return codecs and candidates. So it takes time to connect to camera and get codecs from and. And should get STUN candidates for server. For some users it takes less than second. For if fail with timeout. I don't know timeout value. Maybe it's 5 second.

n1mda commented 1 month ago

Yes of course I have a stream, I mean that the config does not contain anything regarding webrtc or stun

n1mda commented 1 month ago

Is there a way to skip the process of connecting to camera to get codecs? I can specify which codecs that should be used

AlexxIT commented 1 month ago

You can't skip this step. This is base logic of go2rtc. Two way codecs negotiation https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#codecs-negotiation

You ask some codecs from go2rtc (with your SDP). Go2rtc checks if it can provide at lease one codec from your list for your stream. Maybe your stream only has MJPEG/H265/AAC codecs. WHEP API fail.