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

8

6

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?

Daniel

Posted 2015-11-12T05:12:57.303

Reputation: 183

Answers

17

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

nico_lab

Posted 2015-11-12T05:12:57.303

Reputation: 402

That is it exactly and you are amazing. Thanks! – Daniel – 2015-11-12T16:29:25.497

FYI - I found I needed to add -reset_timestamps 1 or the segments after the first one would not play correctly in most browsers. See this explanation: http://www.dahuatu.com/JVwakkLZyM.html

– Daniel – 2015-11-13T02:39:59.507