Configure FFmpeg Segment Muxer to Split Live Streams

This guide explains how to configure the FFmpeg segment muxer to split a continuous live stream into smaller, sequential video chunks. You will learn the exact command-line arguments needed to split streams by duration, generate a dynamic playlist, and ensure clean cuts by managing keyframes.

The segment muxer in FFmpeg splits an input stream into multiple files of a specified duration. This is highly useful for HTTP Live Streaming (HLS) preparation, archiving, or processing live feeds.

Basic Command Syntax

To split a live RTMP or RTSP stream into 10-second MPEG-TS segments, use the following basic command:

ffmpeg -i rtmp://source.com/live/stream \
  -c copy \
  -f segment \
  -segment_time 10 \
  -reset_timestamps 1 \
  -segment_list playlist.m3u8 \
  segment_%03d.ts

Key Configuration Parameters

Handling Keyframes for Accurate Splitting

FFmpeg can only split a video stream at an intra-frame (I-frame or keyframe). If your source stream does not have frequent keyframes, segments may be much longer than your defined -segment_time because FFmpeg must wait for the next keyframe to cut the file.

If you are re-encoding the stream (instead of using -c copy), you should force keyframes at precise intervals to ensure accurate splitting:

ffmpeg -i rtmp://source.com/live/stream \
  -c:v libx264 -g 60 -keyint_min 60 -sc_threshold 0 \
  -f segment \
  -segment_time 2 \
  -reset_timestamps 1 \
  -segment_list live.m3u8 \
  output_%05d.ts

In this configuration: * -g 60 forces a group of pictures (GOP) size of 60 frames. At 30fps, this creates a keyframe exactly every 2 seconds. * -sc_threshold 0 prevents scene-change detection from inserting extra, unexpected keyframes that might disrupt the division interval.