简体   繁体   中英

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. Receiving the stream trough RTMP works, but the HLS stream doesn't seem to work. 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. I'm testing via these pages: https://videojs.github.io/videojs-contrib-hls/ and 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.

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.

#add_header Access-Control-Allow-Origin *;

I also have a reference to "video/mp2t ts;" in my hls location block.

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; Add the code: deny_play_all;

Apparently you can't play the hls or dash files if the rtmp stream can be played. I don't know why. It just worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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