咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

RTSP网络抓包分析

抓包文件在附件中…

一、Play 抓包 Over TCP

  • 推流Client端rtmp-rtsp-stream-client-java
  • server端EasyDarwin
  • 播放Client端 Javacv 录制( 这里用Wireshark抓包

tcp追踪流

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
OPTIONS rtsp://192.168.0.223:554/test/ RTSP/1.0
CSeq: 1
User-Agent: Lavf58.12.100

RTSP/1.0 200 OK
CSeq: 1
Session: PoC0zKnGR
Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD

DESCRIBE rtsp://192.168.0.223:554/test/ RTSP/1.0
Accept: application/sdp
CSeq: 2
User-Agent: Lavf58.12.100
Session: PoC0zKnGR

RTSP/1.0 200 OK
CSeq: 2
Session: PoC0zKnGR
Content-Length: 444

v=0
o=- 0 0 IN IP4 127.0.0.1
s=Unnamed
i=N/A
c=IN IP4 192.168.0.223
t=0 0
a=recvonly
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=Z0LAHtoHgUSAeEAhUA==,aM48gA==;
a=control:trackID=1
m=audio 0 RTP/AVP 96
a=rtpmap:96 MPEG4-GENERIC/32000/2
a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1290; SizeLength=13; IndexLength=3; IndexDeltaLength=3;
a=control:trackID=0
SETUP rtsp://192.168.0.223:554/test/trackID=1 RTSP/1.0
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
CSeq: 3
User-Agent: Lavf58.12.100
Session: PoC0zKnGR

RTSP/1.0 200 OK
CSeq: 3
Session: PoC0zKnGR
Transport: RTP/AVP/TCP;unicast;interleaved=0-1

SETUP rtsp://192.168.0.223:554/test/trackID=0 RTSP/1.0
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
CSeq: 4
User-Agent: Lavf58.12.100
Session: PoC0zKnGR

RTSP/1.0 200 OK
CSeq: 4
Session: PoC0zKnGR
Transport: RTP/AVP/TCP;unicast;interleaved=2-3

PLAY rtsp://192.168.0.223:554/test/ RTSP/1.0
Range: npt=0.000-
CSeq: 5
User-Agent: Lavf58.12.100
Session: PoC0zKnGR

RTSP/1.0 200 OK
CSeq: 5
Session: PoC0zKnGR
Range: npt=0.000-

#这是紧接着一帧一帧rtp包(rtp over tcp)
701ce71cfb29c8ff28ed6843080045000524c1c240004006f1c3c0a800dfc0a8001e022ae383d37e23f074458e0a501800feecab0000240004f88060447500bd14102e9f0a407c85b803f06fe00f0e157e880381bc15565f8c35982ddba36a0312c81fd3800a814eb570c928a7818974f2303f010e39d505ae59ae3ebb42bbe706078d36e0997a0e00020011c000fff70000fea1d04f4480006968249f20dad1f9b600a5b19018a3c169c190e22c754f401f5cb5f3a4fa0736d00d6cbcb19670584cc24d248c1c51ef552de01e01807565e81e0ce8185fc160dbbeea53228011496146e44add661440a93ca0b20a0e6b2455413b9964320ed088f5cb751a24effc030f6b65c1d423a60fcf96247b9e7de03c0ef60020a1d76ad07eab06ad7584bfea63cfc9f5af1516029898299d30daa09cbff265002a099de41d7fa2262cc9a2957e885747b2bfd24b95583fd2007b1dc8060c63d0f9cb6000201a7968ad6b1eb03fc4932ee1efbc13b7a1ef52167acab89f939b0d039dad33c4b541c6ee759e541591f309071a007c130ffd1801818830226664c4db87bc2a00342111c8a630a654263ac5856721e37ed483ab31f8fa7a6797d9135039ffdfffa121bf11d0f440a84cbf443d5c9edd00010114f1c8298d5ad50b189ec1da94250a4826c50f3620d9da18cdffffb8ea614710240104fe5fa6886924bcc0d76987aa095427a80a08e13f0b935ca244c4ed4ff43b4ce7cd881a403cf8932bbffff695047712c3e0b19448ad5405308200306a59632f0a50e9a7a488da16040ece88915077f4299c947fff0794c028eba019c1036e548ce347af0cc3b1a18448fbaca4a4adaa8efd7b06f5be2dc1e7daec2ca97e2070654438fc5fe8dd06e0d30400f6fa7e09acc0c889df44c0a9cfda3c70f1cd3e0c9adcb6e208141e03bdfafd780400a3a3bf0f72fab2f7df9f8d0c701ff82c2105b6e2bcd85ea95fba2f79bbfd03539e2b4c412951d0bd4bf0581855cbcff519f54bd70d41c3b0a2f9bbe5fcf8aae3e87146bbe3c793a202ec6a5f5524a38c7fa7b6df5e90476add0f23a1539f71a2bdb6928320a0a01bdeb58527002d97c3826fcfdf7a6dc9e9a79909d71489e700531cc90d2f252aa97a97e9c1431a76fa785f03b42e60ee9f97fa6dedd63450c29b6f4d34fe3eb5c6b1d556ec510f6b6e6c8e31fede9a7ddfa939b8a9ad15b07e1e911cf2b358b776ee90de750f21b78eb8ad4ecc9c9859576c89856d2238b2feb87ca0a07f5f98bd655755bf2f6e66cb13c5b9cda6b50d605ddc4921c7a69f6fcf80aac42aaac56d5c98d6ec6b9f1e90d3183e9fc46623829bfef4b37de2d6d6d170c862ada69edb71f7723a98e6ad4bd289f42dfcb9cd90dd43cfdbd530a4e028320cdc846dd36e9ff6db77ffb8be74a93c98cce6c37ee9ca9ff1abd7d33b92dddd4d8ffaf2e0b703c21c342837a3460a8fe2002dae062608045068ace00a404e19d8d080527c354e368ce82406ab26eb61b0018c3b9991b036c07153560b53840bd0398c01e01e1c129b5b2e0efc55e32bae349338fa42a8a8c31427df5c18abc6f2f36aae5b55c78a648a6b4e3fdacd931184ea59d1e64cda61c0c0b2fb65e3ab07d70ff4b8988488acf3b25d56fa3039c123b28eff95e380c8dee9530e128920d476f47b28867b80fbb4e96af68a781b7e8bb9663c0130f8f752c7c9bbea0090e3e99b7797ff124528fc31a950e5fc651b85bdedf5ea5daa5ca41e2c2e7940ecb8e58448133afe9acaa6fb63badd2930240346a6eeda99aabb44822a41351c75d0725e36ad4d1fdc1086dbb9e6a5ee416d2df2ee372317b9541c6612d94cbb61357b2be0e37f981772c3880e02e2f4cc47e866

240004f88060447500bd14102e9f0a40 这一段 rtp over tcp 的头信息

240004f8 是 RTSP Interleaved Frame (RTSP交错帧头)

rtp over tcp 发送时要加这四个字节:

第一个字节Magic是 ‘$’ 符号;

第二个字节channel在rtsp的setup时获取;

第三、四个字节是rtp包的大小,第三个字节高4位,第四个字节保存低8位,最大12位。

1
2
3
Magic: 0x24
Channel: 0x00
Length: 1272

8060447500bd14102e9f0a40 是 RTP 头

1
2
3
4
5
6
7
8
9
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
0... .... = Marker: False
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 17525
Timestamp: 12391440
Synchronization Source identifier: 0x2e9f0a40 (782174784)

80-60-4475-00bd1410-2e9f0a40 五组数据一个一个分析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
0               1               2               3
7 6 5 4 3 2 1 0 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 7 6 5 4 3 2 1 0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V=2|P|X| CC |M| PT | sequence number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| synchronization source (SSRC) identifier |
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
| contributing source (CSRC) identifiers |
| .... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 1. RTP header according to RFC 3550
  • 版本号(V):2Bit,用来标志使用RTP版本

  • 填充位:1Bit,如果该位置位,则该RTP包的尾部就包含填充的附加字节

  • 扩展位(X):1Bit,如果该位置位,则该RTP包的固定头部后面就跟着一个扩展头部

  • CSRC技术器(CC):4Bit,含有固定头部后面跟着的CSRC的数据

  • 标记位(M):1Bit,该位的解释由配置文档来承担

  • 载荷类型(PT):7Bit,标识了RTP载荷的类型

  • 序列号(SN):16Bit,发送方在每发送完一个RTP包后就将该域的值增加1,可以由该域检测包的丢失及恢复包的序列。序列号的初始值是随机的。

  • 时间戳timestamp:32比特,记录了该包中数据的第一个字节的采样时刻

  • 同步源标识符(SSRC):32比特,同步源就是RTP包源的来源。在同一个RTP会话中不能有两个相同的SSRC值

  • 贡献源列表(CSRC List):0-15项,每项32比特,这个不常用,可以不用。

  1. 0x80 是指二进制位的值(10000000)
    1
    2
    3
    4
    10.. .... = Version: RFC 1889 Version (2)
    ..0. .... = Padding: False
    ...0 .... = Extension: False
    .... 0000 = Contributing source identifiers count: 0
  2. 0x60
    1
    2
    0... .... = Marker: False
    Payload type: DynamicRTP-Type-96 (96)
  3. 0x4475
    1
    Sequence number: 17525
  4. 0x00bd1410
    1
    Timestamp: 12391440
  5. 0x2e9f0a40
    1
    Synchronization Source identifier: 0x2e9f0a40 (782174784)

头部后面的就是payload负载了。

SDP

在RTSP的DESCRIBE方法响应 SDP Body 中,这一行很重要,下面分析一下。

1
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=Z0LAHtoHgUSAeEAhUA==,aM48gA==;

fmtp:96 其中 96 表示视频格式是H.264
sprop-parameter-sets 则是H.264中比较重要的SPS和PPS信息,它的值是两个Base64编码的值(逗号隔开),
Z0LAHtoHgUSAeEAhUA -> 0x6742c01eda0781448078402150 ,0x67 表示这是SPS。
aM48gA== -> 0x68ce3c80 ,0x68表示这是PPS 。

二、Play 抓包 Over UDP

  • 推流client端rtmp-rtsp-stream-client-java
  • server端EasyDarwin
  • 播放client端VLC( 这里用Wireshark抓包

tcp追踪流(RTSP部分,rtp over udp)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
OPTIONS rtsp://192.168.0.223:554/test/ RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)

RTSP/1.0 200 OK
CSeq: 2
Session: Ub5j54nMR
Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD

DESCRIBE rtsp://192.168.0.223:554/test/ RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp

RTSP/1.0 200 OK
CSeq: 3
Session: Ub5j54nMR
Content-Length: 444

v=0
o=- 0 0 IN IP4 127.0.0.1
s=Unnamed
i=N/A
c=IN IP4 192.168.0.223
t=0 0
a=recvonly
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=Z0LAHtoHgUSAeEAhUA==,aM48gA==;
a=control:trackID=1
m=audio 0 RTP/AVP 96
a=rtpmap:96 MPEG4-GENERIC/32000/2
a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1290; SizeLength=13; IndexLength=3; IndexDeltaLength=3;
a=control:trackID=0
SETUP rtsp://192.168.0.223:554/test/trackID=1 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=49834-49835

RTSP/1.0 200 OK
CSeq: 4
Session: Ub5j54nMR
Transport: RTP/AVP;unicast;client_port=49834-49835

SETUP rtsp://192.168.0.223:554/test/trackID=0 RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=49836-49837
Session: Ub5j54nMR

RTSP/1.0 200 OK
CSeq: 5
Session: Ub5j54nMR
Transport: RTP/AVP;unicast;client_port=49836-49837

PLAY rtsp://192.168.0.223:554/test/ RTSP/1.0
CSeq: 6
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Session: Ub5j54nMR
Range: npt=0.000-

RTSP/1.0 200 OK
CSeq: 6
Session: Ub5j54nMR
Range: npt=0.000-

rtp over udp

1
2
3
4
5
6
7
8
9
10
11
12
13
Real-Time Transport Protocol
[Stream setup by RTSP (frame 13)]
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
0... .... = Marker: False
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 918
[Extended sequence number: 66454]
Timestamp: 849582
Synchronization Source identifier: 0x0ce9d37f (216650623)
Payload: 7c85b8141ff1c6921a6ba385c00040056dd92a7ccbeb7e38…

十六进制 (0x80600396000cf6ae0ce9d37f 是 rtp header)

1
80600396000cf6ae0ce9d37f|我是分隔符|7c85b8141ff1c6921a6ba385c00040056dd92a7ccbeb7e38000837470001067fff1fc3177b46c9c731d84f1e6b6f6ff6fc763b09e21dfe9df6dbc8b84f176dbfe9db4d3b68efff8f1c444b8fca76b5da32e13cda7476ffff477fc47e3c53ebad78fc20f47edf6fe3ffa3fffff3ff043afe1edee6b04a600b730c899d05e4d4dffba8ba5f3adab44c59e08ded760e63763eda138901d3c527ffedff09e0854eb3b7ffe3bef09fd013dfb7ffe9be1d7a32430a449f19848276060df0f31fe941ff8a8976a7039b22b8d910300043c1c004254905641cf077c3c9ed77812f89043040be9a437b35b520bf448436f46f48c000401817b8f391571dc96f9f8515c3225034d14963b27feab77e6a3e8e7722e93bf6bda10b439fbee0f8afa2887e21c776f75fb8c50fff9f50caa27ddf2f17de9e690f29a9780eef43e6b031805184fce2e27feb480fb577381cace9e2bbaf378354bd524c3a3c45812dc55528ee47b8a78ab2f228bddf5372c7964bd0781f5cb673f2dbd45cfe8fc00e8675e64aaca76d34cdbaa6993c69c69c5df77bb0cf48a7ba41457cb8f6d42728128ecd69f2d1b7fdbffc89e3ebe78cbbe90bb557dc8fa006e3e8593fb7f5d3b65a8347e7ffd757e21558f4b17ac009c887912807061fdc1d87e56cfffcd951823d6e8d28060f7038a1605115c154bc0bcec0e77cfbc17ae34e6cf9b2b7641dd1f4e3e5dfff0f060a7bf595121372efffdbd2de14a9c908826749655109894930c25b0cb20fc30327a7ffc2b8973fff6e54b221f641354a50ffffe8e7485551a7fffca8c832481117a78fffdb6d05fd3edf171153a44cb24d580c9862259a3152f54e1565d4694eda2a32519e5ffbbfa88afe7cd956bd2f516f74fffa21042c4e12421c2112488a2a11b4da4055a564a7b022561f103175bd441f8f73fc3d4474f8e62d71bc4c1dc6c6cd295df1690870f73aa0efad48c09f7ec5203c0954554ba7f0a312006e3bd03fbacf6ff9518c1ed5bccb3c49106c150b6bc14c5216e9ab42bfb48cb8d958eb59641482a2946928541f04f49fd74e3b4ea8e67b78147940b2d3813f275f5744028cad6a0d27369bd6b8e6ddf4ae5ea34ac977795b69afa9888a2dc7c657b8428e7f510f971c3d035d0ee31ee67a6185555ceb6610c896d16c32cd8c857bedf56aaf58a49a1e68f28875bedf4bd083601f0ada56fffffe7d61d07fd650b7e045246963c6aa9d28ed1ccf9e37c584401664a2f8e92c711f055b7b52d9d89dc02f7e48280553ca1c2d52cf20159a824cb6fb7eb60971384a9ff7b954807714fcb880952c102ed4fd32af30ce6032668ad447dfae2425f10c04dfcfea34116c1565385b99728679581c8d23dbb18bdf90abeae6fbfa94ca18f486feb34d660bec5c5d76b54db986731a0857db65250c82d293b16060802c1c1037464d9b3709ecf5b770ca586800821738c93c4588a64b80d33292b3ec07c461c7e840bda57c18f4403615df6de9012a2b60b7e066105e60f30aee1506dbc2c4f2b8c89201b293a8fa61dd3d3804498c8c48643c80724573fb77238f65116824d336be409c8ec6a290344368394a6bd00a5872d4107ff54b09eb398c061f5e0c81283da0afdbf06686a383fab987254b835d095f2cabcbe0eaae9c4c03d7286ada203e607156d0d3a9b6f9f9a0034211effb7c0392a47214afbef9ffda37102e821292af133105d4c33b5ddbf0b1ba4e609422f878e94831e6f6909391292a41daafd076146581226a148afcfa1395062fa8

后面 rtp payload 是H264的NAL,这部分可能有三种情况:单NAL,聚合NAL,分包NAL

三、Play 抓包 Over UDP

  • server端live555
  • 播放client端VLC( 这里用Wireshark抓包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
OPTIONS rtsp://192.168.0.226:8554/test81.mkv RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)

RTSP/1.0 200 OK
CSeq: 2
Date: Sat, Aug 01 2020 08:49:00 GMT
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER

DESCRIBE rtsp://192.168.0.226:8554/test81.mkv RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp

RTSP/1.0 200 OK
CSeq: 3
Date: Sat, Aug 01 2020 08:49:00 GMT
Content-Base: rtsp://192.168.0.226:8554/test81.mkv/
Content-Type: application/sdp
Content-Length: 802

v=0
o=- 1596271740645123 1 IN IP4 192.168.0.226
s=Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server
i=test81.mkv
t=0 0
a=tool:LIVE555 Streaming Media v2020.07.31
a=type:broadcast
a=control:*
a=range:npt=0-24.762
a=x-qt-text-nam:Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server
a=x-qt-text-inf:test81.mkv
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:500
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z2QAH6zZQIgeaEAAAAMAQAAADIPGDGWA,aO+8sA==
a=control:track1
m=audio 0 RTP/AVP 97
c=IN IP4 0.0.0.0
b=AS:96
a=rtpmap:97 MPEG4-GENERIC/44100/2
a=fmtp:97 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1210
a=control:track2
SETUP rtsp://192.168.0.226:8554/test81.mkv/track1 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=53828-53829

RTSP/1.0 200 OK
CSeq: 4
Date: Sat, Aug 01 2020 08:49:00 GMT
Transport: RTP/AVP;unicast;destination=192.168.0.30;source=192.168.0.226;client_port=53828-53829;server_port=6970-6971
Session: 19482B64;timeout=65

SETUP rtsp://192.168.0.226:8554/test81.mkv/track2 RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=53830-53831
Session: 19482B64

RTSP/1.0 200 OK
CSeq: 5
Date: Sat, Aug 01 2020 08:49:00 GMT
Transport: RTP/AVP;unicast;destination=192.168.0.30;source=192.168.0.226;client_port=53830-53831;server_port=6972-6973
Session: 19482B64;timeout=65

PLAY rtsp://192.168.0.226:8554/test81.mkv/ RTSP/1.0
CSeq: 6
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Session: 19482B64
Range: npt=0.000-

RTSP/1.0 200 OK
CSeq: 6
Date: Sat, Aug 01 2020 08:49:00 GMT
Range: npt=0.000-
Session: 19482B64
RTP-Info: url=rtsp://192.168.0.226:8554/test81.mkv/track1;seq=51716;rtptime=3858412142,url=rtsp://192.168.0.226:8554/test81.mkv/track2;seq=33672;rtptime=3712761154

PAUSE rtsp://192.168.0.226:8554/test81.mkv/ RTSP/1.0
CSeq: 7
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Session: 19482B64

RTSP/1.0 200 OK
CSeq: 7
Date: Sat, Aug 01 2020 08:49:04 GMT
Session: 19482B64

TEARDOWN rtsp://192.168.0.226:8554/test81.mkv/ RTSP/1.0
CSeq: 8
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Session: 19482B64

RTSP/1.0 200 OK
CSeq: 8
Date: Sat, Aug 01 2020 08:49:09 GMT


四、Play 抓包 Over UDP

  • server端Android Show
  • 播放client端VLC( 这里用Wireshark抓包

这一次抓包没有按照RTSP规范来,先启动了”Android Show”(开始发RTP包了),后启动VLC。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
OPTIONS rtsp://192.168.0.32:8554/ RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)

RTSP/1.0 200 OK
Server: MajorKernelPanic RTSP Server
Cseq: 2
Content-Length: 0
Public: DESCRIBE,SETUP,TEARDOWN,PLAY,PAUSE

DESCRIBE rtsp://192.168.0.32:8554/ RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp

RTSP/1.0 200 OK
Server: MajorKernelPanic RTSP Server
Cseq: 3
Content-Length: 240
Content-Base: 192.168.0.32:8554/
Content-Type: application/sdp

v=0
o=- 0 0 IN IP4 192.168.0.32
s=Unnamed
i=N/A
c=IN IP4 192.168.0.30
t=0 0
a=recvonly
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=000042;sprop-parameter-sets=;
a=control:trackID=1
SETUP 192.168.0.32:8554/trackID=1 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=53754-53755

RTSP/1.0 200 OK
Server: MajorKernelPanic RTSP Server
Cseq: 4
Content-Length: 0
Transport: RTP/AVP/UDP;unicast;destination=192.168.0.30;client_port=53754-53755;server_port=47390-45114;ssrc=d59b4263;mode=play
Session: 1185d20035702ca
Cache-Control: no-cache

PLAY 192.168.0.32:8554/ RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Session: 1185d20035702ca
Range: npt=0.000-

RTSP/1.0 200 OK
Server: MajorKernelPanic RTSP Server
Cseq: 5
Content-Length: 0
RTP-Info: url=rtsp://192.168.0.32:8554/trackID=1;seq=0
Session: 1185d20035702ca


第一个Rtp包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Frame 1011: 86 bytes on wire (688 bits), 86 bytes captured (688 bits) on interface \Device\NPF_{CAE75AB8-102D-4211-B413-07C344B1BD41}, id 0
Ethernet II, Src: HuaweiTe_cc:b7:c3 (ac:e3:42:cc:b7:c3), Dst: IntelCor_1c:fb:29 (70:1c:e7:1c:fb:29)
Internet Protocol Version 4, Src: 192.168.0.32, Dst: 192.168.0.30
User Datagram Protocol, Src Port: 47390, Dst Port: 53754
Real-Time Transport Protocol
[Stream setup by RTSP (frame 1009)]
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
1... .... = Marker: True
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 32
[Extended sequence number: 65568]
Timestamp: 688259944
Synchronization Source identifier: 0xd59b4263 (3583722083)
Payload: 0000000161edab0df03a7126d03a00f27425901cfd5be89afa597d5afab10019

第二个Rtp包(空payload?)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Frame 1012: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface \Device\NPF_{CAE75AB8-102D-4211-B413-07C344B1BD41}, id 0
Ethernet II, Src: HuaweiTe_cc:b7:c3 (ac:e3:42:cc:b7:c3), Dst: IntelCor_1c:fb:29 (70:1c:e7:1c:fb:29)
Internet Protocol Version 4, Src: 192.168.0.32, Dst: 192.168.0.30
User Datagram Protocol, Src Port: 47390, Dst Port: 53754
Real-Time Transport Protocol
[Stream setup by RTSP (frame 1009)]
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
1... .... = Marker: True
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 33
[Extended sequence number: 65569]
Timestamp: 688259944
Synchronization Source identifier: 0xd59b4263 (3583722083)

第三个Rtp包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Frame 1013: 80 bytes on wire (640 bits), 80 bytes captured (640 bits) on interface \Device\NPF_{CAE75AB8-102D-4211-B413-07C344B1BD41}, id 0
Ethernet II, Src: HuaweiTe_cc:b7:c3 (ac:e3:42:cc:b7:c3), Dst: IntelCor_1c:fb:29 (70:1c:e7:1c:fb:29)
Internet Protocol Version 4, Src: 192.168.0.32, Dst: 192.168.0.30
User Datagram Protocol, Src Port: 47390, Dst Port: 53754
Real-Time Transport Protocol
[Stream setup by RTSP (frame 1009)]
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
1... .... = Marker: True
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 34
[Extended sequence number: 65570]
Timestamp: 688261409
Synchronization Source identifier: 0xd59b4263 (3583722083)
Payload: 0000000161efab0df03c74d901cfd5be89afa597d5afab100195

** 这几个都是P帧,原因是:AndroidShow启动投屏之后,就一开始发UDP包了,所以VLC连接上之后,接收到的第一帧不是I帧。 所以要等到接收到下一个I帧才能正常播放**

但是这里有一个疑惑,Sdp中 “sprop-parameter-sets” 为空,Wireshark也显示Sdp这里出现错误,那VLC如何获取到SPS+PPS?

注:VLC能正常播放和识别宽高

通过查看AndroidShow的源码,它是将 SPS+PPS 添加到流里面,每3秒就随rtp一起发送,所以不需要在SDP中携带SPS也能解码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Every 3 secondes, we send two packets containing NALU type 7 (sps) and 8 (pps)
// 每3秒,我们发送两个包,包含NALU类型7 (sps)和8 (pps)

// Those should allow the H264 stream to be decoded even if no SDP was sent to the decoder.
// 即使没有SDP发送到解码器,H264流也允许被解码。
delta2 += duration/1000000;
if (delta2>2000) {
delta2 = 0;
if (sps != null) {
buffer = socket.requestBuffer();
socket.markNextPacket();
socket.updateTimestamp(ts);
System.arraycopy(sps, 0, buffer, rtphl, sps.length);
super.send(rtphl+sps.length);
}
if (pps != null) {
buffer = socket.requestBuffer();
socket.updateTimestamp(ts);
socket.markNextPacket();
System.arraycopy(pps, 0, buffer, rtphl, pps.length);
super.send(rtphl+pps.length);
}
}

其中,super.send是发送rtcp的:

1
2
3
4
/** Updates data for RTCP SR and sends the packet. */
protected void send(int length) throws IOException {
socket.commitBuffer(length);
}

五、Record 抓包 Over TCP

在rtsp的方法中record是指client推流
早期不太清楚,其实用ffmpeg作为推流客户端更好(标准)

  • 推流client端 rtmp-rtsp-stream-client-java 默认推流 ( 这里用Wireshark抓包
  • server端EasyDarwin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
OPTIONS rtsp://192.168.0.223:554/test/ RTSP/1.0
CSeq: 1

RTSP/1.0 200 OK
CSeq: 1
Session: 0sSc8K7Mg
Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD

ANNOUNCE rtsp://192.168.0.223:554/test/ RTSP/1.0
CSeq: 2
Content-Length: 444
Content-Type: application/sdp

v=0
o=- 0 0 IN IP4 127.0.0.1
s=Unnamed
i=N/A
c=IN IP4 192.168.0.223
t=0 0
a=recvonly
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=Z0LAHtoHgUSAeEAhUA==,aM48gA==;
a=control:trackID=1
m=audio 0 RTP/AVP 96
a=rtpmap:96 MPEG4-GENERIC/32000/2
a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1290; SizeLength=13; IndexLength=3; IndexDeltaLength=3;
a=control:trackID=0
RTSP/1.0 200 OK
CSeq: 2
Session: 0sSc8K7Mg

SETUP rtsp://192.168.0.223:554/test//trackID=0 RTSP/1.0
Transport: RTP/AVP/TCP;interleaved=0-1;mode=record
CSeq: 3
Session: 0sSc8K7Mg

RTSP/1.0 200 OK
CSeq: 3
Session: 0sSc8K7Mg
Transport: RTP/AVP/TCP;interleaved=0-1;mode=record

SETUP rtsp://192.168.0.223:554/test//trackID=1 RTSP/1.0
Transport: RTP/AVP/TCP;interleaved=2-3;mode=record
CSeq: 4
Session: 0sSc8K7Mg

RTSP/1.0 200 OK
CSeq: 4
Session: 0sSc8K7Mg
Transport: RTP/AVP/TCP;interleaved=2-3;mode=record

RECORD rtsp://192.168.0.223:554/test/ RTSP/1.0
Range: npt=0.000-
CSeq: 5
Session: 0sSc8K7Mg

RTSP/1.0 200 OK
CSeq: 5
Session: 0sSc8K7Mg

rtp over tcp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
RTSP Interleaved Frame, Channel: 0x00, 284 bytes
Magic: 0x24
Channel: 0x00
Length: 284
Real-Time Transport Protocol
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
1... .... = Marker: True
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 1
Timestamp: 31752
Synchronization Source identifier: 0x4ead93aa (1319998378)
Payload: 00100860211c0fd3f7b904100cd41d9a87d188f484100ea0…
RTSP Interleaved Frame, Channel: 0x01, 28 bytes
Magic: 0x24
Channel: 0x01
Length: 28
Real-time Transport Control Protocol (Sender Report)
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 0000 = Reception report count: 0
Packet type: Sender Report (200)
Length: 6 (28 bytes)
Sender SSRC: 0x1335186a (322246762)
Timestamp, MSW: 29536 (0x00007360)
Timestamp, LSW: 3497974249 (0xd07ed9e9)
[MSW and LSW as NTP timestamp: Feb 7, 2036 14:40:32.814435595 UTC]
RTP timestamp: 992265000
Sender's packet count: 1
Sender's octet count: 284
[RTCP frame length check: OK - 28 bytes]
RTSP Interleaved Frame, Channel: 0x00, 288 bytes
Magic: 0x24
Channel: 0x00
Length: 288
Real-Time Transport Protocol
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
1... .... = Marker: True
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 2
Timestamp: 33004
Synchronization Source identifier: 0x4ead93aa (1319998378)
Payload: 00100880211c0feb7e2005013ccc4515a510e8443a710e88…
RTSP Interleaved Frame, Channel: 0x00, 297 bytes
Magic: 0x24
Channel: 0x00
Length: 297
Real-Time Transport Protocol
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
1... .... = Marker: True
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 3
Timestamp: 33515
Synchronization Source identifier: 0x4ead93aa (1319998378)
Payload: 001008c8211c09bffe4800621cd41d928bd10874c22d1907…
RTSP Interleaved Frame, Channel: 0x00, 248 bytes
Magic: 0x24
Channel: 0x00
Length: 248
Real-Time Transport Protocol
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
1... .... = Marker: True
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 4
Timestamp: 34804
Synchronization Source identifier: 0x4ead93aa (1319998378)
Payload: 00100740211c0f6d4c8000fffcdb348a29d108f462802b9d…
RTSP Interleaved Frame, Channel: 0x00, 257 bytes
Magic: 0x24
Channel: 0x00
Length: 257
Real-Time Transport Protocol
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
1... .... = Marker: True
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 5
Timestamp: 36157
Synchronization Source identifier: 0x4ead93aa (1319998378)
Payload: 00100788211c0fa51e28016f3cdb30dfa316019b72bf3373…

六、Record 抓包 Over UDP

  • 推流client端 rtmp-rtsp-stream-client-java 选用UDP推流 ( 这里用Wireshark抓包
  • server端EasyDarwin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
OPTIONS rtsp://192.168.0.223:554/test/ RTSP/1.0
CSeq: 1

RTSP/1.0 200 OK
CSeq: 1
Session: 6KgD6pnGg
Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD

ANNOUNCE rtsp://192.168.0.223:554/test/ RTSP/1.0
CSeq: 2
Content-Length: 444
Content-Type: application/sdp

v=0
o=- 0 0 IN IP4 127.0.0.1
s=Unnamed
i=N/A
c=IN IP4 192.168.0.223
t=0 0
a=recvonly
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=Z0LAKNoBEA8WXgHhAIVA,aM48gA==;
a=control:trackID=1
m=audio 0 RTP/AVP 96
a=rtpmap:96 MPEG4-GENERIC/44100/2
a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1210; SizeLength=13; IndexLength=3; IndexDeltaLength=3;
a=control:trackID=0
RTSP/1.0 200 OK
CSeq: 2
Session: 6KgD6pnGg

SETUP rtsp://192.168.0.223:554/test//trackID=0 RTSP/1.0
Transport: RTP/AVP/UDP;unicast;client_port=5000-5001;mode=record
CSeq: 3
Session: 6KgD6pnGg

RTSP/1.0 200 OK
CSeq: 3
Session: 6KgD6pnGg
Transport: RTP/AVP/UDP;unicast;client_port=5000-5001;server_port=53646-50516;mode=record

SETUP rtsp://192.168.0.223:554/test//trackID=1 RTSP/1.0
Transport: RTP/AVP/UDP;unicast;client_port=5002-5003;mode=record
CSeq: 4
Session: 6KgD6pnGg

RTSP/1.0 200 OK
Session: 6KgD6pnGg
Transport: RTP/AVP/UDP;unicast;client_port=5002-5003;server_port=50593-32937;mode=record
CSeq: 4

RECORD rtsp://192.168.0.223:554/test/ RTSP/1.0
Range: npt=0.000-
CSeq: 5
Session: 6KgD6pnGg

RTSP/1.0 200 OK
CSeq: 5
Session: 6KgD6pnGg

TEARDOWN rtsp://192.168.0.223:554/test/ RTSP/1.0
CSeq: 6
Session: 6KgD6pnGg

RTSP/1.0 200 OK
CSeq: 6
Session: 6KgD6pnGg


rtp over udp

1
2
3
4
5
6
7
8
9
10
11
12
User Datagram Protocol, Src Port: 62235, Dst Port: 50593
Real-Time Transport Protocol
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
0... .... = Marker: False
Payload type: DynamicRTP-Type-96 (96)
Sequence number: 2
Timestamp: 254255
Synchronization Source identifier: 0x401fd7b1 (1075828657)
Payload: 7c85b82057ffffc2e2450001014fd63fde278f9369f7bbe4…

七、Record 抓包 Over UDP (FFmpeg)

  • 推流FFmpeg(ffmpeg -re -i move.mp4 -vcodec copy -codec copy -f rtsp rtsp://192.168.0.30/live)
  • server端 基于Netty写的接收程序( 这里用Wireshark抓包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
OPTIONS rtsp://192.168.0.30:554/live RTSP/1.0
CSeq: 1
User-Agent: Lavf57.71.100

RTSP/1.0 200 OK
public: OPTIONS, ANNOUNCE, SETUP, RECORD, TEARDOWN
cseq: 1
SESSION: 850601d9
connection: keep-alive

ANNOUNCE rtsp://192.168.0.30:554/live RTSP/1.0
Content-Type: application/sdp
CSeq: 2
User-Agent: Lavf57.71.100
Session: 850601d9
Content-Length: 494

v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 192.168.0.30
t=0 0
a=tool:libavformat 57.71.100
m=video 0 RTP/AVP 96
b=AS:1351
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAIKzZgIgee+EAAAMD6QAB1MAPGDGa,aOl4ssiw; profile-level-id=640020
a=control:streamid=0
m=audio 0 RTP/AVP 97
b=AS:128
a=rtpmap:97 MPEG4-GENERIC/44100/2
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1210
a=control:streamid=1
RTSP/1.0 200 OK
cseq: 2
SESSION: 850601d9
connection: keep-alive

SETUP rtsp://192.168.0.30:554/live/streamid=0 RTSP/1.0
Transport: RTP/AVP/UDP;unicast;client_port=20502-20503;mode=record
CSeq: 3
User-Agent: Lavf57.71.100
Session: 850601d9

RTSP/1.0 200 OK
transport: RTP/AVP/UDP;unicast;client_port=20502-20503;mode=record;server_port=54000-54001;ssrc=1015232941
cseq: 3
SESSION: 850601d9
connection: keep-alive

SETUP rtsp://192.168.0.30:554/live/streamid=1 RTSP/1.0
Transport: RTP/AVP/UDP;unicast;client_port=20504-20505;mode=record
CSeq: 4
User-Agent: Lavf57.71.100
Session: 850601d9

RTSP/1.0 200 OK
transport: RTP/AVP/UDP;unicast;client_port=20504-20505;mode=record;server_port=54000-54001;ssrc=102410565
cseq: 4
SESSION: 850601d9
connection: keep-alive

RECORD rtsp://192.168.0.30:554/live RTSP/1.0
Range: npt=0.000-
CSeq: 5
User-Agent: Lavf57.71.100
Session: 850601d9

RTSP/1.0 200 OK
filename: 1595477112
cseq: 5
SESSION: 850601d9
connection: keep-alive

TEARDOWN rtsp://192.168.0.30:554/live RTSP/1.0
CSeq: 6
User-Agent: Lavf57.71.100
Session: 850601d9