FLV视频和音频解析学习(三)

3.3 Video Tag

如果TAG包中的TagType==9时,就表示这个TAGvideo.

StreamID之后的数据就表示是VideoTagHeaderVideoTagHeader结构如下:

Field

Type

Comment

Frame Type

UB [4]

Type of video frame. The following values are defined:
1 = key frame (for AVC, a seekable frame)
2 = inter frame (for AVC, a non-seekable frame)
3 = disposable inter frame (H.263 only)
4 = generated key frame (reserved for server use only)
5 = video info/command frame

CodecID

UB [4]

Codec Identifier. The following values are defined:
2 = Sorenson H.263
3 = Screen video
4 = On2 VP6
5 = On2 VP6 with alpha channel
6 = Screen video version 2
7 = AVC

扫描二维码关注公众号,回复: 1888338 查看本文章

AVCPacketType

IF CodecID == 7
UI8

The following values are defined:
0 = AVC sequence header
1 = AVC NALU
2 = AVC end of sequence (lower level NALU sequence ender is not required or supported)

CompositionTime

IF CodecID == 7
SI24

IF AVCPacketType == 1
Composition time offset
ELSE
0
See ISO 14496-12, 8.15.3 for an explanation of composition
times. The offset in an FLV file is always in milliseconds.

VideoTagHeader的头1个字节,也就是接跟着StreamID1个字节包含着视频帧类型及视频CodecID最基本信息.表里列的十分清楚.

VideoTagHeader之后跟着的就是VIDEODATA数据了,也就是video payload.当然就像音频AAC一样,这里也有特例就是如果视频的格式是AVCH.264)的话,VideoTagHeader会多出4个字节的信息.

AVCPacketType CompositionTimeAVCPacketType 表示接下来 VIDEODATA AVCVIDEOPACKET的内容:

IF AVCPacketType == 0 AVCDecoderConfigurationRecordAVC sequence header
IF AVCPacketType == 1 One or more NALUs (Full frames are required)

AVCDecoderConfigurationRecord.包含着是H.264解码相关比较重要的spspps信息,再给AVC解码器送数据流之前一定要把spspps信息送出,否则的话解码器不能正常解码。而且在解码器stop之后再次start之前,如seek、快进快退状态切换等,都需要重新送一遍spspps的信息.AVCDecoderConfigurationRecordFLV文件中一般情况也是出现1次,也就是第一个video tag.

AVCDecoderConfigurationRecord的定义在ISO 14496-15, 5.2.4.1中,这里不在详细贴.


H264AAC数据流

RTMP推送的音视频流的封装形式和FLV格式相似,由此可知,向FMS推送H264和AAC直播流,需要首先发送"AVC sequence header"和"AAC sequence header",这两项数据包含的是重要的编码信息,没有它们,解码器将无法解码。

AVC sequence header就是AVCDecoderConfigurationRecord结构,该结构在标准文档ISO-14496-15 AVC file format”中有详细说明。

    

 

AAC sequence header存放的是AudioSpecificConfig结构,该结构则在ISO-14496-3 Audio”中描述。AudioSpecificConfig结构的描述非常复杂,这里我做一下简化,事先设定要将要编码的音频格式,其中,选择"AAC-LC"为音频编码,音频采样率为44100,于是AudioSpecificConfig简化为下表:

    

  这样,AVC sequence header和AAC sequence header的内容可以基本确定了,更详细的信息,大家可以去翻阅相关文档。

注意:

提取AAC音频,需要再AAC RAW 前一个ADST 7个字节的包,存储声道频率等

提取视频需要 SPS PPS 信息 才能播放, H264数据之间使用00000001分隔

播放AAC 使用暴风影音播放

播放H264使用迅雷看看播放

Ffmpeg 测试

参考资料:

http://www.360doc.com/content/16/1013/17/474846_598171645.shtml

http://blog.csdn.net/bsplover/article/details/7426511

FLV视频封装格式详解

http://blog.csdn.net/leixiaohua1020/article/details/17934487

雷霄骅:视音频编解码学习工程:FLV封装格式分析器

http://blog.csdn.net/occupy8/article/details/49870569

http://blog.csdn.net/langsim/article/details/48601263

flv格式中分离出裸h264

http://blog.csdn.net/hellofeiya/article/details/9249709


猜你喜欢

转载自blog.csdn.net/sunshine_505/article/details/80924620