Search code examples
pythonffmpegwmi

Converting code using wmi to code using ffmpy


I have the following code that prints out the names of USB cameras connected to my PC:

import wmi
c = wmi.WMI()
wql = "Select * From Win32_USBControllerDevice"
for item in c.query(wql):
    a = item.Dependent.PNPClass
    b = item.Dependent.Name.upper()
    if (a.upper() == 'MEDIA' or a.upper() == 'CAMERA') and 'AUDIO' not in b:
        print(item.Dependent.Name)

The problem with this code is that it only works in Windows. I want to alter this code so that it works on all operating systems. I know that I have to use something other than wmi, since wmi only works in Windows. So, I was thinking about using an ffmpeg wrapper called ffmpy. So maybe I could convert the code to use ffmpy? I got the code above from the following SO post: Associate USB Video Capture Device Friendly Name with OpenCV Port Number in Python. Any help would be much appreciated! Thanks!


Solution

  • The answer to this question is no; there is no OS-independent way of getting the names of USB cameras connected to your PC. However, there is platform-specific code that can get the job done: https://stackoverflow.com/a/68402011/13386603