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.
First, we will split a single input into 2 outputs with scaled resolutions.
0:v: Select the first input source’s
split=2: Split the stream into 2 and store them as
[720p]scale=-2:720[720p]scales the input to
720pxheight respectively while preserving aspect ratio and sends the output back to the same input name. The
-2is to tell the scaler to scale to a even number as some formats do not support a odd number of pixels
-map "[360p]" 360p.mp4and
-map "[720p]" 720p.mp4take 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.
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):
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
baseand the blurred video as the fade in.
- We will will need to split the input into 2,
blurred, so we use the
- Next we need to generate a blurred version using
- Taking the
blurredinput, we add a fade in start time 1s and duration 3s. The extra
alpha=1mentioned 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
overlayto put input sources on top of each other (like an onion). The
alpha=1from above would then allow the
baseto show through the
blurredlayer as it is being faded in.