简体   繁体   中英

Streaming via nginx and hls not working fully

so I've configured my nginx server on azure to the point that i can in fact connect to it and stream but there is one issue i don't have the.m3u3 file in my hls directory, I'm streaming to this server via obs here is my nginx config

I found some old thread with this error but i've added user root; to file and still nothing

anyone know why it's not working


user root;
worker_processes auto; events {
    worker_connections 1024;
}
# RTMP configuration
rtmp {
    server {
        listen 1935 ; # Listen on standard RTMP port
        chunk_size 4000;
        application show {
            live on;
            # Turn on HLS
            hls on;
            hls_path /mnt/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # disable consuming the stream from nginx as rtmp
            deny play all;
        }
    }
}
http {
    sendfile off;
    tcp_nopush on;
    # aio on;
    directio 512;
    default_type application/octet-stream;
    server {
        listen 8080;
        location / {
            # Disable cache
            add_header 'Cache-Control' 'no-cache';
            # CORS setup
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Expose-Headers' 'Content-Length';
            # allow CORS preflight requests
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                add_header 'Content-Length' 0;
                return 204;
            }
            types {
                application/dash+xml mpd;
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /nginx/;
        }
    }
}



this is my nginx.conf using Ubuntu 18.04../usr/local/nginx/conf/nginx.conf

    worker_processes 1;
    events {
        worker_connections  1024;
    }
rtmp {
   server {
      listen 1935;
      application live {
          live on;
          interleave on;
          record off;

          hls on;
          hls_path /mnt/hls;
          hls_fragment 6s;
          hls_playlist_length 60s;
          deny play all;

          dash on;
          dash_path /mnt/dash;
          dash_fragment 3s;
      }
   }
}

http {
    sendfile off;
    tcp_nopush on;
    directio 512;
    default_type application/octet-stream;

    server {
        listen 8080;
        location / {
               add_header 'Cache-Control' 'no-cache';
               add_header 'Access-Control-Allow-Origin' '*' always;
               add_header 'Access-Control-Expose-Headers' 'Content-Length';
               if ($request_method = 'OPTIONS') {
                   add_header 'Access-Control-Allow-Origin' '*';
                   add_header 'Access-Control-Max-Age' 1728000;
                   add_header 'Content-Type' 'text/plain charset=UTF-8';
                   add_header 'Content-Length' 0;
                   return 204;
                }

        types {
             application/vnd.apple.mpegurl m3u8;
             video/mp2t ts;
             text/html html;
             application/dash+xml mpd;
        }
        root /mnt/;
        }
    }
}

OBS Stream setting: server add: rtmp://[ip-addr]/live stream key: stream

i've tried live stream using android (larix broadcaster app), with this connection setting, server add: rtmp//{ip-addr]:1935/live/stream stram key: stream

and at my website, i've added playerjs.js and use this inside index.html

    <section class="wrapper style1">
    <div class="inner">
            <div class="video">
                    <div class="video-wrapper">
                        <iframe width="100%" height="100%" src="playerjs.html?file=http://[ip-addr]:8080/hls/stream.m3u8" type="text/html" frameborder="0" allowfullscreen></iframe>
                    </div>
            </div>
    </div>
</section>

i'm running my server with apache2 on port:80, php, mySql..while Nginx on port:8080 to serve livestream HLS

.m3u8 will generated automaticly inside /mnt/hls Application name define inside rtmp..>> application live (i named it "live"), you may named it you like..while stream key, you define by yourself via streamer (OBS, Larix etc...) >> rtmp:/{ip-addr]:1935/live/ stream ( i named "stream"). nginx will pull that stream name and put inside mnt/hls/ and create.m3u8 file, devide clips into 60s playlist, and load every clips by 6s fragment..

thats why i like nginx:) and still going smooth.. hope this would help

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