Extract Specific Frames as PNG with FFmpeg
Extracting specific frames from a video file is a common task in video editing, analysis, and archiving. This article provides a straightforward guide on how to use FFmpeg to export high-quality PNG frames at precise timestamps using two different command-line methods depending on your workflow needs.
Method 1: Using Fast Seek (Recommended for Speed and Accuracy)
The most efficient way to extract frames at specific times is to use
the seek parameter (-ss) before the input file. This allows
FFmpeg to quickly jump to the exact timestamp without decoding the
entire video from the beginning.
To extract multiple frames in a single command, you can define multiple inputs and outputs:
ffmpeg -ss 00:01:15 -i input.mp4 -vframes 1 frame_1.png \
-ss 00:02:30 -i input.mp4 -vframes 1 frame_2.png \
-ss 00:03:45 -i input.mp4 -vframes 1 frame_3.pngHow it works: * -ss 00:01:15: Seeks to
1 minute and 15 seconds. You can use HH:MM:SS format or
seconds (e.g., 75). * -i input.mp4: Specifies
the input video. * -vframes 1: Tells FFmpeg to extract only
one frame for this output. * frame_1.png: The output
filename. PNG format is automatically chosen based on the file
extension.
Method 2: Using the Select Filter (Best for Single-Pass Extraction)
If you prefer to process the video in a single pass and specify times
in seconds, you can use the select video filter. This
method evaluates the presentation time (\(t\)) of each frame.
ffmpeg -i input.mp4 -vf "select='eq(t,15)+eq(t,45)+eq(t,120)'" -vsync vfr output_%03d.pngHow it works: * -vf "select='...'":
Activates the select filter. * eq(t,15): Selects the frame
at exactly 15 seconds. You can chain multiple timestamps using the
+ operator (which acts as “OR”). * -vsync vfr:
(Or -fps_mode vfr in newer FFmpeg versions) Prevents FFmpeg
from duplicating frames to maintain the original frame rate, ensuring
you only get the selected frames. * output_%03d.png:
Outputs sequentially numbered files (e.g., output_001.png,
output_002.png).