Get Video Pixel Format using FFmpeg

Get Video Pixel Format using FFmpeg

FFmpeg includes command-line utilities for inspecting multimedia files and retrieving details about individual media streams. The pixel format is a key video property that defines how pixel data is represented and stored, including the arrangement and color components used by the video. Inspecting the pixel format is useful when checking media characteristics, troubleshooting compatibility issues, or preparing files for encoding and processing. This tutorial shows how to get the video pixel format using FFmpeg.

The ffprobe utility can inspect a media file and report the pixel format associated with its video stream.

Download a sample video file for testing:

curl -sSo test.mp4 https://raw.githubusercontent.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4

The pixel format can be obtained with the following command:

ffprobe -v error -select_streams v:0 -show_entries stream=pix_fmt -of csv=p=0 test.mp4

The command returns:

yuv420p

The value yuv420p indicates that the video uses the YUV 4:2:0 planar pixel format with 8-bit components.

Command breakdown:

  • ffprobe - analyzes multimedia files and retrieves information about their streams.
  • -v error - limits the output to error messages and hides other diagnostic information.
  • -select_streams v:0 - selects the first video stream found in the input file.
  • -show_entries stream=pix_fmt - requests the pixel format property from the selected video stream.
  • -of csv=p=0 - formats the result as CSV while removing the property name and additional formatting.
  • test.mp4 - identifies the video file being inspected.

Leave a Comment

Cancel reply

Your email address will not be published.