FFmpeg Cut Video and Re-encode First Frame

This article explains how to use FFmpeg to cut a specific segment of a video while re-encoding the stream to ensure the first frame of your output is a fully rendered keyframe. When cutting videos without re-encoding, the output often starts with a black screen or visual artifacts because the cut begins on a non-keyframe (B-frame or P-frame). By re-encoding the video during the cut, FFmpeg automatically forces the very first frame of the new file to become an IDR/I-frame (keyframe), ensuring smooth playback from the very first second.

The Standard Command to Cut and Re-encode

To cut a video and force FFmpeg to re-encode the stream (which automatically creates a proper keyframe at the start of the cut), use the following command structure:

ffmpeg -ss 00:01:20 -i input.mp4 -to 00:01:50 -c:v libx264 -c:a aac output.mp4

Parameter Breakdown:

Frame-Accurate Cutting

If you place the -ss parameter before the -i parameter, FFmpeg seeks to the closest keyframe before your timestamp, which can sometimes lead to slightly inaccurate cuts. To achieve frame-accurate cutting where the first frame of the output is exactly the timestamp you requested, place the -ss parameter after the input file:

ffmpeg -i input.mp4 -ss 00:01:20 -to 00:01:50 -c:v libx264 -c:a aac output.mp4

This method decodes the input from the beginning and starts the output precisely at the requested timestamp, re-encoding the start point into a perfect keyframe.

Extracting and Re-encoding Just the First Frame as an Image

If your goal is to cut a video and extract only its very first frame as a high-quality, re-encoded image (for a thumbnail or poster image), use this command:

ffmpeg -ss 00:01:20 -i input.mp4 -vframes 1 -q:v 2 output.jpg

Parameter Breakdown: