Blur Background of Vertical Video with FFmpeg
This article provides a step-by-step guide on how to use FFmpeg to convert a vertical (9:16) video into a widescreen (16:9) format with a blurred background. You will learn the exact command-line syntax required to scale the video, apply a box blur filter to the background layer, and overlay the original sharp video directly in the center.
The FFmpeg Command
To achieve this effect, run the following command in your terminal:
ffmpeg -i input.mp4 -filter_complex "[0:v]scale=1920:1080,boxblur=20:10[bg]; [0:v]scale=-1:1080[fg]; [bg][fg]overlay=(W-w)/2:(H-h)/2" -c:a copy output.mp4Command Breakdown
The command utilizes FFmpeg’s -filter_complex option to
process the video stream in three distinct steps:
[0:v]scale=1920:1080,boxblur=20:10[bg](The Background): This takes the input video ([0:v]), stretches it to fill a standard widescreen resolution of 1920x1080, and applies a box blur filter. The20:10parameters represent the power and radius of the blur; you can increase these numbers for a stronger blur effect. This layer is labeled as[bg].[0:v]scale=-1:1080[fg](The Foreground): This takes the input video again and scales it to a height of 1080 pixels while automatically calculating the correct width (-1) to preserve the original 9:16 aspect ratio. This layer is labeled as[fg].[bg][fg]overlay=(W-w)/2:(H-h)/2(The Positioning): This overlays the sharp foreground video ([fg]) on top of the blurred background video ([bg]). The formula(W-w)/2:(H-h)/2mathematically centers the foreground video horizontally and vertically on the canvas.-c:a copy: This copies the audio stream directly from the input to the output without re-encoding, preserving original audio quality and speeding up the export process.