encoding-guide

Temporal Filtering

Temporal filtering smooths motion and reduces noise by analyzing frames over time, leveraging patterns across multiple frames to improve visual consistency and reduce artifacts. It is particularly useful for addressing flickering, noise, and motion artifacts in video sources.

This guide will explore temporal filtering in detail, including common use cases, techniques, and example scripts.


What is Temporal Filtering?

Temporal filtering operates across frames to:

  1. Reduce Flickering: Stabilizes inconsistent lighting or noise.
  2. Preserve Motion: Ensures objects in motion retain their natural flow.
  3. Enhance Compression: Smooths static areas to save bits for dynamic scenes.
  4. Improve Visual Quality: Reduces temporal noise while maintaining texture and detail.

Types of Temporal Artifacts

1. Temporal Noise

2. Motion Artifacts

3. Flickering


Techniques for Temporal Filtering

1. Basic Temporal Smoothing

Temporal smoothing reduces noise and flickering by averaging pixel values across frames.


2. Motion-Compensated Temporal Filtering

Motion-compensated filtering identifies and adjusts motion across frames, preserving sharpness and detail in moving objects.


3. Temporal Degrain

Temporal degrain targets grain and noise specifically, useful for film sources or older analog content.


4. Flicker Removal

Flicker removal stabilizes lighting inconsistencies or color shifts between frames.


Combining Temporal and Spatial Filtering

Combining temporal and spatial filters ensures balanced results, reducing noise and flickering across frames while maintaining intra-frame details.

Workflow:

  1. Apply temporal filtering first to address frame-to-frame inconsistencies.
  2. Follow with spatial filtering to refine individual frames.

Advanced Techniques

1. Masking for Dynamic Filtering

Use masks to apply temporal filtering only to specific areas, such as noisy backgrounds.


2. Adjusting Temporal Radius

Higher temporal radius improves smoothing but increases computational load.


3. Frame Interpolation

Frame interpolation generates new frames for smoother playback or frame rate conversion.


Example Comprehensive Script

Here’s a complete example for addressing temporal artifacts:

import vapoursynth as vs
core = vs.core

# Load source
clip = core.ffms2.Source("noisy_source.mkv")

# Step 1: Temporal Filtering (Noise and Grain)
clip = core.smd.SMD(clip, tr=3, thSAD=400)

# Step 2: Flicker Removal
clip = core.deflicker.Deflicker(clip, mode="light")

# Step 3: Motion-Compensated Filtering
clip = core.mctemporal.MCTemporalDenoise(clip, sigma=2)

# Step 4: Spatial Filtering (Refinement)
clip = core.knlm.KNLMeansCL(clip, d=1, h=1.2)

# Output
clip.set_output()

Best Practices for Temporal Filtering

  1. Start Small: Test settings on a short segment of video before applying them to the full source.
  2. Avoid Over-Smoothing: Over-aggressive temporal filtering can introduce ghosting or smearing.
  3. Combine Filters: Use a combination of temporal and spatial techniques for the best results.
  4. Adjust Parameters: Tailor settings to the specific needs of your source material.

Conclusion

Temporal filtering is a powerful tool for improving video quality, particularly for noisy, grainy, or flickering sources. By understanding the techniques and tools outlined in this guide, you can achieve cleaner, more professional results tailored to your content’s needs. Experiment with different approaches and fine-tune parameters to find the perfect balance between noise reduction and detail preservation.