arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.36k stars 3.51k forks source link

Intermittent 404 errors for m3u8 file #1410

Open jitsunen opened 5 years ago

jitsunen commented 5 years ago

Hello,

I keep getting intermittent errors for my hls stream when the browser tries to download the m3u8 file.

Below is my nginx config. Any help would be much appreciated. I have tried hls_cleanup off, but that did not help.

Thanks much

user www-data;
worker_processes 1;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}
# 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 /hls/;
            hls_fragment 5s;
            hls_playlist_length 30s;
            # disable consuming the stream from nginx as rtmp
            deny play all;
        exec_publish bash -c "echo publish_start $app/$name >> /var/log/nginx/events.log";  
        exec_publish_done bash -c "echo publish_stop $app/$name >> /var/log/nginx/events.log";
        }
    }
}

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 'Access-Control-Allow-Headers' 'Authorization'; 
                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 /hls;
        }

    location /health {
            access_log off;
            return 200 "healthy\n";
        }
    }
}
leolwg commented 5 years ago

hello, I have the same problem as you. Have you solved it。

jitsunen commented 5 years ago

@leolwg , no I haven't solved it yet. I have two options right now:

a. Do a file sync between where nginx is writing to and a different folder from where nginx can serve HLS. The sync will be append only for existing files rather than create/delete the file. (Assuming nginx is creating/deleting the m3u8 files which leads to intermittent 404, I need to verify this) b. Use some alternative RTMP solution - ant media server.

jitsunen commented 5 years ago

I got some inotify events from my OS:

/hls/ CREATE stream2.m3u8.bak /hls/ MOVED_FROM stream2.m3u8.bak /hls/ MOVED_TO stream2.m3u8 /hls/ CREATE stream2-10839.ts /hls/ CREATE stream2.m3u8.bak /hls/ MOVED_FROM stream2.m3u8.bak /hls/ MOVED_TO stream2.m3u8 /hls/ CREATE stream2-10840.ts /hls/ CREATE stream2.m3u8.bak /hls/ MOVED_FROM stream2.m3u8.bak /hls/ MOVED_TO stream2.m3u8

It looks like the m3u8 file is getting created quite frequently which might be causing the intermittent 404s.

leolwg commented 5 years ago

Hello, This is my error message,[ [error] xxx#:xxx *open() "/tmp/hls/livexxxx.m3u8" failed (2: No such file or directory)...],There are some differences from your error message.My guess is that this is due to nginx multi-process,This means that multiple RTMP Stream switch between different nginx processes,and make .m3u8 file miss.

jitsunen commented 5 years ago

@leolwg , I did OS (ubuntu) upgrades, restarted the machine and the errors magically went away. I think the restart might have magically fixed the issue. Still a mystery.

leolwg commented 5 years ago

@jitsunen Are you serious? Big brother?????

jitsunen commented 5 years ago

@leolwg , Yes I am serious, I know it sounds crazy, but I tested multiple times and seems to be fine.

leolwg commented 5 years ago

@jitsunen Well, congratulations. I'm going to find my BUG。。。。。。。。

jitsunen commented 5 years ago

@leolwg , my 404s came back. I have researched different ideas, for now I am going to try out Ant Media Server Community Edition.

leolwg commented 5 years ago

@jitsunen Do you have WChat????