当前位置:网站首页>Live HLS protocol
Live HLS protocol
2022-07-01 19:34:00 【lcyw】
HTTP Live Streaming( abbreviation HLS) It's based on HTTP Streaming media network transmission protocol . It's apple QuickTime X and iPhone Part of a software system . Its working principle is to divide the whole flow into small ones based on HTTP To download , Download only a few at a time . When the media stream is playing , Clients can choose to download the same resources at different rates from many different alternate sources , Allow streaming sessions to adapt to different data rates .
When starting a streaming session , The client will download a extended M3U (m3u8) file , Used to find available media streams .
HLS Just ask for basic HTTP message ,HLS Can go through any permit HTTP Data through firewalls or proxy servers . It's also easy to use content distribution networks to stream media .
HLS protocol
HLS Provisions of the agreement
- The encapsulation format of video is TS.
- The video is encoded in H264, The audio encoding format is MP3、AAC perhaps AC-3.
- except TS The video file itself , It also defines the m3u8 file ( text file ).
Client playback HLS The logic of video streaming is actually very simple , Download level 1 first Index file, It records the secondary index file (Alternate-A、Alternate-B、Alternate-C) The address of , Then the client downloads the secondary index file , The secondary index file records TS Download address of the file , So clients can download in order TS Video file and play continuously .
Class A index file
HLS Is to provide a m3u8 Address ,Apple Of Safari The browser can be opened directly m3u8 Address , for example :
https://dco4urblvsasc.cloudfront.net/811/81095_ywfZjAuP/game/index.m3u8
Android It can't be opened directly , Need to use html5 Of video label , Then open this page in the browser , for example :
```css
<!-- livestream.html -->
<video width="640" height="360"
autoplay controls autobuffer
src="https://dco4urblvsasc.cloudfront.net/811/81095_ywfZjAuP/game/index.m3u8"
type="application/vnd.apple.mpegurl">
</video>
as well as m3u8 After the file is opened, the contents are as follows :
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1064000
1000kbps.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=564000
500kbps.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=282000
250kbps.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2128000
2000kbps.m3u8
bandwidth Specifies the bit rate of the video stream ,
PROGRAM-ID Useless without attention ,
every last #EXT-X-STREAM-INF The next line on the list is level two index Path to file , You can use relative path or absolute path . In the example, the relative path is used . This file records the secondary data of video streams with different bit rates index File path , The client can judge its current network bandwidth by itself , To decide which video stream to play . You can also smoothly switch to the video stream matching the bandwidth when the network bandwidth changes .
second level index file
#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:10
#EXTINF:10,
2000kbps-00001.ts
#EXTINF:10,
2000kbps-00002.ts
#EXTINF:10,
2000kbps-00003.ts
#EXTINF:10,
... ...
#EXTINF:10,
2000kbps-00099.ts
#EXTINF:10,
2000kbps-00100.ts
#ZEN-TOTAL-DURATION:999.66667
#ZEN-AVERAGE-BANDWIDTH:2190954
#ZEN-MAXIMUM-BANDWIDTH:3536205
#EXT-X-ENDLIST
Level II documents are actually responsible for giving ts Download address of the file , Relative paths are also used here .
EXTM3U
Every M3U The first line of the document must be this tag, Provide marking functionEXT-X-PLAYLIST-TYPE
#EXT-X-PLAYLIST-TYPE:VOD The current video stream is an on-demand stream , That is to say, the whole of the video ts The file has been generated ,EXT-X-VERSION
Used to mark the protocol version . Here is 3, So what's used here is HLS The third version of the agreement , This label can only have 0 or 1 individual , Not writing means using version 1EXT-X-TARGETDURATION
#EXT-X-TARGETDURATION Specifies the maximum duration of the slice file in the current video stream , That is to say, these ts The length of slicing cannot be greater than #EXT-X-TARGETDURATION Value .EXT-X-MEDIA-SEQUENCE
The start sequence number of the slice . Each slice has a unique serial number , Serial number between adjacent +1. This number will continue to grow , Ensure the continuity of flow .EXTINF
ts Actual length of slicing .duration : Media duration
#EXTINF <duration>,<title>
- EXT-X-ENDLIST
#EXT-X-ENDLIST End of file symbol , Indicates the end of the video , No more media files are added to the playlist file. This flag also indicates that the current stream is a non live stream .
Play mode
on demand VOD The feature of is that you can get all the information at the current time point index Document and ts file , second level index All of them are recorded in the file ts File address . This client mode allows all content to be accessed . In the above example, it is an on-demand mode m3u8 Structure .
Live Pattern It's real-time generation M3u8 and ts file . Its index file has been in dynamic change , When playing, you need to constantly download secondary index file , To get the latest generated ts File play video . If a secondary index There is no... At the end of the file #EXT-X-ENDLIST sign , That means it's a Live Video streaming .
The client is playing VOD In fact, you only need to download level 1 video once index Documents and secondary index You can get all the files ts Download address of the file , Unless the client performs bit rate switching , Otherwise, there is no need to download any more index file , Just download in sequence ts File and play it . however Live Mode is slightly different , Because while playing , new ts Files are also being generated , So the client is actually downloading a secondary index file , Then download ts file , Download Level 2 index file ( At this time, this secondary index The file has been rewritten , The newly generated ts Download address of the file ), Download new ts file , Play it over and over again .
HLS Main application scenarios
Cross platform :PC The main live broadcast scheme is RTMP, There are also some libraries that can play HLS, for example jwplayer, be based on osmf Of hls There are also a lot of plug-ins . So in fact, if you choose a protocol, you can cross PC/Android/IOS, That's it HLS.
IOS Demanding stability requirements on :IOS Of course, the most stable is HLS, The stability is not worse than RTMP stay PC-flash Performance on .
Amicable CDN Distribution method : at present CDN about RTMP It's also the basic agreement , however HLS The basis of distribution is HTTP, therefore CDN Access and distribution will be better than RTMP More perfect . It can be used in various fields CDN Switch between ,RTMP Can also , It's just that docking tests may be required .
Simple :HLS As a streaming media protocol, it is very simple ,apple The support is also very perfect .Android Yes HLS Our support will become more and more perfect . as for DASH/HDS, There seems to be no special reason , It's like linux Has become popular and open , Other systems are difficult to be widely used .
HLS And RTMP
RTMP finger Adobe Of RTMP(Realtime Message Protocol), It is widely used in low delay live broadcast , It is also the actual standard protocol for the connection between encoder and server , stay PC(Flash) It has the best viewing experience and the best stability .
HLS Mainly to solve RTMP There are some problems with the agreement . such as RTMP The protocol does not use standard HTTP The interface transmits data , So in some special network environment, it may be blocked by firewall . however HLS Because of the HTTP Protocol transfer data
RTMP There is a state of agreement , It's hard to scale the video server smoothly , Because it is necessary to maintain the status for each client playing the video stream . and HLS Based on stateless protocol (HTTP), The client just downloads the common data stored in the server in order TS file , Being responsible and balanced is like ordinary HTTP File server load balancing is as simple as .
Besides ,HLS The protocol itself realizes rate adaptation , Different bandwidth devices can automatically switch to the most suitable video playback rate .
but HLS There are also some problems , Such as HLS The video delay of the protocol is large , Is basically 10 More than seconds , and RTMP The delay of the agreement can be up to 3、4 About seconds .
TS Protocol analysis part I (PAT)
TS Protocol analysis part II (PMT)
TS Protocol analysis part III (PES)
TS Protocol analysis part IV (adaptation field)
边栏推荐
- Bao, que se passe - t - il si le serveur 100 + O & M a mal à la tête? Utilisez le majordome xingyun!
- Digital business cloud: from planning to implementation, how does Minmetals Group quickly build a new pattern of digital development?
- Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
- 【sql优化】with as 和 临时表的区别
- Collation of open source protocols of open source frameworks commonly used in Web Development
- B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
- 为什么一定要从DevOps走向BizDevOps?
- Learning records of building thingsboard, an Internet of things platform
- ffmpeg常用命令(二)
- 研究了11种实时聊天软件,我发现都具备这些功能…
猜你喜欢
sql查询去重统计的方法总结
Thesis reading [distinctive late semantic graph for video capturing]
为什么一定要从DevOps走向BizDevOps?
【To .NET】C#集合类源码解析
智慧防疫系统为建筑工地复工复产提供安全保障
What must be done in graduation season before going to Shanhai
Once the SQL is optimized, the database query speed is increased by 60 times
wireshark报文分析tcp,ftp
pickle.load报错【AttributeError: Can‘t get attribute ‘Vocabulary‘ on <module ‘__main__‘】
ubuntu14安装MySQL并配置root账户本地与远程访问
随机推荐
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
Reading the paper [learning to discretely compose reasoning module networks for video captioning]
Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性
[pytorch record] automatic hybrid accuracy training torch cuda. amp
GB28181之SIP协议
正则表达式=Regex=regular expression
下载(导出)pdf模板文件(比如:审批单),报错:Invalid nested tag *** found, expected closing tag ***
IPv4地址、子网掩码、网关
Crunch简介、安装,使用Crunch制作密码字典
微信小程序 navigator点击后有阴影 ,去掉navigator阴影效果
Learn MySQL from scratch - database and data table operations
音频编解码基础知识
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
Shell高级进阶
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function
Contos 7 set up SFTP to create users, user groups, and delete users
【Go ~ 0到1 】 第五天 7月1 类型别名,自定义类型,接口,包与初始化函数
[English grammar] Unit1 articles, nouns, pronouns and numerals
音视频、编解码相关电子书、小工具,打包奉送!