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

Key Parameters

You can customize the filter behavior using several parameters:

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

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

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

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