How to Use yadif_videotoolbox in FFmpeg on macOS

This article provides a quick guide on how to use the yadif_videotoolbox filter in FFmpeg on macOS. You will learn how to leverage Apple’s hardware-accelerated VideoToolbox framework to deinterlace videos efficiently, reducing CPU usage and speeding up processing times.

What is yadif_videotoolbox?

The yadif_videotoolbox filter is the hardware-accelerated version of the standard YADIF (Yet Another Deinterlacing Filter) in FFmpeg. It is designed specifically for macOS and utilizes Apple’s VideoToolbox framework. This allows the GPU to handle the deinterlacing process, which is significantly faster and more energy-efficient than software-based deinterlacing.

Prerequisites

To use this filter, you must meet the following requirements: * A Mac computer running macOS. * FFmpeg installed with VideoToolbox support. If you installed FFmpeg via Homebrew (brew install ffmpeg), VideoToolbox support is enabled by default.

Basic Command Syntax

To use yadif_videotoolbox, you must decode, filter, and encode the video using Apple’s hardware acceleration pipeline.

Here is the standard command structure:

ffmpeg -hwaccel videotoolbox -i input.ts -vf "yadif_videotoolbox" -c:v h264_videotoolbox output.mp4

Command Breakdown:

Configuring Filter Options

The yadif_videotoolbox filter accepts optional parameters to customize the deinterlacing behavior. You can configure these using the parameter=value syntax:

-vf "yadif_videotoolbox=mode=0:parity=-1:deint=0"

Key Parameters:

  1. mode: Controls the temporal resolution of the output.
    • 0 (default): Outputs 1 frame for each frame (standard deinterlacing).
    • 1: Outputs 1 frame for each field (bob deinterlacing, which doubles the framerate, e.g., 60i to 60p).
  2. parity: Specifies the field dominance (picture field order).
    • -1 (default): Automatic detection.
    • 0: Top field first (TFF).
    • 1: Bottom field first (BFF).
  3. deint: Determines which frames to deinterlace.
    • 0 (default): Deinterlace all frames.
    • 1: Only deinterlace frames marked as interlaced.

Example: Doubling the Framerate (Bob Deinterlacing)

If you have a 1080i50 or 1080i60 video and want a smooth 50p or 60p output, set the mode parameter to 1:

ffmpeg -hwaccel videotoolbox -i input.ts -vf "yadif_videotoolbox=mode=1" -c:v h264_videotoolbox output.mp4