arut / nginx-rtmp-module

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

How to record a RTMP streaming pushed from Open Broadcast Studio? #1184

Open fishfree opened 6 years ago

fishfree commented 6 years ago

I followed this tutorial to push RTMP streaming from Open Broadcast Studio to my Ningx-RTMP server. I add the "record all" command in my config file, but still no work. About 10 seconds after stopping push RTMP streaming in Open Broadcast Studio, all the ts/m3u8 files are automatically deleted by Nginx. I'd like Nginx can record these streaming videos at the same time.

My config is as below:

worker_processes auto; events { worker_connections 1024; }

RTMP configuration

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

server_name mydomain.com;

    application show {
        live on;
    record all;
    record_path /tmp/recordings;
    record_unique on;
        # Turn on HLS
        hls on;
        hls_path /opt/hls/;
        hls_fragment 3;
        hls_playlist_length 60;
    hls_continuous on;
        # disable consuming the stream from nginx as rtmp
        deny play all;
    }
application vod {
    play /opt/hls;
}
}

}

http { sendfile off; tcp_nopush on;

aio on;

directio 512;
default_type application/octet-stream;

server {
    listen 443 ssl;
server_name mydomain.com;
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; 
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;
ssl_session_cache shared:le_nginx_SSL:1m;
ssl_session_timeout 1440m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";

    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 /opt/;
    }
}

}

tepaze commented 6 years ago

ts/m3u8 files are hls streaming fragment, and not the record file. Look at your /tmp/recordings path, and try : record_path /tmp/recordings/; instead of record_path /tmp/recordings;

fishfree commented 6 years ago

@tepaze Thank you! I tried "record_path /tmp/recordings/", but no use. Since my config is wrong, but I do want to record RTMP pushing streaming, then how to make it?

bichkhe commented 6 years ago

i also have the problem as you, too. But i put it in recorder that everything is ok

 #RECORDER
                application recorder {
                        live on;
                         recorder all {
                               record all;
                               record_path /tmp/live;
                               record_max_size 100000K;
                               #record_max_frames 4;
                               record_unique on;
                               record_suffix _%d%m%Y_%H%M%S.flv;
                               #record_append on;
                               #record_interval 5s;
                               #record_notify on;
                              exec_record_done /bin/ffmpeg -i $path  -f mp4 /tmp/live/$basename.mp4;
                       }

                }
aaronprisk commented 5 years ago

I'm a little late on this reply, but make sure NGINX has the right permissions to write to that recording directory.

On Linux chown -R www-data:www-data /path-to/recordings/ On FreeBSD chown -R www:www /path-to/recordings/

chaitanyabd commented 3 years ago

In my case

chown -R nginx:nginx /var/www/mp4

solved the issue

Budkhuu976 commented 1 year ago

how to play recordsuffix %d%m%Y_%H%M%S.flv; multi files?

shubham21155102 commented 8 months ago

how to play recordsuffix %d%m%Y_%H%M%S.flv; multi files?

Use Amazon S3 for storing that and then download that files on local and play