Split Video at Custom Times Using FFmpeg Segment Muxer
This guide explains how to split a video file into multiple parts at
custom, user-defined timestamps using FFmpeg's built-in
segment muxer. You will learn the exact syntax required for
both fast, lossless cuts using stream copying, as well as frame-accurate
splitting that enforces keyframes at exact scene transitions.
The Segment Muxer Syntax
FFmpeg uses the -f segment muxer to chop media into
distinct output chunks. To specify custom split points, use the
-segment_times option followed by a comma-separated list of
times in seconds or HH:MM:SS format.
Fast Splitting (Stream Copy)
If your video's existing keyframes (I-frames) align closely with your desired scene changes, you can split the file without re-encoding by copying the streams:
ffmpeg -i input.mp4 -c copy -map 0 -f segment -segment_times 00:01:30,00:04:15,00:08:45 -reset_timestamps 1 output_%03d.mp4Explanation of Parameters
-i input.mp4: Specifies the input file.-c copy: Copies the audio and video streams without re-encoding, ensuring maximum speed and zero quality degradation.-map 0: Includes all streams (video, audio, subtitles) from the input file in the split outputs.-f segment: Activates the segment muxer.-segment_times 00:01:30,00:04:15,00:08:45: Defines the split timestamps. This creates four output files:- File 1: From start to 00:01:30
- File 2: From 00:01:30 to 00:04:15
- File 3: From 00:04:15 to 00:08:45
- File 4: From 00:08:45 to the end
-reset_timestamps 1: Resets each output segment's internal timestamps to start at zero (00:00:00), preventing playback compatibility issues.output_%03d.mp4: Defines the naming scheme using standard C formatting (output_000.mp4,output_001.mp4, etc.).
Ensuring Frame-Accurate Splits
When using -c copy, FFmpeg can only split a video on
existing keyframes (I-frames). If your custom scene changes do not fall
on an I-frame, FFmpeg will split at the closest preceding keyframe,
resulting in imprecise cuts.
To achieve exact cuts at precise timestamps, force keyframes at those locations while re-encoding the video:
ffmpeg -i input.mp4 -force_key_frames "00:01:30,00:04:15,00:08:45" -c:v libx264 -crf 18 -preset fast -c:a aac -f segment -segment_times 00:01:30,00:04:15,00:08:45 -reset_timestamps 1 output_%03d.mp4Additional Parameters for Frame Accuracy
-force_key_frames "00:01:30,00:04:15,00:08:45": Tells the video encoder to insert an I-frame at the exact timestamps matching your segments.-c:v libx264 -crf 18 -preset fast: Encodes the video using H.264 with high visual quality (-crf 18) at a fast encoding speed.-c:a aac: Encodes the audio stream using AAC.