本文使用的操作系統(tǒng)是Ubuntu20.04筛武,nginx采用源碼編譯安裝芒篷,最終實現(xiàn)效果是nginx提供rtmp服務(wù)贱田。
安裝nginx的依賴包,編譯nginx依賴這些軟件包凤巨,不然會出錯视乐。
apt update
apt install -y build-essential zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxml2-dev libxslt-dev libgd-dev libjpeg-dev libpng-dev
下載nginx的源碼包,我這里是nginx-1.20.2版本敢茁。
cd /usr/local/src
wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar zxvf nginx-1.20.2.tar.gz
cd ./nginx-1.20.2
nginx未提供rtmp功能佑淀,rtmp由第三方模塊提供,從github獲取rtmp源碼彰檬。
git clone https://github.com/arut/nginx-rtmp-module
開始編譯nginx伸刃,編譯參數(shù)可以用我的,也可以自行刪減逢倍。
另外注意rtmp模塊的路徑捧颅,我這里是拉取nginx-rtmp-module到nginx源碼包目錄中的。
./configure --prefix=/usr/local/nginx \
--with-debug \
--with-compat \
--with-threads \
--with-pcre \
--with-pcre-jit \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_addition_module \
--with-http_gzip_static_module \
--with-http_gunzip_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_image_filter_module \
--with-http_xslt_module \
--with-stream \
--add-module=./nginx-rtmp-module
configure沒報錯繼續(xù)下一步较雕。
make && make install
nginx安裝成功后碉哑,打開nginx配置文件,在http{}范圍外增加這些內(nèi)容亮蒋。
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
}
application hls {
live on;
record off;
hls on;
hls_path /tmp;
}
}
}
啟動nginx后使用ss -lnpt | grep 1935
檢查端口是否正常監(jiān)聽谭梗。
推流方式有很多種,我一般用的是ffmpeg和obs宛蚓。
ffmpeg推流激捏,-i指定數(shù)據(jù)來源,rtmp://是rtmp服務(wù)器凄吏。這里表示將mp4推流到localhost的rtmp服務(wù)器上远舅。
ffmpeg -re -i demo.mp4 -c copy -f flv rtmp://localhost/live/demo-test
obs推流不做介紹了。拉流我一般用的是vlc和potplayer痕钢,比較喜歡potplayer吧图柏,無邊框播放真帥,yyds任连。
另外vlc和postplayer還支持播放h265的視頻蚤吹。
image.png
image.png