HEVC (H.265) in Practice | 4K/8K, x265, FFmpeg Tuning & Hardware
이 글의 핵심
HEVC cuts bitrate versus H.264 for the same quality—great for 4K/8K and HDR, but plan for licensing and device support.
Introduction
HEVC (H.265) targets roughly 25–50% bitrate savings vs H.264 (depends on content, settings, and how you measure). It is common for 4K/8K UHD, HDR10/HLG, and saving storage on mobile.
Tradeoffs include patent pools, licensing, and older devices and browsers compared with H.264. This guide focuses on practical encoding and decision points: compress efficiently, control delivery risk.
After reading this post
- Describe HEVC using CTU, CU/PU/TU and spatial/temporal structure
- Connect Main / Main 10 profiles to FFmpeg (x265, NVENC) settings
- Reason about 4K/8K HDR: bitrate savings vs compatibility
- Place HEVC for OTT, mobile, and browsers and typical failure patterns
Table of contents
- Codec overview
- How compression works
- Practical encoding
- Performance comparison
- Real-world use cases
- Optimization tips
- Common problems
- Wrap-up
Codec overview
History and background
HEVC was standardized by JCT-VC, documented as ISO/IEC 23008-2 (MPEG-H Part 2) and ITU-T H.265. Goals include better efficiency than H.264 for UHD, high frame rates, and higher bit depth, plus a parallel-friendly structure.
Technical characteristics
- CTU (Coding Tree Unit): Instead of fixed macroblocks, HEVC uses trees split recursively from up to 64×64 (typical).
- CU / PU / TU: Separate coding, prediction, and transform units for complex texture and edges.
- Richer intra/inter prediction: More directional modes, Merge/Skip to save motion bits.
- Larger transforms, SAO/ALF (profile/implementation dependent): Artifact reduction and efficiency.
Profiles and levels
| Profile | Summary | Practice note |
|---|---|---|
| Main | 8-bit 4:2:0 | Broad VOD and broadcast |
| Main 10 | 10-bit 4:2:0 | HDR, grading, less banding |
| Main Still Picture | Still-image optimization | Photos, slides |
Tier and Level cap resolution, fps, and bitrate. For 4K 60 HDR, verify decoder specs first.
How compression works
Intra / inter prediction
- Intra: More directional modes than H.264—efficient on flat regions and straight edges.
- Inter: Merge shares motion with neighbors to reduce motion-vector cost.
Transform & quantization
Larger TUs (e.g. 32×32) and integer DCT/DST-like transforms. Quantization ties to rate control (x265 CRF, AQ, …) to spend bits where viewers notice.
Entropy coding
CABAC with stronger context adaptation—typically fewer bits than H.264 at the cost of higher decode complexity.
Pipeline (conceptual)
flowchart TB
subgraph frame [Frame input]
F[YUV / RGB conversion]
end
subgraph tree [Spatial split]
CTU[CTU 64x64]
SPLIT[Recursive CU split]
end
subgraph predict [Prediction]
PRED[Intra / inter + merge]
end
subgraph coeff [Coefficients]
TQ[Transform & quantize]
end
subgraph stream [Bitstream]
CABAC[CABAC]
NAL[HEVC NAL units]
end
F --> CTU
CTU --> SPLIT
SPLIT --> PRED
PRED --> TQ
TQ --> CABAC
CABAC --> NAL
Practical encoding
Quality-first: libx265 + CRF (8-bit 4:2:0)
ffmpeg -i input.mov -c:v libx265 -crf 24 -preset slow -tag:v hvc1 \
-pix_fmt yuv420p -c:a aac -b:a 192k output.mp4
- CRF: x265 often lands in 24–28 in practice (not comparable numerically to x264—visual comparison matters).
-tag:v hvc1: Often recommended for Apple ecosystems and some MP4 players—verify per environment.
Main 10 (10-bit): HDR / grading pipelines
ffmpeg -i input.mov -c:v libx265 -crf 22 -preset slow -pix_fmt yuv420p10le \
-tag:v hvc1 -c:a aac -b:a 192k output.mp4
Upscaling 8-bit to 10-bit alone does not magically improve quality—align with source and mastering.
Target bitrate (4K VOD example)
ffmpeg -i input_4k.mov -c:v libx265 -b:v 15M -maxrate 20M -bufsize 40M \
-preset medium -pix_fmt yuv420p -tag:v hvc1 -c:a aac -b:a 192k output.mp4
NVIDIA NVENC (speed)
ffmpeg -hwaccel cuda -i input.mov -c:v hevc_nvenc -rc vbr -cq 26 -preset p5 \
-pix_fmt yuv420p -c:a aac -b:a 192k output.mp4
Always run ffmpeg -h encoder=hevc_nvenc—-cq and -preset semantics vary.
Tuning cheat sheet
| Situation | Direction |
|---|---|
| Fine texture | Slightly lower CRF or tune AQ (encoder docs) |
| Low latency | Fewer B-frames, faster preset, smaller buffer |
| Archive | Slower preset, two-pass for fixed bitrate targets |
Quality vs speed
- HEVC encodes cost more than H.264 at the same quality. Offline VOD favors slow presets; realtime favors GPU encoders.
- At matched file size, HEVC often wins PSNR/SSIM/VMAF—still validate by eye.
Performance comparison
Compression vs other codecs
In production, people often match VMAF or SSIM and compare bitrates. Generally H.264 < HEVC ≤ AV1 (content- and encoder-dependent).
Encode and decode speed
- Encode: libx265 can be very slow (high resolution, slow presets). Batch pipelines may need multi-process or distributed queues.
- Decode: Modern SoCs and GPUs widely support 4K HDR HEVC in hardware. Old PCs may CPU-decode with heat and fan noise.
Hardware acceleration
- Intel: Quick Sync HEVC decode/encode (generation-dependent)
- NVIDIA: HEVC NVENC/NVDEC
- Apple: VideoToolbox
- Mobile SoCs: Often standard, but 10-bit and HDR metadata vary by model
Real-world use cases
Streaming (YouTube, Netflix, etc.)
- 4K HDR often uses HEVC and AV1 together; H.264 ladders remain for legacy clients.
- DRM, DASH/HLS packaging: Codec tags, segment duration, and keyframe interval strongly affect stability.
Mobile apps
- Recent iPhone and Android often default to HEVC for capture. For apps, H.264 fallback is still safe when old OS share matters.
Web browsers
- HEVC in MP4 varies by OS, GPU, and browser build. For web-only reach, H.264 or AV1 (with fallback) is often simpler.
Optimization tips
Smaller files without trashing quality
- Fix resolution and fps, then tune CRF/bitrate.
- For HDR, preserve transfer function (PQ/HLG) and metadata through the pipeline.
Faster encoding
- Move preset toward faster (slow → medium → fast).
- Move to GPU encode and re-check VMAF / visual quality.
- Use x265
--pools/-x265-paramsfor CPU parallelism (check FFmpeg docs).
Batch example
#!/usr/bin/env bash
set -euo pipefail
mkdir -p hevc_out
for f in *.mkv; do
ffmpeg -y -i "$f" -c:v libx265 -crf 26 -preset medium -pix_fmt yuv420p \
-tag:v hvc1 -c:a copy "hevc_out/${f%.mkv}.mp4"
done
-c:a copy avoids re-encoding audio but validate container compatibility.
Common problems
Compatibility
- “Plays but colors look wrong”: Check color range (TV vs PC), metadata (BT.709 vs BT.2020), and player tone mapping. Keep consistent color tags from the master.
- “Won’t play on the web”: Often browser + OS—consider H.264/AV1 alongside HEVC.
Quality
- Low-bitrate 4K: Grass, water, and fine detail show artifacts—raise bitrate, adjust resolution, or tune CRF.
- x265 vs NVENC: Same numeric settings do not mean the same quality curve—match VMAF when comparing.
Licensing
- HEVC has long-standing patent pool discussions. Commercial distribution and hardware may require legal review. “Open-source encoder” ≠ “free to use everywhere.”
Wrap-up
Summary
- HEVC shines for 4K/8K, HDR, and storage/transmission savings.
- x265, NVENC, VideoToolbox, and profile choice (especially Main 10) drive real-world results.
- If you must cover web and old devices, design H.264/AV1 fallback.
When to choose HEVC
- 4K libraries, mobile download size, controlled UHD intranets. For minimum-compatibility web, compare with the H.264 guide and AV1 guide for a multi-codec strategy.