FFmpeg Cut Video at Keyframe Automatically

This article explains how to write an FFmpeg command that automatically cuts a video at the nearest keyframe. By using input seeking combined with stream copying, you can perform lightning-fast video cuts that snap directly to keyframes without the need for time-consuming re-encoding.

The Keyframe Cutting Command

To cut a video at the nearest keyframe without re-encoding, use the following FFmpeg command structure:

ffmpeg -ss 00:01:30 -i input.mp4 -t 00:00:45 -c copy output.mp4

How It Works

Why Keyframes Matter

Video files are compressed using “keyframes” (which contain complete image data) and “interframes” (which only contain the differences between frames).

If you attempt to cut a video at a non-keyframe while copying the stream (-c copy), the player will not have a full image to render at the very beginning of the clip. This results in a frozen screen, black frames, or corrupted video artifacts until the player reaches the next keyframe.

By placing the -ss flag before -i, FFmpeg automatically seeks to the closest preceding keyframe, ensuring the output video starts with a clean, fully-rendered frame.

Keyframe Cutting vs. Accurate Cutting

Because this method snaps to the nearest existing keyframe, the cut may not happen at the exact millisecond you specified.

ffmpeg -i input.mp4 -ss 00:01:30 -t 00:00:45 -c:v libx264 -c:a aac output.mp4