| layout | default |
|---|---|
| nav_order | 4.2 |
| title | HEVC/H.265 Encoding |
| parent | Codec Comparisons |
Table of contents
{: .text-delta } 1. TOC {:toc}H.265 (High Efficiency Video Coding - HEVC) is one of the replacements for H.264. It allows for a reduction of file size compared to H.264 of 25-50% and supports frame formats up to 8K (UHDTV). It also has support for HDR, which we go into more here.
In our tests on macOS, Safari, Chrome and Firefox all played HEVC. Browsers generally rely on the operating system or GPU to decode it, so support varies from machine to machine; see the note under Codecs reviewed.
There are four HEVC encoders available to FFmpeg:
- libx265
- hevc_videotoolbox - Available on MacOS via the videotoolbox library.
- hevc_nvenc - NVIDIA GPU encoder.
- hevc_qsv - Intel Quick Sync Video Acceleration.
Supported pixel formats (FFmpeg 9.0): yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p gbrp yuv420p10le yuv422p10le yuv444p10le gbrp10le yuv420p12le yuv422p12le yuv444p12le gbrp12le gray gray10le gray12le
Example encoding:
ffmpeg -r 24 -start_number 1 -i inputfile.%04d.png -frames:v 200 -c:v libx265 \
-pix_fmt yuv420p10le -crf 22 -preset slow \
-vf "zscale=matrix=709:range=limited:filter=lanczos,setparams=color_primaries=bt709:color_trc=iec61966-2-1" \
-color_range tv -colorspace bt709 -color_primaries bt709 -color_trc iec61966-2-1 \
-movflags +faststart -y outputfile.mp4| Flag | Description |
|---|---|
| -preset slow | Can be one of ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow and placebo |
| -crf 22 | Similar to H.264, default is 28 which is on the low quality side |
| -x265-params lossless=1 | Does lossless encoding, -crf 0 is not required |
| -tag:v hvc1 | Tag the file as hvc1, which Apple players (QuickTime Player, Safari) need to play HEVC in MP4/MOV |
| -profile:v main | Profile can be one of main or main10 or main12 |
| -movflags +faststart | faststart re-organizes the mp4 file, so that it doesn't have to read the whole file to start playback, useful for streaming. It can add a second or so to do this, since it does require re-writing the file. |
| -vf "zscale=...,setparams=..." | Convert the RGB images to BT.709 Y'CbCr with zscale and tag the result; see FFmpeg zscale Filter. The -color_* flags are then not needed, but are harmless. |
To help pick appropriate values with the CRF flag, we have run the Test Framework through some of the reference media.
If you are trying to map crf values from H.264, VS_Fan came up with the following remapping formula:
x265_crf(x264_crf) = 1.09 * x264_crf − 4.19|
This is showing CRF values against encoding time. |
|
This is showing CRF values against file size. |
|
This is showing CRF values against VMAF harmonic mean |
Below is showing a comparison of different preset values with a crf value of 18. It shows that you really can just encode with -preset medium or -preset slow anything higher is really not gaining you anything.
|
This is showing preset values against encoding time. |
|
This is showing preset values against file size. |
|
This is showing preset values against VMAF harmonic mean |
Supported pixel formats (FFmpeg 9.0): nv12 yuv420p bgra ayuv p010le p210le
Supported pixel formats: yuv420p nv12 p010le yuv444p p016le yuv444p16le bgr0 bgra rgb0 rgba x2rgb10le x2bgr10le gbrp gbrp16le cuda d3d11
https://gist.github.com/jbboehr/f487b659cac086b176703c718d797f3b https://superuser.com/questions/1296374/best-settings-for-ffmpeg-with-nvenc