arut / nginx-rtmp-module

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

HLS_Cleanup on; cannot view #903

Open kenanchristian opened 7 years ago

kenanchristian commented 7 years ago

Hi Guys, I'm very new to this media server thing. I've successfully built a RTMP-HLS media server using this module, and I've also manage to generate thumbnail periodically using a npm module.

But the thing is, when the hls fragment is deleted, the thumbnail also deleted. Then I found the hls_cleanup config on docs, but after I use it, I can't view the video.

This is my nginx.conf

daemon  off;
env PATH;

events {
    worker_connections 1024;
}

rtmp {
    server {
        listen 1935;
        chunk_size 4000;

        application encoder {
            live on;

            exec ffmpeg -i rtmp://localhost:1935/encoder/$name
              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 720x1280 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_720p2628kbs
              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 480x854 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_480p1128kbs
              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 360x640 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_360p878kbs
              -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 400k -f flv -g 30 -r 30 -s 240x426 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_240p528kbs
              -c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 200k -f flv -g 15 -r 15 -s 240x426 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_240p264kbs;

            #exec bash -c "mkdir -p /data/hls/thumbnail/$name/";
            #exec bash -c "hls-thumb-gen http://localhost/hls/$name.m3u8 --interval 10 --outputDir /data/hls/thumbnail/$name/ --outputNamePrefix $name";

            record all;
            record_path /data/rec_hls;

            drop_idle_publisher 30s;

        }

        application hls {
            live on;
            hls on;

            hls_fragment_naming system;
            hls_fragment_slicing aligned;

            hls_path /data/hls;
            hls_nested on;
            hls_continuous on;
            hls_cleanup off;

            hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=720x1280;
            hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=480x854;
            hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=360x640;
            hls_variant _240p528kbs BANDWIDTH=528000,RESOLUTION=240x426;
            hls_variant _240p264kbs BANDWIDTH=264000,RESOLUTION=240x426;
        }
    }
}
http {
    server {
        listen 80;

        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /data;
            add_header Cache-Control no-cache;
            add_header Access-Control-Allow-Origin *;
        }

        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet static/stat.xsl;
        }

        location /control {
            rtmp_control all;
        }

        location /static {
            alias /static;
        }

        location /crossdomain.xml {
            default_type text/xml;
            return 200 '<?xml version="1.0"?>
                <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
                <cross-domain-policy>
                    <site-control permitted-cross-domain-policies="all"/>
                    <allow-access-from domain="*" secure="false"/>
                    <allow-http-request-headers-from domain="*" headers="*" secure="false"/>
                </cross-domain-policy>';
            expires 24h;
        }
    }
}
campones commented 7 years ago

nice post. personally I d use profile:v high for 720p and main for 480p

campones commented 7 years ago

about the cleanup, if you switch it off, I guess you ll have soon millions of fragment, except if you script something to remove the fragments once the live is over

campones commented 7 years ago

also you should know ffmpeg has resolution presets, you can use directly : -s hd720 or -s hd480

bharatdevparmar commented 3 years ago

@campones How you deleted hls fragment manually. Can you share script of delete old fragment after some time.