Stream MJPEG to file, but keep only last x minutes Stream MJPEG to file, but keep only last x minutes curl curl

Stream MJPEG to file, but keep only last x minutes


Look at segment muxer from FFmpeg.

With segment muxer it's possible to capture stream and write it to a number of separated files.

The option you may be interested in is segment_wrap.

From the documentation:

segment_wrap limitWrap around segment index once it reaches limit.

So you can use ffmpeg in this way:

ffmpeg -i URL -c copy -f segment -segment_time 120 -segment_wrap 2 out_file

to write cyclically two files.

The duration of each file is equal to the two minutes and in every moment of time you have at least last two minutes of video.

Of course I understand that this solution is terrible but it's the only way to solve your problem with ffmpeg that I can offer.