How to Use FFmpeg tmedian Temporal Denoise Filter

This article provides a straightforward guide on how to apply the tmedian temporal denoise filter in FFmpeg to reduce video noise and flicker. You will learn the basic command syntax, key parameters for customization, and practical examples to clean up noisy video footage effectively by using pixel data from neighboring frames.

What is the tmedian Filter?

The tmedian (temporal median) filter is a video filter in FFmpeg that reduces noise by calculating the median pixel value across a span of consecutive frames. Unlike spatial filters that blur individual frames, temporal filters compare pixels at the exact same coordinates across time. This makes tmedian highly effective at removing random, high-frequency noise, sensor grain, scratches, and dust while preserving sharp edge details.

Basic Syntax

To apply the default tmedian filter to a video, use the -vf (video filter) flag followed by tmedian:

ffmpeg -i input.mp4 -vf tmedian output.mp4

Customizing tmedian Parameters

You can fine-tune the filter's behavior using specific parameters:

  • radius (or r): Sets the temporal radius. The filter will look at radius frames before and radius frames after the current frame. The total number of frames averaged is (2 * radius) + 1.
    • Default: 1 (looks at 3 frames total)
    • Range: 1 to 127
    • Note: Higher values result in stronger denoising but require more processing power and can cause ghosting or motion blur on fast-moving objects.
  • planes (or p): Specifies which color planes to filter.
    • Default: 0xf (all planes: Y, U, V, and Alpha)
    • Value: A bitmap representation of the planes.

Practical Examples

Stronger Denoising (Larger Radius)

To apply a stronger temporal denoise effect, increase the radius. This example uses a radius of 3, meaning it calculates the median across 7 consecutive frames (3 before, the current frame, and 3 after):

ffmpeg -i input.mp4 -vf "tmedian=radius=3" output.mp4

Filtering Specific Planes

If you only want to apply the temporal median filter to the luma (brightness) channel (plane 0) and leave the chroma (color) channels untouched:

ffmpeg -i input.mp4 -vf "tmedian=planes=1" output.mp4

Best Practices

  • Avoid Ghosting: For videos with rapid motion, keep the radius low (1 to 3). High radius values on fast-moving footage will create visible trails or "ghosting" artifacts.

  • Combine with Spatial Filters: For extremely noisy videos, you can chain tmedian with a spatial filter like hqdn3d or nlmeans for a hybrid spatio-temporal denoising effect:

    ffmpeg -i input.mp4 -vf "tmedian=radius=2,hqdn3d" output.mp4