Linux??V4L2???????????
???????????? ???????[ 2013/8/26 14:13:38 ] ????????
??????????test.c
#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
int main(){
//////
int fd = open("/dev/video0"??O_RDWR);
printf("TK------->>>fd is %d
"??fd);
//////
struct v4l2_capability cap;
ioctl(fd??VIDIOC_QUERYCAP??&cap);
printf("TK---------->>>>>Driver Name:%s
Card Name:%s
Bus info:%s
"??cap.driver??cap.card??cap.bus_info);
//////
struct v4l2_fmtdesc fmtdesc;
fmtdesc.index = 0; fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
while(ioctl(fd??VIDIOC_ENUM_FMT??&fmtdesc) != -1){
printf("TK-------->>>>>fmtdesc.description is %s
"??fmtdesc.description);
fmtdesc.index ++;
}
//////
struct v4l2_format fmt;
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ioctl(fd??VIDIOC_G_FMT??&fmt);
printf("TK----------->>>>>fmt.fmt.width is %d
fmt.fmt.pix.height is %d
fmt.fmt.pix.colorspace is %d
"??fmt.fmt.pix.width??fmt.fmt.pix.height??fmt.fmt.pix.colorspace);
//////
struct v4l2_requestbuffers req;
req.count = 4;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
ioctl(fd??VIDIOC_REQBUFS??&req);
struct buffer{
void *start;
unsigned int length;
}*buffers;
buffers = (struct buffer*)calloc (req.count?? sizeof(*buffers));
unsigned int n_buffers = 0;
for(n_buffers = 0; n_buffers < req.count; ++n_buffers){
struct v4l2_buffer buf;
memset(&buf??0??sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = n_buffers;
if(ioctl(fd??VIDIOC_QUERYBUF??&buf) == -1){
printf("TK---------_>>>>>>error
");
close(fd);
exit(-1);
}
buffers[n_buffers].length = buf.length;
buffers[n_buffers].start = mmap(NULL??buf.length??PROT_READ|PROT_WRITE??MAP_SHARED??fd??buf.m.offset);
if(MAP_FAILED == buffers[n_buffers].start){
printf("TK--------__>>>>>error 2
");
close(fd);
exit(-1);
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11