x264 Encoder Guide

FFmpeg parameters and quality settings for x264 video encoding

Overview

This guide provides FFmpeg parameters and quality settings for x264 video encoding across different frame rates. The x264 encoder is widely supported and offers excellent quality-to-filesize ratios.

Note: These recommendations are somewhat a matter of opinion and based on community consensus and testing. Your optimal settings may vary depending on your source material and specific goals.

FFmpeg Parameters by Frame Rate

Medium Preset (Default)

The encoder settings vary based on video frame rate. Each configuration specifies keyframe intervals and B-frame counts optimized for that framerate:

24 fps

-x264-params keyint=240:bframes=6:ref=4:me=umh:subme=9:no-fast-pskip=1:b-adapt=2:aq-mode=2

25 fps

-x264-params keyint=250:bframes=6:ref=4:me=umh:subme=9:no-fast-pskip=1:b-adapt=2:aq-mode=2

30 fps

-x264-params keyint=300:bframes=6:ref=4:me=umh:subme=9:no-fast-pskip=1:b-adapt=2:aq-mode=2

50 fps

-x264-params keyint=500:bframes=7:ref=4:me=umh:subme=9:no-fast-pskip=1:b-adapt=2:aq-mode=2

60 fps

-x264-params keyint=600:bframes=7:ref=4:me=umh:subme=9:no-fast-pskip=1:b-adapt=2:aq-mode=2

Very Slow Preset

For maximum quality encoding with the veryslow preset, I only recommend setting two additional parameters:

  • keyint - Set to 10× your frame rate
  • aq-mode - Set to 2 for better quality distribution

The veryslow preset already includes optimal values for most other parameters, so additional tuning is generally unnecessary.

Example (30 fps)

-preset veryslow -x264-params keyint=300:aq-mode=2

For other frame rates, simply adjust the keyint value accordingly (e.g., 240 for 24fps, 600 for 60fps).

Quality Settings (CRF Values)

The x264 encoder uses Constant Rate Factor (CRF) as a rate control mode that prioritizes consistent visual quality over fixed bitrate. The encoder dynamically allocates more bits to complex scenes while using fewer for simpler ones, resulting in variable bitrate output.

CRF Scale

  • Range: 0 to 51, where lower values mean higher quality (larger files) and higher values mean lower quality (smaller files)
  • Default: 23 offers a good balance of quality and efficiency
  • Lossless: 0 for lossless encoding (8-bit only; use -qp 0 for 10-bit)
  • A change of ±6 in CRF typically halves or doubles the bitrate

Note: CRF values are not directly comparable across codecs (x264 CRF 23 ≈ x265 CRF 28).

Recommended CRF by Purpose and Resolution

Higher resolutions can often tolerate higher CRF values due to better compression efficiency at scale:

Purpose/Use Case CRF Range Typical Resolution Notes
High-Quality Archival 16–20 Any (720p+) Near-transparent quality; larger files. For source preservation or upscale viewing
Visually Transparent 18–23 480p–1080p Indistinguishable from source to most viewers; CRF 18 for demanding content
General/Balanced 20–24 720p–1080p Good for Blu-ray rips, personal libraries. CRF 21–23 recommended baseline
Efficient Compression 24–28 1080p–4K Smaller files with minimal visible loss; suitable for web sharing
Low-Bitrate/Streaming 28+ 480p–720p Mobile/web distribution; test for artifacts. Avoid exceeding 30

Resolution-Specific Guidelines

  • Standard Definition (480p/576p): CRF 18–22 helps combat upscaling artifacts on HD displays
  • 720p HD: CRF 19–23, with 19–20 for movies to maintain detail
  • 1080p Full HD: CRF 20–24, the sweet spot for most consumer encodes
  • 4K UHD (2160p): CRF 22–28, leveraging codec efficiency at high resolutions

Recommended baseline: CRF 21 is a suggested starting point. For live-action content, apply film tuning (-tune film). Always test a short clip and evaluate quality before encoding your full video.

Essential x264 Parameters

These settings consistently improve encoding quality:

  • Motion estimation (me=umh) - Uses uneven multi-hexagon search for better motion vectors
  • Subpixel refinement (subme=9) - Maximum quality subpixel motion estimation
  • B-frame adaptation (b-adapt=2) - Optimal B-frame placement
  • Adaptive quantization (aq-mode=2) - Better quality distribution across the frame
  • P-frame skip disabled (no-fast-pskip=1) - Prevents quality loss from skipped macroblocks
  • Reference frames (ref=4) - Number of previous frames to reference

Complete Example Command

Here's a complete FFmpeg command for 30fps content:

ffmpeg -i input.mp4 \
  -c:v libx264 \
  -crf 21 \
  -tune film \
  -x264-params keyint=300:bframes=6:ref=4:me=umh:subme=9:no-fast-pskip=1:b-adapt=2:aq-mode=2 \
  -c:a aac -b:a 192k \
  output.mp4

Notes

  • The keyint value should generally be set to 10× the frame rate for optimal seeking
  • Higher bframes values (7 for 50/60fps) can improve compression efficiency at higher framerates
  • The tune parameter should match your content type (film, animation, grain, etc.)