'Using nginx-rtmp-module to save rtmp stream to mp4 instead of flv

I am trying to save an incoming rtmp stream on my server as an mp4 file. I am using the nginx-rtmp module and changing the container from flv to mp4 on the exec_record_done directive. This is done using ffmpeg as follows

ffmpeg -i input.flv output.mp4

I am sending h264 video streams and aac audio streams (in an flv container), so as to keep it compatible even with mp4

I would like to know if it is possible to directly save the incoming stream as an mp4 and avoid the transcoding at the end of each session

I am guessing this will help avoid the abrupt CPU spikes that I see when a recording is done

nginx.conf

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

events {
    worker_connections 1024;
}

rtmp {
    server {
        listen 1935;
        chunk_size 4096;
        allow publish all;
        allow play all;

        application live {
            live on;

            record all;
            record_suffix .flv;
            record_path /tmp/videos/;
            record_unique on;

            exec_record_done ffmpeg -y -i $path  /home/ubuntu/videos/$basename.mp4;
        }
    }
}

I thought this would be simple enough because the underlying streams remain the same. Any help is appreciated :)



Solution 1:[1]

It's because your FFmpeg command is incorrect, try this:

exec_record_done ffmpeg -i $path -c copy /home/ubuntu/videos/$basename.mp4;

Remember to add the -c copy to tell FFmpeg convert FLV to MP4 without transcoding.

Another solution is copying the HLS files and covert HLS to MP4 by yourself.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Winlin