UVC摄像头技术笔记
+ -

USB摄像头UVC视频流描述符中的bFormatIndex和bFrameIndex

2023-02-23 533 0

bFormatIndex

USB摄像头一般支持多种视频格式,比如MJPG,H264,YUY2,NV12,RGB等,这些不同的视频格式代表着传输的视频图像的数据组织方式。这些视频格式通过UVC视频流各视频流相关的类型描述符来进行描述符。

在Windows系统下,我们可以通过PotPlayer来查看摄像头支持的格式:
PotPlayer

当然,这些不同的视频格式的数据结构描述可以通过UsbTreeViewer来查看其数据结构
如MJPG的如下:

   ----- Video Streaming MJPEG Format Type Descriptor ----
bLength                  : 0x0B (11 bytes)
bDescriptorType          : 0x24 (Video Streaming Interface)
bDescriptorSubtype       : 0x06 (Format MJPEG)
bFormatIndex             : 0x01 (1)
bNumFrameDescriptors     : 0x05 (5)
bmFlags                  : 0x00 (Sample size is not fixed)
bDefaultFrameIndex       : 0x01 (1)
bAspectRatioX            : 0x00
bAspectRatioY            : 0x00
bmInterlaceFlags         : 0x00
 D0 IL stream or variable: 0 (no)
 D1 Fields per frame     : 0 (2 fields)
 D2 Field 1 first        : 0 (no)
 D3 Reserved             : 0
 D4..5 Field pattern     : 0 (Field 1 only)
 D6..7 Display Mode      : 0 (Bob only)
bCopyProtect             : 0x00 (No restrictions)
*!*ERROR:  no Color Matching Descriptor for this format
Data (HexDump)           : 0B 24 06 01 05 00 01 00 00 00 00                  .$.........

YUY2的如下:

  ------- VS Uncompressed Format Type Descriptor --------
bLength                  : 0x1B (27 bytes)
bDescriptorType          : 0x24 (Video Streaming Interface)
bDescriptorSubtype       : 0x04 (Uncompressed Format Type)
bFormatIndex             : 0x02 (2)
bNumFrameDescriptors     : 0x07 (7 Frame Descriptors)
guidFormat               : {32595559-0000-0010-8000-00AA00389B71} (YUY2)
bBitsPerPixel            : 0x10 (16 bits per pixel)
bDefaultFrameIndex       : 0x01 (Index 1)
bAspectRatioX            : 0x00
bAspectRatioY            : 0x00
bmInterlaceFlags         : 0x00
 D0 IL stream or variable: 0 (no)
 D1 Fields per frame     : 0 (2 fields)
 D2 Field 1 first        : 0 (no)
 D3 Reserved             : 0
 D4..5 Field pattern     : 0 (Field 1 only)
 D6..7 Display Mode      : 0 (Bob only)
bCopyProtect             : 0x00 (No restrictions)
Data (HexDump)           : 1B 24 04 02 07 59 55 59 32 00 00 10 00 80 00 00   .$...YUY2.......
                           AA 00 38 9B 71 10 01 00 00 00 00                  ..8.q......

UVC规范中,不同的视频格式采用不同的视频流格式类型描述符来描述符,这些描述符的数据结构是通过UVC规范定义的。可参见:https://www.usbzh.com/article/detail-6.html
不过由于市面上的视频格式多种多样,不可能一个摄像头支持所有格式,故在一个摄像头内部,可通过其bFormatIndex来代表这个摄像头支持的一种视频格式,故在同一个摄像头的配置描述符下,如果bFormatIndex不同,代表着不同的视频格式。有几种bFormatIndex,代表该摄像头支持几种视频格式。

另外,在UVC的视频流输入头描述符中bNumFormats也描述符系统支持的视频格式数量。

        ---- VC-Specific VS Video Input Header Descriptor -----
bLength                  : 0x0F (15 bytes)
bDescriptorType          : 0x24 (Video Streaming Interface)
bDescriptorSubtype       : 0x01 (Input Header)
bNumFormats              : 0x02
wTotalLength             : 0x01A3 (419 bytes)
           后续省略....

