How to Use FFmpeg tmedian Filter for Noise Reduction
This guide explains how to use the FFmpeg tmedian filter
to apply a temporal median filter to your videos. You will learn the
basic syntax, key parameters for controlling the filter’s strength, and
practical command-line examples to achieve effective progressive noise
reduction while preserving spatial details.
Understanding the tmedian Filter
The tmedian (Temporal Median) filter in FFmpeg reduces
video noise by comparing pixels across consecutive frames (temporally)
rather than within a single frame (spatially). For each pixel, the
filter looks at the same coordinate across a sequence of frames, sorts
the color values, and outputs the median value.
This approach is highly effective for removing random, fast-moving noise—such as sensor hiss, film grain, or digital artifacts—without blurring the fine details of static objects.
Basic Syntax and Parameters
The basic syntax for applying the tmedian filter in an
FFmpeg command is:
ffmpeg -i input.mp4 -vf tmedian=radius=1 output.mp4The filter accepts several key parameters to customize its behavior:
radius(orr): Defines the temporal radius. The total number of frames used to calculate the median is(2 * radius) + 1.- Default:
1(uses 3 frames: the current frame, 1 before, and 1 after). - Range:
1to127. - Impact: Larger values result in stronger noise reduction but can introduce motion blur or “ghosting” artifacts on fast-moving objects.
- Default:
planes(orp): Specifies which color planes to filter (Luma, Chroma, Alpha).- Default:
15(filters all planes).
- Default:
percentile(orc): Adjusts the percentile used for sorting.- Default:
0.5(the exact median).
- Default:
Practical Examples
1. Light Noise Reduction (Default Settings)
For mild digital noise, a radius of 1 or 2 is usually sufficient. This keeps processing fast and minimizes motion artifacts.
ffmpeg -i input.mp4 -vf "tmedian=radius=1" -c:a copy output.mp42. Strong Noise Reduction for Static Scenes
If you are processing security footage or a static camera shot with heavy noise, you can increase the radius to analyze more frames.
ffmpeg -i input.mp4 -vf "tmedian=radius=4" -c:a copy output.mp4Note: A radius of 4 analyzes 9 frames in total (the current frame plus 4 frames before and 4 frames after).
3. Noise Reduction on the Luma Plane Only
To reduce brightness noise while leaving color data untouched, target only the luma channel (plane 0).
ffmpeg -i input.mp4 -vf "tmedian=radius=2:planes=1" -c:a copy output.mp4Tips for Best Results
Avoid Ghosting: High
radiusvalues (above 5) can cause moving objects to leave trails or “ghost” behind. Keep the radius low (1 to 3) for videos with high-speed motion.Combine Filters: For severely degraded videos, combine
tmedianwith a spatial denoiser likehqdn3dornlmeansto clean up both temporal and static frame noise:ffmpeg -i input.mp4 -vf "tmedian=radius=2,hqdn3d=1.5:1.5:6:6" -c:a copy output.mp4