Nginx-http-flv

版本:1.16.0

为方便用户快速搭建Window平台nginx-http-flv流媒体服务器,特基于nginx1.16.0+nginx-http-flv1.2.7源码进行编译;linux版请参照网上教材自行编译,由于window版本部分功能受限推荐使用linux版本。

2022-8-4 变更 如下

1、修复推流接口与rtspliveserver默认不一直导致部分用户使用不了,默认统一10000

2、默认启用hls功能,若不需要hls请在nginx.conf live节点注释掉下述语句

    #hls on;

    #hls_path html/hls;

    #hls_fragment 6s;

    #hls_playlist_length 30s;

3、减少hls直播延迟配置参考值

    hls_fragment 3s;

    hls_playlist_length 9s;

    hls_playlist_length 取值建议为hls_fragment 的3倍以上,刚启动rtmp推流 hls分片还未完全建立不要去播放hls否则会有卡顿。

2023-3-8变更如下:

1、修复nginx.config部分摄像机音频转hls无法播放

目录结构


程序操作

1、启动:双击根目录nginx.exe或run.bat;

2、停止:双击kill.bat(由于nginx默认带守护进程,运行此脚本才能干净结束进程);

3、可以将nginx加入window开机启动项保证开机运行服务。

查看运行状态

打开浏览器输入127.0.0.1:7070/stat出现如下界面则启动成功


查看推流状态

打开浏览器输入127.0.0.1:7070/stat或F5刷新界面可查看当前推流实时信息,用于视频推流协助诊断问题

预览rtmp hls视频

打开行业最牛逼的vlc播放器或其他rtmp播放器输入rtmp地址即可预览

rtmp播放地址格式:rtmp://127.0.0.1:1935/live/通道名称

hls播放地址格式:http://127.0.0.1:7070/hls/通道名称


配置说明

conf/nginx.conf文件说明

下述配置rtmp服务,推流端口1935, http端口7070  netcall_timeout 设置2s减少延迟等待不同播放器延迟不同。


#user  nobody;

worker_processes  1;


#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{

 server{

  listen 1935;

  chunk_size 4096;

  netcall_timeout 3s;

  application vod{

   play vod;

  }

  application record{

   play record;

  }

  application live {

    live on;

    hls on;

    hls_path html/hls;

    hls_fragment 6s;

    hls_playlist_length 30s;

    on_play http://127.0.0.1:10000/api/rtmp/play;

    on_play_done http://127.0.0.1:10000/api/rtmp/done; 

    on_update http://127.0.0.1:10000/api/rtmp/notice;

    drop_idle_publisher 5s;#drop no video/audio publisher

    notify_update_timeout 10s;

 }

}

}


http {

    include       mime.types;

    default_type  application/octet-stream;


    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';


    #access_log  logs/access.log  main;


    sendfile        on;

    #tcp_nopush     on;


    #keepalive_timeout  0;

    keepalive_timeout  65;


    #gzip  on;


    server {

        listen       7070;

        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;

        location /live{

        flv_live on;

chunked_transfer_encoding  on;

#Since some players don't support HTTP chunked transmission, it's better to specify chunked_transfer_encoding off;

add_header 'Access-Control-Allow-Origin' '*';

add_header 'Access-Control-Allow-Credentials' 'true';

        }

        location / {

            root   html;

            index  index.html index.htm;

        }

        location /hls {

            types {

                application/vnd.apple.mpegurl m3u8;

                video/mp2t ts;

            }

            expires -1;

            add_header Cache-Control no-cache;

            add_header Access-Control-Allow-Origin *;

        }

        location /stat {

            rtmp_stat all;

            rtmp_stat_stylesheet stat.xsl;

        }

        location /stat.xsl {

            root html/nginx-rtmp-module/;

        }

        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root           html;

        #    fastcgi_pass   127.0.0.1:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}


        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }



    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;


    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}



    # HTTPS server

    #

    #server {

    #    listen       443 ssl;

    #    server_name  localhost;


    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;


    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;


    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;


    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}


}