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

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:

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

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

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

Combining 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