I’m using OpenCV in Python to read frames from an RTSP stream. I’m actually trying to read many streams for a multi-camera tool, but I have this problem with a single stream as well. So long as I call read() at least as fast as the video stream’s framerate, things work out. But if I fall behind and don’t call read() fast enough, then calls to read() hang for very long periods of time, like half a minute. It is effectively dead. There is no timeout option for read() or for configuring the VideoCapture object that I am aware of, and read() simply won’t tolerate a failure to maintain pace. I’m already running the frame retrieval on a background thread (bearing in mind that threading in Python doesn’t really amount to much, GIL), but ultimately, any solution that boils down “really really never ever miss a single frame or else it’ll hang” isn’t a sufficient solution. Any reasonable expectation would be that an app is permitted to request a frame from the stream whenever it is able to do so and receive the current or most recent frame without risking having VideoCapture veritably freeze up.
Does anyone have a solution in mind? I’m desperate to get this working and have no ideas what to try next. I’ve been hammering this thing for days and I’ve made basically no progress on this issue.