GLSL Temporal Video Deinterlacing Algorithms

This article explores real-time video deinterlacing in graphics pipelines using the OpenGL Shading Language (GLSL), focusing specifically on algorithms that utilize temporal neighborhood texture sampling. By analyzing adjacent temporal fields alongside spatial pixel neighborhoods, algorithms such as Motion-Adaptive Deinterlacing (MADI) and Yet Another Deinterlacing Filter (YADIF) reconstruct full-resolution progressive frames, eliminating interlacing artifacts while preserving static image detail.

The Primary Algorithm: YADIF and Motion-Adaptive Deinterlacing

The standard algorithm used for video deinterlacing via temporal neighborhood texture sampling in GLSL is YADIF (Yet Another Deinterlacing Filter), along with its generalized family of Motion-Adaptive Deinterlacing (MADI) techniques. While simple spatial algorithms (like Bob or simple edge-directed interpolation) operate only on the current field, YADIF checks spatial trends and temporal differences across multiple consecutive fields to choose the best pixel reconstruction method.

How Temporal Neighborhood Sampling Works in GLSL

In a GLSL implementation, the host application passes consecutive video fields to the fragment shader as distinct 2D texture uniforms:

  • sampler2D prevField: The frame field captured at time \(t-1\).
  • sampler2D curField: The current field being reconstructed at time \(t\).
  • sampler2D nextField: The frame field captured at time \(t+1\).

Advanced variations may also sample \(t-2\) and \(t+2\) for five-field temporal checks.

The fragment shader samples texels across these temporal textures at identical spatial coordinates \((x, y)\), as well as immediate vertical neighbors \((x, y \pm 1)\), to measure local motion and edge orientation.

Algorithmic Execution Steps

  1. Spatial Edge Detection: The shader samples the current field's vertical neighbors to determine local directional gradients, identifying the orientation of edges to prevent stair-stepping (aliasing).
  2. Temporal Motion Measurement: The shader calculates the absolute difference between texel values in the previous field (prevField) and the next field (nextField). If the difference is below a defined threshold, the region is determined to be static.
  3. Adaptive Pixel Synthesis:
    • Low Motion (Static Regions): The algorithm applies temporal weaving or field insertion, preserving the original vertical detail of the image without blurring.
    • High Motion (Moving Regions): The algorithm falls back to edge-directed spatial interpolation (bobbing) along the detected edge angle, preventing the jagged "combing" artifacts typical of simple weaving.
  4. Clamping: The synthesized pixel value is clamped between temporal and spatial min/max bounds to avoid introducing visual overshoot artifacts or temporal flicker.

By leveraging GLSL hardware texture filtering and multi-texture binding, YADIF and motion-adaptive shaders execute this multi-tap temporal sampling in a single render pass, delivering artifact-free progressive video at high frame rates.