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
opened 03:39PM - 18 May 21 UTC
category: videoio
category: 3rdparty
On windows when opening up RTSP streams with VideoCapture::open() and the FFMPEG… back end, there is normally a delay, say 2000ms while the stream is setup, which is to be expected.
While this is happening any additional calls to VideoCapture::open() and VideoWriter.open() in other threads are blocked.
Is this blocking/queuing part of OpenCV or FFMPEG and can it be removed?
##### System information (version)
- OpenCV => 4.5.2
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2019
##### Steps to reproduce
<!-- to add code example fence it with triple backticks and optional file extension
```.cpp
// C++ code example
```
or attach as .txt or .zip file
-->
##### Issue submission checklist
- [* ] I report the issue, it's not a question
<!--
OpenCV team works with forum.opencv.org, Stack Overflow and other communities
to discuss problems. Tickets with question without real issue statement will be
closed.
-->
- [ *] I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found solution
<!--
Places to check:
* OpenCV documentation: https://docs.opencv.org
* FAQ page: https://github.com/opencv/opencv/wiki/FAQ
* OpenCV forum: https://forum.opencv.org
* OpenCV issue tracker: https://github.com/opencv/opencv/issues?q=is%3Aissue
* Stack Overflow branch: https://stackoverflow.com/questions/tagged/opencv
-->
- [ ] I updated to latest OpenCV version and the issue is still there
<!--
master branch for OpenCV 4.x and 3.4 branch for OpenCV 3.x releases.
OpenCV team supports only latest release for each branch.
The ticket is closed, if the problem is not reproduced with modern version.
-->
- [ ] There is reproducer code and related data files: videos, images, onnx, etc
<!--
The best reproducer -- test case for OpenCV that we can add to the library.
Recommendations for media files and binary files:
* Try to reproduce the issue with images and videos in opencv_extra repository
to reduce attachment size
* Use PNG for images, if you report some CV related bug, but not image reader
issue
* Attach the image as archive to the ticket, if you report some reader issue.
Image hosting services compress images and it breaks the repro code.
* Provide ONNX file for some public model or ONNX file with with random weights,
if you report ONNX parsing or handling issue. Architecture details diagram
from netron tool can be very useful too. See https://lutzroeder.github.io/netron/
-->
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