V4L2 中error 22, Invalid argument的解決方案

來源:互聯網
上載者:User

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

通過

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.