convolution

Watch on youtube.com
doc

https://ffmpeg.org/ffmpeg-filters.html#convolution

You can also use the “convolution” filter to get a blur effect.

As the name suggests, this filter only performs “convolution” and is not a filter for blurring. However, there is a possibility that fine control over the “boxblur” filter can be done accordingly.

Example 1

00:00:26

This example is an example of the official document itself. A matrix of 3 × 3 is given to all four planes.

#! /bin/sh
ifn="Pexels_flowers.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"

#
ffmpeg -y -i "${ifn}" -filter_complex "
[0:v]
crop=600:400:960:540,drawbox=c=blue,setsar=1,
convolution='
1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:
1/9:
1/9:
1/9:
1/9'
[blurring];

[0:v][blurring]overlay=960:540[v]
" -map '[v]' -an "${pref}_${ifnb}.mp4"

Example 2

00:00:56

If you want to blur more strongly, you can apply the same filter repeatedly. It seems like a ridiculous idea, but actually, “power” of the “boxblur” filter does exactly the same.

#! /bin/sh
ifn="Pexels_flowers.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"

#
ffmpeg -y -i "${ifn}" -filter_complex "
[0:v]
crop=600:400:960:540,drawbox=c=blue,setsar=1,
convolution='
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:1/9:1/9:1/9:1/9',
convolution='
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:1/9:1/9:1/9:1/9',
convolution='
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:1/9:1/9:1/9:1/9',
convolution='
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:1/9:1/9:1/9:1/9',
convolution='
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:1/9:1/9:1/9:1/9',
convolution='
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:1/9:1/9:1/9:1/9',
convolution='
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:1/9:1/9:1/9:1/9',
convolution='
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:
1 1 1  1 1 1  1 1 1:1 1 1  1 1 1  1 1 1:1/9:1/9:1/9:1/9'
[blurring];

[0:v][blurring]overlay=960:540[v]
" -map '[v]' -an "${pref}_${ifnb}.mp4"

Example 3

00:01:26

This is the same as the topic “Blur an image using 3x3 Gaussian kernel?” in StackOverflow applied to Y Plane, I think. I do not guarantee that this will correctly reproduce the one of StackOverflow, but in any case such a fine control can be done with “convolution”. In other words, if you do not need these fine controls, you should obviously use another blur specialty filter.

#! /bin/sh
ifn="Pexels_flowers.mp4"
ifnb="`basename \"${ifn}\" .mp4`"
pref="`basename $0 .sh`"
#
ffmpeg -y -i "${ifn}" -filter_complex "
[0:v]crop=600:400:960:540,drawbox=c=blue,setsar=1,
convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16'
[blurring];

[0:v][blurring]overlay=960:540[v]
" -map '[v]' -an "${pref}_${ifnb}.mp4"

#
# uploaded video was made by following:
#
##
##ffmpeg -y -i "${ifn}" -filter_complex "
##[0:v]crop=600:400:960:540,drawbox=c=blue,setsar=1,
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16',
##convolution=0m='1 2 1  2 4 2  1 2 1':0rdiv='1/16'
##[blurring];
##
##[0:v][blurring]overlay=960:540[v]
##" -map '[v]' -an "${pref}_${ifnb}.mp4"