Skip to main content

Overview

Pixel formats define how image data is stored in memory. FFmpeg supports a wide range of pixel formats for various video processing needs, from standard RGB/YUV formats to specialized hardware-accelerated formats.

Format Naming Convention

Pixel formats follow the pattern AV_PIX_FMT_<FORMAT><BITS><ENDIAN>:
  • FORMAT: Color space or layout (RGB, YUV, GRAY, etc.)
  • BITS: Bit depth per component
  • ENDIAN: Byte order (BE = big-endian, LE = little-endian)

Listing Available Formats

ffmpeg -pix_fmts
Query specific format:
ffmpeg -pix_fmts | grep yuv420p

Color Spaces

YUV Formats

YUV (luma + chroma) formats are standard for video compression and broadcast.

YUV 4:2:0 (Most Common)

AV_PIX_FMT_YUV420P - Planar YUV 4:2:0, 12bpp
  • Chroma Subsampling: 2x2 (1 Cr & Cb sample per 2x2 Y samples)
  • Use: Most common video format (H.264, HEVC, VP9)
  • Storage: Separate Y, U, V planes
ffmpeg -i input.mp4 -pix_fmt yuv420p output.mp4
AV_PIX_FMT_NV12 - Planar Y + interleaved UV, 12bpp
  • Chroma: Interleaved U and V (first byte U, next byte V)
  • Use: Hardware encoding/decoding, mobile devices
  • Performance: Often faster than YUV420P on hardware
AV_PIX_FMT_NV21 - Planar Y + interleaved VU, 12bpp
  • Chroma: Interleaved V and U (swapped from NV12)
  • Use: Some Android devices

YUV 4:2:2 (Broadcast Quality)

AV_PIX_FMT_YUV422P - Planar YUV 4:2:2, 16bpp
  • Chroma Subsampling: 2x1 (1 Cr & Cb sample per 2x1 Y samples)
  • Use: Professional video, broadcast (MPEG-2, ProRes)
AV_PIX_FMT_YUYV422 - Packed YUV 4:2:2, 16bpp
  • Layout: Y0 Cb Y1 Cr (packed)
  • Use: Cameras, capture devices
AV_PIX_FMT_UYVY422 - Packed YUV 4:2:2, 16bpp
  • Layout: Cb Y0 Cr Y1
  • Use: Professional equipment, SDI

YUV 4:4:4 (No Chroma Subsampling)

AV_PIX_FMT_YUV444P - Planar YUV 4:4:4, 24bpp
  • Chroma Subsampling: None (1:1:1)
  • Use: High-quality encoding, lossless compression
  • Quality: Highest quality YUV format
ffmpeg -i input.mp4 -pix_fmt yuv444p -c:v libx264 -qp 0 output.mp4

High Bit Depth YUV

AV_PIX_FMT_YUV420P10LE - 10-bit YUV 4:2:0, 15bpp, little-endian
  • Bit Depth: 10 bits per component
  • Use: HDR video, professional grading
  • Codecs: HEVC, VP9, AV1
AV_PIX_FMT_YUV422P10LE - 10-bit YUV 4:2:2, 20bpp
  • Use: Professional broadcast, ProRes
AV_PIX_FMT_YUV444P10LE - 10-bit YUV 4:4:4, 30bpp
  • Use: High-end production, mastering
AV_PIX_FMT_YUV420P12LE - 12-bit YUV 4:2:0, 18bpp AV_PIX_FMT_YUV420P16LE - 16-bit YUV 4:2:0, 24bpp

YUV with Alpha

AV_PIX_FMT_YUVA420P - Planar YUV 4:2:0 + alpha, 20bpp
  • Alpha: Separate alpha plane
  • Use: Video with transparency
AV_PIX_FMT_YUVA444P - Planar YUV 4:4:4 + alpha, 32bpp

RGB Formats

RGB formats store red, green, and blue components.

Packed RGB

