Search code examples
pythonffmpegsubprocesswebcam

How can I get the name of the webcams present on the computer in python?


I have a problem. I would need to use ffmpeg with subprocess in python for video capture.

For this I need to identify the name of the cameras present in the computer in order to be able to pass this parameter to the ffmpeg process.

So far I have used the WMI module, but it only works on windows and is not very easy to use.

Is there any easier way to extract the names of the webcams on your computer and save them to an array? Maybe also using the ffmpeg list-devices and filtering the results? Can you help me?

I would not like to use the WMI module anymore, as I would like a universal solution for windows or linux, perhaps using subprocess and the ffmpeg list_devices command. Thank you


Solution

  • Windows

    In Windows use dshow:

    ffmpeg -list_devices true -f dshow -i dummy
    

    Linux

    In Linux use v4l2-ctl:

    v4l2-ctl --list-devices
    

    Then connect using the FFmpeg video4linux2/v4l2 demuxer.

    Also see