【入门】ffmpeg、nginx、nginx-http-flv-module转发rtsp流、VLC查看

【入门】ffmpeg、nginx、nginx-http-flv-module转发rtsp流、VLC查看

参考:https://blog.csdn.net/string_kai/article/details/100598268

  1. 使用ffmpeg将rtsp转成rtmp

  2. 使用nginx中的nginx-http-flv-module 模块:

    • 转发到rtmp的1935端口上
    • 转发到http的80端口上
  3. 使用VLC查看

nginx安装 nginx-http-flv-module 模块并添加到nginx

1.clone nginx-http-flv-module

cd /usr/local/src/
git clone https://github.com/winshining/nginx-http-flv-module.git

**2.将模块编译进 NGINX:**注意/usr/local/src/nginx-1.6.2是下载解压nginx的位置,/usr/local/webserver/nginx是nginx安装的位置,用来运行nginx

cd /usr/local/src/nginx-1.6.2  #nginx安装位置
./configure --prefix=/usr/local/webserver/nginx --add-module=/usr/local/src/nginx-http-flv-module
make
make install

3./usr/local/webserver/nginx/conf/nginx.conf添加rtmplocation /live

http {
	server {
    # rtsp -> flv
    location /live {
      flv_live on;
      chunked_transfer_encoding  on; #open 'Transfer-Encoding: chunked' response
      add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
      add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
      add_header Access-Control-Allow-Headers X-Requested-With;
      add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
      add_header 'Cache-Control' 'no-cache';
    }
	}
}

rtmp {
    out_queue           4096;
    out_cork            8;
    max_streams         128;
    timeout             15s;
    drop_idle_publisher 15s;
    log_interval 5s; #interval used by log module to log in access.log, it is very useful for debug
    log_size     1m; #buffer size used by log module to log in access.log
    server {
        listen 1935; #Nginx监听的RTMP推流/拉流端口
        server_name localhost; #for suffix wildcard matching of virtual host name
        application live {
            live on;
            gop_cache off; #open GOP cache for reducing the wating time for the first picture of video
        }
    }
}

4.重新载入配置文件

/usr/local/webserver/nginx/sbin/nginx -s reload            # 重新载入配置文件

注意重新载入配置文件可能不成功。我在重新载入的时候1935端口并没有开启,实际可能需要关闭nginx,再开启:

/usr/local/webserver/nginx/sbin/nginx -s stop              # 停止 Nginx
/usr/local/webserver/nginx/sbin/nginx # 运行

hint:可以通过linux查看端口占用情况

lsof -i:1935

如果1935端口开启,会有类似如下的信息:

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值