sipsorcery icon indicating copy to clipboard operation
sipsorcery copied to clipboard

FfmpegToWebRTC Latency problem

Open Smurfj3 opened this issue 1 year ago • 1 comments

I am using the FfmpegToWebRTC example and no matter what I try, I seem to always have about a 1.5 second delay. Currently using the following ffmpeg command: ffmpeg -re -rtsp_transport tcp -hwaccel auto -probesize 32 -analyzeduration 0 -strict experimental -i "rtsp://192.168.2.6:554/user=admin&password=&channel=1&stream=1.sdp?" -crf 23 -tune fastdecode -preset ultrafast -tune zerolatency -f lavfi -movflags +faststart -vcodec libx264 -strict experimental -g 1 -f rtp rtp://127.0.0.1:5020 -sdp_file "C:\Program Files\ffmpeg\bin\ffmpeg.sdp"

As you can tell by the command, I have tried about everything to decrease the delay. However I feel like the delay may not be related to the command because I can literally set the quality to be like 5 pixels and there is still that 1.5 second delay. I was wondering is there anywhere in the code where there is a delay set? I find it to much of a coincidence that the delay is always about 1.5 seconds.

Smurfj3 avatar May 25 '23 19:05 Smurfj3

I've tried to approach this issue a little bit differently without using ffmpeg and I did notice only a very small delay in AAC audio when transcoding to OPUS is required. You can take a look at my sample here: https://github.com/jimm98y/SharpRTSPtoWebRTC

Basically, I am not using ffmpeg and I feed the RTP obtained from RTSP directly to sipsorcery's WebRTC PeerConnection. This works for H264 RTSP because H264 is mandatory in WebRTC, but for H265 it only works in Safari after you enable the experimental H265 WebRTC support. Supporting H265 RTSP in all browsers would currently require ffmpeg to convert it to VP8/H264 on the fly and that would add latency and also increase the HW requirements quite a bit.

jimm98y avatar Jun 16 '23 19:06 jimm98y