Microsoft Media Foundation官方文档翻译(16)《Extended Color Information》

官方英文文档链接:https://docs.microsoft.com/en-us/windows/desktop/medfound/extended-color-information

基于05/31/2018

In this article

  1. Color Space in Media Types
  2. Color Space Conversion
  3. Using Extended Color Information
  4. Related topics

如果你了解 RGB 颜色,那么你会知道(255, 255, 255)是白色。但是这三个 255 到底代表什么颜色?

答案可能令人惊讶:如果没有一些额外信息,这三个数字并不代表任何特定颜色。实际上任何 RGB 的颜色值都取决于色彩空间。如果我们不知道色彩空间,严格来说我们就不知道一组数字代表的颜色。

颜色空间定义了如何将一组数字表示为物理光线的颜色。当视频在一个颜色空间内编码,但显示在另一个颜色空间中时,将导致颜色扭曲,除非对视频进行色彩校正。因此,为了获得准确的颜色,了解源视频的色彩空间很重要。以前,Windows 中的视频管道不包含有关色彩空间的信息。从 Windows Vista 开始,DirectShow 和 Media Foundation 都支持在 media type 中扩展颜色信息。此信息也可用于 DirectX Video Acceleration (DXVA)。

数学上描述色彩空间的标准办法是使用 CIE XYZ 色彩空间。直接在视频中使用 CIE XYZ 是不实际的,但是 CIE XYZ 色彩空间可以在转换色彩空间时当作中间形式使用。

要准确再现颜色,需要以下信息:

  • 颜色原色。颜色原色定义了 CIE XYZ 值如何表示为 RGB 颜色,the color primaries define the "meaning" of a given RGB value.
  • 转换函数。这个转换函数需要把线性 RGB 值转换为非线性 R'G'B' 值。这个操作又称为伽马校正(gamma correction)
  • 转换矩阵。转换矩阵定义了 R'G'B' 如何转换为 Y'PbPr。
  • 色度采样。大多数 YUV 视频中色度的分辨率低于 luma 的分辨率。色度的采样格式用 FOURCC 表示。例如,YUY2 是一种 4:2:2 格式,表示色度水平采样是每两个像素采一个样。
  • Chroma siting。色度采样时,色度样本基于 luma 样本的位置决定了应该如何插值缺失的样本。
  • 数值范围。表示了 Y'PbPr 值转化为 Y'CbCr 值时该如何缩放。

Color Space in Media Types

DirectShow, Media Foundation, 和 DirectX Video Acceleration (DXVA) 都有不同的方式来表示视频格式。幸运的是,很容易将色彩空间信息转换成另一个,因为相关的枚举是相同的。

  • DXVA 1.0: Color-space 信息在 DXVA_ExtendedFormat 结构体中给出。

  • DXVA 2.0: Color-space 信息在 DXVA2_ExtendedFormat 结构体中给出。这个结构体与 DXVA 1.0 结构相同,并且字段的含义相同。

  • DirectShow: Color-space 信息在 VIDEOINFOHEADER2 结构中。信息存储在 24-bit 的 dwControlFlags 标志字段上。如果存在色彩空间信息,则 AMCONTROL_COLORINFO_PRESENT 设置在 dwControlFlags 上。当此标志位设置时,dwControlFlags 标志字段应解释为 DXVA_ExtendedFormat 结构,except that the lower 8 bits of the structure are reserved for AMCONTROL_xxx flags.

  • Video capture drivers: Color-space information is given in the KS_VIDEOINFOHEADER2 structure. This structure is identical to the VIDEOINFOHEADER2 structure, and the meaning of the fields is the same.

  • Media Foundation: 色彩空间信息以 attributes 存储在 media type 中:

    Color information Attribute
    Color primaries MF_MT_VIDEO_PRIMARIES
    Transfer function MF_MT_TRANSFER_FUNCTION
    Transfer matrix MF_MT_YUV_MATRIX
    Chroma subsampling MF_MT_SUBTYPE
    (Given by the FOURCC, which is stored in the first DWORD of the subtype GUID.)
    Chroma siting MF_MT_VIDEO_CHROMA_SITING
    Nominal range MF_MT_VIDEO_NOMINAL_RANGE

Color Space Conversion

从 Y'CbCr 色彩空间转换到其他色彩空间需要以下几步。

  1. Inverse quantization: 将 Y'CbCr 表示转换为 Y'PbPr 表示。

  2. Upsampling: 通过插值将色度采样转换为 4:4:4。

  3. YUV to RGB conversion: 使用 source transfer matrix 将 Y'PbPr 转换为非线性 R'G'B'。

  4. Inverse transfer function: 反向使用转换函数将非线性 R'G'B' 转换为线性 RGB。

  5. RGB color space conversion: 使用 color primaries 从源 RGB 空间转换为目标 RGB 空间。

  6. Transfer function: 使用转换函数将线性 RGB 转换为非线性 R'G'B。

  7. RGB to YUV conversion: 使用转换矩阵将 R'G'B' 转为 Y'PbPr。

  8. Downsampling: 减少 chroma 值来降低采样,将 4:4:4 转为 4:2:2,4:2:0 或 4:1:1。

  9. Quantization: 将 Y'PbPr 转为 Y'CbCr,并注意数值范围。

步骤  1–4 发生在源色彩空间,步骤 6–9 发生在目标色彩空间。在实际实现中,中间步骤可以近似,相邻的步骤可以组合。通常在准确性和计算成本之间进行权衡。

例如,从 RT.601 转换到 RT.709 需要步骤如下:

  • Inverse quantization: Y'CbCr(601) to Y'PbPr(601)

  • Upsampling: Y'PbPr(601)

  • YUV to RGB: Y'PbPr(601) to R'G'B'(601)

  • Inverse transfer function: R'G'B'(601) to RGB(601)

  • RGB color space conversion: RGB(601) to RGB(709)

  • Transfer function: RGB(709) to R'G'B'(709)

  • RGB to YUV: R'G'B'(709) to Y'PbPr(709)

  • Downsampling: Y'PbPr(709)

  • Quantization: Y'PbPr(709) to Y'CbCr(709)

Using Extended Color Information

为了在整个 pipeline 中保证色彩的准确,必须在源或者解码器处引入色彩空间信息,并通过整个 pipeline,最后到达接收器。

Video Capture Devices

Most analog capture devices use a well-defined color space when capturing video. Capture drivers should offer a format with a KS_VIDEOINFOHEADER2 format block that contains the color information. For backward compatibility, the driver should accept formats that do not contain the color information. This will enable the driver to work with components that do not accept the extended color information.

File-based Sources

处理视频文件时,media source (或者 DirectShow 中的 parser filter) 可能会提供一些色彩信息。例如 DVD Navigator 可以根据视频内容确定色彩空间。其他的色彩信息可能可以从解码器获得。例如 MPEG-2 视频流在 sequence_display_extension field 中提供色彩信息。如果源没有显示提供色彩信息,则可能由内容隐式定义。例如 DV 视频的 NTSC 和 PAL 使用不同的色彩空间。Finally, the decoder can use whatever color information it gets from the source's media type.(最后这句没理解意思)

Other Components

Other components might need to use the color-space information in a media type:

  • Software color-space converters should use color-space information when selecting a conversion algorithm.
  • Video mixers, such as the enhanced video renderer (EVR) mixer, should use the color information when mixing video streams from different types of content.
  • The DXVA video processing APIs and DDIs enable the caller to specify color-space information information. The GPU should use this information when it performs hardward video mixing.
原创文章 59 获赞 41 访问量 10万+

猜你喜欢

转载自blog.csdn.net/rzdyzx/article/details/88595389