简体   繁体   English

nginx HLS 流不起作用

[英]nginx HLS stream not working

I've installed nginx with RTMP module on my linux server where I want it to receive a RTMP stream from Open Broadcaster Software, convert it to HLS and play it on my private website with some HTML5 player.我已经在我的 linux 服务器上安装了带有 RTMP 模块的 nginx,我希望它从 Open Broadcaster Software 接收 RTMP 流,将其转换为 HLS 并使用一些 HTML5 播放器在我的私人网站上播放。 Receiving the stream trough RTMP works, but the HLS stream doesn't seem to work.通过 RTMP 接收流有效,但 HLS 流似乎不起作用。 My current config is like so:我目前的配置是这样的:

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

To recieve the RTMP stream I use rtmp://ip/stream/streamname which works fine, for receiving HLS I try to use http://ip:8080/hls/streamname.m3u8 which gives me the .m3u8 file if I type it in a browser, but doesn't seem to work on the webpage when I try to play the file in a HTML5 player.为了接收 RTMP 流,我使用rtmp://ip/stream/streamname ,它工作正常,为了接收 HLS,我尝试使用http://ip:8080/hls/streamname.m3u8如果我输入,它会给我 .m3u8 文件它在浏览器中,但当我尝试在 HTML5 播放器中播放文件时,它似乎在网页上不起作用。 I'm testing via these pages: https://videojs.github.io/videojs-contrib-hls/ and https://demo.theoplayer.com/test-hls-mpeg-dash-stream我正在通过这些页面进行测试: https : //videojs.github.io/videojs-contrib-hls/https://demo.theoplayer.com/test-hls-mpeg-dash-stream

Can anyone help me understand what I'm doing wrong?谁能帮我理解我做错了什么?

It would help if you shared what type of console or network errors you get when testing your HLS stream on those pages.如果您分享在这些页面上测试 HLS 流时遇到的控制台或网络错误类型,将会有所帮助。

It might provide some insight for you to troubleshoot.它可能会为您进行故障排除提供一些见解。 For example, you might be getting Access Control Allow Origin errors by accessing your stream from a different domain.例如,您可能会通过从不同域访问您的流而收到访问控制允许来源错误。 Try uncommenting this line in your nginx.conf and reloading.尝试在 nginx.conf 中取消注释此行并重新加载。

#add_header Access-Control-Allow-Origin *;

I also have a reference to "video/mp2t ts;"我也参考了“video/mp2t ts;” in my hls location block.在我的 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' '*';
}

Cheers.干杯。 Ian伊恩

Under the line: #hls_fragment 6s;线下:#hls_fragment 6s; Add the code: deny_play_all;添加代码:deny_play_all;

Apparently you can't play the hls or dash files if the rtmp stream can be played.如果可以播放 rtmp 流,显然您无法播放 hls 或 dash 文件。 I don't know why.我不知道为什么。 It just worked for me.它只是为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM