實驗環境說明: ubuntu 16.04
進行本實驗的前提:需要在ubuntu上搭建好ffmpeg環境,參考我的另一篇博文
ffmpeg編譯過程經歷的99八十一難
下面開始本文內容
PART1 編譯安裝帶Nginx-rtmp-module的Nginx服務器
1 下載Nginx (Nginx從官網下載比較好,不要去github下)
上圖是我下載的版本
2 下載Nginx-rtmp-module (github)
https://github.com/arut/nginx-rtmp-module
3 執行配置
4. Openssl下載 (github)
https://github.com/openssl/openssl
PS:官網 https://www.openssl.org
下了幾個版本,實測多次都不行, make時候報錯
來自網友網盤的openssl-1.0.2h , 實測OK
鏈接:https://pan.baidu.com/s/1lAZ9VgFUX6Nx72MYD1NmIQ
提取碼:vuq5
下載后, 我取自己所需的openssl-1.0.2h.tar.gz即可。不參考其他資料。
./config --prefix=/usr/local/openssl-1.0.2h
make
make install
5. 下載安裝好openssl后,再次進入到Nginx文件夾內進行編譯
需要注意,下方 --add-module 和 --with-openssl 指定的是源碼目錄!
./configure --prefix=/usr/local/nginx-with-rtmp-module --add-module=/home/lmw/MINE/nginx-rtmp-module/nginx-rtmp-module-master --with-openssl=/home/lmw/MINE/openssl/openssl-1.0.2h
顯示上圖這些,就是配置正常。
make -j4
make install
最終如上圖所示,安裝正常
PART2 運行RTMP服務器
1 修改nginx配置文件,配置RTMP服務
vim.tiny conf/nginx.conf
#---------- my add : rtmp server config----------- rtmp { server{ listen 1935; chunk_size 4000; application live { live on; allow play all; } } } #-------------------------------------------------
2 啟動nginx
./sbin/nginx -c conf/nginx.conf
同時可見1935端口已經處於監聽狀態
3 推流拉流干起來:
ffplay rtmp://localhost/live/my_room_007
ffmpeg -re -i rtmp-test.flv -c copy -f flv rtmp://localhost/live/my_room_007
下面介紹下:視頻傳輸基礎知識、RTMP與RTSP比較、直播服務常規方案
本實驗內我們使用ffmpeg的ffplay工具進行拉流播放,根據上面的介紹,針對RTMP流,我們也可以通過瀏覽器進行拉流播放。
PART3 運行HTTP服務器
雖然我們這里安裝了nginx-rtmp模塊,主要是當做rtmp服務器使用。
但是nginx也自帶提供http服務,高並發網絡編程是nginx大神神威的領域。
在不安裝任何其他模塊的情況下,安裝nginx完畢后,
一般都是通過測試http服務來檢測nginx是否安裝正確的。
.