How to Use FFmpeg tmedian for Video Noise Reduction
The tmedian filter in FFmpeg offers an effective way to
reduce temporal video noise, grain, and sensor artifacts across
progressive footage by calculating the median pixel value across a
defined window of sequential frames. This article explains how the
tmedian filter works, details its essential parameters, and
provides ready-to-use FFmpeg commands for processing static and
low-motion footage without losing spatial sharpness.
How the tmedian
Filter Works
Unlike spatial denoisers that smooth pixel values within the same
frame, the tmedian filter operates temporally. It looks at
the current frame alongside preceding and succeeding frames, sorting the
values for each pixel coordinate across time and selecting the
median.
Because random noise (such as sensor grain or compression specks) fluctuates rapidly from frame to frame, the outlier pixel values caused by noise are discarded, while consistent visual elements are preserved.
Core Parameters
The tmedian filter provides several parameters to
control how frames are sampled:
radius: Specifies the number of frames to inspect before and after the current frame. The total window size is calculated as(2 * radius) + 1. The default radius is4(a 9-frame window). Higher values produce stronger denoising but increase processing time and the likelihood of ghosting artifacts on moving objects.planes: Sets which color planes to filter. Available options are1(Y/Luma),7(all planes: Y, U, and V), or specific bitmasks. The default applies filtering to all planes.percentile: Determines the temporal percentile to pick instead of a strict median. The default is0.5(the exact median). Values lower than0.5pick darker temporal pixels, while values higher pick brighter temporal pixels.
Practical FFmpeg Examples
1. Basic Denoising with Default Settings
To apply the filter with default settings (radius of 4 across all color planes):
ffmpeg -i input.mp4 -vf "tmedian" -c:a copy output.mp42. Subtle Denoising for Moderate Motion
When working with footage containing moderate motion, reduce the
radius to minimize ghosting or motion trails:
ffmpeg -i input.mp4 -vf "tmedian=radius=2" -c:v libx264 -crf 18 -c:a copy output.mp4A radius of 2 checks 2 frames forward and 2 frames back
(5 frames total), effectively removing high-frequency grain while
preserving moving edges.
3. Heavy Denoising for Static Shots
For stationary camera setups, such as tripod-mounted landscape or
surveillance video with heavy low-light noise, increase the
radius:
ffmpeg -i input.mp4 -vf "tmedian=radius=6" -c:v libx264 -crf 18 -c:a copy output.mp4This inspects 13 consecutive frames to average out persistent temporal noise.
4. Denoising Chroma Noise Only
If the luma detail is clean but color noise (chroma jitter) is visible, target only the chroma planes (planes 2 and 4, or U and V components):
ffmpeg -i input.mp4 -vf "tmedian=radius=3:planes=6" -c:v libx264 -crf 18 -c:a copy output.mp4Best Practices and Limitations
- Motion Sensitivity: Because
tmediandoes not use motion estimation or motion vectors, fast-moving objects will leave translucent trails (ghosting). Keep the radius low (between1and3) for videos with moving subjects. - Progressive Scan Only: Ensure your input video is
progressive. If the source is interlaced, deinterlace it first (e.g.,
using
-vf "yadif,tmedian") to prevent combining fields incorrectly. - Bitrate Efficiency: Temporal median filtering makes video streams substantially easier for encoders like H.264 or H.265 to compress, resulting in smaller file sizes at equivalent CRF values.