FFmpeg Split Video at Specific Timestamps

This article provides a straightforward, step-by-step guide on how to split a single video file into multiple parts at precise, custom timestamps using FFmpeg’s powerful segment muxer. You will learn the exact command-line syntax, how to handle keyframes for clean cuts, and how to format the output filenames.

The Basic Command Syntax

To split a video at specific timestamps using the segment muxer, you use the -f segment option along with the -segment_times option to define your split points.

Here is the fundamental command:

ffmpeg -i input.mp4 -f segment -segment_times 60,120,180 -reset_timestamps 1 -c copy output_%03d.mp4

Parameter Breakdown

Achieving Frame-Accurate Splits

When using -c copy, FFmpeg can only split the video at the closest I-frame (keyframe) before or after your specified timestamp. If your timestamps must be frame-accurate, you have two choices:

To force FFmpeg to cut exactly at your specified timestamps, you must re-encode the video and tell the encoder to create keyframes at those exact seconds using the -force_key_frames option:

ffmpeg -i input.mp4 -f segment -segment_times 60,120,180 -force_key_frames 60,120,180 -reset_timestamps 1 output_%03d.mp4

Because the video is re-encoded, this process takes longer than stream copying, but it guarantees that the cuts happen exactly at the specified seconds.

Option 2: Split and Re-encode Specific Codecs

If you want to use a specific video codec (like H.264) and audio codec (like AAC) while forcing keyframes, use this command:

ffmpeg -i input.mp4 -f segment -segment_times 00:01:30,00:03:00 -force_key_frames 00:01:30,00:03:00 -c:v libx264 -c:a aac -reset_timestamps 1 output_%03d.mp4