標籤:
Simple-RTMP-Server 伺服器搭建1. 伺服器鏡像擷取
git clone https://github.com/winlinvip/simple-rtmp-server.git
git clone https://code.csdn.net/winlinvip/srs-csdn.git
git clone https://git.oschina.net/winlinvip/srs.oschina.git
2. 關閉防火牆和selinux或者開放連接埠
# disable the firewallsudo /etc/init.d/iptables stopsudo /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
4.2 添加服務
#centos 6sudo /sbin/chkconfig --add srs
或者
#ubuntu12sudo 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.conflisten 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/liveStream: 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流
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
最新最早最熱
Simple-RTMP-Server 伺服器搭建