linux搭建nginx+rtmp+nginx-http-flv-module环境

一、rtmp局限性

      由于各家浏览器到今年年底不在支持flash,所以在视频监控将rtsp流转换成让rtmp的方式需要改进。

 

二、环境准备

     1、下载nginx包

      下载地址:https://nginx.org/download/nginx-1.14.2.tar.gz

      2、下载nginx-http-flv-module 模块包

      下载地址:https://github.com/winshining/nginx-http-flv-module

      3、创建目录 /opt/tools

      安装虚拟机,并在opt文件夹下新建一个文件夹tools ,将下载的nginx 和nginx-rtmp-module 拷贝到opt 文件夹下

       4、创建nginx 文件夹

mkdir /usr/local/nginx

三、环境搭建

      1、解压nginx-http-flv-module-master,并放到/usr/local/nginx下面

      2、将nginx-http-flv-module模板添加到nginx中,生成make文件并安装nginx

cd /opt/tools
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx  --add-module=/usr/local/nginx/nginx-http-flv-module
make && make install

          3、配置文件修改nginx.conf,github上有示例参考


#user  nobody;
worker_processes  10;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  10240;
}
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_size 1m;
        server{
          listen 1935;
          server_name  127.0.0.1;
          application myapp{
                live on;
                gop_cache on;
          }
         application hls{
                live on;
                hls on;
                hls_path /usr/local/nginx/html/hls;
         }
         application dash{
                live on;
                dash on;
                dash_path /usr/local/nginx/html/dash;
         }
}
}
http{
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8002;
        server_name  127.0.0.1;
        location /live{
            flv_live on;
            chunked_transfer_encoding  on;
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
        }
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location /hls{
             types {
             application/vnd.apple.mpegurl m3u8;
             video/mp2t ts;
               }
               root /usr/local/nginx/html/hls;
               add_header 'Cache-Control' 'no-cache';
        }
        location /dash {
              root /usr/local/nginx/html/dash;
              add_header 'Cache-Control' 'no-cache';
        }
        location /stat {
              #configuration of push & pull status
              rtmp_stat all;
              rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
              root /usr/local/nginx/nginx-http-flv-module;
        }
        location /control {
              rtmp_control all;
       }
    }
}

四、http-flv流测试

         1、安装ffmpeg,网上有很多方法

         2、大华摄像机ffmpeg命令:

ffmpeg -i "rtsp://<username>:<password>@<ip地址>:554/cam/realmonitor?channel=1&subtype=0" -rtsp_transport tcp -vcodec copy -acodec copy -f flv "rtmp://127.0.0.1:1935/myapp/test"

         3、http-flv流格式

http://<ip>:8002/live?port=1935&app=myapp&stream=test

五、问题汇总

       1、转流时报错情况:

          [tcp @ 0x1826bc0]Connection to tcp://127.0.0.1:1935 failed: Connection refused

          解决方法:除了更改nginx.conf文件,还要同步修改nginx.conf.default文件

       2、重启nginx (./nginx -s reload)

          报错:nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

          解决方法:执行命令 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值