流媒体传输 - RTMP 协议
RTMP 是 Real-Time Message Protocol(实时消息传输协议)的首字母缩写。该协议由 Adobe 公司开发作为一种应用层技术,并旨在解决多媒体信息传输流的多路复用与分组编码的问题。
该协议遵循 TCP 协议基础,并属于一类用于传输控制协议(TCP)的类别。其中包含 RTMP 的基本框架以及 RTMPT、RTMPS 和 RTMPE 等不同版本的变种。
RTMP 作为一种专为实时数据传输设计的网络协议,在Flash/AIR平台及支持其的应用系统中被用于实现音视频与数据的实时交互与传输。
协议介绍
RTMP 协议支持发送或显示流媒体内容的前提条件是:首先需要创建一个网络连接(NetConnection),其次则需要配置相应的数据流量(NetStream)。
其中,在服务器端应用程序与客户端之间象征着基本的通信联系的是网络通信连接。代表着多媒体数据传输通道的是数据传输通道。在这些端点之间只能存在一条独特的通信线路,并可通过这条线路建立多个数据传输通道。它们之间的关系如图所示:
通过 RTMP 协议传输流媒体的过程涉及以下四个阶段:首先是通信初始化阶段(握手),随后是建立通信通道(建立连接),接着是数据传输通道的建立(建立流),最后是发送实时数据传输(播放)。具体过程分为以下四个阶段:
+----------+ +----------+
|Client|TCP/IP Network|Server|
+----------+ +----------+
--------+---| | |
|Uninitialized | Uninitialized
|----------C0-------->|||
|---------C0--------->|||
|----------C1-------->|||
|<--------S0----------|||
|Version sent|<--------S1----------|
Hand- | |<---------S0---------| |
shake | |<---------S1---------| Version sent
|---------C1--------->|||
|----------C2-------->|||
|<--------S2----------|||
|Ack Sent | Ack Sent
|<---------S2---------|||
|---------C2--------->|||
|Handshake Done | Handshake Done
--------+---| |
||
--------+---|---------- Command Message(connect) ------>|
|||
|<------ Window Acknowledgement Size -------||
|||
|<---------- Set Peer Bandwidth ------------||
|||
Appli- | |------- Window Acknowledgement Size ------>|
cation | | |
Connect | |<---- User Control Message(StreamBegin) ---|
|||
|<----------- Command Message --------------||
|(_result- connect response)||
--------+---| |
||
--------+---|------ Command Message(createStream) ----->|
Create | | |
Stream | |<----------- Command Message --------------|
--------+---| (_result- createStream response) |
||
--------+---|--------- Command Message (play) --------->|
|||
|<-------------- SetChunkSize --------------||
|||
|<---- User Control (StreamIsRecorded) -----||
|||
|<------- UserControl (StreamBegin) --------||
|||
Play | |<-- Command Message(onStatus-play reset) --|
|||
|<-- Command Message(onStatus-play start) --||
|||
|<------------- Audio Message --------------||
|||
|<------------- Video Message --------------||
||||
||
Keep receiving audio and video stream till finishes
握手(HandShake)
握手交互流程
一个 RTMP 连接以握手开始,双方分别发送大小固定的三个数据块:
握手开始于客户端发送 C0、C1 块。服务器收到 C0 或 C1 后发送 S0 和 S1。
当客户端收齐 S0 和 S1 后,开始发送 C2。当服务器收齐 C0 和 C1 后,开始发送 S2。
当客户端和服务器分别收到 S2 和 C2 后,握手完成。
1. +----------+ +----------+
2. | Client | TCP/IP Network | Server |
3. +----------+ +----------+
4. --------+---| | |
5. |Uninitialized | Uninitialized
6. | |----------C0-------->| |
7. | | |---------C0--------->|
8. | |----------C1-------->| |
9. | | |<--------S0----------|
10. |Version sent |<--------S1----------|
11. Hand- | |<---------S0---------| |
12. shake | |<---------S1---------| Version sent
13. | | |---------C1--------->|
14. | |----------C2-------->| |
15. | | |<--------S2----------|
16. |Ack Sent | Ack Sent
17. | |<---------S2---------| |
18. | | |---------C2--------->|
19. |Handshake Done | Handshake Done
20. --------+---| |
21. Pictorial Representation of Handshake
简化的握手交互流程
而在实际应用中,通常使用三次握手来简化以上握手流程:
Client ---- C0&C1 ----> Server
Client <---- S0&S1&S2 ---- Server
Client ---- C2 ----> Server
握手交互抓包
学习地址
文章福利
学习入口

