How to Use FFmpeg scale_vaapi for Hardware Scaling
This article explains how to use the scale_vaapi filter
in FFmpeg to leverage hardware-accelerated video scaling on systems with
Intel or AMD graphics. You will learn the correct command-line syntax to
initialize VAAPI hardware, decode videos directly into GPU memory, scale
the video stream, and encode the output using hardware acceleration for
maximum efficiency and minimal CPU usage.
To use VAAPI (Video Acceleration API) for scaling in FFmpeg, your
system must have compatible hardware (Intel or AMD GPU), the appropriate
VAAPI drivers installed, and an FFmpeg binary compiled with VAAPI
support (--enable-vaapi).
The Basic Command Structure
For optimal performance, the entire video pipeline—decoding, scaling, and encoding—should happen inside the GPU memory (VRAM). Copying frames back and forth between system RAM and GPU memory introduces significant latency.
Here is the standard command to scale a video to 720p (1280x720) using VAAPI:
ffmpeg -init_hw_device vaapi=hw:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -i input.mp4 -filter_hw_device hw -vf "scale_vaapi=w=1280:h=720" -c:v h264_vaapi output.mp4Parameter Breakdown
-init_hw_device vaapi=hw:/dev/dri/renderD128: Initializes the VAAPI hardware device./dev/dri/renderD128is the standard path for the primary GPU on Linux systems.-hwaccel vaapi: Enables hardware-accelerated decoding of the input video.-hwaccel_output_format vaapi: Ensures the decoded frames remain in GPU memory (VAAPI surfaces) instead of being copied to the CPU.-filter_hw_device hw: Informs the filter graph to use the previously initialized hardware device named “hw”.-vf "scale_vaapi=w=1280:h=720": Applies the hardware scaling filter, resizing the video to 1280x720 pixels.-c:v h264_vaapi: Encodes the scaled video using the hardware-accelerated H.264 encoder.
Maintaining Aspect Ratio
If you want to scale a video while maintaining its original aspect
ratio, set either the width (w) or height (h)
to -1. The filter will automatically calculate the missing
dimension.
To scale a video to a height of 1080 pixels while preserving the aspect ratio:
ffmpeg -init_hw_device vaapi=hw:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -i input.mp4 -filter_hw_device hw -vf "scale_vaapi=w=-1:h=1080" -c:v h264_vaapi output.mp4Scaling Software-Decoded Input
If you are working with an input format that cannot be decoded by
your GPU, you can still use the CPU for decoding and upload the frames
to the GPU solely for scaling and encoding. This requires using the
hwupload filter before applying
scale_vaapi:
ffmpeg -init_hw_device vaapi=hw:/dev/dri/renderD128 -filter_hw_device hw -i input_software_codec.mp4 -vf "format=nv12,hwupload,scale_vaapi=w=1920:h=1080" -c:v h264_vaapi output.mp4In this scenario, format=nv12 ensures the software pixel
format is compatible with VAAPI, and hwupload transfers the
frames from system RAM to GPU VRAM.