Simple-RTMP-Server 服务器搭建

简介: Simple-RTMP-Server 服务器搭建 1. 服务器镜像获取 github源码地址 git clone https://github.com/winlinvip/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
目录
相关文章
|
Web App开发 应用服务中间件 nginx
利用Simple-RTMP-Server(SRS)来进行直播
1、下载SRS 官方地址:http://www.ossrs.net/srs.release/releases/ 百度地址:http://pan.baidu.com/s/1kV8WQpx   2、编译安装SRS tar zxvf srs-2.0-b2.tar.gz cd srs-2.0-b2 mv trunk/ /usr/local/srs cd /usr/local/srs  ./configure --full     #--full,开启SRS所有的功能。
2739 0
|
3月前
|
NoSQL 容器 消息中间件
rtsp-simple-server + srs搭建流媒体服务器
rtsp-simple-server + srs搭建流媒体服务器
190 0
|
3月前
|
Linux C++
【VS Code开发】使用Live Server搭建MENJA小游戏并发布至公网远程访问
【VS Code开发】使用Live Server搭建MENJA小游戏并发布至公网远程访问
28 0
|
4月前
live server
live server
31 0
|
弹性计算 IDE Linux
服务器部署 code-server
服务器部署 code-server
886 0
服务器部署 code-server
|
容器 应用服务中间件 nginx
|
安全 Linux 程序员
使用阿里云服务器部署Code-server
本人是iPad党,实在不想感受游戏本的重量,但是又要用到C++,Go语言开发,于是想起了GitHub上Code-server的项目,正巧有个服务器,所以就开始干了!
|
存储 编解码 Linux
NTV Media Server G3流媒体服务器搭建经验
系统要求 最低要求: 操作系统:  64位CentOS 6.4或更高版本 / Red Hat Enterprise Linux Server CPU:      Intel双核 2.
3748 0
|
应用服务中间件 nginx
利用Simple-RTMP-Server搭建RTMP和HLS直播服务(上)
SRS(Simple-RTMP-Server)定位是运营级的互联网直播服务器集群,追求更好的概念完整性和最简单实现的代码,在Github上人气颇高。
5285 0

热门文章

最新文章