# Mutlti Threads Not working

**URL:** <https://forum.opencv.org/t/mutlti-threads-not-working/8994>\
**Category:** Python\
**Tags:** programming\
**Created:** [June 1, 2022, 1:54pm UTC](https://forum.opencv.org/t/mutlti-threads-not-working/8994 "2022-06-01T13:54:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tricky](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@Tricky](https://forum.opencv.org/u/Tricky)\
**Post date:** [June 1, 2022, 1:54pm UTC](https://forum.opencv.org/t/mutlti-threads-not-working/8994/1 "2022-06-01T13:54:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [June 1, 2022, 2:11pm UTC](https://forum.opencv.org/t/mutlti-threads-not-working/8994/2 "2022-06-01T14:11:40Z")

</div>

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

> <https://github.com/opencv/opencv/issues/20114>
>
> 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.
