Videocapture open lag with rtsp

I`m opening my rtsp stream with ffmpeg background at opencv 4.6.0, and have some freeze . Code:
vector a;
a.push_back(2000);, CAP_FFMPEG, a);

When i use web camera, i have no problems, and when i use ffmpeg directly( ffplay) i also have no lag. But here - it just freeze for like 0.9s and causes delay.

I would guess that you are observing the delay in negotiating the connection between yourself and the rtsp end point. By the way CAP_PROP_OPEN_TIMEOUT_MSEC, won’t change matters it will just force to return if CAP_PROP_OPEN_TIMEOUT_MSEC ms is exceeded before successfully opening the stream.

Im using CAP_PROP_OPEN_TIMEOUT_MSEC just for reduce open time in case, that user will print wrong url. About first part, why then i have no such delay when using directly ffmpeg - (ffplay -fflags nobuffer -flags low_delay rtsp://url)? And how can i reduce that delay?

I guess your are lucky, I get a delay with ffplay -fflags nobuffer -flags low_delay, even when streaming from live555 through localhost. You are also passing additional flags to reduce the startup delay, currently I don’t think there is any way to pass these to VideoCapture so I don’t think there is anything you can do to remove this delay but I may be wrong.

Can i remove negotiation delay somehow? Maybe do some setups for port(using ethernet connection) or some camera setup? Actually, i have low delay at one computer(only one, old laptop, and didnt understand why, cause port is older then any else i tried). And im sure that this is not a port problem.

keep the connection open and keep reading from it in a thread.

I really hope you didn’t plan to constantly open, read a frame, close, open, read a frame, close…

No, im not. I am always trying to read frame in thread, if its possible. And opening stream when i need it(when connecting to another cam). But exactly one line in my code just freeze program → when i open Videocapture(rtsp!), it just freezes for 0.9-1s and then just connect and fast write some frames and after just write frames with delay

I have trouble only with that and only with rtsp connection. I thought i can solve it with CAP_PROP_STREAM_OPEN_TIME_USEC but i dont know how to use it, and cant find any documentation.

Also i even tried to do on another thread, but that changed nothing

I believe you have your answer. opening an RTSP stream can take a moment.

consider it a law of nature. wishing something doesn’t make it possible.

… unless you plan to deeply understand the protocol and the data and how to decode it, and you’re able to implement all of that yourself, you will not be able to work around this. even then, you might just realize that there are physical limits to the whole process.


I understand that, but i dont understand why it have different delays with same background directly and using opencv( i mean, with directly ffmpeg i have 0.5, with opencv ffmpeg i have 1s). I dont need moment stream, i need as low delay as posible.

Im using opencv because in future i need to do some additional function with frames(undistortion, stabilization)

That will be because OpenCV will be using the FFMpeg api slightly differently to the ffmpeg application.