hughfenghen.github.io icon indicating copy to clipboard operation
hughfenghen.github.io copied to clipboard

MP4 的 avcC box 内容解析与 VideoDecorder 初始化

Open hughfenghen opened this issue 1 year ago • 3 comments

一个完整的 avcC box 示例数据内容

00 00 00 3A 61 76 63 43 01 64 00 1e ff e1 00 1d 67 64 00 1e ac d9 40 a0 2f f9 66 a0 c0 20 d6 e0 00 00 03 00 20 00 00 06 01 e2 c5 b2 c0 01 00 06 68 eb e3 cb 22 c0 fd f8 f8 00

减去前面八个字节 00 00 00 3A 61 76 63 43,长度 4 字节, avcC 文本 4 字节; 后面的二进制数据是初始化 VideoDecoder 的 description 参数内容

下面是 GPT 对以上数据的分析结果,暂时存档,正确性待确认


解析如下:

  • Box Size:0x3A(58 字节),整个 avcC box 的大小,包括 Box Size 本身和所有子元素的大小。

  • Box Type:'avcC'

  • Configuration Version:0x01,AVC 配置的版本号。

  • AVC Profile Indication:0x64,AVC 编码器所使用的 Profile(Main Profile)。

  • Profile Compatibility:0x00,Profile 兼容性。

  • AVC Level Indication:0x1E,AVC 编码器所使用的 Level(H.264 Level 3.0)。

  • Length Size Minus One:0xFF,NAL 单元长度字段的大小减去 1 的值(对应 0x03,表示 NAL 长度字段为 4 个字节)。

  • SPS Count:0x01,Sequence Parameter Set(SPS)的数量。

  • SPS Length:0x001D(29 字节),第一个 SPS 的长度(以字节为单位)。

  • SPS NAL Unit

    67 64 00 1E AC D9 40 A0 2F F9 66 A0 C0 20 D6 E0 00 00 03 00 20 00 00 06 01 E2 C5 B2 C0 01 00 06
    

    这是 29 字节的 SPS 数据,表示视频序列参数集。

  • PPS Count:0x01,Picture Parameter Set(PPS)的数量。

  • PPS Length:0x0006(6 字节),第一个 PPS 的长度(以字节为单位)。

  • PPS NAL Unit

    68 EB E3 CB 22 C0
    

    这是 6 字节的 PPS 数据,表示图像参数集。

现在我们了解了每个字段的含义:

  • Configuration VersionAVC Profile IndicationProfile CompatibilityAVC Level Indication 是指明编码器所用的版本、Profile 和 Level 的参数。
  • Length Size Minus One 表示了 NAL 单元长度字段的大小减去 1 的值。在这个例子中,是 0xFF,对应 0x03,表示 NAL 长度字段为 4 个字节。
  • SPS CountSPS Length 表示了有 1 个 SPS,长度为 29 字节。
  • SPS NAL Unit 包含了实际的 SPS 数据,用于描述视频序列的特性。
  • PPS CountPPS Length 表示了有 1 个 PPS,长度为 6 字节。
  • PPS NAL Unit 包含了实际的 PPS 数据,用于描述图像的特性。

这些信息组成了 avcC box,在 H.264/AVC 编码中非常重要,解析器使用这些数据来正确解码视频流。

hughfenghen avatar Mar 28 '24 12:03 hughfenghen