Blurring is a video editing technique that softens or distorts details in a video. This makes the video or the parts that were blurred appear out of focus. You can use blur for many things. These include hiding sensitive information, creating transitions, and making focus effects.

In this guide, we'll learn how to apply different types of FFmpeg blur effects. We'll cover the Gaussian blur, box blur, and directional blur. We'll also cover how to apply a blur on only part of a video.

About FFmpeg

FFmpeg is a powerful open-source command-line tool for processing multimedia files. It is used for decoding, encoding, transcoding, muxing, demuxing, streaming, filtering, and playing almost anything that humans and machines have created.

Its versatility makes it popular among developers and video enthusiasts alike. FFmpeg also has another advantage. It works on all major operating systems, such as Windows, Linux, and macOS.

You can download the newest FFmpeg from the official FFmpeg download page.

For this guide we'll be using the following video to apply the different FFmpeg blur filters:

Apply FFmpeg Gaussian Blur Effect

A Gaussian blur creates an out-of-focus effect. It does this by applying a Gaussian function to the video or image.

It's popular because, compared to other blur types, it keeps the shapes of objects. It still gives a softened, out-of-focus look. It's often used for background blurring.

To apply an FFmpeg gaussian blur, run the following command in the terminal:

ffmpeg -i input.mp4 -vf "gblur=sigma=5" -c:a copy output.mp4

Breakdown of the command

  • -i input.mp4: Specifies the input file. In this case, input.mp4 is the name of the file we're applying the Gaussian blur to.
  • -vf: Stands for "video filter". It shows the next argument gblur=sigma=5 is a filter to be applied to the input video.
  • gblur=sigma=5: Applies the Gaussian blur with a sigma value of 5. The sigma parameter controls the amount of blurring. A higher value will create a more intense blur effect.
  • -c:a: Specifies the codec to use for the audio stream.
  • copy: Copies the audio stream from the input video to the output video without any re-encoding. This preserves the original audio quality and also reduces processing time.
  • output.mp4 Specifies the output file. It means the processed video with the Gaussian blur effect will be named output.mp4.

The following is the result of the command that applies the Gaussian blur (sigma value of 5):

Here is another example with a sigma value of 15:

Apply FFmpeg Box Blur Effect

A Box blur effect is a simple blur technique. The algorithm replaces each pixel in the image or video with the average of its neighboring pixels.

It's widely used to blur out sensitive information. This includes faces or license plates, without ruining the image.

To create an FFmpeg box blur, run the following command in the terminal:

ffmpeg -i input.mp4 -vf "boxblur=10" -c:a copy output.mp4

The value of the boxblur parameter determines the intensity of the blur. A higher value results in a more intense blur. See the two examples below.

Box blur effect example with a boxblur value of 10:

Box blur effect example with a boxblur value of 20:

Apply FFmpeg Directional Blur Effect

A directional blur is a type of blur effect that applies the blur along a specific direction or angle. Unlike other blur effects, the blur is not applied uniformly in all directions. It's often used to simulate motion in images and videos.

To apply an FFmpeg directional blur run the following command:

ffmpeg -i input.mp4 -vf "dblur=angle=30:radius=10" -c:a copy output.mp4
  • -vf "dblur=angle=30:radius=10": applies the directional blur effect.
  • angle=30 Shows the angle or direction of the blur, measured in degrees and clockwise from the horizontal axis.
  • radius=10 Applies the radius or intensity of the blur effect. A higher radius will result in a more intense blur.

The following is the output video for the command above:

Here is a second example of applying a directional with an angle of 90 degrees:

ffmpeg -i input.mp4 -vf "dblur=angle=90:radius=10" -c:a copy output.mp4

Output video:

Apply blur to part of a video with FFmpeg

So far, with all the examples, we've applied the blur filter on the entire video. But there are times when you want to apply the blur on only parts of a video while keeping the rest of the video clear.

The following is a video of a car with a "SANTA CLAUS" license plate. We can add a blur effect to the video that covers only the license plate using the FFmpeg command below:

ffmpeg -i car.mp4 -filter_complex "[0:v]crop=180:90:160:380,boxblur=10[mask];[0:v][mask]overlay=160:380[v]" -map "[v]" -map 0:a -c:a copy car-with-blur.mp4

The command crops part of the video, applies a blur on the cropped part, and overlays it back on the video. Below is a proper breakdown of the command.

Breakdown of the command

  • -filter_complex: This option allows you to apply advanced filtering operations to the input.
  • "[0:v]crop=180:90:160:380,boxblur=10[mask];[0:v][mask]overlay=160:380[v]": The complex filter above does the following:
  • [0:v]: Refers to the video stream of the first input video.
  • crop=180:90:160:380: Crops a 180x90 pixel area from the video starting at coordinates (160, 380).
  • boxblur=10: Applies a box blur with an intensity level of 10.
  • [mask]: Labels the output of the previous filter chain as mask.
  • [0:v][mask]overlay=160:380[v]: Overlays the blurred mask onto the original video at coordinates (60, 30) and labels the results v.
  • -map "[v]": Maps the resulting video of the filter chain labeled v to the output file.
  • -map 0:a: Maps the audio stream, if any, from the input file (index 0) to the output file.
  • -c:a copy: Copies the audio stream without re-encoding.
  • car-with-blur.mp4 Specifies the output file. The output file will be named car-with-blur.mp4.

Below is the output video car-with-blur.mp4 with the license plate blurred out:

Apply blur to part of a video

You can also use FFmpeg, to blur part of a video. For example, consider the "SANTA CLAUS" car video. Let's add a blur effect from the 4th to the 7th seconds with this command.

ffmpeg -i input.mp4 -vf "boxblur=10:enable='between(t,4,7)'" -c:v libx264 -c:a copy output.mp4
  • enable='between(t,4,7): allows the box blur effect to be applied only between the 4th and 7th second.
  • -c:v libx264: Specifies the video codec to use for encoding as H.264 using the libx264 encoder.

Conclusion

FFmpeg is a versatile tool. It is feature-rich and can do complex video editing operations with simple commands. This guide covered how to blur videos using FFmpeg. You now know how to apply Gaussian blur, box blur, and directional blur.

You also learned about applying a blur to only parts of a video and to a specific time range. Check out our other FFmpeg tutorials to learn more about how to use FFmpeg for video and image editing.

Get started with Shotstack's video editing API in two steps:

  1. Sign up for free to get your API key.
  2. Send an API request to create your video:
    curl --request POST 'https://api.shotstack.io/v1/render' \
    --header 'x-api-key: YOUR_API_KEY' \
    --data-raw '{
    "timeline": {
    "tracks": [
    {
    "clips": [
    {
    "asset": {
    "type": "video",
    "src": "https://shotstack-assets.s3.amazonaws.com/footage/beach-overhead.mp4"
    },
    "start": 0,
    "length": "auto"
    }
    ]
    }
    ]
    },
    "output": {
    "format": "mp4",
    "size": {
    "width": 1280,
    "height": 720
    }
    }
    }'
Maab Saleem

BY MAAB SALEEM
3rd July 2024

Studio Real Estate
Experience Shotstack for yourself.
SIGN UP FOR FREE

You might also like

Generate audio waveform videos using FFmpeg

Generate audio waveform videos using FFmpeg

Jeff Shillitto
How to use FFmpeg (with examples)

How to use FFmpeg (with examples)

Andrew Bone
 Convert videos to MP3 using FFmpeg

Convert videos to MP3 using FFmpeg

Jeff Shillitto