nginx 搭建http-flv(rtmp)流媒体的方法步骤

2023-12-01 0 702
目录
  • 下载nginx-flv模块
  • 安装nginx依赖
  • 安装nginx
  • 配软链接
  • 启动nginx
  • 配置流媒体
  • 重启
  • 测试
    • 推流
    • 拉流

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 中记录日志的间隔时间,对调试非常有用
    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 头      
         }
        }
    }

重启

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://服务器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)流媒体内容请搜索悠久资源以前的文章或继续浏览下面的相关文章希望大家以后多多支持悠久资源!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 Nginx服务器 nginx 搭建http-flv(rtmp)流媒体的方法步骤 https://www.u-9.cn/server/nginx/7792.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务