hughfenghen / hughfenghen.github.io

blog
https://hughfenghen.github.io/
42 stars 2 forks source link

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

Open hughfenghen opened 3 months ago

hughfenghen commented 3 months ago

一个完整的 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 对以上数据的分析结果,暂时存档,正确性待确认


解析如下:

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

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

hughfenghen commented 3 months ago

WebCodecs VideoDecoder 解码的数据类型为 EncodedVideoChunk EncodedVideoChunk 是由一个或多个 H264 的 NALU 组成的

NALU 的结构及二进制含义参考: https://github.com/dreamsxin/example/blob/master/codec/H.264视频码流解析.md

hughfenghen commented 3 months ago

使用 WebCodecs 在浏览器中解析视频,请参考作者的文章 https://hughfenghen.github.io/posts/2023/07/23/webav-2-parse-video/