H.264/AVC编码的FLV文件的第二个Tag: AVCDec
AVCDecoderConfigurationRecord
即AVC Sequence Header
。
对于H.264/AVC
编码格式的FLV
文件,onMetaData
是第一个Tag,之后的第二个Tag就是AVCDecoderConfigurationRecord
, 也是第一个Video Tag, 在FLV文件中一般情况也是出现1次。

AVCDecoderConfigurationRecord包含H.264解码相关比较重要的sps和pps信息。
- 在给AVC解码器送数据流之前一定要把sps和pps信息送出否则的话解码器不能正常解码。
- 而且在解码器stop之后再次start之前,如seek、快进快退状态切换等,须重新送一遍sps和pps的信息。
FLV文件中的AVCDecoderConfigurationRecord
找了一个视频编码格式为H.264/AVC的文件来分析:

00 00 00 09:
onMetaData
结束的标志.
**00 00 01 66 **:
4
个字节的PreviousTagSize1
,即上个Tag
的大小(包括Tag Header
和Tag Data
),也就是onMetaData
的大小。
09 00 00 2b 00 00 00 00 00 00 00:
即11个字节的FLV Tag Header
。

首个字节的
0x09
表明该Tag
是Video Tag
。
17 00 00 00 00:
VideoTagHeader
, 编码格式为AVC
时,该Header
长度为5
。


首个字节0x17含义如下:
- 1: key frame(for AVC, a seekable frame)
- 7: AVC
0x17之后的那个字节表明: AVPacketType
:
- 0x00: AVC Sequence header
- 0x01: AVC NALU
- 0x02: AVC end of sequence(lower level NALU sequence ender is not required or supported)
接下来就是AVCDecoderConfigurationRecord了。


01 42 c0 1e ff e1:
需要注意的是第2
个字节: 0x42
,即十进制的66
(Baseline Profile)。
第6
个字节0xe1
, 它的后5
位表示SPS
的数目,0xe1
的后5
位就是0 0001
,即1
,说明存在一个SPS
。
00 17:
表明SPS的数据长度,0x00 0x17,即23个字节,表明其后的23个字节都是SPS。

SPS
一般以0x67
开头(也可以是0x27
等,首个字节的后5
位表明该NALU的类型)。
01 00 04 68 cb 8c b2:

01: 表明PPS的数目。
00 04: 表明PPS的数据长度。
68 cb 8c b2: PPS, 一般以0x68开头。
至此,AVCDecoderConfigurationRecord
结束。
References:
Information technology — Coding of audio-visual objects — Part 15:
Advanced Video Coding (AVC) file format
http://www.360doc.com/content/12/1212/15/4550476_253606537.shtml