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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM