Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg: how to add pixellate effect?

Tags:

ffmpeg

I need to blur some uploaded videos and encoded them. Infact by blur, it means pixellate them so "big squares" appear and blur it.

Any idea on how I can do that ? (ffmpeg would be great, by any command line windows tool should be ok)

Thanks.

like image 224
yarek Avatar asked Feb 01 '12 09:02

yarek


2 Answers

FFmpeg can support the frei0r filters which includes pixeliz0r

originalpixeliz0r

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
like image 152
llogan Avatar answered Sep 22 '22 12:09

llogan


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.

like image 44
Tom Avatar answered Sep 22 '22 12:09

Tom