Reduce latency for RTSP streams
Posted: Tue May 16, 2023 7:45 pm
I'm building an user interface with multiple IP camera streams running at the same time. I'm using TRVCamMultiView with up to 16 viewers running. My problem is that the latency for all my cameras start from 1-2 seconds at program launch to 15-30 seconds after a couple of minutes.
This is my setup:
- Delphi 11.3 on Windows 11 x64
- FMX project, using FFMpeg
- Dahua PTZ IP camera, model DH-SD5A432XAN-HNR, supports H265, H264 and MJPEG over RTSP.
I'm using the substream 1 for these cameras for reduced bandwidth usage and this is how such stream is set up:
- Codec: H.264H (seems like an optimized codec)
- Resolution: 704*480
- FPS: 30
- Bitrate: 1024 Kb/S constant
- iFrame interval: 60
Things I have tried so far without improvement:
- Switching DeviceType between rvdtRTSP and rvdtIPCamera
- Switching VideoFormat between rvvfH264, rvvfAVI_H264 and rvvfMP4_H264
- FFMpegProperty.Audio:=False
- FFMpegProperty.TcpNodelay:=True
- FFMpegProperty.RecvBufferSize:=10000 (and smaller values)
Things I have tried but made the situation worse:
- FFMpegProperty.FrameDrop:=True (it causes the stream to end as soon as the first frame arrives)
- FFMpegProperty.RTSPTransport:=[rvpeUDP] (it causes the video to show artifacts, turns black and white, pixelated, jumping lots of frames)
I'm wondering why this latency "stabilizes" at 15-30 seconds and doesn't get larger while at the same time never recovering for real time video.
This is my setup:
- Delphi 11.3 on Windows 11 x64
- FMX project, using FFMpeg
- Dahua PTZ IP camera, model DH-SD5A432XAN-HNR, supports H265, H264 and MJPEG over RTSP.
I'm using the substream 1 for these cameras for reduced bandwidth usage and this is how such stream is set up:
- Codec: H.264H (seems like an optimized codec)
- Resolution: 704*480
- FPS: 30
- Bitrate: 1024 Kb/S constant
- iFrame interval: 60
Things I have tried so far without improvement:
- Switching DeviceType between rvdtRTSP and rvdtIPCamera
- Switching VideoFormat between rvvfH264, rvvfAVI_H264 and rvvfMP4_H264
- FFMpegProperty.Audio:=False
- FFMpegProperty.TcpNodelay:=True
- FFMpegProperty.RecvBufferSize:=10000 (and smaller values)
Things I have tried but made the situation worse:
- FFMpegProperty.FrameDrop:=True (it causes the stream to end as soon as the first frame arrives)
- FFMpegProperty.RTSPTransport:=[rvpeUDP] (it causes the video to show artifacts, turns black and white, pixelated, jumping lots of frames)
I'm wondering why this latency "stabilizes" at 15-30 seconds and doesn't get larger while at the same time never recovering for real time video.