So all I need is simple - a list of currently avaliable video capture devices (web cameras). I need it in simple C or C++ console app. By list I mean something like such console output:
1) Asus Web Camera
2) Sony Web Camera
So It seems simple but I have one requirement - use of native OS apis as much as possible - no external libs - after all - all we want is to print out a a list - not to fly onto the moon!)
How to do such thing?
also from this series:
- How to get a list of video capture devices on linux? and special details on getting cameras NAMES with correct, tested answers
- How to get a list of video capture devices on Mac OS? with correct, not yet tested by my answers
- How to get a list of video capture devices on windows? with correct, tested answers
- How to get a list video capture devices NAMES using Qt (crossplatform)?
V4L2 documentation says that there can be 64 allowed devices for each type. For instance for path /dev/video there can be 64 devices addresssed as /dev/video0, /dev/video1, /dev/video2 ...
Iterate over 64 devices until the ioctl retuens ENIVAL which specifies end of the tree.
This is a code snippet I had laying around. Probably from a book. I guess you could just iterate over all /dev/videoN nodes and get the info.
It's easy by just traversing sysfs devices by a given class. The following command-line one liner would do so:
You can do the same thing in C/C++ application, by just opening up
/sys/class/video4linux
directory, it will have symlinks to all your web cameras as video4linux devices:You can follow every symlink to a directory of every device and read full contents of
name
file in that directory to get the name.You can use the following bash command:
In order to use the above command, you must install package v4l-utils before. In Ubuntu/Debian you can use the command: