ffmpeg: how to add pixellate effect?

FFmpeg can support the frei0r filters which includes pixeliz0r

original pixeliz0r

Example:

ffmpeg -i input -vf "frei0r=filter_name=pixeliz0r:filter_params=0.02|0.02" output

The two pixeliz0r filter_params parameters are:

  • BlockSizeX: horizontal size of one "pixel"
  • BlockSizeY: vertical size of one "pixel"

Larger values will create larger blocks.

Where to get ffmpeg with frei0r support

  • Windows users can get the "full build" from gyan.dev.

  • Linux users can download or compile:

    • Download ffmpeg with frei0r support at johnvansickle.com.
    • Or compile ffmpeg by installing whatever package provides frei0r.h (such as frei0r-plugins-dev in Ubuntu or frei0r-devel in CentOS) and then add --enable-frei0r to your ffmpeg configure. See FFmpeg Wiki: Compile Guides.
  • macOS users can use Homebrew. You may need the --with-frei0r option.

More info

  • frei0r homepage
  • FFmpeg frei0r filter documentation

If you don't want to install the frei0r plugin for this, there's an alternative way.

dimensions=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of "csv=p=0:s=\:" input)

ffmpeg -i input -filter_complex \
"[0:v] scale='iw/15:-1', scale='$dimensions:flags=neighbor'" output

This scales down the input size (in this example, by 15) and then scales it back up to the original dimensions. The flags=neighbor tells ffmpeg to use the nearest neighbor rescaling algorithm which results in the pixelated effect. You can change the block size by changing the number 15.

The first line is needed to find out the input's original dimensions and scale back directly to it, otherwise the scaling down and scaling up might result in rounding errors that slightly alter the size of the output.

Tags:

Ffmpeg