簡體   English   中英

nginx HLS 流不起作用

[英]nginx HLS stream not working

我已經在我的 linux 服務器上安裝了帶有 RTMP 模塊的 nginx,我希望它從 Open Broadcaster Software 接收 RTMP 流,將其轉換為 HLS 並使用一些 HTML5 播放器在我的私人網站上播放。 通過 RTMP 接收流有效,但 HLS 流似乎不起作用。 我目前的配置是這樣的:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    #include       mime.types;
    #default_type  application/octet-stream;
    sendfile        off;
    #keepalive_timeout  65;

    server {
        listen       8080;
        #server_name  localhost;

        #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 /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
        }
            root /mnt/;
            add_header Cache-Control no-cache;

            # To avoid issues with cross-domain HTTP requests (e.g. during development)
            #add_header Access-Control-Allow-Origin *;
        }
        #*********************************************************************************************************************************

    }

}

rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application stream {
                        live on;
                        #record off;

            hls on;
            hls_path /mnt/hls;
            #hls_fragment 6s;
                }
        }
}

為了接收 RTMP 流,我使用rtmp://ip/stream/streamname ,它工作正常,為了接收 HLS,我嘗試使用http://ip:8080/hls/streamname.m3u8如果我輸入,它會給我 .m3u8 文件它在瀏覽器中,但當我嘗試在 HTML5 播放器中播放文件時,它似乎在網頁上不起作用。 我正在通過這些頁面進行測試: https : //videojs.github.io/videojs-contrib-hls/https://demo.theoplayer.com/test-hls-mpeg-dash-stream

誰能幫我理解我做錯了什么?

如果您分享在這些頁面上測試 HLS 流時遇到的控制台或網絡錯誤類型,將會有所幫助。

它可能會為您進行故障排除提供一些見解。 例如,您可能會通過從不同域訪問您的流而收到訪問控制允許來源錯誤。 嘗試在 nginx.conf 中取消注釋此行並重新加載。

#add_header Access-Control-Allow-Origin *;

我也參考了“video/mp2t ts;” 在我的 hls 位置塊中。

location /hls/ {
    # Serve HLS fragments
    types {
        application/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
    }
    root /tmp;
    add_header Cache-Control no-cache;
    add_header 'Access-Control-Allow-Origin' '*';
}

干杯。 伊恩

線下:#hls_fragment 6s; 添加代碼:deny_play_all;

如果可以播放 rtmp 流,顯然您無法播放 hls 或 dash 文件。 我不知道為什么。 它只是為我工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM