Table of Contents

ffmpeg - Encoding - h265 - Constant Rate Factor (CRF)

Use this mode to retain good visual quality and do not care about the exact bitrate or filesize of the encoded file.


ffmpeg -i "input.mkv" -map 0:v -map 0:a:m:language:eng? -map 0:s:m:language:eng? -map 0:d? -map 0:t? -c:v libx265 -crf 23 -c:a copy -threads 12 -bufsize 4M "out.mkv"

Example

ffmpeg -i input -c:v libx265 -crf 26 -preset fast -c:a aac -b:a 128k output.mp4

NOTE:

  • -crf: CRF affects the quality.
    • The default is 28, and it should visually correspond to libx264 video at CRF 23, but result in about half the file size.
    • CRF works just like in x264, so choose the highest value that provides an acceptable quality.
  • -preset fast: Choose a preset.
    • The default is medium.
    • The preset determines compression efficiency and therefore affects encoding speed.
    • Valid presets are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, and placebo.
      • Use the slowest preset you have patience for.
      • Ignore placebo as it provides insignificant returns for a significant increase in encoding time.
  • -tune: Choose a tune (optional).
    • By default, this is disabled, and it is generally not required to set a tune option.
    • x265 supports the following -tune options: psnr, ssim, grain, zerolatency, fastdecode.

References

https://trac.ffmpeg.org/wiki/Encode/H.264#crf