x265 (HEVC) Encoder Guide
Configuration recommendations for x265 video encoding in FFmpeg
Overview
This guide provides configuration recommendations for x265 (HEVC) video encoding within FFmpeg workflows. The x265 encoder offers superior compression compared to x264, making it ideal for high-resolution content and archival purposes.
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.
Quality Settings (CRF Values)
The x265 encoder uses Constant Rate Factor (CRF) mode to maintain consistent perceptual quality by dynamically allocating bitrate. x265 offers 25–50% better compression efficiency than x264 at equivalent quality levels.
CRF Scale
- Range: 0 to 51, where lower values mean higher quality (larger files) and higher values mean lower quality (smaller files)
- Default: 28 offers a balanced starting point
- Lossless: 0 for lossless encoding (use
-qp 0for 10-bit) - A change of ±6 in CRF typically halves or doubles the bitrate
- Compared to x264: x265 CRF 28 ≈ x264 CRF 23 (general rule: add ~5 to x264 values)
Recommended CRF by Purpose and Resolution
x265's superior efficiency allows higher CRF values for equivalent quality. Slower presets improve quality at a given CRF without increasing file size significantly.
| Purpose/Use Case | CRF Range | Typical Resolution | Notes |
|---|---|---|---|
| High-Quality Archival | 20–25 | Any (1080p+) | Near-lossless preservation; CRF 20 with veryslow preset for critical sources like 4K HDR. 40–50% smaller than x264 equivalents |
| Visually Transparent | 23–28 | 720p–2160p | Indistinguishable from source; CRF 23 for film-like content, 28 default for most. Matches x264 18–23 visually |
| General/Balanced | 25–30 | 1080p–4K | Everyday use like Blu-ray rips or personal libraries; start at 28 |
| Efficient Compression | 28–33 | 1080p–4K | Smaller files with minimal artifacts; ideal for sharing or moderate storage. Test at 30 for 4K |
| Low-Bitrate/Streaming | 32+ | 480p–720p | Bandwidth-focused; avoid >35 to prevent visible loss in motion |
Resolution-Specific Guidelines
- Standard Definition (480p/576p): CRF 23–27 to counter artifacts on larger displays
- 720p HD: CRF 24–28, with 25 for balanced streaming
- 1080p Full HD: CRF 25–29, versatile for most consumer setups
- 4K UHD (2160p): CRF 26–32, leveraging HEVC's strengths; lower (22–26) for HDR/10-bit content
Recommended baseline: CRF 28 is a good starting point. For high-quality archival or transparent encodes, use CRF 23–25. Always test a short clip and evaluate quality before encoding your full video.
Frame-Rate-Specific Parameters
Medium Preset
The encoding parameters adjust based on frame rates to optimize GOP structure and B-frame usage. These parameters are optimized for the medium preset:
24 fps
-x265-params no-open-gop=1:keyint=240:gop-lookahead=12:bframes=6:weightb=1:hme=1:strong-intra-smoothing=0:rect=0:aq-mode=4
25 fps
-x265-params no-open-gop=1:keyint=250:gop-lookahead=12:bframes=6:weightb=1:hme=1:strong-intra-smoothing=0:rect=0:aq-mode=4
30 fps
-x265-params no-open-gop=1:keyint=300:gop-lookahead=12:bframes=6:weightb=1:hme=1:strong-intra-smoothing=0:rect=0:aq-mode=4
50 fps
-x265-params no-open-gop=1:keyint=500:gop-lookahead=11:bframes=7:weightb=1:hme=1:strong-intra-smoothing=0:rect=0:aq-mode=4
60 fps
-x265-params no-open-gop=1:keyint=600:gop-lookahead=11:bframes=7:weightb=1:hme=1:strong-intra-smoothing=0:rect=0:aq-mode=4
General Parameter Recommendations
Universal settings across all framerates include:
- Closed GOP structure (
no-open-gop=1) - Enforces closed GOP for better seeking and editing compatibility - Keyframe interval (
keyint) - Set to 10× the frame rate for optimal seeking - GOP lookahead (
gop-lookahead) - 12 for lower framerates, 11 for 50/60fps - B-frames (
bframes) - 6 for standard framerates, 7 for high framerates (50/60fps) - Weighted prediction (
weightb=1) - Enables weighted prediction in B-frames for better compression - Hierarchical motion estimation (
hme=1) - Activates hierarchical ME for improved motion vectors - Strong intra smoothing (
strong-intra-smoothing=0) - Disabled for better quality - Rectangular partitions (
rect=0) - Disabled to prevent certain compression artifacts - Adaptive quantization (
aq-mode=4) - Uses variance and edge detection for optimal quality distribution
Complete Example Command
Here's a complete FFmpeg command for 30fps content with medium preset:
ffmpeg -i input.mp4 \
-c:v libx265 \
-crf 28 \
-preset medium \
-x265-params no-open-gop=1:keyint=300:gop-lookahead=12:bframes=6:weightb=1:hme=1:strong-intra-smoothing=0:rect=0:aq-mode=4 \
-c:a aac -b:a 192k \
output.mp4
Notes
- x265 encoding is significantly slower than x264 but produces smaller files at equivalent quality (25–50% better compression)
- For 10-bit encoding, add
-pix_fmt yuv420p10lebefore the codec selection (recommended for 4K HDR content) - The parameters shown here are optimized for the
mediumpreset, balancing quality and encoding speed - Preset options: Use
-preset slowor-preset veryslowfor better quality at the same CRF (improves compression efficiency without significantly increasing file size). Faster presets likefastorveryfastspeed up encoding but reduce compression efficiency - The frame-rate-specific parameters prioritize quality over encoding speed and are compatible with the medium preset