How can I convert RTMP nginx livestream from Flv to mp4 file?

4.3k Views Asked by At

I have an RTMP server running using nginx that records the livestream into flv files but what I want to do is record the files into a mp4 format... Here’s my nginx.conf file:

I want when I rtmp livestream going I can convert it from flv to an mp4 file... How can I do this? Here is my nginx.conf file:

user  www-data;  
worker_processes auto;  
rtmp_auto_push on;  
events {  
    worker_connections  1024;  
}  
rtmp {  
    server {  
        listen 1935;  
        chunk_size 4096;  
        application s9-live {  
            exec ffmpeg -i rtmp://localhost:1935/s9-rtmp/$name  
            \-c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:1935/s9-rtmp/$name;  
            live on;  
            meta copy;  
            hls_cleanup off;  
            record all;  
            record_path /rec/videos;  
            record_max_size 1k;  
            record_unique on;  
            record_suffix %y%m%d_%H%M%S.flv;  
            exec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 $dirname/$basename.mp4;  
        }  
    }  
}  
http {   
    default_type application/octet-stream;  
   
    server {   
        listen 8000;   
        location /tv {   
            root /tmp/hls;   
        }  
 \# This URL provides RTMP statistics  
        location /stats {  
            rtmp_stat all;  
        }  
        location /control {  
            rtmp_control all;  
        }  
    }  
   
    types {  
        application/vnd.apple.mpegurl m3u8;  
        video/mp2t ts;  
        text/html html;  
    }   
}

The application runs well without any issues at all the only if possible that I would like to know is how to get an mp4 or the recorded stream converted from the flv files.

1

There are 1 best solutions below

0
On

You already have the command to convert flv to mp4 in your config:

exec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 $dirname/$basename.mp4;

While recording is on, you will only see an flv file. Once the recording is done, exec_record_done is triggered and the flv is converted to an mp4 file. You will then have an flv and a corresponding mp4 in your folder.