且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

列出可用的捕获格式

更新时间:2023-11-30 17:06:40

在 Linux 中,命令行实用程序 v4l2-ctl 显示网络摄像头本机支持的所有格式 -- 使用 sudo 安装apt-get install v4l-utils,使用 v4l2-ctl -dX --list-formats-ext 运行它,其中 X 是相机索引,如 /dev/videoX.这些格式通过 uvcvideo 模块报告给 v4l2 内核模块,并且它们由网络摄像头芯片组本地支持.v4l2 仅支持列出的格式,其他任何格式都需要用户编码,而 RGB 很少提供,尽管几乎所有 CCD 都在拜耳 RGGB 中工作.目前最常见的格式是 YUV422(YUYV 或 YUY2)和 MJPEG,具有一定的重叠:MJPEG 为大分辨率实现更大的帧速率.

In Linux, command line utility v4l2-ctl displays all of a webcam's natively supported formats -- install it with sudo apt-get install v4l-utils, run it with v4l2-ctl -dX --list-formats-ext where X is the camera index as in /dev/videoX. These formats are reported to the v4l2 kernel module via uvcvideo module and they are supported natively by the webcam chipset. Only the listed formats are supported by v4l2, anything else would need to be coded by the user, and RGBs are very seldom provided, despite virtually all CCDs working in Bayer RGGB. The most common formats by far are YUV422 (YUYV or YUY2) and MJPEG, with a certain overlap: MJPEG achieve larger frame rates for large resolutions.

可以在 Linux 的 Chromium GetDeviceSupportedFormats() 实现中找到用于列出相机格式的 C++ 代码 这里.

C++ code for listing the camera formats can be found in Chromium GetDeviceSupportedFormats() implementation for Linux here.

如果您必须插入代码以将 YUV 转换为 RGB,我建议使用 libyuv已针对大量架构进行了优化.

If you have to plug code to convert YUV to RGB I'd recommend libyuv which has been optimized for plenty of architectures.