How to Use FFmpeg scale_npp for NVIDIA GPU Scaling
This article provides a practical guide on how to use the
scale_npp filter in FFmpeg to perform hardware-accelerated
video scaling on NVIDIA graphics cards. You will learn how to set up the
proper command-line syntax to keep the video processing pipeline
entirely within the GPU memory, ensuring maximum performance and minimal
CPU usage during transcoding.
Prerequisites
To use the scale_npp (NVIDIA Performance Primitives)
filter, your FFmpeg build must be compiled with CUDA and NPP support.
You can verify this by running ffmpeg -filters in your
terminal and checking if scale_npp is listed in the output.
Additionally, you must have compatible NVIDIA proprietary drivers
installed on your system.
Basic Command Syntax
To achieve maximum efficiency, you must decode the input video in
hardware, scale it using scale_npp, and encode the output
using an NVIDIA encoder like h264_nvenc or
hevc_nvenc. Keeping the frames in the GPU memory prevents
costly data transfers between system RAM and GPU VRAM.
Here is the standard command to scale a video to 1080p (1920x1080):
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: Forces the decoded video frames to remain in the GPU memory (VRAM) as CUDA surfaces, which is required byscale_npp.-vf "scale_npp=1920:1080": Invokes the NPP scaler and sets the output resolution to width 1920 and height 1080.-c:v h264_nvenc: Uses the NVIDIA hardware-accelerated H.264 encoder to compress the scaled frames.
Customizing the Scaling Quality
The scale_npp filter allows you to choose different
interpolation algorithms to balance quality and speed. You can specify
the algorithm using the interp_algo parameter.
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf "scale_npp=1280:720:interp_algo=lanczos" -c:v h264_nvenc output.mp4Common interpolation algorithms include: * linear:
Bilinear interpolation (fastest, default). * cubic: Bicubic
interpolation (good balance of speed and quality). * super:
Supersampling (excellent for downscaling). * lanczos:
Lanczos resampling (high-quality sharpening).
Handling Aspect Ratios
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 other dimension.
ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -vf "scale_npp=1280:-1" -c:v h264_nvenc output.mp4