AV_PIX_FMT_RGB24 - Packed RGB 8:8:8, 24bpp
  • Layout: RGBRGB… (3 bytes per pixel)
  • Use: Image processing, display
ffmpeg -i input.mp4 -pix_fmt rgb24 output.avi
AV_PIX_FMT_BGR24 - Packed BGR 8:8:8, 24bpp
  • Layout: BGRBGR… (reversed RGB)
  • Use: Windows bitmaps, OpenCV
AV_PIX_FMT_RGBA - Packed RGBA 8:8:8:8, 32bpp
  • Layout: RGBARGBA… (includes alpha)
  • Use: Compositing, overlays, PNG
AV_PIX_FMT_ARGB - Packed ARGB 8:8:8:8, 32bpp
  • Layout: ARGBARGB…
  • Use: Some graphics APIs
AV_PIX_FMT_BGRA - Packed BGRA 8:8:8:8, 32bpp
  • Layout: BGRABGRA…
  • Use: Windows, DirectX
AV_PIX_FMT_ABGR - Packed ABGR 8:8:8:8, 32bpp AV_PIX_FMT_0RGB - Packed XRGB 8:8:8, 32bpp (X=unused)

High Bit Depth RGB

AV_PIX_FMT_RGB48LE - Packed RGB 16:16:16, 48bpp, little-endian
  • Bit Depth: 16 bits per component
  • Use: High-quality image processing
AV_PIX_FMT_RGBA64LE - Packed RGBA 16:16:16:16, 64bpp AV_PIX_FMT_RGB565LE - Packed RGB 5:6:5, 16bpp
  • Use: Low-memory devices, embedded systems
AV_PIX_FMT_RGB555LE - Packed RGB 5:5:5, 16bpp

Planar RGB

AV_PIX_FMT_GBRP - Planar GBR 4:4:4, 24bpp
  • Planes: Separate G, B, R planes
  • Use: Some codecs prefer planar RGB
AV_PIX_FMT_GBRAP - Planar GBRA 4:4:4:4, 32bpp
  • Planes: G, B, R, A separate planes
AV_PIX_FMT_GBRP10LE - Planar GBR 10-bit, 30bpp AV_PIX_FMT_GBRP16LE - Planar GBR 16-bit, 48bpp

Grayscale Formats

AV_PIX_FMT_GRAY8 - 8-bit grayscale, 8bpp
ffmpeg -i input.mp4 -pix_fmt gray output.mp4
AV_PIX_FMT_GRAY16LE - 16-bit grayscale, 16bpp AV_PIX_FMT_YA8 - 8-bit gray + 8-bit alpha, 16bpp AV_PIX_FMT_YA16LE - 16-bit gray + 16-bit alpha, 32bpp AV_PIX_FMT_MONOWHITE - 1-bit monochrome (0=white, 1=black) AV_PIX_FMT_MONOBLACK - 1-bit monochrome (0=black, 1=white)

Palette Formats

AV_PIX_FMT_PAL8 - 8-bit palettized RGB32
  • Storage: 8-bit index + 256-entry RGB32 palette
  • Use: GIF, indexed PNG

Special Formats

AV_PIX_FMT_XYZ12LE - Packed XYZ 4:4:4, 36bpp
  • Use: Digital cinema (DCI)

Bayer Formats

Raw sensor data from cameras. AV_PIX_FMT_BAYER_BGGR8 - Bayer BGGR pattern, 8-bit AV_PIX_FMT_BAYER_RGGB8 - Bayer RGGB pattern, 8-bit AV_PIX_FMT_BAYER_GBRG8 - Bayer GBRG pattern, 8-bit AV_PIX_FMT_BAYER_GRBG8 - Bayer GRBG pattern, 8-bit

Hardware Acceleration Formats

AV_PIX_FMT_VAAPI - VA-API hardware surfaces
  • Use: Intel hardware decoding/encoding