**

通过 Wirshark 抓包,得到以下数据包:
Client ---- C0&C1 ----> Server
1. 0000 03 00 00 00 00 09 00 7c 02 f7 78 55 1e ce ab 8e .......|..xU....
2. 0010 1e 36 2f 07 c5 86 8a 70 b2 66 d4 02 20 e5 08 61 .6/....p.f.. ..a
3. ···· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················
4. 05f0 c4 10 96 07 08 84 39 34 53 ce 50 96 94 af be ab ......94S.P.....
5. 0600 e0 .
6. -------------------------------------------------------------------------
7. Protocol version: 03
8. Handshake C1: 0000000009007c02f778551eceab8e1e362f07c5868a70b2…
Client <---- S0&S1&S2 ---- Server
1. 0000 03 06 a7 7f 3b 0d 0e 0a 0d 8b 4c 51 8d d0 a9 c7 ....;.....LQ....
2. 0010 21 e8 6a 5b b0 4a 9d 74 91 0f 30 03 fa bc 77 6e !.j[.J.t..0...wn
3. ···· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················
4. 0600 2d a1 d7 ca 81 18 80 02 9a d4 94 92 ab 14 ea 8a -...............
5. ···· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················
6. 0bf0 96 4b 7e 0c f1 27 fb fd 52 02 19 5d d7 73 57 47 .K~..'..R..].sWG
7. 0c00 f0 .
8. -------------------------------------------------------------------------
9. Protocol version: 03
10. Handshake S1: 06a77f3b0d0e0a0d8b4c518dd0a9c721e86a5bb04a9d7491…
11. Handshake S2: a1d7ca811880029ad49492ab14ea8a119cd415aa26c62ee4…
Client ---- C2 ----> Server
1. 0000 e2 5c 15 c2 2c af 72 d0 98 6f bd 3e da 0d 71 51 .\..,.r..o.>..qQ
2. ···· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················
3. 05f0 94 e0 bc b0 94 31 f4 20 d6 e7 d3 03 6d 2c 71 77 .....1. ....m,qw
4. -------------------------------------------------------------------------
5. Handshake C2: e25c15c22caf72d0986fbd3eda0d7151973e19083e0abbef…
握手报文分析
C0 与 S0
C0 与 S0
+-+-+-+-+-+-+-+-+
|version|
+-+-+-+-+-+-+-+-+
C0:客户端发送其所支持的 RTMP 版本号:3~31。一般都是写 3
S1:服务端返回其所支持的版本号。如果没有客户端的版本号,默认返回 3
C1 与 S1
C1 与 S1
+-+-+-+-+-+-+-+-+-+-+
|time (4 bytes)|
+-+-+-+-+-+-+-+-+-+-+
|zero (4 bytes)|
+-+-+-+-+-+-+-+-+-+-+
|random bytes|
+-+-+-+-+-+-+-+-+-+-+
|random bytes(cont)|
|....|
+-+-+-+-+-+-+-+-+-+-+
C1/S1 长度为 1536B。主要目的是确保握手的唯一性。
格式为 time + zero + random
time 发送时间戳,长度 4 byte
zero 保留值 0,长度 4 byte
random 随机值,长度 1528 byte,保证此次握手的唯一性,确定握手的对象
C2 与 S2
C2 与 S2
+-+-+-+-+-+-+-+-+-+-+
|time (4 bytes)|
+-+-+-+-+-+-+-+-+-+-+
|time2(4 bytes)|
+-+-+-+-+-+-+-+-+-+-+
|random bytes|
+-+-+-+-+-+-+-+-+-+-+
|random bytes(cont)|
|....|
+-+-+-+-+-+-+-+-+-+-+
C2/S2 的大小同样是 1536B。这相当于对应于 S1/C1 的响应值,在这里主要体现在字段设置上。与之对应的是 C1/S1 的 Copy 值,在这里主要体现在字段设置上。
time, C2/S2 发送的时间戳,长度 4 byte
time2, S1/C1 发送的时间戳,长度 4 byte
random,S1/C1 发送的随机数,长度为 1528B
建立网络连接(NetConnection)
建立网络连接交互流程
Client ----> Server : Command Message Connect
Client <---- Server : Window Acknowledgement Size
Client <---- Server : Set Peer Bandwidth
Client ----> Server : Window Acknowledgement Size
Client <---- Server : User Control Message Stream Begin
Client <---- Server : Command Message _result
1. +----------+ +----------+
2. | Client | | | Server |
3. +----------+ | +----------+
4. --------+---|---------- Command Message(connect) ------>|
5. | | |
6. | |<------ Window Acknowledgement Size -------|
7. | | |
8. | |<---------- Set Peer Bandwidth ------------|
9. | | |
10. Appli- | |------- Window Acknowledgement Size ------>|
11. cation | | |
12. Connect | |<---- User Control Message(StreamBegin) ---|
13. | | |
14. | |<----------- Command Message --------------|
15. | | (_result- connect response) |
16. --------+---| |
17. Message flow in the connect command
建立网络连接抓包
Client ----> Server : AMF0 Command connect()
1. 0000 03 00 00 00 00 00 cc 14 00 00 00 00 02 00 07 63 ...............c
2. 0010 6f 6e 6e 65 63 74 00 3f f0 00 00 00 00 00 00 03 onnect.?........
3. 0020 00 03 61 70 70 02 00 06 6d 79 6c 69 76 65 00 08 ..app...mylive..
4. 0030 66 6c 61 73 68 56 65 72 02 00 0d 4c 4e 58 20 39 flashVer...LNX 9
5. 0040 2c 30 2c 31 32 34 2c 32 00 05 74 63 55 72 6c 02 ,0,124,2..tcUrl.
6. 0050 00 20 72 74 6d 70 3a 2f 2f 36 32 2e 32 33 34 2e . rtmp://62.234.
7. 0060 31 31 31 2e 31 33 3a 31 39 33 35 2f 6d 79 6c 69 111.13:1935/myli
8. 0070 76 65 00 04 66 70 61 64 01 00 00 0c 63 61 70 61 ve..fpad....capa
9. 0080 62 69 6c 69 74 69 65 73 00 40 2e 00 00 00 00 00 bilities.@......
10. 0090 00 00 0b 61 75 64 69 6f 43 6f 64 65 63 73 00 40 ...audioCodecs.@
11. 00a0 af ce 00 00 00 00 00 00 0b 76 69 64 65 6f 43 6f .........videoCo
12. 00b0 64 65 63 73 00 40 6f 80 00 00 00 00 00 00 0d 76 decs.@o........v
13. 00c0 69 64 65 6f 46 75 6e 63 74 69 6f 6e 00 3f f0 00 ideoFunction.?..
14. 00d0 00 00 00 00 00 00 00 09 ........
15. -------------------------------------------------------------------------
16. Real Time Messaging Protocol (AMF0 Command connect('mylive'))
17. Response to this call in frame: 20
18. RTMP Header
19. 00.. .... = Format: 0
20. ..00 0011 = Chunk Stream ID: 3
21. Timestamp: 0
22. Body size: 204
23. Type ID: AMF0 Command (0x14)
24. Stream ID: 0
25. RTMP Body
26. String 'connect'
27. Number 1
28. Object (8 items)
29. AMF0 type: Object (0x03)
30. Property 'app' String 'mylive'
31. Property 'flashVer' String 'LNX 9,0,124,2'
32. Property 'tcUrl' String 'rtmp://62.234.111.13:1935/mylive'
33. Property 'fpad' Boolean false
34. Property 'capabilities' Number 15
35. Property 'audioCodecs' Number 4071
36. Property 'videoCodecs' Number 252
37. Property 'videoFunction' Number 1
38. End Of Object Marker
Server ----> Client : Window Acknowledgement Size
1. 0000 02 00 00 00 00 00 04 05 00 00 00 00 00 4c 4b 40 .............LK@
2. -------------------------------------------------------------------------
3. Real Time Messaging Protocol (Window Acknowledgement Size 5000000)
4. RTMP Header
5. 00.. .... = Format: 0
6. ..00 0010 = Chunk Stream ID: 2
7. Timestamp: 0
8. Body size: 4
9. Type ID: Window Acknowledgement Size (0x05)
10. Stream ID: 0
11. RTMP Body
12. Window acknowledgement size: 5000000
Server ----> Client : Set Peer Bandwidth
1. 0000 02 00 00 00 00 00 05 06 00 00 00 00 00 4c 4b 40 .............LK@
2. 0010 02 .
3. -------------------------------------------------------------------------
4. Real Time Messaging Protocol (Set Peer Bandwidth 5000000,Dynamic)
5. RTMP Header
6. 00.. .... = Format: 0
7. ..00 0010 = Chunk Stream ID: 2
8. Timestamp: 0
9. Body size: 5
10. Type ID: Set Peer Bandwidth (0x06)
11. Stream ID: 0
12. RTMP Body
13. Window acknowledgement size: 5000000
14. Limit type: Dynamic (2)
Server ----> Client : Set Chunk Size
1. 0000 02 00 00 00 00 00 04 01 00 00 00 00 00 00 10 00 ................
2. -------------------------------------------------------------------------
3. Real Time Messaging Protocol (Set Chunk Size 4096)
4. RTMP Header
5. 00.. .... = Format: 0
6. ..00 0010 = Chunk Stream ID: 2
7. Timestamp: 0
8. Body size: 4
9. Type ID: Set Chunk Size (0x01)
10. Stream ID: 0
11. RTMP Body
12. Chunk size: 4096
Server ----> Client : AMF0 Command _result
1. 0000 03 00 00 00 00 00 be 14 00 00 00 00 02 00 07 5f ..............._
2. 0010 72 65 73 75 6c 74 00 3f f0 00 00 00 00 00 00 03 result.?........
3. 0020 00 06 66 6d 73 56 65 72 02 00 0d 46 4d 53 2f 33 ..fmsVer...FMS/3
4. 0030 2c 30 2c 31 2c 31 32 33 00 0c 63 61 70 61 62 69 ,0,1,123..capabi
5. 0040 6c 69 74 69 65 73 00 40 3f 00 00 00 00 00 00 00 lities.@?.......
6. 0050 00 09 03 00 05 6c 65 76 65 6c 02 00 06 73 74 61 .....level...sta
7. 0060 74 75 73 00 04 63 6f 64 65 02 00 1d 4e 65 74 43 tus..code...NetC
8. 0070 6f 6e 6e 65 63 74 69 6f 6e 2e 43 6f 6e 6e 65 63 onnection.Connec
9. 0080 74 2e 53 75 63 63 65 73 73 00 0b 64 65 73 63 72 t.Success..descr
10. 0090 69 70 74 69 6f 6e 02 00 15 43 6f 6e 6e 65 63 74 iption...Connect
11. 00a0 69 6f 6e 20 73 75 63 63 65 65 64 65 64 2e 00 0e ion succeeded...
12. 00b0 6f 62 6a 65 63 74 45 6e 63 6f 64 69 6e 67 00 00 objectEncoding..
13. 00c0 00 00 00 00 00 00 00 00 00 09 ..........
14. -------------------------------------------------------------------------
15. Real Time Messaging Protocol (AMF0 Command _result('NetConnection.Connect.Success'))
16. Call for this response in frame: 17
17. RTMP Header
18. 00.. .... = Format: 0
19. ..00 0011 = Chunk Stream ID: 3
20. Timestamp: 0
21. Body size: 190
22. Type ID: AMF0 Command (0x14)
23. Stream ID: 0
24. RTMP Body
25. String '_result'
26. Number 1
27. Object (2 items)
28. AMF0 type: Object (0x03)
29. Property 'fmsVer' String 'FMS/3,0,1,123'
30. Property 'capabilities' Number 31
31. End Of Object Marker
32. Object (4 items)
33. AMF0 type: Object (0x03)
34. Property 'level' String 'status'
35. Property 'code' String 'NetConnection.Connect.Success'
36. Property 'description' String 'Connection succeeded.'
37. Property 'objectEncoding' Number 0
38. End Of Object Marker
Client ----> Server : Window Acknowledgement Size
1. 0000 02 00 00 00 00 00 04 05 00 00 00 00 00 4c 4b 40 .............LK@
2. -------------------------------------------------------------------------
3. Real Time Messaging Protocol (Window Acknowledgement Size 5000000)
4. RTMP Header
5. 00.. .... = Format: 0
6. ..00 0010 = Chunk Stream ID: 2
7. Timestamp: 0
8. Body size: 4
9. Type ID: Window Acknowledgement Size (0x05)
10. Stream ID: 0
11. RTMP Body
12. Window acknowledgement size: 5000000
建立网络流(NetStream)
客户端发送命令消息中的 “创建流”(createStream)命令到服务器端。
当服务器端接收“创建流”命令时,在命令消息中包含的结果字段(_result),以指示客户端当前的流状态
1. +----------+ +----------+
2. | Client | | | Server |
3. +----------+ | +----------+
4. --------+---|------ Command Message(createStream) ----->|
5. Create | | |
6. Stream | |<----------- Command Message --------------|
7. --------+---| (_result- createStream response) |
建立网络流抓包
Client ----> Server : AMF0 Command createStream()
1. 0000 43 00 00 00 00 00 19 14 02 00 0c 63 72 65 61 74 C..........creat
2. 0010 65 53 74 72 65 61 6d 00 40 00 00 00 00 00 00 00 eStream.@.......
3. 0020 05 .
4. -------------------------------------------------------------------------
5. Real Time Messaging Protocol (AMF0 Command createStream())
6. Response to this call in frame: 25
7. RTMP Header
8. 01.. .... = Format: 1
9. ..00 0011 = Chunk Stream ID: 3
10. Timestamp delta: 0
11. Timestamp: 0 (calculated)
12. Body size: 25
13. Type ID: AMF0 Command (0x14)
14. RTMP Body
15. String 'createStream'
16. Number 2
17. Null
Server ----> Client : AMF0 Command _result
1. 0000 03 00 00 00 00 00 1d 14 00 00 00 00 02 00 07 5f ..............._
2. 0010 72 65 73 75 6c 74 00 40 00 00 00 00 00 00 00 05 result.@........
3. 0020 00 3f f0 00 00 00 00 00 00 .?.......
4. -------------------------------------------------------------------------
5. Real Time Messaging Protocol (AMF0 Command _result())
6. Call for this response in frame: 23
7. RTMP Header
8. 00.. .... = Format: 0
9. ..00 0011 = Chunk Stream ID: 3
10. Timestamp: 0
11. Body size: 29
12. Type ID: AMF0 Command (0x14)
13. Stream ID: 0
14. RTMP Body
15. String '_result'
16. Number 2
17. Null
18. Number 1
播放(Play)
客户端发送命令消息中的播放(play)命令到服务器。
接收到播放命令后,服务器发送设置块大小(ChunkSize)协议消息。
服务器发送用户控制消息中的 streambegin,告知客户端流 ID。
当播放命令成功时,服务器将响应消息中的NetStream.Play.Start与NetStream.Play.reset指令,并通知客户端播放操作已完成。
在此之后服务器发送客户端要播放的音频和视频数据。
1. +----------+ +----------+
2. | Client | | | Server |
3. +----------+ | +----------+
4. --------+---|--------- Command Message (play) --------->| | | | | |<-------------- SetChunkSize --------------| | | | | |<---- User Control (StreamIsRecorded) -----| | | | | |<------- UserControl (StreamBegin) --------| | | | Play | |<-- Command Message(onStatus-play reset) --| | | | | |<-- Command Message(onStatus-play start) --| | | | | |<------------- Audio Message --------------| | | | | |<------------- Video Message --------------| | | | | | Keep receiving audio and video stream till finishes
播放抓包
Client ----> Server : Command getStreamLength()
1. 0000 08 00 00 00 00 00 1f 14 00 00 00 00 02 00 0f 67 ...............g
2. 0010 65 74 53 74 72 65 61 6d 4c 65 6e 67 74 68 00 40 etStreamLength.@
3. 0020 08 00 00 00 00 00 00 05 02 00 00 ...........
4. -------------------------------------------------------------------------
5. Real Time Messaging Protocol (AMF0 Command getStreamLength())
6. RTMP Header
7. 00.. .... = Format: 0
8. ..00 1000 = Chunk Stream ID: 8
9. Timestamp: 0
10. Body size: 31
11. Type ID: AMF0 Command (0x14)
12. Stream ID: 0
13. RTMP Body
14. String 'getStreamLength'
15. Number 3
16. Null
17. String ''
Client ----> Server : Command play('')
1. 0000 08 00 00 00 00 00 1d 14 01 00 00 00 02 00 04 70 ...............p
2. 0010 6c 61 79 00 40 10 00 00 00 00 00 00 05 02 00 00 lay.@...........
3. 0020 00 c0 9f 40 00 00 00 00 00 ...@.....
4. -------------------------------------------------------------------------
5. Real Time Messaging Protocol (AMF0 Command play(''))
6. RTMP Header
7. 00.. .... = Format: 0
8. ..00 1000 = Chunk Stream ID: 8
9. Timestamp: 0
10. Body size: 29
11. Type ID: AMF0 Command (0x14)
12. Stream ID: 1
13. RTMP Body
14. String 'play'
15. Number 4
16. Null
17. String ''
18. Number -2000
Client ----> Server : User Control Message Set Buffer Length
1. 0000 42 00 00 01 00 00 0a 04 00 03 00 00 00 01 00 00 B...............
2. 0010 0b b8 ..
3. -------------------------------------------------------------------------
4. Real Time Messaging Protocol (User Control Message Set Buffer Length 1,3000ms)
5. RTMP Header
6. 01.. .... = Format: 1
7. ..00 0010 = Chunk Stream ID: 2
8. Timestamp delta: 1
9. Timestamp: 1 (calculated)
10. Body size: 10
11. Type ID: User Control Message (0x04)
12. RTMP Body
13. Event type: Set Buffer Length (3)
Server ----> Client : User Control Message Stream Begin
1. 0000 02 00 00 00 00 00 06 04 00 00 00 00 00 00 00 00 ................
2. 0010 00 01 ..
3. -------------------------------------------------------------------------
4. Real Time Messaging Protocol (User Control Message Stream Begin 1)
5. RTMP Header
6. 00.. .... = Format: 0
7. ..00 0010 = Chunk Stream ID: 2
8. Timestamp: 0
9. Body size: 6
10. Type ID: User Control Message (0x04)
11. Stream ID: 0
12. RTMP Body
13. Event type: Stream Begin (0)
Server ----> Client : Command onStatus('NetStream.Play.Start')
1. 0000 05 00 00 00 00 00 60 14 01 00 00 00 02 00 08 6f ......`........o
2. 0010 6e 53 74 61 74 75 73 00 00 00 00 00 00 00 00 00 nStatus.........
3. 0020 05 03 00 05 6c 65 76 65 6c 02 00 06 73 74 61 74 ....level...stat
4. 0030 75 73 00 04 63 6f 64 65 02 00 14 4e 65 74 53 74 us..code...NetSt
5. 0040 72 65 61 6d 2e 50 6c 61 79 2e 53 74 61 72 74 00 ream.Play.Start.
6. 0050 0b 64 65 73 63 72 69 70 74 69 6f 6e 02 00 0a 53 .description...S
7. 0060 74 61 72 74 20 6c 69 76 65 00 00 09 tart live...
8. -------------------------------------------------------------------------
9. Real Time Messaging Protocol (AMF0 Command onStatus('NetStream.Play.Start'))
10. RTMP Header
11. 00.. .... = Format: 0
12. ..00 0101 = Chunk Stream ID: 5
13. Timestamp: 0
14. Body size: 96
15. Type ID: AMF0 Command (0x14)
16. Stream ID: 1
17. RTMP Body
18. String 'onStatus'
19. Number 0
20. Null
21. Object (3 items)
Server ----> Client : Data |RtmpSampleAccess()
1. 0000 05 00 00 00 00 00 18 12 01 00 00 00 02 00 11 7c ...............|
2. 0010 52 74 6d 70 53 61 6d 70 6c 65 41 63 63 65 73 73 RtmpSampleAccess
3. 0020 01 01 01 01 ....
4. -------------------------------------------------------------------------
5. Real Time Messaging Protocol (AMF0 Data |RtmpSampleAccess())
6. RTMP Header
7. 00.. .... = Format: 0
8. ..00 0101 = Chunk Stream ID: 5
9. Timestamp: 0
10. Body size: 24
11. Type ID: AMF0 Data (0x12)
12. Stream ID: 1
13. RTMP Body
14. String '|RtmpSampleAccess'
15. Boolean true
16. Boolean true
Server ----> Client : Data onMetaData()
1. 0000 05 00 00 00 00 01 83 12 01 00 00 00 02 00 0a 6f ...............o
2. 0010 6e 4d 65 74 61 44 61 74 61 03 00 06 53 65 72 76 nMetaData...Serv
3. ···· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················
4. 0180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 ...............
5. -------------------------------------------------------------------------
6. Real Time Messaging Protocol (AMF0 Data onMetaData())
7. RTMP Header
8. 00.. .... = Format: 0
9. ..00 0101 = Chunk Stream ID: 5
10. Timestamp: 0
11. Body size: 387
12. Type ID: AMF0 Data (0x12)
13. Stream ID: 1
14. RTMP Body
15. String 'onMetaData'
16. Object (14 items)
17. AMF0 type: Object (0x03)
18. Property 'Server' String 'NGINX RTMP (github.com/arut/nginx-rtmp-module)'
19. Property 'width' Number 1280
20. Property 'height' Number 720
21. Property 'displayWidth' Number 1280
22. Property 'displayHeight' Number 720
23. Property 'duration' Number 0
24. Property 'framerate' Number 25
25. Property 'fps' Number 25
26. Property 'videodatarate' Number 0
27. Property 'videocodecid' Number 7
28. Property 'audiodatarate' Number 125
29. Property 'audiocodecid' Number 1
30. Property 'profile' String ''
31. Property 'level' String ''
32. End Of Object Marker
数据传输
音频数据
0000 80 fa 5b 46 e3 29 dc a6 32 90 25 1e 08 00 45 00 ..[F.)..2.%...E.
···· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················
05e0 aa aa 02 ab 2a 26 a8 20 06 60 ....*&. .`
-------------------------------------------------------------------------
Real Time Messaging Protocol (Audio Data)
RTMP Header
00.. .... = Format: 0
..00 0110 = Chunk Stream ID: 6
Timestamp: 59947
Body size: 2054
Type ID: Audio Data (0x08)
Stream ID: 1
RTMP Body
Control: 0x1f (ADPCM 44 kHz 16 bit stereo)
0001 .... = Format: ADPCM (1)
.... 11.. = Sample rate: 44 kHz (3)
.... ..1. = Sample size: 16 bit (1)
.... ...1 = Channels: stereo (1)
Audio data: 80a1a80292a0884488cccd0c9088cd54cc88888888c8ccd0…
视频数据
0000 47 00 00 28 00 1a 1b 09 27 01 00 00 a0 00 00 1a G..(....'.......
···· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················
1a20 b4 9e 58 ..X
-------------------------------------------------------------------------
Real Time Messaging Protocol (Video Data)
RTMP Header
01.. .... = Format: 1
..00 0111 = Chunk Stream ID: 7
Timestamp delta: 40
Timestamp: 129960 (calculated)
Body size: 6683
Type ID: Video Data (0x09)
RTMP Body
Control: 0x27 (inter-frame H.264)
0010 .... = Type: inter-frame (2)
.... 0111 = Format: H.264 (7)
Video data: 010000a000001a12419aab49a8416c994c085ffffe8d340d…
