8/27/2020

Creating Retro Glow Effects with FFmpeg

In this post I'm going to be breaking down a retro glow effect I recently created using FFmpeg. If you enjoy this topic, you might also like this post where I cover a number of different techniques I've been experimenting with recently to create retro video filters using FFmpeg.

I recently stumbled onto this effect kind of by accident, and I've been pleasantly surprised with the results it has gotten so far.

The filter I'm going to be breaking down in this post will add a retro "dreamy" glowing effect to any video or image you apply it to. Think of dream sequences in movies, or your favorite any music video created in the 1980's - that's basically what this effect does.

First, let's look at a quick side-by-side example. In the demo below, the video on the left is the original, and the video on the right has been edited using FFmpeg to add my glow filter:

Before
After

Pretty cool right? Let's look at a step-by-step break down of how to recreate the effect.

1. RGBAShift

The first thing I did is apply FFmpeg's rgbashift filter to the video. Here is the FFmpeg command that I used for this:

ffmpeg -i original.mp4 -vf rgbashift=rh=15:bv=15:gh=-15 -pix_fmt yuv420p rgba-shifted.mp4

In this example I'm shifting red horizontally 15 pixels, blue vertically 15 pixels, and green horizontally -15 pixels. Here is the resulting output we get for this step:

2. Blend The Output From Step One Back Into Origin

Now that we have the rgba shifted output, next I created another FFmpeg command that blends the output from step 1 back into our original video, using the blend filter set to "overlay":

ffmpeg -i original.mp4 -i rgbashifted.mp4 -filter_complex "[1]format=rgba[in2];[in2][0]scale2ref[in2][in1];[in1][in2]blend=overlay" overlay.mp4

Here is the output we get from this step:

3. Add Gaussian blur

Next, using the output from step 2 as my input, I create another FFmpeg command that applies a heavy amount of gaussian blur using FFmpeg's gblur filter.

My parameter settings that I used for this are steps=6 and sigma=42. I think there is a lot of room to experiment here, but the main point is that I wanted to apply a significant amount of gaussian blur in this step. So here is what my command looks like:

ffmpeg -i overlay.mp4 -vf gblur=sigma=42:steps=6 -pix_fmt yuv420p gblur.mp4

And here is the output we get from this step:

4. Blend Our Gblur Results Back into Origin

So now, let's take the output from step 3 and blend it back into the original video. This time though, the important piece is that I'm setting the blend mode to 'screen' instead of 'overlay'. Here is my FFmpeg command for this:

ffmpeg -i original.mp4 -i gblur.mp4 -filter_complex "[1]format=yuv420p[in2];[in2][0]scale2ref[in2][in1];[in1][in2]blend=screen" output.mp4

And that's it! Here is the final result:

Conclussion

I'm pretty excited about the results I've been getting with this filter. So far, it has produced consistently good looking results on every image or video I've tested it on.

Additionally, I've been a little dissapointed with the results I've gotten in the past from trying to use the frie0r=glow filter, but this technique actually creates the exact glow effect that I was hoping acheive with that.

I think there is a ton of room to play around with things like gblur parameters to further customize the results you get with this as well. Based on the heavy blur being applied in step 3, it's also possible that you may be able to skip steps 1 and 2 entirely and still get similar results to the final output.