How to use ffmpeg to extract live stream into a sequence of mp4

I would like to record a live stream to a sequence of mp4 on disk. I'm able to do one file like this:

ffmpeg -i rtmp://source.com/live/stream -r 5 -t 60 c:\test.mp4

This results in one 60s mp4 (test.mp4). What I would like is something like this:

ffmpeg -i rtmp://source.com/live/stream -r 5 -t 60 c:\test%d.mp4

That results in one 60s mp4 per minute (test1.mp4, test2.mp4, etc) I'm finding plenty of examples for extracting single frames in a similar way, but not video.

I realize I can just loop a call to the first example, but I was hoping there would be a good way to do it with minimal loss between each file by letting ffmpeg handle the sequencing. What is the cleanest way to record a live stream into a sequence of mp4?


Solution 1:

You can use the segment muxer. Example command:

ffmpeg -i rtmp://source.com/live/stream -c copy -flags +global_header -f segment -segment_time 60 -segment_format_options movflags=+faststart -reset_timestamps 1 test%d.mp4