-
- Notifications
You must be signed in to change notification settings - Fork 5.6k
migrate_v5_CN_delivery http flv
Note: 如果觉得Github的Wiki访问太慢,可以访问 Gitee 镜像。
SRS支持将RTMP流转封装为HTTP flv流,即在publish发布RTMP流时,在SRS的http模块中挂载一个对应的http地址(根据配置),用户在访问这个http flv文件时,从rtmp流转封装为flv分发给用户。
分发HTTP FLV直播流的配置如下:
http_server { enabled on; listen 8080; } vhost __defaultVhost__ { http_remux { enabled on; mount [vhost]/[app]/[stream].flv; } } 配置项的详细信息参考下面的配置章节的说明。
SRS支持将RTMP流转封装为HTTPS flv流,即在publish发布RTMP流时,在SRS的http模块中挂载一个对应的http地址(根据配置),用户在访问这个https flv文件时,从rtmp流转封装为flv分发给用户。
分发HTTPS FLV直播流的配置如下:
http_server { enabled on; listen 8080; https { enabled on; listen 8088; key ./conf/server.key; cert ./conf/server.crt; } } vhost __defaultVhost__ { http_remux { enabled on; mount [vhost]/[app]/[stream].flv; } } Remark: 请使用你的证书文件,代替上面配置中的key和cert。
Note: 若需要开启HTTPS API,请参考HTTPS API
配置项的详细信息参考下面的配置章节的说明。
SRS可以和HTTP/HTTPS代理一起工作得很好,比如Nginx, HTTPX, CaddyServer, 等等。详细配置请参考 #2881。
SRS支持将RTMP流转封装为HTTP ts流,即在publish发布RTMP流时,在SRS的http模块中挂载一个对应的http地址(根据配置),用户在访问这个http ts文件时,从rtmp流转封装为ts分发给用户。
分发HTTP TS直播流的配置如下:
http_server { enabled on; listen 8080; } vhost __defaultVhost__ { http_remux { enabled on; mount [vhost]/[app]/[stream].ts; } } 配置项的详细信息参考下面的配置章节的说明。
SRS支持将rtmp流中的视频丢弃,将音频流转封装为mp3格式,在SRS的http模块中挂载对应的http地址(根据配置),用户在访问这个http mp3文件时,从rtmp转封装为mp3分发给用户。
分发HTTP mp3直播流的配置如下:
http_server { enabled on; listen 8080; } vhost __defaultVhost__ { http_remux { enabled on; fast_cache 30; mount [vhost]/[app]/[stream].mp3; } } 配置项的详细信息参考下面的配置章节的说明。
SRS支持将rtmp流中的视频丢弃,将音频流转封装为aac格式,在SRS的http模块中挂载对应的http地址(根据配置),用户在访问这个http aac文件时,从rtmp转封装为aac分发给用户。
分发HTTP aac直播流的配置如下:
http_server { enabled on; listen 8080; } vhost __defaultVhost__ { http_remux { enabled on; fast_cache 30; mount [vhost]/[app]/[stream].aac; } } 配置项的详细信息参考下面的配置章节的说明。
HTTP Flv/Mp3/Aac Live Stream的配置如下,更改不同的扩展名即可以不同方式分发:
http_server { # whether http streaming service is enabled. # default: off enabled on; # the http streaming listen entry is <[ip:]port> # for example, 192.168.1.100:8080 # where the ip is optional, default to 0.0.0.0, that is 8080 equals to 0.0.0.0:8080 # @remark, if use lower port, for instance 80, user must start srs by root. # default: 8080 listen 8080; # For https_server or HTTPS Streaming. https { # Whether enable HTTPS Streaming. # default: off enabled on; # The listen endpoint for HTTPS Streaming. # default: 8088 listen 8088; # The SSL private key file, generated by: # openssl genrsa -out server.key 2048 # default: ./conf/server.key key ./conf/server.key; # The SSL public cert file, generated by: # openssl req -new -x509 -key server.key -out server.crt -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net" # default: ./conf/server.crt cert ./conf/server.crt; } } vhost __defaultVhost__ { # http flv/mp3/aac/ts stream vhost specified config http_remux { # whether enable the http live streaming service for vhost. # default: off enabled on; # the fast cache for audio stream(mp3/aac), # to cache more audio and send to client in a time to make android(weixin) happy. # @remark the flv/ts stream ignore it # @remark 0 to disable fast cache for http audio stream. # default: 0 fast_cache 30; # the stream mout for rtmp to remux to live streaming. # typical mount to [vhost]/[app]/[stream].flv # the variables: # [vhost] current vhost for http live stream. # [app] current app for http live stream. # [stream] current stream for http live stream. # @remark the [vhost] is optional, used to mount at specified vhost. # the extension: # .flv mount http live flv stream, use default gop cache. # .ts mount http live ts stream, use default gop cache. # .mp3 mount http live mp3 stream, ignore video and audio mp3 codec required. # .aac mount http live aac stream, ignore video and audio aac codec required. # for example: # mount to [vhost]/[app]/[stream].flv # access by http://ossrs.net:8080/live/livestream.flv # mount to /[app]/[stream].flv # access by http://ossrs.net:8080/live/livestream.flv # or by http://192.168.1.173:8080/live/livestream.flv # mount to [vhost]/[app]/[stream].mp3 # access by http://ossrs.net:8080/live/livestream.mp3 # mount to [vhost]/[app]/[stream].aac # access by http://ossrs.net:8080/live/livestream.aac # mount to [vhost]/[app]/[stream].ts # access by http://ossrs.net:8080/live/livestream.ts # @remark the port of http is specified by http_server section. # default: [vhost]/[app]/[stream].flv mount [vhost]/[app]/[stream].flv; } } 备注:若需要同时分发不同的http live stream,可以使用forward到其他vhost,不同的vhost配置不同的http live stream。
备注:HTTP服务器配置,参考HTTP Server
这一节详细解释HTTP FLV的背景。
SRS的HTTP FLV边缘只能使用单进程,如何做到多进程呢?可以使用HTTP反向代理,SRS提供了go-sharp,支持根据SRS边缘的负载均衡以及心跳检测。参考:go-sharp
所有的HTTP FLV流都是一个HTTP FLV地址,譬如:http://ossrs.net:8081/live/livestream.flv,但是,流的形式却至少有三种:
- FLV文件,渐进式HTTP流。放一个文件到nginx目录,可以访问下载在播放器播放,这是HTTP FLV文件,也就是渐进式下载流。所谓渐进式下载,也就是用户观看时无法从未下载的地方开始看。
- FLV伪流。一般说的HTTP FLV,比上面的渐进式流高级一点,譬如,一个120分钟的电影,作为渐进式流播放时,用户需要从60分钟开始看,如何支持呢?因为nginx是当做文件下载的,无法直接跳转到第60分钟(nginx也不知道60分钟对应的字节偏移是多少呀)。后来有人就支持这种跳着播放,通过指定时间服务器从指定的位置开始给流,这种支持flv?start=,就是http flv的伪流,本质上还是点播流。
- FLV直播流。SRS所指的HTTP FLV流,是严格意义上的直播流,有RTMP的所有特征,譬如集群、低延迟、热备、GOP cache,而且有HTTP的优势,譬如302、穿墙、通用。由于SRS内部实现了HTTP服务器,所以SRS是在边缘将RTMP流转换成HTTP流,SRS集群内部还是使用RTMP分发。当前唯一将RTMP和HTTP协议都解析的服务器,目前只有SRS和nginx-rtmp,可惜nginx-rtmp没有实现这个流。
用一句话概括,SRS的HTTP FLV就是增强的RTMP,真正的实时流媒体分发。
SRS的HTTP FLV容易和下面的几种分发方式混淆:
- RTMPT:这个实际上是最接近SRS的HTTP FLV的概念的。但是从本质上来讲,rtmpt是基于HTTP的RTMP,所以还是RTMP而不是FLV。
- HDL/HFL:国内一些厂家的HXX流,就是FLV流,主要和SRS的区别在于服务器集群内部SRS还是走RTMP,所以延迟可能会有很大差异。SRS的HTTP FLV和RTMP延迟一样,0.8-3秒。
- HDS:这个差的太远了,不是一个东西。HDS和HLS像,但是HTTP FLV和他们两个都完全不像。
为何要整个HTTP FLV出来呢?当下HTTP FLV流正大行其道。主要的优势在于:
- 互联网流媒体实时领域,还是RTMP。HTTP-FLV和RTMP的延迟一样,因此可以满足延迟的要求。
- 穿墙:很多防火墙会墙掉RTMP,但是不会墙HTTP,因此HTTP FLV出现奇怪问题的概率很小。
- 调度:RTMP也有个302,可惜是播放器as中支持的,HTTP FLV流就支持302方便CDN纠正DNS的错误。
- 容错:SRS的HTTP FLV回源时可以回多个,和RTMP一样,可以支持多级热备。
- 通用:Flash可以播RTMP,也可以播HTTP FLV。自己做的APP,也都能支持。主流播放器也都支持http flv的播放。
- 简单:FLV是最简单的流媒体封装,HTTP是最广泛的协议,这两个到一起维护性很高,比RTMP简单多了。
配置实例参考:https://github.com/ossrs/srs/issues/293#issuecomment-70449126
一步一步配置HTTP FLV: Sample
可以将HTTP-FLV转成WebSocket-FLV流,这样就可以使用MSE(flv.js)播放了,参考videojs-flow。
关于HTTP转WebSocket参考mse.go。
关于HTTP flv 点播流,参考:v5_CN_FlvVodStream
Winlin 2015.1
Welcome to SRS wiki!
Please select your language:
Please select your language:
Please select your language:
Please select your language:
Please select your language: