码迷,mamicode.com
首页 > 其他好文 > 详细

v4l2获取摄像头信息

时间:2015-08-04 15:13:49      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

//本程序输出摄像头驱动、码流格式等信息
#include <stdio.h> #include <stdlib.h> //stdio.h and stdlib.h are needed by perror function #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> //O_RDWR #include <unistd.h> #include <sys/mman.h> //unistd.h and sys/mman.h are needed by mmap function #include <stdbool.h>//false and true #include <sys/ioctl.h> #include <linux/videodev2.h>//v4l2 API static int video_capability(int fd) { int ret = 0; /***********get the device capability********/ struct v4l2_capability cap; ret = ioctl(fd, VIDIOC_QUERYCAP, &cap); if (ret < 0) { perror("VIDIOC_QUERYCAP failed "); return ret; } printf("\n****Capability informations****\n"); printf("driver: %s\n", cap.driver); if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) printf("Capture capability is supported\n"); if (cap.capabilities & V4L2_CAP_STREAMING) printf("Streaming capability is supported\n"); if (cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) printf("Overlay capability is supported\n"); return 0; } static int video_fmtdesc(int fd) { /***********Format Enumeration************/ int ret = 0; struct v4l2_fmtdesc fmtdes; // CLEAR(fmtdes); fmtdes.index = 0; fmtdes.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; printf("\n**********vidioc enumeration stream format informations:****\n"); while (1) { ret = ioctl(fd, VIDIOC_ENUM_FMT, &fmtdes); if (ret < 0) break; printf("{ pixelformat = %c%c%c%c, description = %s }\n", (fmtdes.pixelformat & 0xFF), (fmtdes.pixelformat >> 8) & 0xFF, (fmtdes.pixelformat >> 16) & 0xFF, (fmtdes.pixelformat >> 24) & 0xFF, fmtdes.description); if (fmtdes.type == V4L2_BUF_TYPE_VIDEO_CAPTURE) printf("video capture type:\n"); if (fmtdes.pixelformat == V4L2_PIX_FMT_YUYV) printf("V4L2_PIX_FMT_YUYV\n"); if (fmtdes.pixelformat == V4L2_PIX_FMT_YUV420) printf("V4L2_PIX_FMT_YUV420\n"); if (fmtdes.pixelformat == V4L2_PIX_FMT_RGB24) printf("V4L2_PIX_FMT_RGB24\n"); if (fmtdes.pixelformat == V4L2_PIX_FMT_YUV422P) printf("V4L2_PIX_FMT_YUV422P\n"); if (fmtdes.pixelformat == V4L2_PIX_FMT_UYVY) printf("V4L2_PIX_FMT_UYVY\n"); fmtdes.index++; } return 0; } void main() { int fd = open(DEFAULT_DEVICE, O_RDWR | O_NONBLOCK, 0); video_capability(fd); video_fmtdesc(fd); }

代码应该还可以用,不能用的话跟我说一声。

v4l2好像ubuntu系统自带了,如果没有的话安装也很方便,好像是sudo apt-get install  libv4l-dev,百度一下吧

 

v4l2获取摄像头信息

标签:

原文地址:http://www.cnblogs.com/chaingank/p/4701825.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!