Problem definition
Say that I have a large number of rtsp cameras (> 100) and I want to perform some operation on it, like image features extraction.
Important: I am not interested in real-time performance, I can do the features extraction even 4 times in a minute. Obviously, the more, the better!
As now, the bottleneck is image acquisition. The frames are acquired with cv2
Read the section below for what I tried.
Pseudocode (current solution)
while True:
for every rstp_cameras:
open_connection
read_current_frame(no batch - the real time frame)
process_frame
close
What I have tried
Here on stackoverflow you can find a lot of answers about reading rtsp cameras in real-time, but all are limited on the number of cameras or have some drawbacks. I tried (with python):
- A thread for each camera [cv2 with ffmpeg]
- Open a connection for each camera in a thread, then get the last frame available for each camera.
- This solution works, but only with a small number of cameras. If we increase the number, a high-end cpu will be 100% on usage (because the thread, in the background, are always reading the last frame and discard it if I am not asking the last)
- [Current solution, no thread, ffmpeg with cv2] Open a connection at every iteration, read the frame and close the connection. This solution allows me to have the last frame available, but the major drawback is the time lost during the opening (~70s lost to open all the frames)
- Cv2 with gstreamer, no thread
- Based on this answer. Is the best solution that I found if you have a small number of cameras. With 20 or plus cameras I have the same problem with the threading solution.
Question & recap
Now, It's clear to me that processing all those cameras in one workstation is hard, because all the solutions that I found, in order to return the last frame available (the one in real-time) continuously reading the frame in the background.
For now, I have not found a solution that allows me to open a connection once, read the real time frame with low-cpu usage, so I can use it with high number of cameras.
Is the parallelization of the reading the only way to solve the problem? I mean, split the cameras into batches, assign batches at a different workstation and then combine the images in some ways?
Thank you.