Use FFmpeg removegrain to Smooth Compression Artifacts
This article explains how to use the removegrain filter
in FFmpeg to reduce and smooth out video compression artifacts. You will
learn the basic syntax of the filter, understand the most effective
processing modes for compression noise, and see practical command-line
examples to clean up your videos.
The removegrain filter is a fast and efficient spatial
denoising filter ported from AviSynth. It processes pixels in a 3x3
grid, making it highly effective at removing “mosquito noise,” blocking,
and high-frequency compression artifacts without causing significant
motion blur or heavy CPU overhead.
Filter Syntax and Modes
The basic syntax for the filter is:
removegrain=m0:m1:m2:m3
- m0: Mode for the first plane (Luma / Y)
- m1: Mode for the second plane (Chroma / U)
- m2: Mode for the third plane (Chroma / V)
- m3: Mode for the fourth plane (Alpha)
If you only specify one mode (e.g., removegrain=2), that
mode is automatically applied to all planes.
The filter offers 24 different modes (0 to 24). The most effective modes for tackling compression artifacts include:
- Mode 0: No processing (pass-through).
- Mode 1: A simple 3x3 blur. This is very soft and works well for light blockiness.
- Modes 2, 3, and 4: Various degrees of median filtering. Mode 2 is a gentle denoiser, while Mode 4 provides stronger artifact reduction by replacing pixels with the closest value of their neighbors.
- Modes 17 and 18: These modes are highly recommended for compression artifacts. They perform a smart spatial smoothing that cleans up “mosquito noise” around sharp edges while preserving original textures.
Practical FFmpeg Examples
1. Gentle Artifact Removal (Mode 2) To apply a mild cleanup to the entire video, use Mode 2 on all channels. This is ideal for high-quality sources that have minor compression noise.
ffmpeg -i input.mp4 -vf removegrain=2 -c:a copy output.mp42. Targetted Luma Denoising (Mode 17) Compression noise is often most visible in the luma (brightness) channel. You can clean up the luma channel with Mode 17 while leaving the chroma (color) channels untouched (Mode 0) to preserve color detail and save processing power:
ffmpeg -i input.mp4 -vf removegrain=17:0:0 -c:a copy output.mp43. Strong Compression Smoothing (Mode 4) For heavily compressed videos with noticeable pixelation and blocky artifacts, Mode 4 offers stronger filtering:
ffmpeg -i input.mp4 -vf removegrain=4 -c:a copy output.mp4Combining removegrain with Other Filters
For severely degraded videos, removegrain can be
combined with a deblocking filter like atadenoise or
hqdn3d in a filter chain. Place removegrain at
the end of the chain to clean up any remaining high-frequency noise:
ffmpeg -i input.mp4 -vf "hqdn3d=1.5:1.5:3:3,removegrain=2" -c:a copy output.mp4