Use FFmpeg scale_cuda for Hardware Accelerated Scaling
This article explains how to use the scale_cuda filter
in FFmpeg to perform high-speed, hardware-accelerated video scaling
using NVIDIA GPUs. You will learn the basic command syntax, how to keep
the entire decoding-scaling-encoding pipeline on the GPU for maximum
performance, and how to handle hybrid CPU-to-GPU workflows.
To get the highest possible speed when scaling video with FFmpeg, you
must avoid copying video frames back and forth between system RAM (CPU)
and VRAM (GPU). By leveraging NVIDIA’s CUDA cores, the
scale_cuda filter resizes video frames directly in graphics
memory.
Prerequisites
To use scale_cuda, you need: * An NVIDIA graphics card.
* Properly installed NVIDIA drivers. * A build of FFmpeg compiled with
CUDA support (specifically enabled with --enable-cuda-nvcc
and --enable-libnpp).
The Optimal Full-Hardware Pipeline
For maximum performance, you should decode, scale, and encode entirely on the GPU. This prevents hardware bottlenecks. Use the following command template:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf scale_cuda=1920:1080 -c:v h264_nvenc output.mp4Command Breakdown: * -hwaccel cuda:
Activates hardware-accelerated decoding using CUDA. *
-hwaccel_output_format cuda: Keeps the decoded video frames
in GPU memory (VRAM) instead of copying them back to system memory. *
-vf scale_cuda=1920:1080: Calls the CUDA scaler filter to
resize the video to 1080p. * -c:v h264_nvenc: Uses the
hardware-accelerated NVIDIA H.264 encoder to write the output file.
Scaling with Aspect Ratio Preservation
If you want to scale a video while maintaining its original aspect
ratio, you can set one of the dimensions to -1. FFmpeg will
automatically calculate the correct value for the other dimension:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf scale_cuda=-1:720 -c:v h264_nvenc output.mp4Hybrid Workflow: CPU Decode to GPU Scale
If your input video codec is not supported by hardware decoding, you
can decode the video on the CPU, upload it to the GPU memory, scale it
using CUDA, and then encode it. Use the hwupload_cuda
filter for this scenario:
ffmpeg -i input.mp4 -vf "hwupload_cuda,scale_cuda=1280:720" -c:v h264_nvenc output.mp4Note: While functional, this method is slower than the full-hardware pipeline due to the overhead of copying uncompressed frames from system memory to the GPU.