Nginx RTMP配置

2019-06-04  本文已影响0人  Morgan7
#user  nobody;
worker_processes  2;

#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;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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;
        }


        location /control {
            # 开始录制 curl "http://localhost:8080/control/record/start?app=hls&name=demo&rec=rec1"
            # 停止录制 curl "http://localhost:8080/control/record/stop?app=hls&name=demo&rec=rec1"
            rtmp_control all;
        }


        # This URL provides RTMP statistics in XML
        location /stat {
            rtmp_stat all;

            # Use this stylesheet to view XML as web page
            # in browser
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            # XML stylesheet to view RTMP stats.
            # Copy stat.xsl wherever you want
            # and put the full directory path here
            root /usr/local/Cellar/rtmp-nginx-module/1.1.7.11-dev_3/share/rtmp-nginx-module/stat.xsl/;
        }

        location /hls {

            # Serve HLS fragments

            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }


            alias /Users/mht/Downloads/rtmp/hls;


            add_header Cache-Control no-cache;
        }

        
    }

    include servers/*;
}

rtmp {
    server {

        listen 1935;


        application live{
            # enable live streaming
            live on;

            max_connections 1024;

            recorder rec1 { 
                record all manual; 
                record_suffix -%Y-%m-%d-%H_%M_%S.mp4; 
                record_unique on; 
                record_path /Users/mht/Downloads/rtmp/mp4s; 
            } 


            # publish only from localhost
            allow publish 127.0.0.1;
            deny publish all;

            #allow play all;
        }

        application hls{
            live on; 
            hls on; 
            # 对视频切片进行保护
            wait_key on;
            # 每个视频切片的时长
            hls_fragment 10s;
            # 切片视频文件存放位置
            hls_path /Users/mht/Downloads/rtmp/hls;
            # 连续模式
            hls_continuous on;
            # 对多余的切片进行删除
            hls_cleanup off;
            # 嵌套模式
            hls_nested on;

            recorder rec1 { 
                record all manual; 
                record_suffix -%Y-%m-%d-%H_%M_%S.mp4; 
                record_unique on; 
                record_path /Users/mht/Downloads/rtmp/mp4s; 
            } 

        }

        # video on demand
        application vod {
            play /Users/mht/Downloads/rtmp/flvs;
        }

        application vod2 {
            play /Users/mht/Downloads/rtmp/mp4s;
        }

    }
    
}

上一篇下一篇

猜你喜欢

热点阅读