linux下视频采集时,ioctl函数报无效变量错误,回答好的我会速度给分的 30
#include<stdio.h>#include<stdlib.h>#include<sys/types.h>#include<sys/stat.h>#include<...
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <string.h>
#include <linux/videodev.h>
#define VIDEO_MAXFRAME 2
typedef struct _v4l_struct
{
int fd;
struct video_capability capability;
struct video_picture picture;
struct video_mmap mmap;
struct video_mbuf mbuf;
unsigned char* map;
int frame_current;
int frame_using[VIDEO_MAXFRAME];
}v4l_device;
int debug = 1;
int main()
{
v4l_device vd;
vd.fd = open("/dev/video0", O_RDWR);
if (vd.fd < 0)
{
perror("open camera error:");
return -1;
}
if (ioctl(vd.fd, VIDIOCGCAP, &(vd.capability)) < 0)
{
perror("ioctl capability error:");
return -1;
}
if (debug)
{
printf("video name : %s\n",vd.capability.name);// struct video_capability video_caps;
printf("video_caps.channels :%d\n",vd.capability.channels);
printf("video_caps.type : 0x%x\n",vd.capability.type);
printf("video maxwidth : %d\n",vd.capability.maxwidth);
printf("video maxheight : %d\n",vd.capability.maxheight);
printf("video minwidth : %d\n",vd.capability.minwidth);
printf("video minheight : %d\n",vd.capability.minheight);
}
if (ioctl(vd.fd, VIDIOCGPICT, &(vd.picture)) < 0)
{
perror("ioctl picture error:");
return -1;
}
if (debug)
{
printf("video_pic.brightness : %d\n",vd.picture.brightness);
printf("video_pic.colour : %d\n",vd.picture.colour);
printf("video_pic.contrast : %d\n",vd.picture.contrast);
printf("video_pic.depth : %d\n",vd.picture.depth);
printf("video_pic.hue : %d\n",vd.picture.hue);
printf("video_pic.whiteness : %d\n",vd.picture.whiteness);
printf("video_pic.palette : %d\n",vd.picture.palette);
}
struct video_channel video_chan;
if (ioctl(vd.fd,VIDIOCGCHAN,&video_chan) == -1)//銮峰彇淇″佛婧愮殑灞炴€? {
perror("ioctl (VIDIOCGCHAN)");
return -1;
}
if (debug)
{
printf("video channel: %d\n",video_chan.channel);
printf("video channel name: %s\n",video_chan.name);
printf("video channel type: %d\n",video_chan.type);
}
memset(&vd.mbuf, 0, sizeof (vd.mbuf));
if (ioctl(vd.fd, VIDIOCGMBUF, &(vd.mbuf)) < 0)
{
perror("ioctl mbuf error:");
return -1;
}
return 0;
}
ioctl(vd.fd,VIDIOCGCHAN,&video_chan)和ioctl(vd.fd, VIDIOCGMBUF, &(vd.mbuf)报参数无效,这是怎么回事?? 展开
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <string.h>
#include <linux/videodev.h>
#define VIDEO_MAXFRAME 2
typedef struct _v4l_struct
{
int fd;
struct video_capability capability;
struct video_picture picture;
struct video_mmap mmap;
struct video_mbuf mbuf;
unsigned char* map;
int frame_current;
int frame_using[VIDEO_MAXFRAME];
}v4l_device;
int debug = 1;
int main()
{
v4l_device vd;
vd.fd = open("/dev/video0", O_RDWR);
if (vd.fd < 0)
{
perror("open camera error:");
return -1;
}
if (ioctl(vd.fd, VIDIOCGCAP, &(vd.capability)) < 0)
{
perror("ioctl capability error:");
return -1;
}
if (debug)
{
printf("video name : %s\n",vd.capability.name);// struct video_capability video_caps;
printf("video_caps.channels :%d\n",vd.capability.channels);
printf("video_caps.type : 0x%x\n",vd.capability.type);
printf("video maxwidth : %d\n",vd.capability.maxwidth);
printf("video maxheight : %d\n",vd.capability.maxheight);
printf("video minwidth : %d\n",vd.capability.minwidth);
printf("video minheight : %d\n",vd.capability.minheight);
}
if (ioctl(vd.fd, VIDIOCGPICT, &(vd.picture)) < 0)
{
perror("ioctl picture error:");
return -1;
}
if (debug)
{
printf("video_pic.brightness : %d\n",vd.picture.brightness);
printf("video_pic.colour : %d\n",vd.picture.colour);
printf("video_pic.contrast : %d\n",vd.picture.contrast);
printf("video_pic.depth : %d\n",vd.picture.depth);
printf("video_pic.hue : %d\n",vd.picture.hue);
printf("video_pic.whiteness : %d\n",vd.picture.whiteness);
printf("video_pic.palette : %d\n",vd.picture.palette);
}
struct video_channel video_chan;
if (ioctl(vd.fd,VIDIOCGCHAN,&video_chan) == -1)//銮峰彇淇″佛婧愮殑灞炴€? {
perror("ioctl (VIDIOCGCHAN)");
return -1;
}
if (debug)
{
printf("video channel: %d\n",video_chan.channel);
printf("video channel name: %s\n",video_chan.name);
printf("video channel type: %d\n",video_chan.type);
}
memset(&vd.mbuf, 0, sizeof (vd.mbuf));
if (ioctl(vd.fd, VIDIOCGMBUF, &(vd.mbuf)) < 0)
{
perror("ioctl mbuf error:");
return -1;
}
return 0;
}
ioctl(vd.fd,VIDIOCGCHAN,&video_chan)和ioctl(vd.fd, VIDIOCGMBUF, &(vd.mbuf)报参数无效,这是怎么回事?? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询