HEVC (H.265) Video Codec Practical Guide | 4K, 8K, x265, FFmpeg Tuning
이 글의 핵심
HEVC can significantly reduce bits vs H.264 at same quality, advantageous for 4K/8K and HDR, but license and device compatibility must be designed together.
Introduction
HEVC (H.265) is a next-generation general-purpose codec aiming for roughly 25-50% bitrate reduction vs H.264 (varies by content, settings, and measurement criteria). Particularly often reviewed for 4K/8K UHD broadcasting, HDR10/HLG, and mobile storage savings.
However, licensing and patent pool issues and old device and web browser compatibility are more difficult than H.264. This guide organizes practical encoding and decision points from the perspective of “capture compression efficiency while controlling deployment risk”.
After Reading This
- Explain HEVC’s spatial and temporal prediction structure with CTU, CU/PU/TU concepts
- Connect profile selection like Main / Main 10 with FFmpeg (x265, NVENC) tuning
- Judge bit reduction vs compatibility tradeoff in 4K/8K and HDR pipelines
- Organize position and failure patterns in OTT, mobile, and browsers
Table of Contents
- Codec Overview
- Compression Principles
- Practical Encoding
- Performance Comparison
- Real-World Use Cases
- Optimization Tips
- Common Issues and Solutions
- Conclusion
Codec Overview
History and Development Background
HEVC was standardized by JCT-VC (Joint Collaborative Team on Video Coding) and documented as ISO/IEC 23008-2 (MPEG-H Part 2) and ITU-T H.265. Design goals are efficiency improvement vs H.264 and parallel processing-friendly structure for UHD, high frame, and high bit depth.
Technical Features
- CTU (Coding Tree Unit): Uses recursively divisible block tree from maximum 64×64 (typical) instead of H.264’s macroblock.
- CU / PU / TU: Separates coding unit, prediction unit, and transform unit to match complex textures and boundaries.
- Enhanced intra/inter prediction: More directional modes, Merge/Skip, etc., reduce motion information bits.
- Large transforms, SAO/ALF (by implementation and profile): Aim for artifact mitigation and compression efficiency simultaneously.
Major Profiles and Levels
| Profile | Summary | Practical Note |
|---|---|---|
| Main | 8-bit 4:2:0 | Widely used for general VOD and broadcasting |
| Main 10 | 10-bit 4:2:0 | Advantageous for HDR, grading, banding mitigation |
| Main Still Picture | Still image optimization | Photos, slides, etc. |
Tier and Level specify resolution, fps, and bitrate limits. Higher requirements like 4K 60fps HDR require checking decoder specs first.
Compression Principles
Intra / Inter Prediction
- Intra: Directional prediction modes more refined than H.264, better efficiency for flat areas and straight boundaries.
- Inter: Merge mode shares same motion with adjacent blocks, reducing motion vector coding bits.
Transform & Quantization
Uses larger TU (e.g., 32×32) and integer DCT/DST family transforms. Quantization works with rate control (x265’s CRF, AQ, etc.) to redistribute bits to visually sensitive areas.
Entropy Coding
CABAC-centric, with enhanced context adaptation tending to use fewer bits than H.264 (decoding complexity increases).
Compression Pipeline Diagram
flowchart TB
subgraph frame [Frame Input]
F[YUV / RGB Conversion]
end
subgraph tree [Spatial Partitioning]
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 Priority: libx265 + CRF (8-bit 420)
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 is practically 24~28 range often (CRF number meaning is not same as H.264, so direct visual comparison is important).
-tag:v hvc1: Often recommended for MP4 quality in some Apple ecosystem and players (verify by environment).
Main 10 (10-bit): HDR and Grading Pipeline
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
If source is 8-bit, quality does not magically improve from bit depth up-conversion alone. Decide matching source and mastering stage.
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
-cq and -preset meanings may differ by driver and FFmpeg version, so always check with ffmpeg -h encoder=hevc_nvenc.
Parameter Tuning Guide
| Situation | Direction |
|---|---|
| Fine texture | Slightly lower CRF or review AQ-related options (encoder docs) |
| Low latency | Reduce B-frame count, faster preset, small buffer |
| Archive | Slow preset, 2-pass (when fixed bitrate target) |
Quality vs Speed Tradeoff
- HEVC often has higher encoding cost than H.264 for same quality. Offline VOD uses slow preset, real-time uses GPU encoder realistically.
- Comparing at same file size, HEVC is often advantageous in PSNR/SSIM/VMAF, but final judgment is visual viewing.
Performance Comparison
Compression Ratio vs Other Codecs
In practice, matching bitrate to same VMAF/SSIM target is common. Generally understand as H.264 < HEVC ≤ AV1 (order varies by content, encoder, settings).
Encoding and Decoding Speed
- Encoding: libx265 can be very slow (especially high resolution and slow preset). Batch pipelines consider multi-process and distributed queue.
- Decoding: Modern SoC and GPU widely support HEVC 4K and HDR HW decoding. Old PCs may have heat and fan noise with CPU software decoding.
Hardware Acceleration Support
- Intel: Quick Sync HEVC decoding/encoding (varies by generation)
- NVIDIA: HEVC NVENC/NVDEC
- Apple: VideoToolbox
- Mobile SoC: Almost standard (but 10-bit and HDR metadata differ by model)
Real-World Use Cases
Streaming Services (YouTube, Netflix, etc.)
- 4K HDR content often uses HEVC and AV1 together, and may maintain H.264 ladder for old devices.
- In DRM and DASH/HLS packaging, codec tags, segment length, and keyframe interval greatly affect playback stability.
Mobile Apps
- Latest iPhone and Android devices often have HEVC recording and playback as default option. For app distribution, design with H.264 fallback is safe depending on old OS user ratio.
Web Browser Support
- HEVC in MP4 playback depends on OS, GPU, and browser build. If targeting wide web only, H.264 or AV1 (with fallback) strategy is often simpler.
4K/8K Broadcasting
# 4K HEVC Main 10 for HDR
ffmpeg -i input_4k_hdr.mov -c:v libx265 -crf 20 -preset slow \
-pix_fmt yuv420p10le -tag:v hvc1 \
-color_primaries bt2020 -color_trc smpte2084 -colorspace bt2020nc \
-c:a aac -b:a 256k output_4k_hdr.mp4
Optimization Tips
Reduce File Size While Maintaining Quality
- Confirm resolution and fps first, then adjust CRF/bitrate.
- HDR: Preserve transfer function (PQ/HLG) and metadata matching mastering tone in pipeline.
Improve Encoding Speed
- Increase preset (slow → medium → fast).
- Switch to GPU encoder then VMAF/visual check.
- Frame workers: Tune CPU core utilization with x265’s
--poolsand-x265-params(check FFmpeg build and version docs).
Batch Processing Automation
#!/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 audio re-encoding to save time, but container compatibility must be verified.
Advanced Encoding Options
# HDR10 with color metadata
ffmpeg -i input_hdr.mov -c:v libx265 -crf 20 -preset slow \
-pix_fmt yuv420p10le -tag:v hvc1 \
-color_primaries bt2020 -color_trc smpte2084 -colorspace bt2020nc \
-x265-params "hdr-opt=1:repeat-headers=1" \
-c:a aac -b:a 256k output_hdr.mp4
# 2-pass for precise bitrate control
ffmpeg -y -i input.mov -c:v libx265 -b:v 10M -preset medium -pass 1 -an -f mp4 NUL
ffmpeg -i input.mov -c:v libx265 -b:v 10M -preset medium -pass 2 -tag:v hvc1 -c:a aac -b:a 192k output.mp4
Common Issues and Solutions
Compatibility Issues
- “Plays but colors are strange”: May be color range (tv vs pc), metadata (BT.709/2020), player tone mapping issue. Maintain consistent color tags from master file.
- Does not open on web: May be browser and OS combination issue, consider H.264/AV1 parallel.
# Force color metadata
ffmpeg -i input.mov -c:v libx265 -crf 24 -preset medium \
-pix_fmt yuv420p -tag:v hvc1 \
-color_primaries bt709 -color_trc bt709 -colorspace bt709 \
-c:a aac -b:a 192k output.mp4
Quality Degradation Issues
- Low bitrate 4K: Artifacts easily appear in fine grass and ripples. Adjust bitrate, resolution, and CRF together.
- x265 vs NVENC: Quality curves differ even at same number settings. Compare matching same VMAF.
# Increase bitrate for complex 4K content
ffmpeg -i input_4k.mov -c:v libx265 -b:v 20M -maxrate 25M -bufsize 50M \
-preset medium -pix_fmt yuv420p -tag:v hvc1 -c:a aac -b:a 256k output.mp4
Licensing Considerations
- HEVC has long-standing discussions about patent pools and licensing programs, and commercial distribution and hardware may need legal review. Safe to not conclude “open-source encoder = free use”.
Playback Issues
# Check HEVC stream info
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,profile,level,pix_fmt,color_space,color_transfer,color_primaries -of default=noprint_wrappers=1 video.mp4
# Verify HDR metadata
ffprobe -v error -select_streams v:0 -show_entries stream_side_data -of json video.mp4
Conclusion
Key Summary
- HEVC has strengths in 4K/8K, HDR, and storage/transmission cost reduction.
- Tool selection like x265, NVENC, VideoToolbox and profile (especially Main 10) determine practical results.
- If covering web and old devices all at once, include H.264/AV1 fallback in design.
Recommended Use Scenarios
- 4K library storage, mobile download size reduction, internal UHD streaming — HEVC is very practical in decoder-controlled environments. If lowest compatibility web distribution is goal, compare multi-codec strategy together with H.264 Guide and AV1 Guide.
Quick Command Reference
# High quality 4K archive (Main 10)
ffmpeg -i input_4k.mov -c:v libx265 -crf 20 -preset slow -pix_fmt yuv420p10le -tag:v hvc1 -c:a aac -b:a 256k output.mp4
# Web streaming (8-bit)
ffmpeg -i input.mov -c:v libx265 -crf 26 -preset medium -pix_fmt yuv420p -tag:v hvc1 -c:a aac -b:a 128k output.mp4
# Hardware encoding (NVENC)
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
# HDR10 with metadata
ffmpeg -i input_hdr.mov -c:v libx265 -crf 20 -preset slow -pix_fmt yuv420p10le -tag:v hvc1 \
-color_primaries bt2020 -color_trc smpte2084 -colorspace bt2020nc \
-x265-params "hdr-opt=1:repeat-headers=1" -c:a aac -b:a 256k output_hdr.mp4
Related Posts
- H.264 (AVC) Complete Guide
- AV1 Next-Generation Codec Guide
- H.264 vs HEVC vs AV1 Comparison
Keywords
HEVC, H.265, Video Codec, 4K, 8K, HDR, FFmpeg, libx265, NVENC, Compression Efficiency, Main 10, CTU, Streaming