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的編碼格式不同,後面處理碼流也要相對於的變化。
通過