How to Use scale_cuda Filter in FFmpeg
This guide explains how to use the hardware-accelerated
scale_cuda filter in FFmpeg to resize videos using NVIDIA
GPUs. You will learn the basic syntax, system requirements, and
practical command-line examples for integrating CUDA-based scaling into
your video processing workflows.
Prerequisites
To use the scale_cuda filter, your system must meet the
following requirements: * An NVIDIA graphics card that supports CUDA. *
NVIDIA proprietary drivers installed. * A build of FFmpeg compiled with
CUDA support (specifically enabled with --enable-cuda-nvcc
and --enable-libnpp).
The Basic Command Structure
Because scale_cuda runs on the GPU, the video frames
must reside in GPU memory (VRAM) before the filter can process them. The
most efficient way to use this filter is within a fully
hardware-accelerated pipeline, where decoding, scaling, and encoding all
happen on the GPU.
Here is the standard command for a full hardware pipeline:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf scale_cuda=1920:1080 -c:v h264_nvenc output.mp4Command Breakdown:
-hwaccel cuda: Enables CUDA hardware acceleration for decoding.-hwaccel_output_format cuda: Keeps the decoded video frames in GPU memory, preventing costly transfers between system RAM and GPU VRAM.-vf scale_cuda=1920:1080: Invokes the CUDA scaling filter to resize the video to a width of 1920 pixels and a height of 1080 pixels.-c:v h264_nvenc: Uses the NVIDIA hardware-accelerated H.264 encoder to compress the scaled video.
Advanced Usage and Syntax
Maintaining Aspect Ratio
You can scale a video while preserving its original aspect ratio by
setting one of the dimensions to -1 or -2
(which ensures the dimension is divisible by 2, required by many
encoders):
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf scale_cuda=1280:-2 -c:v h264_nvenc output.mp4Scaling Software-Decoded Video (Hybrid Pipeline)
If your input video format cannot be decoded by your GPU, you must
decode it using the CPU, upload the frames to the GPU using the
hwupload_cuda filter, apply the scaling, and then
encode:
ffmpeg -i input.mp4 -vf "hwupload_cuda,scale_cuda=1280:720" -c:v h264_nvenc output.mp4Specifying Interpolation Algorithm
The scale_cuda filter supports different scaling
algorithms (such as bilinear, bicubic, or
lanczos) to balance speed and visual quality. You can
specify the algorithm using the interp option:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf scale_cuda=1920:1080:interp=lanczos -c:v h264_nvenc output.mp4