TareqAlqutami / rtmp-hls-server

a docker file to create a streaming server that supports RTMP, HLS and DASH content based on nginx and nginx-rtmp-module.
MIT License
399 stars 192 forks source link

stops streaming/ playing the stream after around 7 min #35

Open dio99 opened 2 years ago

dio99 commented 2 years ago

hellu any hints on why it s just stops stream after 5-7 min

my nginx conf worker_processes auto; error_log /var/log/nginx/nginx_error.log;

events { worker_connections 1024; }

RTMP configuration

rtmp { server { listen 1935; # Listen on standard RTMP port chunk_size 4000;

ping 30s;

    # notify_method get;

    # This application is to accept incoming stream
    application live {
        live on; # Allows live input
        interleave on;

        # for each received stream, transcode for adaptive streaming
        # This single ffmpeg command takes the input and transforms
        # the source into 4 different streams with different bitrates
        # and qualities. # these settings respect the aspect ratio.
        #exec_push  /usr/local/bin/ffmpeg -i rtmp://localhost:1935/$app/$name -async 1 -vsync -1
        #           -c:v libx264 -c:a aac -b:v 256k  -b:a 64k -vf "scale=480:trunc(ow/a/2)*2"  -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_low
        #           -c:v libx264 -c:a aac -b:v 768k  -b:a 64k -vf "scale=720:trunc(ow/a/2)*2"  -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_mid
        #           -c:v libx264 -c:a aac -b:v 1024k -b:a 64k -vf "scale=960:trunc(ow/a/2)*2"  -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_high
        #           -c:v libx264 -c:a aac -b:v 1920k -b:a 64k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset superfast -crf 23 -f flv rtmp://localhost:1935/show/$name_hd720
        #           -c copy -f flv rtmp://localhost:1935/show/$name_src;            
        #

;

Reolink cam

        exec_static /usr/local/bin/ffmpeg -i rtsp://ip//h264Preview_01_main -c copy -b:a 64k -f flv rtmp://localhost:1935/live/std;

        drop_idle_publisher 10s; 

    # This is the HLS application
    #application show {
    #   live on; # Allows live input from above application
        #deny play all; # disable consuming the stream from nginx as rtmp

        hls on; # Enable HTTP Live Streaming
        #hls_fragment 3;
        hls_playlist_length 20;
        hls_fragment            5s;
               hls_path /mnt/hls/;  # hls fragments path
        # Instruct clients to adjust resolution according to bandwidth
        #hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
        #hls_variant _hd720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
        #hls_variant _high BANDWIDTH=1152000; # High bitrate, higher-than-SD resolution
        #hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution
        #hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution

        # MPEG-DASH
        dash on;
        dash_path /mnt/dash/;  # dash fragments path
        dash_fragment 3;
        dash_playlist_length 20;            
    }
}

}

http { access_log /var/log/nginx/nginx_access.log; sendfile off; tcp_nopush on; directio 512;

aio on;

# HTTP server required to serve the player and HLS fragments
server {
    listen 8080;

    # Serve HLS fragments
    location /hls {
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }

        root /mnt;

        add_header Cache-Control no-cache; # Disable 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;
        }
    }

    # Serve DASH fragments
    location /dash {
        types {
            application/dash+xml mpd;
            video/mp4 mp4;
        }

        root /mnt;

        add_header Cache-Control no-cache; # Disable 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;
        }
    }       

    # This URL provides RTMP statistics in XML
    location /stat {
        rtmp_stat all;
        rtmp_stat_stylesheet stat.xsl; # Use stat.xsl stylesheet 
    }

    location /stat.xsl {
        # XML stylesheet to view RTMP stats.
        root /usr/local/nginx/html;
    }

}

}

dio99 commented 2 years ago

when i launch in the docker i get this /usr/local/bin/ffmpeg -i rtsp://ip_to_cam//h264Preview_01_main -c copy -b:a 64k -f flv rtmp://localhost:1935/live/std

Input #0, rtsp, from 'rtsp://ip_to cam//h264Preview_01_main': Metadata: title : Session streamed by "preview" comment : h264Preview_01_main Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: h264, yuv420p(progressive), 2304x1296, 30 tbr, 90k tbn, 180k tbc Stream #0:1: Audio: aac, 16000 Hz, mono, fltp Output #0, flv, to 'rtmp://localhost:1935/live/std': Metadata: title : Session streamed by "preview" comment : h264Preview_01_main encoder : Lavf58.29.100 Stream #0:0: Video: h264 ([7][0][0][0] / 0x0007), yuv420p(progressive), 2304x1296, q=2-31, 30 tbr, 1k tbn, 90k tbc Stream #0:1: Audio: aac ([10][0][0][0] / 0x000A), 16000 Hz, mono, fltp, 64 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help [flv @ 0x7f36a137c300] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly WriteN, RTMP send error 32 (129 bytes)56kB time=00:00:15.77 bitrate=8443.3kbits/s speed=1.08x
WriteN, RTMP send error 32 (38 bytes) WriteN, RTMP send error 9 (42 bytes) av_interleaved_write_frame(): Operation not permitted [flv @ 0x7f36a137c300] Failed to update header with correct duration.852.3kbits/s speed=1.12x
[flv @ 0x7f36a137c300] Failed to update header with correct filesize. Error writing trailer of rtmp://localhost:1935/live/std: Operation not permitted frame= 400 fps= 15 q=-1.0 Lsize= 16536kB time=00:00:27.91 bitrate=4852.3kbits/s speed=1.04x
video:16399kB audio:129kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.050750%

alcarazolabs commented 2 years ago

@dio99 I have the same problem, have you fixed this issue?

dio99 commented 2 years ago

hellu well sort of i installed newer version and did not launch in docker, moved the nginx to a intel nuc and there i also have/had some issues but seems ok now it runs for almost 24/7 now.

The cam's are on 4G net so most probblay that is the cause.