Ch. 13 · Hardware Encoders

한국어日本語
8 min

ffmpeg Hardware Encoding Option Examples

We look at a representative command for each vendor and point out how they differ from the software command. The option numbers are examples and need to be re-tuned for each machine.

The examples below show the shape of the command. The input file and bitrate numbers are just placeholders, so change them to fit your own hardware and video. Option names can vary with the ffmpeg version and driver, so if you get stuck, check your build's own help first, for example ffmpeg -h encoder=hevc_nvenc.

The baseline: software x265

Software encoding with CRF (Chapters 3 and 10)
ffmpeg -i input.mp4 -c:v libx265 -preset slow -crf 22 -c:a copy output.mp4

NVIDIA: NVENC

hevc_nvenc: quality-target (cq) mode
ffmpeg -i input.mp4 -c:v hevc_nvenc -preset p5 -rc vbr -cq 28 -b:v 0 -c:a copy output.mp4

-preset p1 to p7: the higher the number, the slower it is and the more it favors quality. The -cq value is not on the same scale as x265's -crf. The same number won't give the same quality, so you have to measure to pick a value. HEVC encoding requires that GPU generation to support HEVC encoding; if it doesn't, use h264_nvenc.

Intel: Quick Sync

hevc_qsv: global_quality mode
ffmpeg -i input.mp4 -c:v hevc_qsv -preset slower -global_quality 25 -c:a copy output.mp4

AMD: AMF

hevc_amf: set a bitrate, quality-first mode
ffmpeg -i input.mp4 -c:v hevc_amf -quality quality -b:v 6M -c:a copy output.mp4

Apple: VideoToolbox

hevc_videotoolbox: set a bitrate
ffmpeg -i input.mp4 -c:v hevc_videotoolbox -b:v 6M -tag:v hvc1 -c:a copy output.mp4

-tag:v hvc1 is a tag commonly added so that Apple devices and QuickTime-family players recognize HEVC stored in MP4.

Linux: VAAPI

h264_vaapi: upload frames to GPU memory, then encode
ffmpeg -vaapi_device /dev/dri/renderD128 -i input.mp4 -vf 'format=nv12,hwupload' -c:v h264_vaapi -qp 24 -c:a copy output.mp4
Be careful when copying commands

The commands above are written on one line. If you split a long command across lines, in bash the line break must come immediately after the \ at the end of the line. If you put a space or a # comment after the \, the command breaks off there and fails. Put your notes on a separate line above the command.

How it differs from the software command

  • Preset names differ. Instead of x265's ultrafast through placebo, each vendor uses its own system (p1–p7, quality/speed, and so on).
  • The quality knob differs. Many encoders have no CRF and use cq, global_quality, QP, or a set bitrate instead. Even the same number is on a different scale.
  • Memory location matters when you mix in video filters. Some paths, like VAAPI, require uploading frames to GPU memory, and then the filter chain looks different from the software case.

If assembling commands is a hassle, it's easy to build the software baseline with the ffmpeg command builder, then swap in only the encoder name and quality option from the examples above.

hwuploadHardware upload

An ffmpeg filter that uploads frames from CPU memory to GPU memory. Used in VAAPI encoding and elsewhere.

cq (constant quality)Constant quality target

NVENC's quality-target option. Similar in idea to CRF, but the values are on a different scale.

global_qualityglobal_quality

The quality-target option of the Quick Sync encoder. Lower values mean higher quality.

Check yourself

What happens if you change -c:v libx265 -crf 22 to -c:v hevc_nvenc -cq 22?