ubuntu + rtmp + ffmpeg(硬解碼) + 樹莓派實現視訊直播(第一步)
阿新 • • 發佈:2019-02-12
1. 編譯安裝nginx
a. 如果以前通過apt-get安裝了nginx,需要解除安裝(sudo apt remove nginx)b. 去官網下載nginx http://nginx.org/en/download.html(我用的是1.12)
c. 下載nginx-rtmp-module
官方github地址:https://github.com/arut/nginx-rtmp-module
git clone https://github.com/arut/nginx-rtmp-module.git
d. 解壓下載的nginx,進入nginx目錄,寫一個配置指令碼config_nginx_1.12.sh內容如下:執行:chmod +x config_nginx_1.12.sh./configure --prefix=/usr/local/nginx \ --add-module=../nginx-rtmp-module \ --with-http_flv_module \ --with-http_mp4_module \
./config_nginx_1.12.sh
會報出如下錯誤:
意思就是HTTP rewrite模組需要PCRE 庫,要麼你加個不要這個模組的選項重新配置nginx,要麼就安裝PCRE。當然必須選擇安裝PCRE。./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
sudo apt install libpcre3 libpcre3-dev
系統報告libpcre3早就裝好了,其實只需要裝開發庫libpcre3-dev。
重新配置,這次報告是需要OpenSSL,繼續裝:
sudo apt install openssl libssl-dev
系統報告openssl早就裝好了,已經是最新版本了,想來還是跟PCRE一樣,只需要裝個開發庫。
繼續./config_nginx_1.12.sh
然後 make
sudo make install
2. 配置nginx
在最下面新增如下內容:
rtmp {
server {
listen 1935; #監聽的埠
chunk_size 4000;
application hls { #rtmp推流請求路徑: rtmp://ipaddress:1935/hls
live on;
hls on;
hls_path /usr/local/nginx/html/hls;
hls_fragment 5s;
}
}
}
這裡的視訊流目錄:hls_path設定為 /usr/local/nginx/html/hls,這個目錄的許可權用chmod設定為775。3. 啟動nginx
cd /usr/local/nginx/sbinsudo ./nginx -t
sudo ./nginx