Configure FFmpeg Tmedian Filter Frame Count
The FFmpeg tmedian (temporal median) filter is a
powerful tool used for noise reduction and video smoothing by
calculating the median pixel values across consecutive video frames.
This article explains how to configure the number of frames to average
using the filter’s radius parameter, enabling you to control the
strength and temporal reach of the noise reduction effect.
To configure the number of frames the tmedian filter
processes, you must adjust the radius (or r)
option.
Understanding the Radius Formula
The tmedian filter does not let you input an arbitrary
even number of frames. Instead, you specify a radius (\(N\)), and the filter calculates the median
using a temporal window of frames determined by the following
formula:
\[\text{Total Frames} = (2 \times \text{radius}) + 1\]
This means the temporal window always consists of an odd number of frames. The window is centered on the current frame and extends symmetrically into both the preceding (past) and succeeding (future) frames: * Radius of 1 (Default): Processes 3 frames (1 past, 1 current, 1 future). * Radius of 3: Processes 7 frames (3 past, 1 current, 3 future). * Radius of 5: Processes 11 frames (5 past, 1 current, 5 future).
The allowed range for the radius option is from 1 to
127 (which would average 255 frames).
FFmpeg Command Examples
To apply the tmedian filter with a custom frame radius,
use the -vf (video filter) flag in your FFmpeg command.
Example 1: Using the default radius (3 frames total)
ffmpeg -i input.mp4 -vf "tmedian" output.mp4Example 2: Setting a custom radius of 3 (7 frames total)
ffmpeg -i input.mp4 -vf "tmedian=radius=3" output.mp4You can also use the short alias r instead of writing
out radius:
ffmpeg -i input.mp4 -vf "tmedian=r=3" output.mp4Example 3: Processing specific video planes By
default, the filter applies to all color planes. You can specify which
planes to process using the planes parameter. For example,
to apply a radius of 5 (11 frames total) only to the luma plane (plane
0):
ffmpeg -i input.mp4 -vf "tmedian=r=5:planes=1" output.mp4Increasing the radius increases the noise-filtering strength, but it requires more system memory and can introduce motion blur or “ghosting” artifacts in fast-moving scenes.