bFormatIndex一般从1开始,对于当前比较新的windows操作系统,该值可以不从1开始,但对于老的操作系统,如不从1开始,在设备管理器中会显示设备启动失败。
另外,对于支持多种视频格式的摄像头,bFormatIndex的连续性本人并未做深入研究,不过为了兼容性,还是建议从1开始,连续的自然数即可。

bFrameIndex & bDefaultFrameIndex

不同的视频格式下得根据需求的不同,支持不同的分辨率,如常见的1080x1920,720x1280等。在同一个bForamtIndex下,通过其Frame描述符来这定义支持的不同的分辨率。bFrameIndex一般从1开始,但也可以不从1开始并且可以不连续。
同一格式下支持的分辨率的个数由bFormatIndex所在的视频格式描述符中的bNumFrameDescriptors指定。

另外视频格式描述符中的bDefaultFrameIndex指定了当前格式下的默认分辨率。


        ----- Video Streaming MJPEG Frame Type Descriptor -----
bLength                  : 0x1E (30 bytes)
bDescriptorType          : 0x24 (Video Streaming Interface)
bDescriptorSubtype       : 0x07 (MJPEG Frame Type)
bFrameIndex              : 0x02
bmCapabilities           : 0x00
wWidth                   : 0x03C0 (960)
wHeight                  : 0x021C (540)
dwMinBitRate             : 0x0ED4E000 (248832000 bps -> 31.104 MB/s)
dwMaxBitRate             : 0x0ED4E000 (248832000 bps -> 31.104 MB/s)
dwMaxVideoFrameBufferSize: 0x000FD44D (1037389 bytes)
dwDefaultFrameInterval   : 0x00051615 (33.3333 ms -> 30.000 fps)
bFrameIntervalType       : 0x01 (1 discrete frame interval supported)
adwFrameInterval[1]      : 0x00051615 (33.3333 ms -> 30.000 fps)
Data (HexDump)           : 1E 24 07 02 00 C0 03 1C 02 00 E0 D4 0E 00 E0 D4   .$..............
                           0E 4D D4 0F 00 15 16 05 00 01 15 16 05 00         .M............

        ----- Video Streaming MJPEG Frame Type Descriptor -----
bLength                  : 0x1E (30 bytes)
bDescriptorType          : 0x24 (Video Streaming Interface)
bDescriptorSubtype       : 0x07 (MJPEG Frame Type)
bFrameIndex              : 0x03
bmCapabilities           : 0x00
wWidth                   : 0x0350 (848)
wHeight                  : 0x01E0 (480)
dwMinBitRate             : 0x0BA54000 (195379200 bps -> 24.422 MB/s)
dwMaxBitRate             : 0x0BA54000 (195379200 bps -> 24.422 MB/s)
dwMaxVideoFrameBufferSize: 0x000C6E4D (814669 bytes)
dwDefaultFrameInterval   : 0x00051615 (33.3333 ms -> 30.000 fps)
bFrameIntervalType       : 0x01 (1 discrete frame interval supported)
adwFrameInterval[1]      : 0x00051615 (33.3333 ms -> 30.000 fps)
Data (HexDump)           : 1E 24 07 03 00 50 03 E0 01 00 40 A5 0B 00 40 A5   .$...P....@...@.
                           0B 4D 6E 0C 00 15 16 05 00 01 15 16 05 00         .Mn...........

        ----- Video Streaming MJPEG Frame Type Descriptor -----
