Windows Rtmp使用OBS推流&Nginx配置流媒体服务器&VCL拉流显示直播内容

Nginx配置:

worker_processes  1;    #Nginx进程数,建议设置为等于CPU总核数

error_log  logs/error.log info;

events {
    worker_connections  1024;     #工作模式与连接数上限
}

rtmp_auto_push on;

rtmp {
    server {
        listen 9000; #rtmp端口号
        chunk_size 4000;
        
        #rtmp协议推流
        application live { 
            live on;
            record all;
            record_path "C:/Users/29561/Desktop/nginx-rtmp-win32/temp/live_temp";    #保存路径,需要先创建, 不然执行推流会报错 
            #record_max_size 1 K;
            #append current timestamp to each flv;
            #record_unique on;
            #publish only from localhost    #allow publish 127.0.0.1;
            #deny publish all;
        }
        record_unique on;
         
        #rtmp/hls直播配置
        application hls { 
            live on;                    #开启rtmp直播
            hls on;                      #开启hls支持
            wait_key on;                #使视频流从第一个关键帧开始
            wait_video on;              #第一个视频帧发送前禁用音频
            hls_path temp/hls;          #指定HLS目录,需要先创建, 不然执行推流会报错
            hls_fragment 1s;            #用来设置每一个块的大小。默认是5秒。只能为整数
            hls_max_fragment 1800ms;
            hls_playlist_length 3s;        #设置播放列表的长度,单位是秒,听说设置成3秒延迟低点
            hls_nested off;             #默认是off。打开后的作用是每条流自己有一个文件夹
            hls_cleanup on;             #不清理ts , on|off 默认是开着的,是否删除列表中已经没有的媒体块
            #hls_continuous:on;         #on|off 设置连续模式,是从停止播放的点开始还是直接跳过
        }
    }
}

http {
    include mime.types;
    default_type application/octet-stream;
    sendfile off;
    server_names_hash_bucket_size 128;
    map_hash_bucket_size 64;
    client_body_timeout 10;
    client_header_timeout 10;
    keepalive_timeout 30;
    send_timeout 10;
    keepalive_requests 10;
    
    autoindex on;               #开启nginx目录浏览功能
    autoindex_exact_size off;   #文件大小从KB开始显示
    autoindex_localtime on;       #显示文件修改时间为服务器本地时间
    
    server {
        listen      9001;
        server_name  localhost;
        location / {         
            root   html;
            index  index.html index.htm;
        }
        
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        
        location /stat.xsl {
            root html;
        }
         
        location /hls {  
            #server hls fragments  
            types{  
                application/vnd.apple.mpegurl m3u8;  #m3u8 type设置
                video/mp2t ts;                       #ts分片文件设置
            } 
             
            add_header Cache-Control no-cache;          #禁止缓存
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Methods 'GET,POST,OPTIONS';
            add_header Access-Control-Allow-Headers 'Origin,Accept,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
                   
            alias temp/hls;                           #指向访问m3u8文件目录,视频流文件目录(自己创建)
            expires -1;  
        } 
 
    }
}
#   .\nginx.exe -c conf\nginx.conf
#    D:\Nginx>nginx.exe -t
#    nginx: the configuration file D:\Nginx/conf/nginx.conf syntax is ok
#    nginx: configuration file D:\Nginx/conf/nginx.conf test is successful 
#    本机Nginx服务器的推流和拉流的地址就是:rtmp://127.0.0.1:9000/live
#    拉流地址和推流地址是一样的:rtmp://127.0.0.1:9000/live
Nginx配置

 

 

 

 

 

 

posted @ 2022-09-21 09:38  彪悍的代码不需要注释  阅读(528)  评论(0编辑  收藏  举报
39
0