Originally published at ffmpeg-micro.com
The FFmpeg segment muxer splits a video into multiple files based on duration. Three flags cause most of the confusion: segment_time, strftime, and reset_timestamps. The official FFmpeg docs define each in one sentence. This guide shows what they actually do, with verified examples and the gotchas that trip people up.
Quick answer: Split a video into 5-second segments with timestamped filenames and clean playback timestamps:
ffmpeg -i input.mp4 -c copy -f segment -segment_time 5 -reset_timestamps 1 -strftime 1 "segment_%Y%m%d_%H%M%S.mp4"
What segment_time Does (and Why Your Segments Are the Wrong Length)
segment_time sets the target duration for each segment in seconds. With -c copy (stream copy, no re-encoding), FFmpeg can only cut at keyframe boundaries. If your video has keyframes every 8 seconds and you set -segment_time 3, your segments will be roughly 8 seconds each.
Actual segment durations from a 13-second test video with -segment_time 3 -c copy:
| Segment | Expected | Actual |
|---|---|---|
| output_000.mp4 | ~3s | 8.34s |
| output_001.mp4 | ~3s | 5.01s |
The muxer waited for the next keyframe after the 3-second mark. Stream copying can't split mid-GOP because there's no re-encoding to create a new keyframe at the cut point.
Fix: force keyframes at your split points. This requires re-encoding:
ffmpeg -i input.mp4 -c:v libx264 -preset ultrafast -crf 23 \
-force_key_frames "expr:gte(t,n_forced*3)" \
-f segment -segment_time 3 -reset_timestamps 1 "output_%03d.mp4"
Now the segments are exactly 3 seconds each.
reset_timestamps: Why Your Player Shows the Wrong Time
Without reset_timestamps, each segment inherits its position from the original video. Check with ffprobe: start_time=8.408000. Add -reset_timestamps 1 and it becomes start_time=0.000000.
If you're generating segments for standalone playback, always use -reset_timestamps 1.
strftime: Timestamped Filenames
With -strftime 1, use date/time tokens in the filename: segment_%Y%m%d_%H%M%S.mp4 produces files like segment_20260530_050835.mp4. You can't mix %03d and strftime in the same pattern.
Common Pitfalls
-
Segments way longer than segment_time: Using
-c copywith a GOP interval larger than segment time. Re-encode with-force_key_framesor accept keyframe-aligned cuts. -
Player shows black frames: Missing
-reset_timestamps 1. -
"Could not write header" error: Use
-segment_format mp4explicitly.
FAQ
Does segment_time guarantee exact segment durations?
Only when re-encoding. With -c copy, FFmpeg cuts at the nearest keyframe after the target time.
What's the difference between the segment muxer and HLS muxer?
The HLS muxer (-f hls) is purpose-built for Apple HLS streaming. The segment muxer (-f segment) is a general-purpose splitter. Use HLS muxer for streaming delivery, segment muxer for batch splitting.
Last verified: 2026-05-30 against FFmpeg 4.3
Top comments (0)