How to Use FFmpeg scale_npp Filter
The scale_npp filter in FFmpeg is a hardware-accelerated
video scaling filter that utilizes NVIDIA’s Performance Primitives (NPP)
library. This article provides a quick guide on how to leverage
scale_npp for high-performance video resizing directly on
NVIDIA GPUs, covering the required command-line syntax, essential
parameters, and practical usage examples.
Prerequisites
To use the scale_npp filter, your FFmpeg build must be
compiled with CUDA and NPP support. This requires the following
configuration flags during compilation:
--enable-cuda-nvcc--enable-libnpp--enable-nonfree(required for NVIDIA SDK components)
You also need a compatible NVIDIA graphics card and the latest NVIDIA proprietary drivers installed on your system.
Basic Syntax and Workflow
The scale_npp filter operates on CUDA hardware frames.
To use it efficiently, the video decoding, scaling, and encoding should
all happen on the GPU to avoid performance bottlenecks caused by copying
data between system memory (RAM) and GPU memory (VRAM).
The standard hardware-accelerated pipeline looks like this:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf "scale_npp=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 (VRAM).-vf "scale_npp=1920:1080": Applies the NPP scaler to resize the video to 1920x1080.-c:v h264_nvenc: Uses the hardware-accelerated NVIDIA H.264 encoder.
Key Filter Parameters
The scale_npp filter accepts several arguments to
control the output size and scaling quality:
1. Dimensions (Width and Height)
You can specify the target resolution using explicit pixel values or
scale options: * scale_npp=1280:720 (Width: 1280, Height:
720) * scale_npp=1280:-1 (Keep aspect ratio based on width)
* scale_npp=-1:720 (Keep aspect ratio based on height)
2. Scaling Algorithm
(interp_algo)
You can choose different interpolation algorithms to balance quality
and speed. The default is cubic. * nn: Nearest
neighbor * linear: Bilinear * cubic: Bicubic *
supersample: Supersampling * lanczos:
Lanczos
Example utilizing Lanczos interpolation:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf "scale_npp=1280:720:interp_algo=lanczos" -c:v hevc_nvenc output.mp43. Format Conversion
The scale_npp filter can also change the pixel format of
the video frames while scaling.
Example converting output to 10-bit YUV420P:
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf "scale_npp=1920:1080:format=yuv420p10" -c:v hevc_nvenc output.mp4Handling Software Decoded Inputs
If you cannot use the hardware decoder for your input source, you
must manually upload the video frames to the GPU before applying the
scale_npp filter, and then download them back to CPU memory
if you are using a software encoder.
Example using software decoder and hardware scaler:
ffmpeg -i input.mp4 -vf "hwupload_cuda,scale_npp=1280:720,hwdownload,format=yuv420p" -c:v libx264 output.mp4