# Viewing multiple USB or IP cameras simultaneously with OpenCV

**URL:** <https://forum.opencv.org/t/viewing-multiple-usb-or-ip-cameras-simultaneously-with-opencv/4223>\
**Category:** Python\
**Tags:** videoio\
**Created:** [July 7, 2021, 8:04pm UTC](https://forum.opencv.org/t/viewing-multiple-usb-or-ip-cameras-simultaneously-with-opencv/4223 "2021-07-07T20:04:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MMIX2009](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mmix2009/32/2248_2.png) [@MMIX2009](https://forum.opencv.org/u/MMIX2009)\
**Post date:** [July 7, 2021, 8:05pm UTC](https://forum.opencv.org/t/viewing-multiple-usb-or-ip-cameras-simultaneously-with-opencv/4223/1 "2021-07-07T20:05:00Z")

</div>

I am looking for some guidance and/or sample Python code on running multiple USB or IP cameras simultaneously with OpenCV.  
My application will use either 4 cameras connected to a PC via a USB hub and/or 4 IP cameras o the same local network as the PC.  
Examples that I found on the Internet show grabbing frames sequentially on the same thread or using multiple threads.  
Does [OpenCV.org](http://OpenCV.org) officially support the multiple camera captures? Where can I find some working/validated code? If no code is available, I’d appreciate some guidance on how to make it work.  
Thanks.  
BT

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 7, 2021, 9:32pm UTC](https://forum.opencv.org/t/viewing-multiple-usb-or-ip-cameras-simultaneously-with-opencv/4223/2 "2021-07-07T21:32:48Z")

</div>

sure, opencv supports opening multiple cameras. use one VideoCapture object per source.

frame rates never perfectly match in practice. it’s the same problem as in socket programming.

if you simply ran it all in lockstep, reading one frame from every camera, the slowest would hold all the others up, which would eventually run out of buffer and give up.

to handle that properly, you have to read each camera as soon as possible.

OpenCV recently gained `waitAny`:  
[https://docs.opencv.org/master/d8/dfe/classcv\_1\_1VideoCapture.html#ade1c7b8d276fea4d000bc0af0f1017b3](https://docs.opencv.org/master/d8/dfe/classcv_1_1VideoCapture.html#ade1c7b8d276fea4d000bc0af0f1017b3)

wtf it’s not exposed to python. that’s a bummer! you could open an issue about it. it might be an easy fix.

before that, people had to use multiple threads and synchronization primitives to do the job.

---

<div class="post-metadata">

**Author:** ![MMIX2009](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mmix2009/32/2248_2.png) [@MMIX2009](https://forum.opencv.org/u/MMIX2009)\
**Post date:** [July 8, 2021, 12:55am UTC](https://forum.opencv.org/t/viewing-multiple-usb-or-ip-cameras-simultaneously-with-opencv/4223/3 "2021-07-08T00:55:59Z")

</div>

Thanks for your feedback.  
I typically program in Python, but I am willing to give C++ a try and use this new function.

I welcome any other feedback from others if any.  
Thanks again.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 23, 2024, 8:20am UTC](https://forum.opencv.org/t/viewing-multiple-usb-or-ip-cameras-simultaneously-with-opencv/4223/4 "2024-08-23T08:20:03Z")

</div>

A post was split to a new topic: [The trick is to use “cv2.CAP\_ANY”](https://forum.opencv.org/t/the-trick-is-to-use-cv2-cap-any/18571)
