How to Use yadif_cuda in FFmpeg for Deinterlacing

This guide provides a practical overview of using the yadif_cuda filter in FFmpeg to perform fast, hardware-accelerated video deinterlacing using an NVIDIA GPU. You will learn the required prerequisites, the core command syntax for complete hardware transcoding pipelines, and how to configure key filter parameters such as field parity and frame rate modes.

Prerequisites

To use yadif_cuda, your environment must meet the following requirements:

  • An NVIDIA GPU that supports hardware-accelerated video decoding and encoding.
  • Up-to-date NVIDIA proprietary display drivers.
  • A build of FFmpeg compiled with CUDA support (typically built with --enable-cuda-nvcc or --enable-ffnvcodec, --enable-cuvid, --enable-nvenc, and --enable-nonfree).

Verify that your FFmpeg build includes the filter by running:

ffmpeg -filters | grep yadif_cuda

Core Command Syntax

The yadif_cuda filter operates directly on CUDA device memory. For optimal performance, the video should be decoded, filtered, and encoded entirely on the GPU to avoid costly memory transfers between system RAM and VRAM.

This command uses hardware decoding (-hwaccel cuda), keeps the decoded frames in GPU memory (-hwaccel_output_format cuda), applies yadif_cuda, and encodes the output with h264_nvenc:

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

Software Decode with Hardware Filtering and Encoding

If your input format is not supported by NVDEC hardware decoding, you can decode via CPU and upload the frames to GPU memory using the hwupload_cuda filter:

ffmpeg -i input.ts \
  -vf "hwupload_cuda,yadif_cuda" \
  -c:v h264_nvenc -preset p5 -c:a copy output.mp4

Hardware Filtering with Software Encoding

If you need to encode with a CPU-based encoder (such as libx264), download the frames back to host memory using hwdownload and set the pixel format:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.ts \
  -vf "yadif_cuda,hwdownload,format=nv12" \
  -c:v libx264 -crf 20 -c:a copy output.mp4

Key Filter Parameters

The yadif_cuda filter accepts several configuration options formatted as yadif_cuda=key=value:key=value:

  • mode: Controls temporal frame output.
    • send_frame (or 0): Outputs 1 progressive frame for each interlaced frame (default). Preserves original frame rate (e.g., 29.97i to 29.97p).
    • send_field (or 1): Outputs 1 progressive frame for each field (often called "bob" deinterlacing). Doubles the frame rate for smoother motion (e.g., 29.97i to 59.94p).
  • parity: Specifies the field order.
    • auto (or -1): Automatically detects field dominance from the input metadata (default).
    • tff (or 0): Assumes Top Field First.
    • bff (or 1): Assumes Bottom Field First.
  • deint: Determines which frames to process.
    • all (or 0): Deinterlaces every frame (default).
    • interlaced (or 1): Deinterlaces only frames flagged as interlaced.

Example: Doubling Frame Rate with Field Detection

To deinterlace a video to double frame rate while ensuring proper field order detection:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.ts \
  -vf "yadif_cuda=mode=send_field:parity=auto:deint=all" \
  -c:v hevc_nvenc -cq 22 -c:a copy output.mp4