文章目錄
- 快速搭建基于rmtp協定的直播平台
-
- 環境
- 準備
-
- client端
- server端
- 安裝
-
- server端
- 配置
-
- Server端
- 運作
-
- Server端
- Client端
- 參考
快速搭建基于rmtp協定的直播平台
環境
- client端 win10
- server端(直播) Ubuntu16.04
準備
- 先在server端将目錄建好, 假設我們所有的檔案都放在
中root/live
$ cd /root
$ mkdir live
$ mkdir nginx
$ mkdir video
$ cd live
client端
- CLV
server端
- nginx下載下傳位址: nginx
- ffmepg安裝教程: ffmepg
- nginx-rtmp-module下載下傳位址: nginx-rtmp-module
$ wget http://nginx.org/download/nginx-1.8.1.tar.gz
$ wget https://github.com/arut/nginx-rtmp-module/archive/v1.2.1.tar.gz
安裝
- client端就不用說了, exe檔案一直點選安裝就行
server端
- 假設我的目錄檔案都放在
下面root/live
- 解壓
,nginx
nginx-rtmp-module
$ tar -zxvf nginx-1.8.1.tar.gz -C ./ $ tar -zxvf nginx-rtmp-module-1.2.1.tar -C ./
- 給
重新命名nginx-rtmp-module-1.2.1
nginx-rtmp-module-master
$ mv nginx-rtmp-module-1.2.1 nginx-rtmp-module-master
- 安裝
nginx
$ cd nginx-1.8.1 $ ./configure --add-module=../nginx-rtmp-module-master --prefix=/root/live/nginx $ make $ make install
- 檢查nginx安裝成功
$ cd /root/live/nginx && ./sbin/nginx
- 浏覽器通路你的服務端ip位址, 假設是
, 将出現nginx的歡迎頁面1.2.3.4
nginx 預設是
端口80
配置
Server端
- 修改
的通路端口nginx
,推流
端口和拉流
配置, 端口這裡假設為18080和18081, 用阿裡雲的朋友記得給端口開放權限location
$ cd /root/live/nginx $ vim conf/nginx.conf
看下面的配置, 需要修改的地方都加了重點
TODO
http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { # TODO from 80 -> 18080 listen 18080; server_name 0.0.0.0; #charset koi8-r; #access_log logs/host.access.log main; # TODO add location /stat location /stat{ rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } # TODO add location /stat.xsl location /stat.xsl{ root /root/live/nginx-rtmp-module-master/; } location / { root html; index index.html index.htm; } ... ...
運作
Server端
- 重新開機
nginx
$ cd /root/live/nginx $ ./sbin/nginx -s reload
然後還是可以通過通路1.2.3.4:18080來确定nginx成功重新開機
- 浏覽器通路
, 會出現如下圖1.2.3.4:18080/stat
- 建立直播
, 需要在推流
目錄下放好一個/root/live/video
檔案(可以使用scp進行遠端傳輸)audio.mp4
$ cd /root/live/video $ ffmpeg -re -i ./audio.mp4 -vcodec copy -acodec copy -f flv rtmp://1.2.3.4:18081/live/audio
是我們在nginx配置檔案中配置的application,live
随便寫的, 可以換成别的audio
-
的話将會出現以下資訊成功
-
Client端
- 這個時候我們可以打開之前下載下傳的CLV工具了, 選擇如下:
- Media->Open Network Stream
- 輸入我們的
位址rtmp
rtmp://1.2.3.4:18081/live/audio
- 等待幾秒, 我們的直播平台就搭建好了!
參考
[1] RTMP官方文檔
[2] nginx-rtmp-module
[3] nginx官方文檔
[4] 使用nginx-rtmp-module搭建RTMP直播伺服器
[5] 如何從零開始搭建高性能直播平台