字體:  

在 ubuntu 16.04 上安裝 nginx rtmp server 影片串流伺服器Streaming

dannyliao 發表於: 2017-1-02 15:28 來源: ADJ網路控股集團


這裡介紹使用Ubuntu 16.04 安裝 nginx 架設 RTMP 串流伺服器,不過我只用到 Video On Demand。
研究到後來才發現.原來這個解決方案主要是搭配線上直播用.如果只是要做影片串流,就用HTML5 的 Video 標籤就好了.

# apt-get install build-essential libpcre3 libpcre3-dev libssl-dev unzip software-properties-common libexpat-dev libgd-dev libgeoip-dev libluajit-5.1-dev libmhash-dev libpam0g-dev libperl-dev libxslt1-dev autotools-dev debhelper po-debconf dh-systemd
# apt-get install nginx nginx-extras

步驟1: Get nginx apt source & build-dep
# apt-get update
# apt-get install dpkg-dev
# mkdir -p build ; cd build
# apt-get source nginx
# apt-get build-dep nginx

步驟2: Git clone nginx-rtmp-module source
# git clone git://github.com/arut/nginx-rtmp-module.git

步驟3: 編輯 debian/rules
# cd nginx-1.10.0/
# vi debian/rules
增加 --add-module=/root/build/nginx-rtmp-module 這一行 (下述紅字部分)

QUOTE:


...
extras_configure_flags := \
$(common_configure_flags) \
--with-http_addition_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_geoip_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_mp4_module \
--with-http_perl_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_v2_module \
--with-http_sub_module \
--with-http_xslt_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_ssl_module \
--with-threads \
--add-module=$(MODULESDIR)/headers-more-nginx-module \
--add-module=$(MODULESDIR)/nginx-auth-pam \
--add-module=$(MODULESDIR)/nginx-cache-purge \
--add-module=$(MODULESDIR)/nginx-dav-ext-module \
--add-module=$(MODULESDIR)/nginx-development-kit \
--add-module=$(MODULESDIR)/nginx-echo \
--add-module=$(MODULESDIR)/ngx-fancyindex \
--add-module=$(MODULESDIR)/nginx-http-push \
--add-module=$(MODULESDIR)/nginx-lua \
--add-module=$(MODULESDIR)/nginx-upload-progress \
--add-module=$(MODULESDIR)/nginx-upstream-fair \
--add-module=$(MODULESDIR)/ngx_http_substitutions_filter_module \
--add-module=/root/build/nginx-rtmp-module
...


步驟4: 開始編譯/build package
# dpkg-buildpackage -b

步驟5: 安裝 package
# cd ..
# dpkg --install nginx-extras_1.10.0-0ubuntu0.16.04.4_amd64.deb

(Reading database ... 208049 files and directories currently installed.)
Preparing to unpack nginx-extras_1.10.0-0ubuntu0.16.04.2_amd64.deb ...
Unpacking nginx-extras (1.10.0-0ubuntu0.16.04.2) over (1.10.0-0ubuntu0.16.04.2) ...
Setting up nginx-extras (1.10.0-0ubuntu0.16.04.2) ...
Processing triggers for man-db (2.7.5-1)

步驟6: 重新啟動 nginx
# service nginx restart
# systemctl status nginx.service

步驟7: 設定 nginx.conf
# vi /etc/nginx/nginx.conf

QUOTE:


....
rtmp {
server {
listen 1935;
notify_method get;
buflen 100ms;
chunk_size 65536;
timeout 60s;
max_streams 1024;

# Video on demand
application vod {
play /var/www/html/video;
}
}
}
...


網頁檔:
請到這個地方下載網頁語法
http://flash.flowplayer.org/plugins/streaming/rtmp.html

參考資料:
http://lexra.pixnet.net/blog/post/176386325-how-to-rebuild-ubuntu-nginx-package-and-install-with-nginx-r
https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/