git地址
https://github.com/winshining/nginx-http-flv-module/blob/master/README.CN.md
下载nginx-flv模块
1 | git clone https: //github .com /arut/nginx-http-flv-module |
安装nginx依赖
1 | yum -y install openssl openssl-devel |
安装nginx
1 2 3 4 5 6 | 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 |
配软链接
1 | ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/ |
启动nginx
1 2 3 | nginx 启动 nginx -s reload 重启 nginx -s stop 停止 |
配置流媒体
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 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 中记录日志的间隔时间,对调试非常有用 log_size 1m; #log 模块用来记录日志的缓冲区大小 server { listen 54321 reuseport; server_name _; application myapp { live on; meta off; # 为了兼容网页前端的 flv.js,设置为 off 可以避免报错 gop_cache on; # 支持GOP缓存,以减少首屏时间 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'方式回复 add_header 'Access-Control-Allow-Origin' '*' ; #添加额外的 HTTP 头 add_header 'Access-Control-Allow-Credentials' 'true' ; #添加额外的 HTTP 头 } } } |
重启
1 | nginx -s reload |
测试
推流
1.ffmpeg -re -i C:UsersEDYDesktop1.mp4 -vcodec libx264 -acodec aac -f flv rtmp://122.112.245.213:54321/myapp/video_test
1 2 3 4 | ffmpeg -re -i 本地视频路径 -vcodec libx264 -acodec aac -f flv rtmp://服务器ip:端口/rtmp的路由匹配/自定义 |
2. ffmpeg -re -i “video” -c:v copy -c:a aac -b:a 192k -strict -2 -f flv “rtmp”
视频加水印,水印位置默认在右上角
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等于推流后自定义的文件名
到此这篇关于nginx 搭建http-flv(rtmp)流媒体的方法步骤的文章就介绍到这了,更多相关nginx 搭建http-flv(rtmp)流媒体内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!