Hardware‑Accelerated FFmpeg: NVENC, VAAPI, and VideoToolbox
Tue Jul 16 2024
Speed up encodes on NVIDIA, Intel, and Apple hardware with sensible quality settings.
Hardware encoders can be multiple times faster than software, with some trade‑offs in compression efficiency. Here’s how to enable them on common platforms.
Pros and Cons
- Pros: speed, lower CPU usage.
- Cons: slightly lower compression efficiency than slow software presets; limited filter support on GPU.
Examples
# NVIDIA NVENC (H.264) ffmpeg -i in.mp4 -c:v h264_nvenc -preset p5 -rc vbr -cq 23 -b:v 5M -maxrate 7M -bufsize 10M \ -c:a aac -b:a 160k out_nvenc.mp4 # Intel VAAPI (Linux) ffmpeg -vaapi_device /dev/dri/renderD128 -i in.mp4 \ -vf 'format=nv12,hwupload,scale_vaapi=w=1920:h=1080' -c:v h264_vaapi -b:v 5M -c:a copy out_vaapi.mp4 # Apple VideoToolbox (macOS) ffmpeg -i in.mp4 -c:v h264_videotoolbox -b:v 5M -maxrate 7M -bufsize 10M \ -c:a aac -b:a 160k out_vt.mp4
Pitfalls
- Ensure drivers/devices are set up (Linux: permissions for
/dev/dri). - Not all filters run on GPU; sometimes frames must be uploaded/downloaded.
Use hardware when turnaround time matters; for maximum compression, software encoders at slower presets still win.