Extract Color Accurate PNG Frames Using FFmpeg

This article provides a straightforward guide on how to extract a single frame from a video as a PNG image using FFmpeg while preserving exact color accuracy. You will learn the specific command-line arguments and video filters needed to prevent color shifting, gamma issues, and color space mismatches during the YUV-to-RGB conversion process.

When converting video frames (which are typically stored in YUV color space) to PNG images (which use the RGB color space), FFmpeg can sometimes apply incorrect color matrices. This results in washed-out colors, crushed blacks, or subtle color shifts. To maintain perfect color accuracy, you must explicitly define the color space conversion parameters.

The Color-Accurate Command

To extract a highly accurate PNG frame from an HD video (which typically uses the BT.709 color standard), use the following command:

ffmpeg -ss 00:01:30 -i input.mp4 -vf "scale=in_color_matrix=auto:out_color_matrix=bt709" -pix_fmt rgb24 -vframes 1 output.png

Parameter Breakdown

Adjusting for SD and HDR Videos

If you are working with standard definition (SD) video or high-dynamic-range (HDR) video, you must match the color matrix to the source material:

By explicitly declaring the input and output color matrices alongside the standard rgb24 pixel format, FFmpeg will bypass default, inaccurate conversion presets and yield a mathematically accurate PNG representation of the video frame.