nginx?搭建http-flv(rtmp)流媒體的方法步驟
git地址
https://github.com/winshining/nginx-http-flv-module/blob/master/README.CN.md
下載nginx-flv模塊
git clone https://github.com/arut/nginx-http-flv-module
安裝nginx依賴
yum -y install openssl openssl-devel
安裝nginx
wget http://nginx.org/download/nginx-1.10.3.tar.gz? tar -zxvf nginx-1.10.3.tar.gz? cd nginx-1.10.3 //添加rtmp和openssl支持 ./configure --add-module=/絕對路徑/nginx-http-flv-module --with-http_ssl_module make && make install
配軟鏈接
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
啟動nginx
nginx 啟動 nginx -s reload 重啟 nginx -s stop 停止
配置流媒體
vim /usr/local/nginx/conf/nginx.conf #user ?nobody; worker_processes ?4; #error_log ?logs/error.log; #error_log ?logs/error.log ?notice; #error_log ?logs/error.log ?info; #pid ? ? ? ?logs/nginx.pid; events { ? ? worker_connections ?1024; } rtmp_auto_push on; rtmp_auto_push_reconnect 1s; rtmp_socket_dir /tmp; rtmp { ? ? out_queue ? ? ? ? ? 4096; ? ? out_cork ? ? ? ? ? ?8; ? ? max_streams ? ? ? ? 128; ? ? timeout ? ? ? ? ? ? 15s; ? ? drop_idle_publisher 15s; ? ? log_interval 5s; #log 模塊在 access.log 中記錄日志的間隔時(shí)間,對調(diào)試非常有用 ? ? log_size ? ? 1m; #log 模塊用來記錄日志的緩沖區(qū)大小 ? ? ?server { ? ? ? ? listen 54321 reuseport; ? ? ? ? server_name _; ? ? ? ? application myapp { ? ? ? ? ? ? live on; ? ? ? ? ? ? meta off;# 為了兼容網(wǎng)頁前端的 flv.js,設(shè)置為 off 可以避免報(bào)錯(cuò) ? ? ? ? ? ? gop_cache on; # 支持GOP緩存,以減少首屏?xí)r間 ? ? ? ? ? ? allow play all; # 允許來自任何 ip 的人拉流 ? ? ? ? } ? ? } }?? ? http { ? ? include ? ? ? mime.types; ? ? default_type ?application/octet-stream; ? ? keepalive_timeout ?65; ? ? server { ? ? ? ? listen ? ? ? 80; ? ? ? ? server_name ?_; ? ? ? ? location /live { ? ? ? ? ? ? flv_live on; ? ? ? ? ? ? chunked_transfer_encoding on; #支持'Transfer-Encoding: chunked'方式回復(fù)? ? ? ? ? ? ? add_header 'Access-Control-Allow-Origin' '*'; #添加額外的 HTTP 頭 ? ? ? ? ? ? add_header 'Access-Control-Allow-Credentials' 'true'; #添加額外的 HTTP 頭 ? ? ? ? ? ? ? ?} ? ? ? ? } ? ? }
重啟
nginx -s reload
測試
推流
1.ffmpeg -re -i C:\Users\EDY\Desktop\1.mp4 -vcodec libx264 -acodec aac -f flv rtmp://122.112.245.213:54321/myapp/video_test
ffmpeg -re -i \ 本地視頻路徑 \ -vcodec libx264 -acodec aac -f flv \ rtmp://服務(wù)器ip:端口/rtmp的路由匹配/自定義
2. ffmpeg -re -i "video" -c:v copy -c:a aac -b:a 192k -strict -2 -f flv "rtmp"
視頻加水印,水印位置默認(rèn)在右上角
3. ffmpeg -re -i "video" -i "image" -filter_complex overlay=W-w-5:5 -c:v libx264 -c:a aac -b:a 192k -strict -2 -f flv "rtmp"
拉流
http://122.112.245.213/live?port=54321&app=myapp&stream=video_test
live為拉流地址路由匹配,
port等于推流的端口號
app等于推流的路由
stream等于推流后自定義的文件名
到此這篇關(guān)于nginx 搭建http-flv(rtmp)流媒體的方法步驟的文章就介紹到這了,更多相關(guān)nginx 搭建http-flv(rtmp)流媒體內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決nginx+uwsgi部署Django的所有問題(小結(jié))
本篇文章主要介紹了解決nginx+uwsgi部署Django的所有問題(小結(jié)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04filebeat同時(shí)收集錯(cuò)誤日志與普通日志并存詳解
這篇文章主要為大家介紹了filebeat同時(shí)收集錯(cuò)誤日志與普通日志并存詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Linux中Nginx的防盜鏈和優(yōu)化的實(shí)現(xiàn)代碼
今天是周末小編在值班哈,很開森,工作使我快樂,本文重點(diǎn)給大家介紹Linux中Nginx的防盜鏈和優(yōu)化問題及實(shí)現(xiàn)代碼,需要的朋友跟隨小編一起看看吧2021-06-06