bLength                  : 0x1E (30 bytes)
bDescriptorType          : 0x24 (Video Streaming Interface)
bDescriptorSubtype       : 0x07 (MJPEG Frame Type)
bFrameIndex              : 0x04
bmCapabilities           : 0x00
wWidth                   : 0x0280 (640)
wHeight                  : 0x01E0 (480)
dwMinBitRate             : 0x08CA0000 (147456000 bps -> 18.432 MB/s)
dwMaxBitRate             : 0x08CA0000 (147456000 bps -> 18.432 MB/s)
dwMaxVideoFrameBufferSize: 0x0009624D (614989 bytes)
dwDefaultFrameInterval   : 0x00051615 (33.3333 ms -> 30.000 fps)
bFrameIntervalType       : 0x01 (1 discrete frame interval supported)
adwFrameInterval[1]      : 0x00051615 (33.3333 ms -> 30.000 fps)
Data (HexDump)           : 1E 24 07 04 00 80 02 E0 01 00 00 CA 08 00 00 CA   .$..............
                           08 4D 62 09 00 15 16 05 00 01 15 16 05 00         .Mb...........

        ----- Video Streaming MJPEG Frame Type Descriptor -----
bLength                  : 0x1E (30 bytes)
bDescriptorType          : 0x24 (Video Streaming Interface)
bDescriptorSubtype       : 0x07 (MJPEG Frame Type)
bFrameIndex              : 0x05
bmCapabilities           : 0x00
wWidth                   : 0x0280 (640)
wHeight                  : 0x0168 (360)
dwMinBitRate             : 0x06978000 (110592000 bps -> 13.824 MB/s)
dwMaxBitRate             : 0x06978000 (110592000 bps -> 13.824 MB/s)
dwMaxVideoFrameBufferSize: 0x00070A4D (461389 bytes)
dwDefaultFrameInterval   : 0x00051615 (33.3333 ms -> 30.000 fps)
bFrameIntervalType       : 0x01 (1 discrete frame interval supported)
adwFrameInterval[1]      : 0x00051615 (33.3333 ms -> 30.000 fps)
Data (HexDump)           : 1E 24 07 05 00 80 02 68 01 00 80 97 06 00 80 97   .$.....h........
                           06 4D 0A 07 00 15 16 05 00 01 15 16 05 00         .M............

当然,dwDefaultFrameInterval同时也指定了在同一分辨率下支持的帧率,如常见的20帧,25帧,30帧,60帧,这代表着在1秒钟时间内摄像头传输视频图片的张数。不过都有一个默认的帧率,由dwDefaultFrameInterval来指定。

HID人机交互QQ群:564808376    UAC音频QQ群:218581009    UVC相机QQ群:331552032    BOT&UASP大容量存储QQ群:258159197    STC-USB单片机QQ群:315457461    USB技术交流QQ群2:580684376    USB技术交流QQ群:952873936   

0 篇笔记 写笔记

UVC 视频流接口描述符
视频流接口描述符包含了所有完整的视频流接口信息。视频流接口信息以标准的视频流接口开头。视频流接口描述符由标准视频控制接口描述符以及各控制相关描述符组成。标准视频流接口描述符使用通用USB设备接口描述符数据结构。struct _INTERFACE_DESCRIPTOR_STRUCT; { BY......
USB摄像头UVC视频流描述符中的bFormatIndex和bFrameIndex
bFormatIndexUSB摄像头一般支持多种视频格式,比如MJPG,H264,YUY2,NV12,RGB等,这些不同的视频格式代表着传输的视频图像的数据组织方式。这些视频格式通过UVC视频流各视频流相关的类型描述符来进行描述符。在Windows系统下,我们可以通过PotPlayer来查看摄像头......
LINUX&UVC驱动视频流接口描述符与视频控制接口描述符的解析关系
UVC控制接口描述符包其下的子各类描述符代表着UVC设备的拓扑结构,关于UVC设备的控制一般都是通过UVC控制接口描述符各个终端,实例的特定类请求来实现的,其中也包括用于用户自定义通讯的扩展单元描述符。与UVC控制接口描述符相对的是UVC视频流接口描述符,UVC规范可以有0个或者多个。至于有多少个,......
uvc_parse_streaming分析
除过usb_driver_claim_interface函数功能有之外,uvc_parse_streaming主要是对申请的内存结构体struct uvc_streaming 进行初始化,其数据来源于对UVC视频流接口描述符的解析。视频流接口描述符的内存布局大致如下:视频流对应的接口描述符视频......
关注公众号
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!