Mutlti Threads Not working

Newbee question.
I try to screenshot multiple rtsp streams using threads. unfortunately it seems that opencv only handle one stream at the time

ex;

def mutiple_threads() # run x 100 threads
cap = cv2.VideoCapture(stream)
ret, frame = cap.read()
cv2.imwrite(pathtosave, frame)

only one opencv is running and blocking the rest from the threads.
Is there a way to run multiple opencv at the same time using threads ?

also how do i kill a running opencv after a certain time. Can’t find a timeout or similar.

timer + cap.release() no succes.

regards,
Tricky

VideoCapture with the FFMpeg backend has a lock in VideoCapture::open() which means that only one open can happen in any thread at any one time. See below for more details

With rtsp streams this is more apparent because each stream can take a number of seconds to open. Try with a video file to see if the situation improves.

1 Like