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配置

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章