通过RTMP play分析FLV格式详解
来源:互联网 发布:单片机定时器工作原理 编辑:程序博客网 时间:2024/06/06 14:02
最近做了一个rtmp中转服务程序,通过实践,熟悉rtmp play和push中各类格式,这里总结一下。
程序github地址: https://github.com/runner365/rtmp_relay
rtmp play接收报文分析
第一帧收到的报文:
1) 0x46 4c 56:可参考文后:参考一
字符FLV头
2) 0x01 05
Version TypeFlagsReserved TypeFlagsAudio TypeFlagsReserved TypeFlagsVideo
这个解析的时候,一般不用管
3)0x00 00 00 09
FLV header offset: 也就是从开头9字节后,才是FLV真正的报文头。
4)0x00 00 00 00
这个是第1帧的PreviousTagSize0(前帧长度),因为是第一帧,所以肯定是0;
5)0x08 可参考文后:参考二,参考三
帧开头第一字节:0x08表示音频,0x09表示视频
6)0x00 00 04
帧payload长度:因为音频第一帧是ASC,所以只有4字节。
7) 0x 00 00 00 00
timestamp,时间戳
8) 0x 00 00 00
streamid,流ID
9) 0x AF 00 13 90
音频payload: 0xaf00开头的后面是asc flag, 0xaf01开头的后面是真正的音频数据
0x13 90,也就是0b0001 0011 1001 0000,
ASC flag格式:xxxx xyyy yzzz z000
x字符: aac type,类型2表示AAC-LC,5是SBR, 29是ps,5和29比较特殊ascflag的长度会变成4;
y字符: sample rate, 采样率, 7表示22050采样率
z字符: 通道数,2是双通道
10) 0x 00 00 00 0F
这个还是PreviousTagSize1,上一帧长度15bytes
11) 0x09 视频类型,新的一帧
12)0x00 00 22
视频帧payload长度
13) 0x00 00 0a 00
时间戳:这个地方有个大坑,顺序是:a[3] a[0] a[1] a[2],最后一位是最高位。
14) 0x00 00 00
streamid, 流id。
15) 0x 17 00
视频帧开头2字节:
0x17 00: 表示内容是SPS和PPS
0x17 01: 表示内容是I-FRAME
0x27: 表示内容是P-FRAME
16)
0000002bh: 17 00 00 00 00 01 42 C0 1F FF E1 00 0E 67 42 C0 ; ......B??.gB?
0000003bh: 1F 8C 8D 40 F0 28 90 0F 08 84 6A 01 00 04 68 CE ; .實@??.刯...h?
0000004bh: 3C 80 ; <€
第12, 13字节: 0x00 0E是spslen,也就是14字节长度
跳过14字节后,0x01是pps开始的标识,跳过它。
0x00 04是ppslen,也就是4个字节,最后0x68 ce 3c 80就是pps。
参考:
1, The FLV header
TypeCommentSignatureUI8Signature byte always 'F' (0x46)SignatureUI8Signature byte always 'L' (0x4C)SignatureUI8Signature byte always 'V' (0x56)VersionUI8File version (for example, 0x01 for FLV version 1)TypeFlagsReservedUB [5]Shall be 0TypeFlagsAudioUB [1]1 = Audio tags are presentTypeFlagsReservedUB [1]Shall be 0TypeFlagsVideoUB [1]1 = Video tags are presentDataOffsetUI32The length of this header in bytesSignature: FLV 文件的前3个字节为固定的‘F’‘L’‘V’,用来标识这个文件是flv格式的.在做格式探测的时候,
如果发现前3个字节为“FLV”,就认为它是flv文件.
Version: 第4个字节表示flv版本号.
Flags: 第5个字节中的第0位和第2位,分别表示 video 与 audio 存在的情况.(1表示存在,0表示不存在)
DataOffset : 最后4个字节表示FLV header 长度.
2,FLV body整体
FieldTypeCommentPreviousTagSize0UI32Always 0Tag1FLVTAGFirst tagPreviousTagSize1UI32Size of previous tag, including its header, in bytes. For FLV version1,
this value is 11 plus the DataSize of the previous tag.
Tag2FLVTAGSecond tag.........PreviousTagSizeN-1UI32Size of second-to-last tag, including its header, in bytes.TagNFLVTAGLast tagPreviousTagSizeNUI32Size of last tag, including its header, in bytesFLV header之后,就是 FLV File Body.
FLV File Body是由一连串的back-pointers + tags构成.back-pointers就是4个字节数据,表示前一个tag的size.
3,FLV body细节
FieldTypeCommentReservedUB [2]Reserved for FMS, should be 0FilterUB [1]Indicates if packets are filtered.
0 = No pre-processing required.
1 = Pre-processing (such as decryption) of the packet is
required before it can be rendered.
Shall be 0 in unencrypted files, and 1 for encrypted tags.
See Annex F. FLV Encryption for the use of filters.TagTypeUB [5]
Type of contents in this tag. The following types are
defined:
8 = audio
9 = video
18 = script data
end of tag (Equal to length of the tag – 11)TimestampUI24Time in milliseconds at which the data in this tag applies.
This value is relative to the first tag in the FLV file, which
always has a timestamp of 0.TimestampExtendedUI8Extension of the Timestamp field to form a SI32 value. This
field represents the upper 8 bits, while the previous
Timestamp field represents the lower 24 bits of the time in
milliseconds.StreamIDUI24Always 0.AudioTagHeaderIF TagType == 8
AudioTagHeader VideoTagHeaderIF TagType == 9
VideoTagHeader EncryptionHeaderIF Filter == 1
EncryptionTagHeader FilterParamsIF Filter == 1
FilterParams DataIF TagType == 8
AUDIODATA
IF TagType == 9
VIDEODATA
IF TagType == 18
SCRIPTDATAData specific for each media t
- 通过RTMP play分析FLV格式详解
- 通过RTMP play分析FLV格式详解
- 流媒体-FLV格式详解及数据分析
- flv 格式分析
- flv 格式分析2
- flv 格式分析3
- FLV格式分析
- FLV封装格式分析
- FLV视频文件格式分析
- 视频FLV格式详解
- flv封装格式详解
- flv格式详解
- flv格式详解
- SRS 代码分析【RTMP信息play/publish】
- 【多媒体封装格式详解】---FLV
- FLV视频封装格式详解
- FLV视频封装格式详解
- FLV视频封装格式详解
- DAY_12 baconic crpetogram
- 湖南省第六届省赛 汽水瓶(模拟)
- 如何禁止(表单)用户名、密码自动填充
- PHP过滤常用标签的正则表达式
- Mac下安装pillow
- 通过RTMP play分析FLV格式详解
- 自定义AlertDialog对话框,包括解决对话框中edittext不能输入的问题
- 记一次Ubuntu安装Oracle纪录
- hh:mm:ss 跟 HH:mm:ss 区别
- JS之定时器
- C++中使用vector容器
- SWift Lesson 2
- POJ 1251 Jungle Roads 最小生成树
- String、StringBuffer与StringBuilder之间区别