Configure FFmpeg Median Filter Radius and Percentile
The FFmpeg median video filter is a spatial denoising
tool that replaces each pixel with a calculated percentile of
surrounding pixels, effectively eliminating salt-and-pepper noise while
maintaining edge definition. This guide covers how to properly define
the filter's radius to control the sample area size and
adjust the percentile parameter to bias the output values
between minimum, median, and maximum luminance.
Understanding the Parameters
The median filter accepts two primary parameters for
controlling blur spread and pixel selection:
radius(orr): Sets the horizontal radius of the filtering window (valid range: 1 to 127). The full window width is(2 * radius) + 1. If the vertical radius (radiusV) is not set, it defaults to the same value asradius.percentile(orp): Sets the percentile value to pick from the sorted neighborhood window (valid range: 0.0 to 1.0, with a default of0.5). A value of0.5represents a true median filter, while0.0yields a minimum filter (erosion) and1.0yields a maximum filter (dilation).
Basic Command Syntax
The parameters are passed into the filtergraph via the
-vf flag, using standard key-value formatting:
ffmpeg -i input.mp4 -vf "median=radius=3:percentile=0.5" -c:a copy output.mp4You can also use the shorthand aliases r and
p:
ffmpeg -i input.mp4 -vf "median=r=3:p=0.5" -c:a copy output.mp4Practical Configuration Examples
1. Light Denoising with Standard Median
For removing fine grain or sensor noise without heavily blurring fine details, use a small radius of 1 or 2 with the default 0.5 percentile:
ffmpeg -i input.mp4 -vf "median=radius=1:percentile=0.5" -c:a copy output.mp42. Aggressive Smoothing
Increasing the radius samples a wider neighborhood, creating an oil-painting or watercolor effect while retaining sharp contrast boundaries:
ffmpeg -i input.mp4 -vf "median=radius=5:percentile=0.5" -c:a copy output.mp43. Dark Artifact Removal (Higher Percentile)
Setting the percentile above 0.5 forces the filter to
favor brighter pixels from the surrounding window. A percentile of
0.75 or higher is useful for suppressing dark speckles,
dust, or scratches:
ffmpeg -i input.mp4 -vf "median=radius=2:percentile=0.75" -c:a copy output.mp44. Bright Speckle Suppression (Lower Percentile)
Setting the percentile below 0.5 favors darker values,
making it effective for stripping away bright dead pixels, hot sensor
noise, or harsh glare:
ffmpeg -i input.mp4 -vf "median=radius=2:percentile=0.25" -c:a copy output.mp45. Independent Vertical and Horizontal Radius
If your source footage has non-square pixels or directional noise
(such as interlacing artifacts), configure horizontal and vertical radii
separately using radius and radiusV:
ffmpeg -i input.mp4 -vf "median=radius=3:radiusV=1:percentile=0.5" -c:a copy output.mp4