if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
printf("******************* Device is no video capture device *********************
");
return -1;
}
struct v4l2_input input;
CLEAR(input);
if (-1 == ioctl (fd, VIDIOC_G_INPUT, &input.index)) { error_exit ("VIDIOC_G_INPUT");}
if (-1 == ioctl (fd,VIDIOC_ENUMINPUT, &input)) { error_exit ("VIDIOC_ENUMINPUT");}
int fd_init()
{
fd = open("/dev/video0", O_RDWR);
if(fd == -1) { error_exit("capture device"); }
else { printf("******************** Open capture devive success ******************** ");}
struct v4l2_capability cap;
if(ioctl(fd,VIDIOC_QUERYCAP,&cap)==-1) { error_exit("VIOIOV_QUERYCAP"); }
printf("*********************** Capability Informations ************************* ");
printf(" driver: %s ", cap.driver);
printf(" card: %s ", cap.card);
printf(" bus_info: %s ", cap.bus_info);
printf(" version: %u.%u.%u ", (cap.version >> 16) & 0xFF,(cap.version >> 8) & 0xFF,cap.version & 0xFF);
printf(" capabilities: %08x ", cap.capabilities);
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
printf("******************* Device is no video capture device ********************* ");
return -1;
}
struct v4l2_input input;
CLEAR(input);
if (-1 == ioctl (fd, VIDIOC_G_INPUT, &input.index)) { error_exit ("VIDIOC_G_INPUT");}
if (-1 == ioctl (fd,VIDIOC_ENUMINPUT, &input)) { error_exit ("VIDIOC_ENUMINPUT");}
printf("************************ Input information ************************ ");
printf (" inputname: %s ", input.name);
switch (input.type) {
case V4L2_INPUT_TYPE_TUNER: printf(" V4L2_INPUT_TYPE_TUNER ");
case V4L2_INPUT_TYPE_CAMERA: printf(" V4L2_INPUT_TYPE_CAMERA ");
}
printf (" status: %0x ", input.status);
struct v4l2_fmtdesc fmtdesc;
CLEAR(fmtdesc);
fmtdesc.index = 0;
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
printf("********************* Support Format Informations ********************** ");
while ((ret = ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc)) == 0)
{
fmtdesc.index++;
printf(" pixelformat ''%c%c%c%c'', description ''%s'' ",
fmtdesc.pixelformat & 0xFF, (fmtdesc.pixelformat >> 8) & 0xFF, (fmtdesc.pixelformat >> 16) & 0xFF,
(fmtdesc.pixelformat >> 24) & 0xFF, fmtdesc.description);
}
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
CLEAR(cropcap);
cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (-1 == ioctl (fd, VIDIOC_CROPCAP, &cropcap)) { error_exit("VIDIOC_CROPCAP"); }
CLEAR(crop);
crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
crop.c = cropcap.defrect;
if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop) && errno != EINVAL) { error_exit("VIDIOC_S_CROP"); }
一周热门 更多>