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.mp4Customizing tmedian Parameters
You can fine-tune the filter’s behavior using specific parameters:
radius(orr): Sets the temporal radius. The filter will look atradiusframes before andradiusframes after the current frame. The total number of frames averaged is(2 * radius) + 1.- Default:
1(looks at 3 frames total) - Range:
1to127 - Note: Higher values result in stronger denoising but require more processing power and can cause ghosting or motion blur on fast-moving objects.
- Default:
planes(orp): Specifies which color planes to filter.- Default:
0xf(all planes: Y, U, V, and Alpha) - Value: A bitmap representation of the planes.
- Default:
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.mp4Filtering 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.mp4Best Practices
Avoid Ghosting: For videos with rapid motion, keep the
radiuslow (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
tmedianwith a spatial filter likehqdn3dornlmeansfor a hybrid spatio-temporal denoising effect:ffmpeg -i input.mp4 -vf "tmedian=radius=2,hqdn3d" output.mp4