'Get list of Video Device in python on Windows machine

I am working on a software, where an USB video device is used. I use cv2.VideoCapture() function from the openCV library in the software. The function need to get index of the video device, but my usb cam has sometimes index 0, sometimes index 1 or index 7. Because the software must be user friendly, so I would like to get list of all available USB video devices and let the user choose what device he wants. The best would be get name and address of the devices. I tried search in older questions but if there was answer, user used c++ and I do not know how to do it in python. The solution should be easy and elegant Thank you very much for your help and I hope that the question is understandable.



Solution 1:[1]

There is a solution https://github.com/pvys/CV-camera-finder

from pymf import get_MF_devices
device_list = get_MF_devices()
for i, device_name in enumerate(device_list):
    print(f"opencv_index: {i}, device_name: {device_name}")

=> opencv_index: 0, device_name: Integrated Webcam

with get_MF_devices function, you can recieve device list (opencv index and friendly name). But if you have multiple cameras with same friendly names, this library can't solve your problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 O?uz Alper ?sen