Blur a Video using FFmpeg’s BoxBlur Filter

Blurring is an important operation in video post-production. Instead of using costly software, you can use FFmpeg’s boxblur to blur your videos and even choose which area of the frames to blur.

In this post, let’s learn how to use FFmpeg’s boxblur function to blur a section of a video or a part of a frame.

Anatomy of FFmpeg’s boxblur function 

Before providing the full command, let’s get familiar with the baseline filter-complex function.

"[0:v]crop=400:400:300:350,boxblur=10[fg]; [0:v][fg]overlay=300:350[v]"

There are 2 sets of coordinates mentioned here-

  • crop=400:400:300:350 : This denotes a 400x400 pixel box located 300 pixels to the right and 350 pixels to the bottom from the top left corner
  • overlay=300:350 : This determines the pixels to overlay inside the box. Unless required otherwise, use the same last two coordinates mentioned in the crop to ensure the blurred effect is applied on the pixels that are located where the box is. 
  • the 10 indicates the power of the blurring effect or its intensity. You can set it individually for the luma, chroma, and alpha planes and also set the blurring power. If you don’t provide the radius or the blurring power, it defaults to 2.

With that, let’s take a look at the command to take a video input and blur a portion of it across its entire playback.

ffmpeg -i inputVideo.mp4 \
-filter_complex "[0:v]crop=200:400:300:350,boxblur=10[fg]; [0:v][fg]overlay=300:350[v]" \
-map "[v]"  \
blurredVideo.mp4

Here is what the output looks like. We have a 200x400 block of pixels blurred out.

boxblur blur a video using ffmpeg

Next, let’s take a look at how to change the blurring power and what the output looks like.

FFmpeg’s boxblur with power = 10

FFmpeg’s boxblur with power = 30

Now let’s look at a blurring power = 30 to show how you can change the blurring effect using boxblur.

It’s as simple as that. But that’s not all. There are a lot of fancy tricks and techniques we can use to make much more of the “boxblur”. 

How to Blur all but a Specific Area of the Video using Boxblur

Let’s find out how to do the opposite of what we’ve just done, and blur everything that is not in the cropped box. Just like above, crop and overlay are used exactly in the same manner.

ffmpeg -i inputVideo.mp4 \
-filter_complex "[0:v]boxblur=10[bg];[0:v]crop=600:600:100:500[fg];[bg][fg]overlay=100:500" \
-map 0:v \
blurredVideo.mp4

Conclusion

In this article, we learned to use FFmpeg’s boxblur function to selectively blur a portion of the video. Hope this was helpful and do check out the rest of OTTVerse’s FFmpeg tutorials.

About The Author

Akshay is a student at the NYU Tandon School of Engineering, completing his M.S. in Computer Engineering. His area of interests include software system design, machine learning, and cybersecurity.

Akshay also serves as a Contributing Author on OTTVerse.com

LinkedIn: https://www.linkedin.com/in/akshay-r-816767117

Leave a Reply

Scroll to Top