FFmpeg yadif_cuda Hardware Deinterlacing Guide

This guide explains how to use the yadif_cuda filter in FFmpeg to perform high-performance, hardware-accelerated deinterlacing on NVIDIA graphics cards. You will learn the system prerequisites, the correct command syntax for full hardware pipelines, and how to configure key filter parameters for optimal video quality.

Prerequisites

To use yadif_cuda, your system and FFmpeg build must meet the following requirements: * NVIDIA GPU: A graphics card supporting CUDA. * NVIDIA Drivers: Up-to-date proprietary NVIDIA drivers installed on your system. * FFmpeg compiled with CUDA support: Your FFmpeg binary must be compiled with --enable-cuda-nvcc and --enable-libnpp. You can verify this by running ffmpeg -filters | grep yadif_cuda in your terminal. If the filter is listed, your build is ready.

Basic Command Syntax

Because yadif_cuda runs directly on the GPU, the input video frames must reside in GPU memory (VRAM) before the filter can process them. The most efficient way to do this is to use hardware-accelerated decoding (nvdec) alongside the filter.

Here is the standard command for a fully hardware-accelerated pipeline (decode, deinterlace, and encode on the GPU):

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.ts -vf yadif_cuda -c:v h264_nvenc -c:a copy output.mp4

Command Breakdown:

Advanced Filter Options

The yadif_cuda filter supports several parameters to customize the deinterlacing behavior. You can apply these parameters using the format -vf yadif_cuda=parameter=value.

1. Mode (Output Frame Rate)

The mode option controls how many frames are output for each input frame: * 0 (send_frame): Outputs one frame for each frame (standard frame rate, e.g., 30i to 30p). * 1 (send_field): Outputs one frame for each field (double frame rate/bobbing, e.g., 60i to 60p). This is the default option and offers the smoothest motion.

Example (Double Frame Rate):

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.ts -vf yadif_cuda=mode=1 -c:v h264_nvenc output.mp4

2. Parity (Field Dominance)

The parity option specifies the field order of the input video: * 0 (tff): Top field first. * 1 (bff): Bottom field first. * -1 (auto): Automatically detects the field order (default).

Example (Forcing Top Field First):

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.ts -vf yadif_cuda=parity=0 -c:v h264_nvenc output.mp4

3. Deinterlacing Target

The deint option determines which frames are processed: * 0: Deinterlaces all frames. * 1: Only deinterlaces frames marked as interlaced (default).

Software Decoding to Hardware Deinterlacing

If you need to use a software decoder (for formats not supported by NVIDIA’s hardware decoder) but still want to use the GPU for deinterlacing, you must manually upload the video frames to the GPU using hwupload_cuda:

ffmpeg -i input.ts -vf "hwupload_cuda,yadif_cuda,hwdownload,format=yuv420p" -c:v libx264 output.mp4

Note: Transferring frames between system RAM and GPU VRAM introduces latency, so a pure hardware pipeline is always recommended when possible.