Skip to main content

Video Decoding Guide

FFmpeg’s decoders convert compressed video into raw frames for processing, analysis, or re-encoding.

Understanding Decoders

Decoders are configured elements that enable playback and processing of multimedia streams. FFmpeg includes native decoders for most formats, with additional support through external libraries.
List all available decoders: ffmpeg -decoders

Basic Decoding

Decoding happens automatically when you specify an output format or processing operation.

Extract Raw Video

1

Extract raw YUV frames

ffmpeg -i input.mp4 -c:v rawvideo -pix_fmt yuv420p output.yuv
2

Extract raw RGB frames

ffmpeg -i input.mp4 -c:v rawvideo -pix_fmt rgb24 output.rgb
3

Extract individual PNG frames

ffmpeg -i input.mp4 frame_%04d.png

H.264/H.265 Decoding

FFmpeg’s native decoders handle H.264 and HEVC efficiently.
Decode H.264
ffmpeg -i input.mp4 -c:v rawvideo output.yuv
Decode HEVC/H.265
ffmpeg -i input_hevc.mp4 -c:v rawvideo output.yuv

Force Specific Decoder

Use native H.264 decoder
ffmpeg -c:v h264 -i input.mp4 output.avi
Use libdav1d for AV1
ffmpeg -c:v libdav1d -i input.mkv output.mp4
Explicitly specifying a decoder can improve performance for certain formats.

AV1 Decoding

FFmpeg supports AV1 decoding through multiple decoders.

Using libdav1d

libdav1d is a fast, optimized AV1 decoder.
ffmpeg -c:v libdav1d -i input.webm output.mp4

libdav1d Options

  • max_frame_delay: Maximum frames to buffer (0 = auto, lower = less latency)
  • filmgrain: Apply film grain if present in bitstream
  • operating_point: Select scalable AV1 operating point (0-31)
  • alllayers: Output all spatial layers
Film grain synthesis increases decoding time but preserves artistic intent in the encoded video.

Decoder Thread Control

Optimize decoding performance with threading options.
Auto thread detection
ffmpeg -threads 0 -i input.mp4 output.avi
Specific thread count
ffmpeg -threads 4 -i input.mp4 output.avi
Slice-level threading for H.264
ffmpeg -threads 8 -thread_type slice -i input.mp4 output.avi

Thread Types

  • frame: Decode multiple frames in parallel
  • slice: Decode slices within frames in parallel
  • slice+frame: Use both methods (default)
-threads 0 enables automatic detection of CPU cores and optimal thread allocation.

Hardware-Accelerated Decoding

Use GPU decoders for better performance and lower CPU usage.

Intel QSV Decoding

H.264 QSV decode
ffmpeg -c:v h264_qsv -i input.mp4 output.avi
HEVC QSV decode
ffmpeg -c:v hevc_qsv -i input.mp4 output.avi
AV1 QSV decode
ffmpeg -c:v av1_qsv -i input.mp4 output.avi

VAAPI Decoding (Linux)

ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -i input.mp4 output.avi

NVIDIA CUVID Decoding

H.264 CUVID
ffmpeg -c:v h264_cuvid -i input.mp4 output.avi
HEVC CUVID with scaling
ffmpeg -c:v hevc_cuvid -resize 1280x720 -i input.mp4 output.avi
1

Check hardware decoder availability

ffmpeg -hwaccels
2

List QSV decoders

ffmpeg -decoders | grep qsv
3

Test hardware decode

ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mp4 -f null -

Decode and Analyze

Extract information while decoding.

Get Frame Information

Show frame data
ffmpeg -i input.mp4 -vf showinfo -f null -
Extract frame timestamps
ffmpeg -i input.mp4 -vf "showinfo" -f null - 2>&1 | grep pts_time

Decode Specific Range

ffmpeg -ss 00:01:30 -i input.mp4 -frames:v 100 output_%04d.png

Rawvideo Decoder

Decode raw video data when format information is known.
Decode raw YUV
ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -i input.yuv output.mp4
Decode raw RGB
ffmpeg -f rawvideo -pix_fmt rgb24 -s 1280x720 -r 30 -i input.rgb output.mp4
Required parameters:
  • -pix_fmt: Pixel format (yuv420p, rgb24, etc.)
  • -s: Frame size (WxH)
  • -r: Frame rate (optional)
When decoding raw video, you must specify the pixel format and dimensions explicitly.

HEVC Multi-View Decoding

FFmpeg supports MV-HEVC for 3D/multi-view content.
Decode all views
ffmpeg -c:v hevc -view_ids -1 -i input_mv.mp4 output.mp4
Decode specific views
ffmpeg -c:v hevc -view_ids "0,1" -i input_mv.mp4 output.mp4

MV-HEVC Options

  • view_ids: Comma-separated view IDs to decode
  • -1: Decode all available views
  • view_ids_available: Query available view IDs

Decoder Error Handling

Control how decoders handle errors.
Ignore decode errors
ffmpeg -err_detect ignore_err -i corrupted.mp4 output.mp4
Strict error checking
ffmpeg -err_detect strict -i input.mp4 output.mp4
Continue on missing references
ffmpeg -err_detect +ignore_err -i damaged.mp4 -c copy repaired.mp4

Error Detection Flags

  • ignore_err: Ignore errors and continue
  • crccheck: Verify CRC checksums
  • bitstream: Check bitstream validity
  • buffer: Check buffer boundaries
  • explode: Abort on minor errors
Ignoring errors may result in visual artifacts or corrupted output. Use only when necessary.

Audio Decoding

FFmpeg decodes audio formats automatically.
ffmpeg -i input.mp3 output.wav

Decode Performance Tips

1

Use hardware acceleration

Hardware decoders significantly reduce CPU usage.
ffmpeg -hwaccel auto -i input.mp4 output.avi
2

Optimize thread count

Match threads to your CPU core count.
ffmpeg -threads 8 -i input.mp4 output.avi
3

Skip unnecessary processing

Use -c copy when re-encoding isn’t needed.
ffmpeg -i input.mp4 -c copy -ss 10 -t 30 output.mp4

Pixel Format Conversion

Convert between pixel formats during decoding.
YUV to RGB
ffmpeg -i input.mp4 -pix_fmt rgb24 output.avi
10-bit to 8-bit
ffmpeg -i input_10bit.mp4 -pix_fmt yuv420p output_8bit.mp4
Keep original format
ffmpeg -i input.mp4 -pix_fmt yuv444p output.avi

Common Pixel Formats

FormatDescriptionBits per pixel
yuv420pYUV 4:2:0 planar12
yuv422pYUV 4:2:2 planar16
yuv444pYUV 4:4:4 planar24
rgb24RGB 8-bit24
rgbaRGBA 8-bit32
nv12YUV 4:2:0 semi-planar12
Use ffmpeg -pix_fmts to list all supported pixel formats.

Debugging Decoder Issues

Verbose decoder output
ffmpeg -v debug -i input.mp4 -f null -
Show packet information
ffmpeg -i input.mp4 -vf "showinfo" -frames:v 10 -f null -
Check decoder capabilities
ffmpeg -h decoder=h264

Next Steps

Encoding

Learn encoding techniques and codecs

Hardware Acceleration

Use GPU decoders for better performance

Filtering

Process decoded frames with filters

Format Conversion

Convert between formats efficiently

Build docs developers (and LLMs) love