Linux中通过v4l2框架获取摄像头的能力的方法
v4l2(video for linux two)是Linux中内核提供给应用层访问音视频驱动的统一接口。v4l2中获取摄像头的能力的是通过ioctl函数的VIDIOC_QUERYCAP命令获取,并且获得的能力使用结构体v4l2_capability描述。
v4l2能力藐视结构体v4l2_capability的具体介绍如下:
定义文件:
/kernel/include/uapi/linux/videodev2.h
结构体原型:
struct v4l2_capability {
__u8 driver[16]; //name of the driver module
__u8 card[32]; //name of the card
__u8 bus_info[32];//name of the bus
__u32 version; //kernel version
__u32 capabilities;//capabilities of the physical device as a whole
__u32 device_caps; //capabilities aeccessed via this particular device
__u32 reserved[3];
};
其中capabilities的值各个位所对应的功能:
/* Values for 'capabilities' field */
#define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */
#define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */
#define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */
#define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a raw VBI capture device */
#define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a raw VBI output device */
#define V4L2_CAP_SLICED_VBI_CAPTURE 0x00000040 /* Is a sliced VBI capture device */
#define V4L2_CAP_SLICED_VBI_OUTPUT 0x00000080 /* Is a sliced VBI output device */
#define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */
#define V4L2_CAP_VIDEO_OUTPUT_OVERLAY 0x00000200 /* Can do video output overlay */
#define V4L2_CAP_HW_FREQ_SEEK 0x00000400 /* Can do hardware frequency seek */
#define V4L2_CAP_RDS_OUTPUT 0x00000800 /* Is an RDS encoder */
/* Is a video capture device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_CAPTURE_MPLANE 0x00001000
/* Is a video output device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_OUTPUT_MPLANE 0x00002000
/* Is a video mem-to-mem device that supports multiplanar formats */
#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000
/* Is a video mem-to-mem device */
#define V4L2_CAP_VIDEO_M2M 0x00008000
#define V4L2_CAP_TUNER 0x00010000 /* has a tuner */
#define V4L2_CAP_AUDIO 0x00020000 /* has audio support */
#define V4L2_CAP_RADIO 0x00040000 /* is a radio device */
#define V4L2_CAP_MODULATOR 0x00080000 /* has a modulator */
#define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */
#define V4L2_CAP_ASYNCIO 0x02000000 /* async I/O */
#define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls */
#define V4L2_CAP_DEVICE_CAPS 0x80000000 /* sets device capabilities field */
源代码:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/videodev2.h>
/*VIDIOC_QUERYCAP ---- struct v4l2_capability*/
/*
header path:./kernel/include/uapi/linux/videodev2.hstruct v4l2_capability {__u8 driver[16]; //name of the driver module__u8 card[32]; //name of the card__u8 bus_info[32];//name of the bus__u32 version; //kernel version__u32 capabilities;//capabilities of the physical device as a whole__u32 device_caps; //capabilities aeccessed via this particular device__u32 reserved[3];
};
*/int main(int argc, char *argv[])
{if(argc < 2){printf("this process arg error\n");return -1;}printf("camera device:%s\n", argv[1]);int cam_fd = open(argv[1], O_RDWR);if(cam_fd < 0){printf("open the camera device:%s is error: %s\n", argv[1], strerror(errno));return -2;}struct v4l2_capability cap;if(ioctl(cam_fd, VIDIOC_QUERYCAP, &cap) == -1){printf("Unable query the ability of the device %s\n ", argv[1]);return -3;}printf("driver:\t%s\n", cap.driver);printf("card:\t%s\n", cap.card);printf("bus_info:\t%s\n", cap.bus_info);printf("version:\t%d\n", cap.version);printf("capability:\t%x\n", cap.capabilities);if((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == V4L2_CAP_VIDEO_CAPTURE){printf("the device %s is support capture\n", argv[1]);}else{printf("the device %s is not support capture\n", argv[1]);}if((cap.capabilities & V4L2_CAP_STREAMING) == V4L2_CAP_STREAMING){printf("the device %s is support streaming\n", argv[1]);}else{printf("the device %s is not support streaming\n", argv[1]);}printf("device_caps:\t%x\n", cap.device_caps);close(cam_fd);return 0;
}
使用:
Linux中通过v4l2框架获取摄像头的能力的方法相关推荐
- Qt 中获取摄像头图像数据的方法
Qt 中获取摄像头图像数据的方法 在 Qt 中提供了 QCamera 类用来操作摄像头.(这里的摄像头指的是电脑上常用的那种 USB 摄像头或网络摄像头,暂时还不支持工业相机.)摄像头获取的实时图像可 ...
- linux中spi驱动框架
原 linux中spi驱动框架 2016年09月14日 15:57:06 andylauren 阅读数:403 <span class="tags-box artic-tag-box& ...
- linux中通过date命令获取昨天或明天时间的方法
linux中通过date命令获取昨天或明天时间的方法 date命令可以获取当前的时间,通过man,可以看到date有很多参数可以用,很容易做到格式化 date +"%F" 输出格式 ...
- 在Linux中查找和删除重复文件的4种方法
大神教你在Linux中查找和删除重复文件的4种方法 在本教程中,您将学习如何使用rdfind和fdupes命令行工具以及称为DupeGuru和FSlint的GUI工具在Linux中查找和删除重复文件. ...
- linux vim m,关于linux中使用vim打开文件出现^M的解决方法
在linux下,不可避免的会用VIM打开一些windows下编辑过的文本文件.我们会发现文件的每行结尾都会有一个^M符号,这是因为 DOS下的编辑器和Linux编辑器对文件行末的回车符处理不一致, 各 ...
- html js文本框文字列出,js实现文本框中输入文字页面中div层同步获取文本框内容的方法...
这篇文章主要介绍了js实现文本框中输入文字页面中div层同步获取文本框内容的方法,实例分析了javascript操作dom元素的技巧,需要的朋友可以参考下 本文实例讲述了js实现文本框中输入文字页面中 ...
- 在vuejs 中使用axios不能获取属性data的解决方法
在vuejs 中使用axios不能获取属性data的解决方法 参考文章: (1)在vuejs 中使用axios不能获取属性data的解决方法 (2)https://www.cnblogs.com/lo ...
- linux中使用文本工具截取ip 的几种方法
linux中使用文本工具截取ip 的几种方法 1,使用awk工具 [root@mycentos data]# ifconfig ens33 ens33: flags=4163<UP,BROADC ...
- Linux中如何查看某个端口是否被占用的方法
LINUX中如何查看某个端口是否被占用的方法 之前查询端口是否被占用一直搞不明白,现在总结下: 1.netstat -anp |grep 端口号 如下,我以3306为例,netstat -anp |g ...
最新文章
- Merge into的使用
- 使用驱动器f:中的光盘之前需要将其格式化_mac虚拟光驱Daemon Tools高级功能详解—光盘刻录...
- C++ 智能指针的正确使用方式
- 不可不读的绝对英文经典
- uve (mui/light7)写APP的使用心得(大坑);
- oracle 优化分组 sql语句,Oracle SQL语句之常见优化方法 五
- java请求接口示例_Java 8:功能接口示例
- Neo4j:找到两个纬度/经度之间的中间点
- LeetCode 750. 角矩形的数量(DP)
- OpenState之 Mac学习 实验
- MyBatis学习--高级映射
- i386和x86-64区别通俗易懂版本(转)
- Android应用开发进阶,2021Android最新大厂面试真题
- visio2013安装包及破解工具KMS
- 最新版Eclipse下载及安装(详细)
- 文件描述符 fd 究竟是什么?
- 实现进程互斥需要遵循的原则
- 4.9冰箱的温度c语言,话说夏天冰箱温度调到多少度为最佳?
- 酬乐天扬州初逢席上见赠 唐 · 刘禹锡
- Java---SSM---Spring(1)