Encode H.264 and HEVC With VAAPI in FFmpeg on Linux
Encode H.264 and HEVC on Intel and AMD GPUs in FFmpeg 7.1 with h264_vaapi and hevc_vaapi: device setup, hwupload, rate control and keeping frames on the GPU.

VAAPI, the Video Acceleration API, is the Linux interface to the video engines on Intel and AMD GPUs. FFmpeg 7.1 exposes it through the encoders h264_vaapi and hevc_vaapi, plus av1_vaapi and vp9_vaapi on hardware that supports them. VAAPI encoding differs from software encoding in one way that trips up almost everyone the first time: the encoder does not take ordinary frames. It takes frames that live on the GPU, in a surface format such as NV12, so every command needs a step that uploads the picture. This post sets up the device, shows the minimal command, explains hwupload, covers the rate control options and finishes with a pipeline that keeps frames on the GPU from decode to encode.
Check the device and driver
VAAPI needs a driver for your GPU and a render node under /dev/dri. The tool vainfo, from the libva-utils package, lists what the driver can do:
vainfo --display drm --device /dev/dri/renderD128vainfo: VA-API version: 1.22 (libva 2.22.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 24.3.4 ()
vainfo: Supported profile and entrypoints
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSliceLP
VAProfileH264High : VAEntrypointEncSliceLP
VAProfileHEVCMain : VAEntrypointEncSliceLP
VAProfileHEVCMain10 : VAEntrypointEncSliceLPThe version numbers vary by machine. What to read is the entrypoint. VAEntrypointVLD means decode. VAEntrypointEncSlice and VAEntrypointEncSliceLP mean encode, where LP is the low-power fixed-function engine that most recent Intel GPUs use. A profile without an encode entrypoint cannot be used with h264_vaapi or hevc_vaapi. The render node is usually /dev/dri/renderD128. Your user needs read and write access to it, normally through the render group.
The minimal command
ffmpeg -vaapi_device /dev/dri/renderD128 -i input.mp4 \
-vf "format=nv12,hwupload" -c:v h264_vaapi -qp 23 -c:a copy out.mp4The pieces:
-vaapi_device /dev/dri/renderD128opens the VAAPI device and makes it the device for filters in this command. It is a global option and goes before-i.format=nv12converts frames to NV12, the 8-bit 4:2:0 layout with interleaved chroma that VAAPI surfaces use. Without it, the next filter would receive a format it cannot upload, and FFmpeg inserts a conversion that you did not choose.hwuploadcopies each frame from system memory into a VAAPI surface on the GPU.-c:v h264_vaapiselects the encoder, and-qp 23sets a constant quantisation parameter.
If you omit the upload, FFmpeg stops with an error like this:
[h264_vaapi @ 0x55d0b6c4a0c0] Format yuv420p not supported for hardware encoding.The message is the sign that the encoder received a software frame. The fix is always the format=nv12,hwupload pair, or a pipeline that produces GPU frames in the first place.
Rate control
Rate control decides how the encoder spends bits. In the VAAPI encoders, the mode follows from the options you pass, and the FFmpeg codecs documentation for VAAPI encoders describes the choices:
| Goal | Options | Notes |
|---|---|---|
| Constant quality | -qp 23 | Constant QP, no bitrate target. Lower is better quality |
| Average bitrate | -b:v 6M | Variable bitrate around the target |
| Constant bitrate | -b:v 6M -maxrate 6M | For live streaming |
| Quality with a cap | -global_quality 23 -maxrate 8M | Depends on the driver's support |
Support differs between drivers and generations. If the driver does not support a mode, the encoder reports it, and you pick another. Constant QP is the most widely supported, and it is a reasonable way to begin.
Unlike x264's CRF, constant QP does not adapt to scene complexity, so file sizes vary more between clips. A QP of 23 for H.264 on an Intel GPU produces a bigger file than CRF 23 in x264 at similar visible quality, because the hardware encoder has fewer tools to remove redundancy. Try a few values on your own footage, and expect to land somewhere in the high teens to mid twenties.
HEVC and the low-power engine
HEVC uses the same pattern with a different encoder name. Add -tag:v hvc1 if the file must play in Apple software:
ffmpeg -vaapi_device /dev/dri/renderD128 -i input.mp4 \
-vf "format=nv12,hwupload" -c:v hevc_vaapi -qp 26 -tag:v hvc1 -c:a copy out-hevc.mp4For 10-bit HEVC, use format=p010le in place of nv12 and -profile:v main10, provided that the hardware lists VAProfileHEVCMain10 with an encode entrypoint. Setting -low_power 1 on the encoder asks for the LP engine on drivers that expose both. On many recent Intel GPUs the low-power engine is the encode path that vainfo lists, and the EncSliceLP entrypoint in its output tells you whether yours has it.
Check the result:
ffprobe -v error -select_streams v -show_entries stream=codec_name,profile,pix_fmt -of default=nw=1 out-hevc.mp4codec_name=hevc
profile=Main
pix_fmt=yuv420pThe pixel format is reported as yuv420p because the container holds NV12 data decoded back to that logical layout.
Keep frames on the GPU
The upload step copies every frame across the bus. When the source is also hardware decodable, you can avoid it. Decode on VAAPI, keep the surfaces on the GPU and scale there with scale_vaapi:
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi \
-i input.mp4 -vf "scale_vaapi=w=1280:h=720" -c:v h264_vaapi -qp 23 -c:a copy out-720p.mp4-hwaccel_output_format vaapi tells the decoder to leave frames as VAAPI surfaces instead of downloading them. The decoder, the scaler and the encoder then share the same memory, and no pixels cross the bus until the final stream is written. This only works when every filter in the chain has a VAAPI version. A software filter such as drawtext in the middle needs hwdownload,format=nv12 before it and hwupload after it, which brings the copies back. The reasons and the alternatives are discussed in a later post on mixed GPU and CPU chains.
AMD GPUs and Mesa
On AMD hardware the VAAPI driver comes from Mesa, and vainfo prints Mesa Gallium driver with the radeonsi name. The commands in this post are the same. Two practical differences are worth knowing. Older Mesa releases exposed fewer encode profiles, so a new FFmpeg on an old distribution can fail with a profile error where the hardware could do the work, and updating Mesa fixes it. Some Mesa builds drop patent-encumbered codecs for licensing reasons, which makes H.264 and HEVC encoding vanish from vainfo until you install the freeworld variant of the driver packages that distributions such as Fedora provide.
When VAAPI is the wrong choice
VAAPI works on Linux with open-source drivers for Intel and AMD GPUs. NVIDIA cards use NVENC instead, since NVIDIA does not provide a VAAPI encode driver. On Intel hardware you may prefer Quick Sync through the QSV encoders, which use the same hardware with a different API and offer some extra options. As with every hardware encoder, VAAPI output is larger than a slow x264 or x265 encode at the same quality, so for archives where size matters, use software.
Troubleshooting
"No VA display found for device". The render node path is wrong or the permissions deny access. Check
ls -l /dev/driand your groups."Cannot open DRM render node". The same causes, or a container without the device mapped.
**"Function not implemented" at
vaCreateConfig.** The profile and rate control combination is not supported by the driver. Usevainfoto check the profile and try constant QP.Green or corrupted frames. Often a pixel format problem, such as 10-bit input uploaded as NV12. Convert explicitly.


