前言:
由于个人工作的原因,公司采用了这个作为点播直播服务器,采用这个的原因只有一个,因为开源免费因为不要钱!因为不要钱!因为不要钱!因为很重要所以说三遍。如果不是这个原因,我也不会对此开源软件相识,作为创业公司当然是能省就省,买不起商业的点播直播软件,没人力做不了一个点播直播软件已经用过大半年,各方面使用的情况来看还挺可以的,今日趁我写博客的激情还在遂再写一篇。
#本人的博客尽可能的多注释,注释不是给我看的,我都懂!没错,就是给不会的现在在看我的博客小白们看的!如果发现还有不懂的地方请留言哪里不懂,然后我继续改到让蚂蚁的小大脑都懂的地步?蛤,这么多注释下你还不明白?买块豆腐就去了吧!!不拦你!!!!!
先wait下!!!!!此篇博客稍微写下就作废吧,因为我上github后发现,此开源软件已经死了,曾经的雄心壮志已经荡然无存。。。。。。白研究那么深了
官方已经跪了,源码都清空了,我还往下写不???????
1.SRS(simple-rtmp-server)介绍
SRS定位是运营级的互联网直播服务器集群,追求更好的概念完整性和最简单实现的代码。
- 运营级:商业运营追求极高的稳定性,良好的系统对接,以及错误排查和处理机制。譬如日志文件格式,reload,系统HTTP接口,提供init.d脚本,转发,转码,边缘回多源站,都是根据CDN运营经验作为判断这些功能作为核心的依据。
- 互联网:互联网最大的特征是变化,唯一不变的就是不断变化的客户要求,唯一不变的是基础结构的概念完整性和简洁性。互联网还意味着参与性,听取用户的需求和变更,持续改进和维护。
- 直播服务器:直播和点播这两种截然不同的业务类型,导致架构和目标完全不一致,从运营的设备组,应对的挑战都完全不同。两种都支持只能说明没有重心,或者低估了代价。
- 集群:FMS(AMS)的集群还是很不错的,虽然在运营容错很差。SRS支持完善的直播集群,Vhost分为源站和边缘,容错支持多源站切换、测速、可追溯日志等。
- 概念完整性:虽然代码甚至结构都在变化,但是结构的概念完整性是一直追求的目标。从SRS服务器,P2P,ARM监控产业,MIPS路由器,服务器监控管理,ARM智能手机,SRS的规模不再是一个服务器而已。
- 简单实现:对于过于复杂的实现,宁可不加入这个功能,也不牺牲前面提到的要求。对于已经实现的功能的代码,总会在一个版本release前给予充分的时间来找出最简答案。不求最高性能,最优雅,最牛逼,但求最简单易懂。
备注:概念完整性可以参考Brooks的相关文献,在宏观方面他还是很有造诣
SRS提供了丰富的接入方案将RTMP流接入SRS,包括推送RTMP到SRS、推送RTSP/UDP/FLV到SRS、拉取流到SRS。SRS还支持将接入的RTMP流进行各种变换,譬如将RTMP流转码、流截图、转发给其他服务器、转封装成HTTP-FLV流、转封装成HLS、转封装成HDS、录制成FLV。SRS包含支大规模集群如CDN业务的关键特性,譬如RTMP多级集群、VHOST虚拟服务器、无中断服务Reload、HTTP-FLV集群、Kafka对接。此外,SRS还提供丰富的应用接口,包括HTTP回调、安全策略Security、HTTP API接口、RTMP测速。
2.SRS与其他媒体服务器比较
通过官方广告的描述,总而言之一句话,SRS超级强,无所不能秒杀其他同类媒体服务器
至于你们信不信?我反正是信了!
Stream Delivery(流发送支持类型比较)
Feature | SRS | NGINX | CRTMPD | FMS | WOWZA |
---|---|---|---|---|---|
RTMP | Stable | Stable | Stable | Stable | Stable |
HLS | Stable | Stable | X | Stable | Stable |
HDS | Experiment | X | X | Stable | Stable |
HTTP FLV | Stable | X | X | X | X |
HLS(aonly) | Stable | X | X | Stable | Stable |
HTTP Server | Stable | Stable | X | X | Stable |
Cluster(集群扩展支持比较)
Feature | SRS | NGINX | CRTMPD | FMS | WOWZA |
---|---|---|---|---|---|
RTMP Edge | Stable | X | X | Stable | X |
RTMP Backup | Stable | X | X | X | X |
VHOST | Stable | X | X | Stable | Stable |
Reload | Stable | X | X | X | X |
Forward | Stable | X | X | X | X |
ATC | Stable | X | X | X | X |
Stream Service(流服务功能支持比较)
Feature | SRS | NGINX | CRTMPD | FMS | WOWZA |
---|---|---|---|---|---|
DVR | Stable | Stable | X | X | Stable |
Transcode | Stable | X | X | X | Stable |
HTTP API | Stable | Stable | X | X | Stable |
HTTP hooks | Stable | X | X | X | X |
GopCache | Stable | X | X | Stable | X |
Security | Stable | Stable | X | X | Stable |
Token Traverse | Stable | X | X | Stable | X |
Efficiency(性能比较)
Feature | SRS | NGINX | CRTMPD | FMS | WOWZA |
---|---|---|---|---|---|
Concurrency(并发数) | 7.5k | 3k | 2k | 2k | 3k |
MultipleProcess(多线程) | Experiment | Stable | X | X | X |
RTMP Latency(rtmp延迟) | 0.1s | 3s | 3s | 3s | 3s |
HLS Latency(hls延迟) | 10s | 30s | X | 30s | 30s |
Stream Caster(流推送支持比较)
Feature | SRS | NGINX | CRTMPD | FMS | WOWZA |
---|---|---|---|---|---|
Ingest | Stable | X | X | X | X |
Push MPEGTS | Experiment | X | X | X | Stable |
Push RTSP | Experiment | X | Stable | X | Stable |
Push HTTP FLV | Experiment | X | X | X | X |
Debug System(debug系统支持比较)
Feature | SRS | NGINX | CRTMPD | FMS | WOWZA |
---|---|---|---|---|---|
BW check | Stable | X | X | X | X |
Tracable Log | Stable | X | X | X | X |
Docs(文档比较,有中文wiki,因为是国产开源软件)
Feature | SRS | NGINX | CRTMPD | FMS | WOWZA |
---|---|---|---|---|---|
Demos | Stable | X | X | X | X |
WIKI(EN+CN) | Stable | EN only | X | X | Stable |
Others(其他比较)
Feature | SRS | NGINX | CRTMPD | FMS | WOWZA |
---|---|---|---|---|---|
ARM/MIPS | Stable | Stable | X | X | X |
Client Library | Stable | X | X | X | X |
3.SRS的架构体系
SRS always use the most simple architecture to support complex transaction.
- System arch: the system structure and arch.
- Modularity arch: the main modularity of SRS.
- Stream arch: the stream dispatch arch of SRS.
- RTMP cluster arch: the RTMP origin and edge cluster arch.
- Multiple processes arch (by wenjie): the multiple process of SRS.
- CLI arch: the cli arch for SRS, api to manage SRS.
- Bandwidth specification: the bandwidth test specification of SRS.
System Architecture
+------------------------------------------------------+| SRS(Simple RTMP Server) |+---------------+---------------+-----------+----------+| API/hook | Transcoder | HLS | RTMP || http-parser | FFMPEG/x264 | NGINX/ts | protocol |+---------------+---------------+-----------+----------+| Network(state-threads) |+------------------------------------------------------+| All Linux(RHEL,CentOS,Ubuntu,Fedora...) |+------------------------------------------------------+
Modularity Architecture
+------------------------------------------------------+| Main(srs/bandwidth/librtmp) |+------------------------------------------------------+| App(Server/Client application) |+------------------------------------------------------+| RTMP(Protocol stack) |+------------------------------------------------------+| Kernel(depends on Core, provides error/log) |+------------------------------------------------------+| Core(depends only on system apis) |+------------------------------------------------------+
Stream Architecture
+---------+ +----------+ + Publish + + Deliver | +---|-----+ +----|-----++----------------------+-------------------------+----------------+| Input | SRS(Simple RTMP Server) | Output |+----------------------+-------------------------+----------------+| Encoder(1) | +-> RTMP protocol ----+-> Flash Player || (FMLE,FFMPEG, -rtmp-+->-+-> HLS/NGINX --------+-> m3u8 player || Flash,XSPLIT, | +-> Fowarder ---------+-> RTMP Server || ......) | +-> Transcoder -------+-> RTMP Server || | +-> DVR --------------+-> FILE || | +-> BandwidthTest ----+-> Flash/StLoad |+----------------------+ | || MediaSource(2) | | || (RTSP,FILE, | | || HTTP,HLS, ------+->-- Ingester ----(rtmp)-+-> SRS || Device, | | || ......) | | |+----------------------+-------------------------+----------------+ Remark:(1) Encoder: encoder must push RTMP stream to SRS server.(2) MediaSource: any media source, which can be ingest by ffmpeg.(3) Ingester: SRS will fork a process to run ffmpeg(or your application) to ingest any input to rtmp, push to SRS.
4.SRS实战(测试服务器的ip为192.168.0.20)
官方已经跪了,官方的github源码都清空了,我还往下写不???????
(1)部署SRS提供hls服务(因为懒所以我编译的时候把所有功能先全开启了,你可以编译的时候只开启一个hls的服务)
#获取SRS [[email protected] tools]# git clone https://github.com/wenjiegit/srs Initialized empty Git repository in /application/tools/srs/.git/ remote: Counting objects: 30921, done. remote: Total 30921 (delta 0), reused 0 (delta 0), pack-reused 30921 Receiving objects: 100% (30921/30921), 156.81 MiB | 5.36 MiB/s, done. Resolving deltas: 100% (23934/23934), done. [[email protected] tools]# ll 总用量 4 drwxr-xr-x 4 root root 4096 5月 24 15:21 srs [[email protected] tools]# cd srs/ [[email protected] srs]# ll 总用量 96 -rw-r--r-- 1 root root 1484 5月 24 15:21 AUTHORS.txt -rw-r--r-- 1 root root 1249 5月 24 15:21 DONATIONS.txt -rw-r--r-- 1 root root 1083 5月 24 15:21 LICENSE -rwxr-xr-x 1 root root 81742 5月 24 15:21 README.md drwxr-xr-x 12 root root 4096 5月 24 15:21 trunk [[email protected] srs]# cd trunk/ #进行编译安装 [[email protected] trunk]# ./configure --prefix=/application/srs --full && make #出了点小插曲,由于我没有事先创建这个我指定的根目录/application/srs,它默认给我装在了你编译文件目录下面。。233 ##修改配置文件开启支持hls,想我这样写 [[email protected] conf]# vim hls.conf # the config for srs to delivery hls # @see https://github.com/ossrs/srs/wiki/v1_CN_SampleHLS # @see full.conf for detail config. listen 1935; max_connections 1000; vhost __defaultVhost__ { hls { enabled on; hls_fragment 10; hls_window 60; hls_path /application/tools/srs/trunk/objs/nginx/html/; hls_m3u8_file [app]/[stream].m3u8; hls_ts_file [app]/[stream]/[04]:[05]-[seq].ts; } } #启动srs服务,首先启动srs里面已经内置的nginx服务 [[email protected] ~]# /application/tools/srs/trunk/objs /nginx/sbin/nginx #指定刚才我们修改的配置文件进行启动真正的srs服务 [[email protected] ~]# /application/tools/srs/trunk/objs/srs -c /application/tools/srs/trunk/conf/hls.conf [2016-05-24 15:58:15.730][trace][1909][0] XCORE-SRS/2.0.209(ZhouGuowen) [2016-05-24 15:58:15.768][trace][1909][0] config parse complete [2016-05-24 15:58:15.768][trace][1909][0] write log to file ./objs/srs.log [2016-05-24 15:58:15.768][trace][1909][0] you can: tailf ./objs/srs.log [2016-05-24 15:58:15.768][trace][1909][0] @see: ####蛤蛤,出现了问题,你用绝对路径竟然无法启动程序!!! #只能先cd进去然后启动程序。。。。。 [[email protected] ~]# cd /application/tools/srs/trunk [[email protected] trunk]# ./objs/srs -c conf/hls.conf [2016-05-24 16:00:41.955][trace][1926][0] XCORE-SRS/2.0.209(ZhouGuowen) [2016-05-24 16:00:41.955][trace][1926][0] config parse complete [2016-05-24 16:00:41.955][trace][1926][0] write log to file ./objs/srs.log [2016-05-24 16:00:41.955][trace][1926][0] you can: tailf ./objs/srs.log [2016-05-24 16:00:41.955][trace][1926][0] @see: https://github.com/ossrs/srs/wiki/v1_CN_SrsLog [[email protected] trunk]# ps -ef|grep srs root 1902 1 0 15:56 ? 00:00:00 nginx: master process /application/tools/srs/trunk/objs/nginx/sbin/nginx root 1928 1 0 16:00 pts/0 00:00:00 ./objs/srs -c conf/hls.conf root 1930 1885 0 16:00 pts/0 00:00:00 grep srs
已经部署成功,然后就可以推流上去进行测试了,如果看到这一步的还想往下做的人,请去弄一个推流的软件吧,省时省力,也可以用srs自带的推流软件进行推流。
1)软件推流
我们公司采用的是购买的纳加软件进行多机位推流我去推一个试试,通过看目录的流名和视频播放可以看出已经成功了
2)使用FFMPEG命令推流:
for((;;)); do ./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.200kbps.768x320.flv -vcodec copy -acodec copy -f flv -y rtmp://192.168.0.21/live/livestream; sleep 1; \ done
生成的流地址为:
- RTMP流地址为:
rtmp://192.168.0.20/live/livestream
- HLS流地址为:
http://192.168.0.20/live/livestream.m3u8
观看的流地址也就是上面生成的流地址
好了,完结了。官方已跪让我没有想继续写下去的欲望了。。。。2333