hls协议分点播和直播两种方式,都是通过Http协议get命令来实现,
直播抓包如下:
第一步:获取节目列表
请求命令:
GET /hls/cctv3hd.m3u8 HTTP/1.1
Host: ivi.bupt.edu.cn
Accept: */*
Accept-Language: zh_CN
User-Agent: VLC/3.0.2 LibVLC/3.0.2
Range: bytes=0-
应答命令
HTTP/1.1 206 Partial Content
Server: nginx/1.14.0
Date: Sun, 07 Oct 2018 06:23:46 GMT
Content-Type: application/vnd.apple.mpegurl
Content-Length: 325
Last-Modified: Sun, 07 Oct 2018 06:23:45 GMT
Connection: keep-alive
ETag: "5bb9a671-145"
Expires: Sun, 07 Oct 2018 06:23:45 GMT
Cache-Control: no-cache
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS
Access-Control-Allow-Headers: Accept, Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
Content-Range: bytes 0-324/325
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:126552
#EXT-X-TARGETDURATION:10
#EXTINF:10.000,
cctv3hd-1538893365000.ts
#EXTINF:10.000,
cctv3hd-1538893375000.ts
#EXTINF:10.000,
cctv3hd-1538893385000.ts
#EXTINF:10.000,
cctv3hd-1538893395000.ts
#EXTINF:10.000,
cctv3hd-1538893405000.ts
#EXTINF:10.000,
cctv3hd-1538893415000.ts
命令解析:
参考标准:
https://tools.ietf.org/html/draft-pantos-http-live-streaming-06
#EXTM3U :每个m3u文件第一行必须有这个tag
#EXT-X-VERSION:3 版本号
#EXT-X-MEDIA-SEQUENCE:126552 :每个playlist中唯一的序号,相邻之间序号+1
#EXT-X-TARGETDURATION:10 :指定最大的媒体段时间长(秒)
#EXTINF:10.000,EXTINF是一个记录标记,该标记描述了后边URI所指定的媒体文件。每个媒体文件URI前边必须有EXTINF标签格式如下:#EXTINF: <DURATION>,<TITLE> 。DURATION是一个整数,它指定了媒体文件以秒为单位的持续时间 ,行内逗号后边的剩余部分是媒体文件的名字,该名字是媒体分片的人眼可读的信息标题
cctv3hd-1538893365000.ts 媒体流的路径
每一行的结束,会有个oa,截图如下:
第二步:再通过http协议get命令,获取视频流
请求:
GET /hls/cctv3hd-1538893365000.ts HTTP/1.1
Host: ivi.bupt.edu.cn
Cache-Control: no-cache
User-Agent: VLC/3.0.2 LibVLC/3.0.2
应答:
HTTP/1.1 200 OK
Server: nginx/1.14.0
Date: Sun, 07 Oct 2018 06:23:46 GMT
Content-Type: video/mp2t
Content-Length: 5436020
Last-Modified: Sun, 07 Oct 2018 06:22:55 GMT
Connection: keep-alive
ETag: "5bb9a63f-52f274"
Expires: Sun, 07 Oct 2018 06:23:45 GMT
Cache-Control: no-cache
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS
Access-Control-Allow-Headers: Accept, Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
Accept-Ranges: bytes
点播抓包如下:
第一步:获取节目流
请求:
GET /iphone/samples/bipbop/gear1/prog_index.m3u8 HTTP/1.1
Host: devimages.apple.com
Accept: */*
Accept-Language: zh_CN
User-Agent: VLC/3.0.2 LibVLC/3.0.2
Range: bytes=0-
应答
HTTP/1.1 206 Partial Content
Server: Apache
ETag: "50117c8233644c19b5ab49551b72507f:1239907352"
Last-Modified: Thu, 16 Apr 2009 18:42:32 GMT
Accept-Ranges: bytes
Content-Type: audio/x-mpegurl
Date: Sun, 07 Oct 2018 06:36:13 GMT
Content-Range: bytes 0-7018/7019
Content-Length: 7019
X-Cache: TCP_REFRESH_HIT from a223-119-50-134.deploy.akamaitechnologies.com (AkamaiGHost/9.4.4.1.1-23623864) (S)
Connection: keep-alive
X-Cache-Remote: TCP_REFRESH_HIT from a223-119-50-196.deploy.akamaitechnologies.com (AkamaiGHost/9.4.4.1.1-23623864) (S)
X-Cache-Remote: TCP_IMS_HIT from a223-119-50-196.deploy.akamaitechnologies.com (AkamaiGHost/9.4.4.1.1-23623864) (-)
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10, no desc
fileSequence0.ts
#EXTINF:10, no desc
fileSequence1.ts
#EXTINF:10, no desc
fileSequence2.ts
#EXTINF:10, no desc
fileSequence3.ts
#EXTINF:10, no desc
fileSequence4.ts
#EXTINF:10, no desc
fileSequence5.ts
#EXTINF:10, no desc
fileSequence6.ts
#EXTINF:10, no desc
fileSequence7.ts
#EXTINF:10, no desc
fileSequence8.ts
#EXTINF:10, no desc
fileSequence9.ts
#EXTINF:10, no desc
fileSequence10.ts
#EXTINF:10, no desc
fileSequence11.ts
#EXTINF:10, no desc
fileSequence12.ts
#EXTINF:10, no desc
fileSequence13.ts
#EXTINF:10, no desc
fileSequence14.ts
#EXTINF:10, no desc
fileSequence15.ts
#EXTINF:10, no desc
fileSequence16.ts
#EXTINF:10, no desc
fileSequence17.ts
#EXTINF:10, no desc
fileSequence18.ts
#EXTINF:10, no desc
fileSequence19.ts
#EXTINF:10, no desc
fileSequence20.ts
#EXTINF:10, no desc
fileSequence21.ts
#EXTINF:10, no desc
fileSequence22.ts
#EXTINF:10, no desc
fileSequence23.ts
#EXTINF:10, no desc
fileSequence24.ts
#EXTINF:10, no desc
fileSequence25.ts
#EXTINF:10, no desc
fileSequence26.ts
#EXTINF:10, no desc
fileSequence27.ts
#EXTINF:10, no desc
fileSequence28.ts
#EXTINF:10, no desc
fileSequence29.ts
#EXTINF:10, no desc
fileSequence30.ts
#EXTINF:10, no desc
fileSequence31.ts
#EXTINF:10, no desc
fileSequence32.ts
#EXTINF:10, no desc
fileSequence33.ts
#EXTINF:10, no desc
fileSequence34.ts
#EXTINF:10, no desc
fileSequence35.ts
#EXTINF:10, no desc
fileSequence36.ts
#EXTINF:10, no desc
fileSequence37.ts
#EXTINF:10, no desc
fileSequence38.ts
#EXTINF:10, no desc
fileSequence39.ts
#EXTINF:10, no desc
fileSequence40.ts
#EXTINF:10, no desc
fileSequence41.ts
#EXTINF:10, no desc
fileSequence42.ts
#EXTINF:10, no desc
fileSequence43.ts
#EXTINF:10, no desc
fileSequence44.ts
#EXTINF:10, no desc
fileSequence45.ts
#EXTINF:10, no desc
fileSequence46.ts
#EXTINF:10, no desc
fileSequence47.ts
#EXTINF:10, no desc
fileSequence48.ts
#EXTINF:10, no desc
fileSequence49.ts
#EXTINF:10, no desc
fileSequence50.ts
#EXTINF:10, no desc
fileSequence51.ts
#EXTINF:10, no desc
fileSequence52.ts
#EXTINF:10, no desc
fileSequence53.ts
#EXTINF:10, no desc
fileSequence54.ts
#EXTINF:10, no desc
fileSequence55.ts
#EXTINF:10, no desc
fileSequence56.ts
#EXTINF:10, no desc
fileSequence57.ts
#EXTINF:10, no desc
fileSequence58.ts
#EXTINF:10, no desc
fileSequence59.ts
#EXTINF:10, no desc
fileSequence60.ts
#EXTINF:10, no desc
fileSequence61.ts
#EXTINF:10, no desc
fileSequence62.ts
#EXTINF:10, no desc
fileSequence63.ts
#EXTINF:10, no desc
fileSequence64.ts
#EXTINF:10, no desc
fileSequence65.ts
#EXTINF:10, no desc
fileSequence66.ts
#EXTINF:10, no desc
fileSequence67.ts
#EXTINF:10, no desc
fileSequence68.ts
#EXTINF:10, no desc
fileSequence69.ts
#EXTINF:10, no desc
fileSequence70.ts
#EXTINF:10, no desc
fileSequence71.ts
#EXTINF:10, no desc
fileSequence72.ts
#EXTINF:10, no desc
fileSequence73.ts
#EXTINF:10, no desc
fileSequence74.ts
#EXTINF:10, no desc
fileSequence75.ts
#EXTINF:10, no desc
fileSequence76.ts
#EXTINF:10, no desc
fileSequence77.ts
#EXTINF:10, no desc
fileSequence78.ts
#EXTINF:10, no desc
fileSequence79.ts
#EXTINF:10, no desc
fileSequence80.ts
#EXTINF:10, no desc
fileSequence81.ts
#EXTINF:10, no desc
fileSequence82.ts
#EXTINF:10, no desc
fileSequence83.ts
#EXTINF:10, no desc
fileSequence84.ts
#EXTINF:10, no desc
fileSequence85.ts
#EXTINF:10, no desc
fileSequence86.ts
#EXTINF:10, no desc
fileSequence87.ts
#EXTINF:10, no desc
fileSequence88.ts
#EXTINF:10, no desc
fileSequence89.ts
#EXTINF:10, no desc
fileSequence90.ts
#EXTINF:10, no desc
fileSequence91.ts
#EXTINF:10, no desc
fileSequence92.ts
#EXTINF:10, no desc
fileSequence93.ts
#EXTINF:10, no desc
fileSequence94.ts
#EXTINF:10, no desc
fileSequence95.ts
#EXTINF:10, no desc
fileSequence96.ts
#EXTINF:10, no desc
fileSequence97.ts
#EXTINF:10, no desc
fileSequence98.ts
#EXTINF:10, no desc
fileSequence99.ts
#EXTINF:10, no desc
fileSequence100.ts
#EXTINF:10, no desc
fileSequence101.ts
#EXTINF:10, no desc
fileSequence102.ts
#EXTINF:10, no desc
fileSequence103.ts
#EXTINF:10, no desc
fileSequence104.ts
#EXTINF:10, no desc
fileSequence105.ts
#EXTINF:10, no desc
fileSequence106.ts
#EXTINF:10, no desc
fileSequence107.ts
#EXTINF:10, no desc
fileSequence108.ts
#EXTINF:10, no desc
fileSequence109.ts
#EXTINF:10, no desc
fileSequence110.ts
#EXTINF:10, no desc
fileSequence111.ts
#EXTINF:10, no desc
fileSequence112.ts
#EXTINF:10, no desc
fileSequence113.ts
#EXTINF:10, no desc
fileSequence114.ts
#EXTINF:10, no desc
fileSequence115.ts
#EXTINF:10, no desc
fileSequence116.ts
#EXTINF:10, no desc
fileSequence117.ts
#EXTINF:10, no desc
fileSequence118.ts
#EXTINF:10, no desc
fileSequence119.ts
#EXTINF:10, no desc
fileSequence120.ts
#EXTINF:10, no desc
fileSequence121.ts
#EXTINF:10, no desc
fileSequence122.ts
#EXTINF:10, no desc
fileSequence123.ts
#EXTINF:10, no desc
fileSequence124.ts
#EXTINF:10, no desc
fileSequence125.ts
#EXTINF:10, no desc
fileSequence126.ts
#EXTINF:10, no desc
fileSequence127.ts
#EXTINF:10, no desc
fileSequence128.ts
#EXTINF:10, no desc
fileSequence129.ts
#EXTINF:10, no desc
fileSequence130.ts
#EXTINF:10, no desc
fileSequence131.ts
#EXTINF:10, no desc
fileSequence132.ts
#EXTINF:10, no desc
fileSequence133.ts
#EXTINF:10, no desc
fileSequence134.ts
#EXTINF:10, no desc
fileSequence135.ts
#EXTINF:10, no desc
fileSequence136.ts
#EXTINF:10, no desc
fileSequence137.ts
#EXTINF:10, no desc
fileSequence138.ts
#EXTINF:10, no desc
fileSequence139.ts
#EXTINF:10, no desc
fileSequence140.ts
#EXTINF:10, no desc
fileSequence141.ts
#EXTINF:10, no desc
fileSequence142.ts
#EXTINF:10, no desc
fileSequence143.ts
#EXTINF:10, no desc
fileSequence144.ts
#EXTINF:10, no desc
fileSequence145.ts
#EXTINF:10, no desc
fileSequence146.ts
#EXTINF:10, no desc
fileSequence147.ts
#EXTINF:10, no desc
fileSequence148.ts
#EXTINF:10, no desc
fileSequence149.ts
#EXTINF:10, no desc
fileSequence150.ts
#EXTINF:10, no desc
fileSequence151.ts
#EXTINF:10, no desc
fileSequence152.ts
#EXTINF:10, no desc
fileSequence153.ts
#EXTINF:10, no desc
fileSequence154.ts
#EXTINF:10, no desc
fileSequence155.ts
#EXTINF:10, no desc
fileSequence156.ts
#EXTINF:10, no desc
fileSequence157.ts
#EXTINF:10, no desc
fileSequence158.ts
#EXTINF:10, no desc
fileSequence159.ts
#EXTINF:10, no desc
fileSequence160.ts
#EXTINF:10, no desc
fileSequence161.ts
#EXTINF:10, no desc
fileSequence162.ts
#EXTINF:10, no desc
fileSequence163.ts
#EXTINF:10, no desc
fileSequence164.ts
#EXTINF:10, no desc
fileSequence165.ts
#EXTINF:10, no desc
fileSequence166.ts
#EXTINF:10, no desc
fileSequence167.ts
#EXTINF:10, no desc
fileSequence168.ts
#EXTINF:10, no desc
fileSequence169.ts
#EXTINF:10, no desc
fileSequence170.ts
#EXTINF:10, no desc
fileSequence171.ts
#EXTINF:10, no desc
fileSequence172.ts
#EXTINF:10, no desc
fileSequence173.ts
#EXTINF:10, no desc
fileSequence174.ts
#EXTINF:10, no desc
fileSequence175.ts
#EXTINF:10, no desc
fileSequence176.ts
#EXTINF:10, no desc
fileSequence177.ts
#EXTINF:10, no desc
fileSequence178.ts
#EXTINF:10, no desc
fileSequence179.ts
#EXTINF:1, no desc
fileSequence180.ts
#EXT-X-ENDLIST
其他的字段几乎和直播的一样,这里列出不一样的字段
#EXT-X-ENDLIST 表明m3u8文件的结束
第二步:获取视频流
请求:
GET /iphone/samples/bipbop/gear1/fileSequence0.ts HTTP/1.1
Host: devimages.apple.com
Cache-Control: no-cache
User-Agent: VLC/3.0.2 LibVLC/3.0.2
应答:
HTTP/1.1 200 OK
Server: Apache
ETag: "90e466ad7f45ea3bd52732124f1fa675:1239907291"
Last-Modified: Thu, 16 Apr 2009 18:41:31 GMT
Accept-Ranges: bytes
Content-Length: 250228
Content-Type: video/mp2t
Date: Sun, 07 Oct 2018 06:36:14 GMT
X-Cache: TCP_REFRESH_HIT from a223-119-50-134.deploy.akamaitechnologies.com (AkamaiGHost/9.4.4.1.1-23623864) (S)
Connection: keep-alive
X-Cache-Remote: TCP_REFRESH_HIT from a223-119-50-196.deploy.akamaitechnologies.com (AkamaiGHost/9.4.4.1.1-23623864) (S)
X-Cache-Remote: TCP_IMS_HIT from a223-119-50-196.deploy.akamaitechnologies.com (AkamaiGHost/9.4.4.1.1-23623864) (-)
*******************************************2级目录情况****************************************
请求一级目录:
GET /iphone/samples/bipbop/bipbopall.m3u8 HTTP/1.1
Host: devimages.apple.com
Accept: */*
Accept-Language: zh_CN
User-Agent: VLC/3.0.2 LibVLC/3.0.2
Range: bytes=0-
应答:
HTTP/1.1 206 Partial Content
Server: Apache
ETag: "44f07dfa5af5d23a5b2b7566cdde9a44:1239907290"
Last-Modified: Thu, 16 Apr 2009 18:41:30 GMT
Accept-Ranges: bytes
Content-Type: audio/x-mpegurl
Date: Sun, 07 Oct 2018 14:17:25 GMT
Content-Range: bytes 0-291/292
Content-Length: 292
X-Cache: TCP_REFRESH_HIT from a184-28-218-61.deploy.akamaitechnologies.com (AkamaiGHost/9.4.4.1.1-23623864) (S)
Connection: keep-alive
X-Cache-Remote: TCP_REFRESH_HIT from a184-28-218-116.deploy.akamaitechnologies.com (AkamaiGHost/9.4.4.1-23558169) (S)
X-Cache-Remote: TCP_IMS_HIT from a184-28-218-116.deploy.akamaitechnologies.com (AkamaiGHost/9.4.4.1-23558169) (-)
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000
gear1/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=311111
gear2/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=484444
gear3/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=737777
gear4/prog_index.m3u8
这里的应答不是直接给出媒体流的地址,而是给出了4个新的m3u8的地址,需要再次获取才能获取到媒体流的地址。
#EXTM3U :每个开头需要携带这个字段
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000 :指定一个包含多媒体信息的 media URI 作为PlayList,一般做M3U8的嵌套使用,它只对紧跟后面的URI有效,有以下属性:BANDWIDTH:带宽,必须有。PROGRAM-ID:该值是一个十进制整数,惟一地标识一个在PlayList文件范围内的特定的描述。一个PlayList 文件中可能包含多个有相同ID的此tag。CODECS:不是必须的。RESOLUTION:分辨率。AUDIO:这个值必须和AUDIO类别的“EXT-X-MEDIA”标签中“GROUP-ID”属性值相匹配。VIDEO:同上
格式如下:
#EXT-X-STREAM-INF:<attribute-list>
<URI>
gear1/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=311111
gear2/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=484444
gear3/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=737777
gear4/prog_index.m3u8