如何获得Linux上的列表视频采集设备名称(网络摄像机)(Ubuntu的)? (C / C ++) [英] How to get a list video capture devices NAMES (web cameras) on linux ( ubuntu )? (C/C++)
问题描述
所以,我需要的是简单的 - 目前avaliable视频捕获设备(网络摄像头)的列表。我需要它在简单的C或C ++控制台应用程序。通过列表我的意思是像这样的控制台输出:
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
所以我知道如何使用code喜欢拿道具凸轮如W,H等:
So I know how to get cam props such as W, H etc using code like:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/videodev.h>
int main(){
int fd;
struct video_capability video_cap;
struct video_window video_win;
struct video_picture video_pic;
if((fd = open("/dev/video0", O_RDONLY)) == -1){
perror("cam_info: Can't open device");
return 1;
}
if(ioctl(fd, VIDIOCGCAP, &video_cap) == -1)
perror("cam_info: Can't get capabilities");
else {
printf("Name:\t\t '%s'\n", video_cap.name);
printf("Minimum size:\t%d x %d\n", video_cap.minwidth, video_cap.minheight);
printf("Maximum size:\t%d x %d\n", video_cap.maxwidth, video_cap.maxheight);
}
if(ioctl(fd, VIDIOCGWIN, &video_win) == -1)
perror("cam_info: Can't get window information");
else
printf("Current size:\t%d x %d\n", video_win.width, video_win.height);
if(ioctl(fd, VIDIOCGPICT, &video_pic) == -1)
perror("cam_info: Can't get picture information");
else
printf("Current depth:\t%d\n", video_pic.depth);
close(fd);
return 0;
}
但不能命名(如何获取名称?
but not name( How to get Names?
所以它似乎很简单,但我有一个要求 - 利用原生操作系统的API尽可能 - 无需外部库 - 毕竟 - 我们想要的是打印出AA列表 - !不飞至月球)
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获得视频捕获设备的列表上的Linux?和<一个href=\"http://stackoverflow.com/questions/4483366/how-to-get-a-list-video-capture-devices-names-web-cameras-on-linux-ubuntu\">special在得到相机名称的详细信息,提供正确,测试的答案
- How获得在Mac OS的视频采集设备的列表?用正确的的,还没有被我的答案,测试
- How获得视频捕获设备的列表上的窗口?用正确的的,测试的答案
- How获得使用Qt(跨平台)列表中的视频采集设备的名字呢?
- 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)?
推荐答案
您使用的是V4L1 API,它是德precated - V4L2是新的code中的preferred API
You are using the V4L1 API which is deprecated - V4L2 is the preferred API for new code.
在任何情况下, VIDIOC_QUERYCAP
的ioctl()
可能是你在找什么。你会想看看返回的结构v4l2_capability
结构。
In any case, the VIDIOC_QUERYCAP
ioctl()
is probably what you are looking for. You will want to have a look at the .card
field of the returned struct v4l2_capability
structure.
编辑:
您可以看看源$ C $ c代表的 为v41-信息
工具,这不正是你想要的东西。
You could have a look at the source code for the v4l-info
utility, which does exactly what you want.
这篇关于如何获得Linux上的列表视频采集设备名称(网络摄像机)(Ubuntu的)? (C / C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!