FFmpeg Boxblur: How to Apply Dynamic Video Blur

This guide explains how to use the FFmpeg boxblur filter with dynamic radius settings to create a blur effect that changes over time. You will learn the syntax for the filter, see practical command-line examples using time-based expressions, and understand how to control the blur intensity programmatically throughout your video.

The boxblur filter in FFmpeg accepts parameters for luma, chroma, and alpha arrays. To make the blur dynamic, you can pass mathematical expressions using variables like t (current time in seconds) or n (frame number) directly into the radius parameters.

The Basic Syntax

The primary parameters for the boxblur filter are: * luma_radius (lr): The power of the luma blur. * luma_power (lp): How many times the blur filter is applied to the luma plane. * chroma_radius (cr): The power of the chroma blur. * chroma_power (cp): How many times the blur filter is applied to the chroma plane.

To make the radius dynamic, apply an expression enclosed in single quotes to the luma_radius (lr) and chroma_radius (cr) parameters.

Example 1: Gradual Blur (Fade-In Blur)

To make a video start clear and gradually become blurrier as time progresses, you can multiply the time variable t by a multiplier.

ffmpeg -i input.mp4 -vf "boxblur=lr='t*2':lp=1" output.mp4

In this command, lr='t*2' increases the luma blur radius by 2 pixels for every second of video. At 0 seconds, there is no blur; at 5 seconds, the blur radius is 10 pixels.

Example 2: Pulsing Blur Effect

You can use trigonometric functions like sin or cos to create a pulsing blur effect that continuously fades in and out.

ffmpeg -i input.mp4 -vf "boxblur=lr='(sin(t)*5)+5':lp=1" output.mp4

Here, sin(t) fluctuates between -1 and 1. Multiplying it by 5 and adding 5 ensures the blur radius fluctuates smoothly between 0 and 10 pixels over time.

Example 3: Triggering Blur at a Specific Time

If you want the video to remain sharp for the first few seconds and then start blurring, you can use the if and gt (greater than) functions.

ffmpeg -i input.mp4 -vf "boxblur=lr='if(gt(t,5), (t-5)*3, 0)':lp=1" output.mp4

In this example: * Before 5 seconds (t < 5), the blur radius evaluates to 0. * After 5 seconds (t > 5), the blur radius increases by 3 pixels per second, starting from 0.

Performance Tip

Dynamic evaluation of the boxblur filter can be CPU-intensive because the filter must re-calculate and re-apply the box blur kernel for every frame. To improve rendering speeds, keep the luma_power (lp) set to 1 or 2, as higher power values will significantly increase processing time.