Configure FFmpeg Median Filter Radius and Percentile
The FFmpeg median filter is an effective tool for
reducing image noise, removing salt-and-pepper artifacts, and smoothing
video frames. This article provides a direct guide on how to configure
the filter’s key parameters—radius and
percentile—to control the size of the pixel window and the
blending behavior of the filter.
Understanding the Median Filter Parameters
The median filter in FFmpeg uses a bounding box of
neighboring pixels to calculate a new value for each target pixel. You
can configure this behavior using three primary parameters:
radius(orr): Sets the horizontal radius of the filtering window. The allowed range is from1to127. The default value is1. A larger radius results in a larger search window, which increases the smoothing effect but requires more processing power.radiusV(orrv): Sets the vertical radius of the filtering window. If this is not specified, it defaults to the same value as the horizontalradius. The range is0to127.percentile(orp): Decides which value to pick from the sorted list of pixels inside the window. The value ranges from0.0to1.0. The default is0.5, which represents the actual median. A percentile of0.0will output the minimum value (darkening the image), while1.0will output the maximum value (brightening the image).
Syntax and Examples
The basic syntax for applying the median filter in an FFmpeg command is:
ffmpeg -i input.mp4 -vf "median=radius=X:percentile=Y" output.mp4Example 1: Standard Median Filter
To apply a standard median filter with a horizontal and vertical radius of 3 pixels, and a true median percentile (0.5), use the following command:
ffmpeg -i input.mp4 -vf "median=radius=3:percentile=0.5" output.mp4Example 2: Shorthand Notation
You can use the abbreviated parameter names r and
p to shorten the command:
ffmpeg -i input.mp4 -vf "median=r=5:p=0.5" output.mp4Example 3: Asymmetric Window (Custom Vertical Radius)
If you want to use a wider horizontal search window but a narrower
vertical window, configure radiusV separately. This example
uses a horizontal radius of 5, a vertical radius of 2, and a percentile
of 0.6:
ffmpeg -i input.mp4 -vf "median=radius=5:radiusV=2:percentile=0.6" output.mp4Performance Consideration
Because the median filter must sort the pixel values within the
specified window for every single pixel in a frame, increasing the
radius significantly impacts rendering times. Keep the
radius as low as possible (typically between 1 and 5) to balance noise
reduction with processing speed.