Simple-RTMP-Server 服务器搭建

Simple-RTMP-Server 服务器搭建

1. 服务器镜像获取

  • github源码地址
	git clone https://github.com/winlinvip/simple-rtmp-server.git
  • CSDN镜像地址
	git clone https://code.csdn.net/winlinvip/srs-csdn.git
  • OSChina镜像
	git clone https://git.oschina.net/winlinvip/srs.oschina.git

2. 关闭防火墙和selinux或者开放端口

  • 关闭防火墙
	# disable the firewall
	sudo /etc/init.d/iptables stop
	sudo /sbin/chkconfig iptables off
  • 使selinux失败
  • 编辑配置文件:sudo vi /etc/sysconfig/selinux
  • 把SELINUX的值改为disabled:SELINUX=disabled
  • 重启系统:sudo init 6

3. 编译系统

	./configure --disable-all --with-ssl --with-hls --with-nginx --with-ffmpeg --with-transcode
	make && sudo make install

安装命令会将SRS默认安装到/usr/local/srs中,可以在configure时指定其他目录,譬如./configure --prefix=pwd/_release 可以安装到当前的_release目录(可以不用sudo安装,直接用make install即可安装)

4. 建立启动服务

4.1 建立软连接

	sudo ln -sf   /usr/local/srs/etc/init.d/srs  /etc/init.d/srs
  • 备注:若SRS安装到其他目录,将/usr/local/srs替换成其他目录。

  • 备注:也可以使用其他的名称,譬如/etc/init.d/srs,可以任意名称,启动时也用该名称。

4.2 添加服务

	#centos 6
	sudo /sbin/chkconfig --add srs

或者

	#ubuntu12
	sudo update-rc.d srs defaults

4.3 使用init.d脚本管理SRS

查看SRS状态:

	/etc/init.d/srs status

启动SRS:

	/etc/init.d/srs start

停止SRS:

	/etc/init.d/srs stop

重启SRS:

	/etc/init.d/srs restart

Reload SRS:

	/etc/init.d/srs reload

5. 启动分发hls(m3u8/ts)的nginx

	sudo ./objs/nginx/sbin/nginx

6. 编写SRS配置文件

将以下内容保存为文件,譬如conf/transcode2hls.audio.only.conf,服务器启动时指定该配置文件(srs的conf文件夹有该文件)。

# conf/transcode2hls.audio.only.conf
listen              1935;
max_connections     1000;
http_stream {
    # whether http streaming service is enabled.
    # default: off
    enabled         on;
    # the http streaming port # @remark, if use lower port, for instance 80, user must start srs by root. # default: 8080 listen 8080; # the default dir for http root. # default: ./objs/nginx/html dir ./objs/nginx/html; } vhost __defaultVhost__ { hls { enabled on; hls_path ./objs/nginx/html; hls_fragment 10; hls_window 60; } transcode { enabled on; ffmpeg ./objs/ffmpeg/bin/ffmpeg; engine ff { enabled on; vcodec copy; acodec libaacplus; abitrate 45; asample_rate 44100; achannels 2; aparams { } output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine]; } } } 

备注:这个配置使用只转码音频,因为视频是h.264符合要求

7. 启动SRS

	./objs/srs -c conf/transcode2hls.audio.only.conf

或者使用服务进行启动

8. 启动推流编码器

使用FFMPEG命令推流:

	for((;;)); do \ ./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.200kbps.768x320.flv \ -vcodec copy -acodec copy \ -f flv -y rtmp://192.168.1.170/live/livestream; \ sleep 1; \ done 

或使用FMLE推流:

	FMS URL: rtmp://192.168.1.170/live
	Stream: livestream

生成的流地址为:

  • RTMP流地址为(FMLE推流无HLS地址):rtmp://192.168.1.170/live/livestream
  • 转码后的RTMP流地址为:rtmp://192.168.1.170/live/livestream_ff
  • 转码后的HLS流地址为: http://192.168.1.170/live/livestream_ff.m3u8

备注:因为FMLE推上来的音频有问题,不是aac,所以srs会报错(当然啦,不然就不用转码了)。这个错误可以忽略,srs是说,rtmp流没有问题,但是无法切片为hls,因为音频编码不对。没有关系,ffmpeg会转码后重新推一路流给srs。

备注:如何只对符合要求的流切hls?可以用vhost。默认的vhost不切hls,将转码后的流推送到另外一个vhost,这个vhost切hls。

9. 观看RTMP流

  • RTMP流地址为:rtmp://192.168.1.170/live/livestream_ff
  • 播放器:VLC
  • 或者:
  • http://winlinvip.github.io/srs.release/trunk/research/players/srs_player.html?vhost=defaultVhost&autostart=true&server=192.168.1.170&app=live&stream=livestream_ff

  • HLS流地址为: http://192.168.1.170/live/livestream_ff.m3u8
  • 播放器VLC
  • 或者
  • http://winlinvip.github.io/srs.release/trunk/research/players/jwplayer6.html?vhost=defaultVhost&hls_autostart=true&server=192.168.1.170&app=live&stream=livestream_ff

10. 手机端查看

10.1 Android

<video width="640" height="360" autoplay controls autobuffer src="http://127.0.0.1/live/livestream.m3u8" type="application/vnd.apple.mpegurl"> </video> 

10.2 IOS

	http://127.0.0.1/live/livestream.m3u8
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SRS(Simple Rtmp Server)的定位是运营级的互联网直播服务器集群,追求更好的概念完整性和最简单实现的代码。 • 运营级: 商业运营追求极高的稳定性,良好的系统对接,以及错误排查和处理机制。譬如日志文件格式,reload,系统HTTP接口,提供init.d脚本,转发,转码,边缘回多源站,都是根据CDN运营经验作为判断这些功能作为核心的依据。 • 互联网: 互联网最大的特征是变化,唯一不变的就是不断变化的客户要求,唯一不变的是基础结构的概念完整性和简洁性。互联网还意味着参与性,听取用户的需求和变更,持续改进和维护。 • 直播服务器: 直播和点播这两种截然不同的业务类型,导致架构和目标完全不一致,从运营的设备组,应对的挑战都完全不同。两种都支持只能说明没有重心,或者低估了代价。 • 集群: FMS(AMS)的集群还是很不错的,虽然在运营容错很差。SRS(Simple Rtmp Server)支持完善的直播集群,Vhost分为源站和边缘,容错支持多源站切换、测速、可追溯日志等。 • 概念完整性: 虽然代码甚至结构都在变化,但是结构的概念完整性是一直追求的目标。从SRS(Simple Rtmp Server)服务器,P2P,ARM监控产业,MIPS路由器,服务器监控管理,ARM智能手机,SRS(Simple Rtmp Server)的规模不再是一个服务器而已。 • 简单实现: 对于过于复杂的实现,宁可不加入这个功能,也不牺牲前面提到的要求。对于已经实现的功能的代码,总会在一个版本release前给予充分的时间来找出最简答案。不求最高性能,最优雅,最牛逼,但求最简单易懂。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值