AV_PIX_FMT_CUDA - CUDA device memory
  • Use: NVIDIA GPU acceleration
AV_PIX_FMT_QSV - Intel Quick Sync Video AV_PIX_FMT_DXVA2_VLD - DirectX Video Acceleration 2 AV_PIX_FMT_D3D11VA_VLD - Direct3D 11 Video Acceleration AV_PIX_FMT_VDPAU - VDPAU (NVIDIA Video Decode and Presentation API)

Format Conversion

Basic Conversion

# Convert to YUV420P
ffmpeg -i input.mp4 -pix_fmt yuv420p output.mp4

# Convert to RGB24
ffmpeg -i input.mp4 -pix_fmt rgb24 output.avi

# Convert to 10-bit
ffmpeg -i input.mp4 -pix_fmt yuv420p10le -c:v libx265 output.mp4

Scale with Format Conversion

ffmpeg -i input.mp4 -vf "scale=1920:1080,format=yuv420p" output.mp4

Preserve Quality

# For high-quality conversion
ffmpeg -i input.mp4 -pix_fmt yuv444p -c:v libx264 -qp 0 output.mp4

HDR to SDR

ffmpeg -i hdr_input.mp4 -pix_fmt yuv420p -vf "zscale=t=linear,tonemap=hable,zscale=p=bt709" sdr_output.mp4

Format Properties

Chroma Subsampling

  • 4:4:4: No subsampling (best quality)
  • 4:2:2: Horizontal subsampling by 2
  • 4:2:0: Horizontal and vertical subsampling by 2 (most common)
  • 4:1:1: Horizontal subsampling by 4

Planar vs Packed

Planar: Each component in separate memory plane
  • Example: YUV420P (separate Y, U, V planes)
  • Advantage: Easier to process individual components
Packed: Components interleaved in memory
  • Example: YUYV422 (Y0 Cb Y1 Cr…)
  • Advantage: Sometimes faster memory access

Bit Depth

  • 8-bit: Standard dynamic range (SDR)
  • 10-bit: HDR, professional video
  • 12-bit: Cinema, high-end production
  • 16-bit: Image processing, intermediate formats

Common Use Cases

Web Video

ffmpeg -i input.mp4 -pix_fmt yuv420p -c:v libx264 -preset medium web_output.mp4

HDR Video

ffmpeg -i input.mp4 -pix_fmt yuv420p10le -c:v libx265 -x265-params hdr10=1 hdr_output.mp4

Image Sequences

# Extract as RGB
ffmpeg -i input.mp4 -pix_fmt rgb24 frame_%04d.png

# Extract as YUV
ffmpeg -i input.mp4 -pix_fmt yuv420p frame_%04d.yuv

Transparency

ffmpeg -i input.mov -pix_fmt yuva420p -c:v libvpx-vp9 output.webm

Performance Considerations

Hardware Encoding

# Use NV12 for hardware encoders
ffmpeg -i input.mp4 -pix_fmt nv12 -c:v h264_nvenc output.mp4

Memory Usage

Bits per pixel:
  • YUV420P: 12 bpp
  • YUV422P: 16 bpp
  • YUV444P: 24 bpp
  • RGB24: 24 bpp
  • RGBA: 32 bpp
  • YUV420P10LE: 15 bpp

Compatibility

Most Compatible: YUV420P (8-bit)
  • Supported by all devices and players
  • Required for H.264 baseline/main profiles

Source Code Location

Pixel format definitions: libavutil/pixfmt.h Key file:
  • /home/daytona/workspace/source/libavutil/pixfmt.h - Enum AVPixelFormat definitions
  • Color Range: Limited (16-235) vs Full (0-255)
  • Color Space: BT.601, BT.709, BT.2020
  • Color Primaries: Defines RGB/XYZ color gamut
  • Transfer Characteristics: Gamma, PQ, HLG for HDR

Build docs developers (and LLMs) love