Record Live Stream and Split into 1-Hour Files with FFmpeg

This article provides a straightforward guide on how to use FFmpeg to capture a live streaming video and automatically split the recording into individual, one-hour files. By utilizing FFmpeg’s built-in segment muxer, you can continuously record a stream over long periods without overloading your system’s storage or creating single, unmanageably large video files.

To record a live stream and split it into hourly chunks, you should use the FFmpeg segment muxer. This tool splits the incoming stream on the fly without needing to stop and restart the connection.

Here is the standard command to achieve this:

ffmpeg -i "STREAM_URL" -c copy -f segment -segment_time 3600 -reset_timestamps 1 -strftime 1 "output_%Y-%m-%d_%H-%M-%S.mp4"

How the Command Works

Ensuring Accurate Splits

FFmpeg can only split a video stream cleanly on a keyframe (I-frame). If your live stream does not have a keyframe exactly at the 1-hour mark, FFmpeg will split the file at the nearest keyframe immediately following the 3600-second mark. This prevents any video corruption at the boundaries of your files.