V4L2 中error 22, Invalid argument的解决方法

来源:互联网 发布:华为手机查看网络制式 编辑:程序博客网 时间:2024/05/22 04:53

Error: pixel format not supported

 error 22, Invalid argument


我的摄像头是笔记本上自带的,用命令lsusb看到的情况如下:

Bus 002 Device 003: ID 17ef:4808 Lenovo 


这个问题很多人遇到过,原因是采取的编码与设备的支持的编码不兼容

以我的环境为例,我在代码中设定的编码格式为:

fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420


可以使用函数返回设备支持的pixel format:

ioctl(fd, VIDIOC_ENUM_FMT, &fmt1)


struct v4l2_fmtdesc fmt;int ret;memset(&fmt, 0, sizeof(fmt));fmt.index = 0;fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;while ((ret = ioctl(fd, VIDIOC_ENUM_FMT, fmt)) == 0) //查看编码格式{fmt.index++;printf("pixelformat is '%c%c%c%c', description is '%s' \n",fmt.pixelformat & 0xFF,       (fmt.pixelformat >> 8) & 0xFF, (fmt.pixelformat >> 16) & 0xFF,       (fmt.pixelformat >> 24) & 0xFF,fmt.description); }



这段码返回了

pixelformat is 'YUYV', description is 'YUV 4:2:2 (YUYV)'

把上面的

fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420

改为fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV 即可。不过需要明白,YUV420和YUYV的编码格式不同,后面处理码流也要相对于的变化。


通过

原创粉丝点击