【发布时间】:2011-05-27 20:52:54
【问题描述】:
所以我需要的只是简单的 - 当前可用的视频捕获设备(网络摄像头)的列表。我在简单的 C 或 C++ 控制台应用程序中需要它。通过列表,我的意思是这样的控制台输出:
1) Asus Web Camera
2) Sony Web Camera
所以我知道如何使用以下代码获取诸如 W、H 等 cam 道具:
#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;
}
但不是名字(如何获得名字?
所以看起来很简单,但我有一个要求 - 尽可能使用本机 OS api - 没有外部库 - 毕竟 - 我们想要的只是打印出一个列表 - 而不是飞上月球!)
这样的事情怎么办?
也来自这个系列:
- How to get a list of video capture devices on linux? 和 special details on getting cameras NAMES 提供正确、经过测试的答案
- How to get a list of video capture devices on Mac OS? 正确,但我的答案尚未测试
- How to get a list of video capture devices on windows? 提供正确、经过测试的答案
- How to get a list video capture devices NAMES using Qt (crossplatform)?
【问题讨论】:
-
/sys/class/video4linux/video*/name -
@Ignacio Vazquez-Abrams 您能否提供与我的姓名集成的代码?