Blur Out Videos with FFmpeg
Or how to utilize filter_complex
Harnessing filter_complex
FFmpeg’s filter_complex
works in a similar fashion as Unix pipes. Take a input, modify, output, then rinse and repeat. A filtergraph contains one or more filterchains, each which contains a certain order of filters to be applied to the input source. Like Unix pipes, you can get pretty creative and generate some great results.
Splitting Outputs
First, we will split a single input into 2 outputs with scaled resolutions.
0:v
: Select the first input source’svideo
stream onlysplit=2
: Split the stream into 2 and store them as360p
and720p
[360p]scale=-2:360[360p]
and[720p]scale=-2:720[720p]
scales the input to360px
and720px
height respectively while preserving aspect ratio and sends the output back to the same input name. The-2
is to tell the scaler to scale to a even number as some formats do not support a odd number of pixels-map "[360p]" 360p.mp4
and-map "[720p]" 720p.mp4
take each respective output and encodes it to a file.
The result will be 2 files with different resolutions. Keep in mind, all outputs created in the filtergraph must be connected to an output.
Blurring
The next component is to generate a blurred video. There are many blurring algorithms available, but for this task, we will be using boxblur
. This blur has 3 tunable settings each with radius
(box radius to apply to the frame) and power
(how many times to apply to the frame):
luma
(luma_radius
andluma_power
): Brightnesschroma
(chroma_radius
andchroma_power
): Coloralpha
(alpha_radius
andalpha_power
): Transparency
Fading In
The last part we need is a fade. This is filter is fairly simple as it takes a start and a end with either a fade in or fade out. It supports both frames and time/duration. For our case, we will use the time/duration and skip calculating frames.
Peanut Butter Jelly Time
Now that we have all the tools we need, let’s put this all together. The plan is to put each of the filters above to create a Blur Out effect. A Blur Out is essentially 2 videos (the original and a blurred version) overlayed on top of each other with the one of the videos fading.
For this example, we will choose the original video as the base
and the blurred video as the fade in.
- We will will need to split the input into 2,
base
andblurred
, so we use thesplit
filter - Next we need to generate a blurred version using
boxblur
- Taking the
blurred
input, we add a fade in start time 1s and duration 3s. The extraalpha=1
mentioned here is to allow the video to be transparent when faded out else the background color will be black - The final step is to use
overlay
to put input sources on top of each other (like an onion). Thealpha=1
from above would then allow thebase
to show through theblurred
layer as it is being faded in.