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:

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.mp4

Example 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.mp4

Example 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.mp4

Example 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.mp4

Performance 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.