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.mp4

Parameter Breakdown

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.mp4

Scaling 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.mp4

In this scenario, format=nv12 ensures the software pixel format is compatible with VAAPI, and hwupload transfers the frames from system RAM to GPU VRAM.