Simple-RTMP-Server 伺服器搭建

來源:互聯網
上載者:User

標籤:

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 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
  • 備忘:若SRS安裝到其他目錄,將/usr/local/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流
  • 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
最新最早最熱
  • 評論

Simple-RTMP-Server 伺服器搭建

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.