How to Use FFmpeg Median Filter for Noise Reduction
This guide demonstrates how to use the median video
filter in FFmpeg to eliminate salt-and-pepper noise from your videos.
You will learn the essential syntax, key parameters such as radius and
percentile, and practical command-line examples to clean up noisy
footage while preserving sharp edges.
Understanding the Median Filter in FFmpeg
Salt-and-pepper noise appears as random sparse pixels of extreme brightness or darkness. Standard blur filters often smudge these artifacts, degrading overall image quality. The median filter solves this by replacing each pixel’s value with the median value of its neighboring pixels, effectively discarding outlier noise while preserving sharp image edges.
Basic Command Syntax
To apply the median filter, use the -vf (video filter)
flag followed by median. The simplest command uses default
settings:
ffmpeg -i input.mp4 -vf "median" output.mp4Key Parameters
You can customize the filter behavior using several parameters:
radius(orr): Sets the horizontal radius of the filtering window. The range is 1 to 127 (default is 1). A larger radius removes larger noise artifacts but can result in a loss of fine detail.radiusV(orrv): Sets the vertical radius. If not specified, it defaults to the same value as the horizontal radius.planes(orp): Specifies which color planes to filter. It accepts a bitmap value from 0 to 15 (default is 15, which filters all planes: Y, U, V, and Alpha).percentile(orpercent): Adjusts the percentile used for sorting. The default is0.5(the exact median). Lower values darken the image, while higher values brighten it.
Practical Examples
1. Moderate Noise Reduction
For typical salt-and-pepper noise, a radius of 2 or 3 is usually sufficient:
ffmpeg -i input.mp4 -vf "median=radius=2" output.mp42. Filtering Only the Luma (Y) Plane
If the noise is primarily grayscale and you want to preserve color details without blurring chrominance, target only the luma plane (plane 1):
ffmpeg -i input.mp4 -vf "median=radius=2:planes=1" output.mp43. Asymmetric Filtering
If your video has horizontal noise streaks, you can apply a wider horizontal radius and a smaller vertical radius:
ffmpeg -i input.mp4 -vf "median=radius=4:radiusV=1" output.mp44. Fine-Tuning with Percentile
To bias the filter toward darker pixels (useful if the noise is predominantly bright white “salt” specks), lower the percentile:
ffmpeg -i input.mp4 -vf "median=radius=2:percentile=0.4" output.mp4