FFmpeg Vertical to Horizontal Video with Blurred Sidebars
Converting a vertical 9:16 video into a horizontal 16:9 format often leaves ugly black bars on the sides. This article provides the exact FFmpeg command and filter chain required to replace those black bars with a modern, aesthetically pleasing blurred background generated from the original video.
To achieve this effect, FFmpeg splits the input video into two streams: one for the background and one for the foreground. The background stream is scaled up, cropped to fill the 16:9 canvas, and heavily blurred. The foreground stream is scaled to fit the height of the canvas and overlaid directly in the center.
The FFmpeg Command
Run the following command in your terminal to process your video. This example assumes a standard output resolution of 1920x1080 (1080p horizontal):
ffmpeg -i input.mp4 -lavfi "[0:v]scale=1920:1080:force_original_aspect_ratio=increase,crop=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 core of this command relies on the complex filtergraph
(-lavfi). Here is how each part of the filter works:
[0:v]scale=1920:1080:force_original_aspect_ratio=increase: Takes the input video and scales it up so that it completely covers a 1920x1080 area. Because the original aspect ratio is preserved, parts of the top and bottom will extend beyond the canvas.crop=1920:1080: Crops the scaled background video to exactly 1920x1080, discarding the overflow.boxblur=20:10: Applies a box blur to the background. The first number (20) is the blur radius, and the second number (10) is the power (how many times the blur is applied).[bg]: Saves this blurred, cropped background stream as a temporary variable namedbg.[0:v]scale=-1:1080[fg]: Takes the original video again, scales its height to 1080 pixels while automatically maintaining its original vertical aspect ratio, and labels itfg.[bg][fg]overlay=(W-w)/2:(H-h)/2: Places the foreground (fg) directly in the center of the blurred background (bg).-c:a copy: Copies the audio stream without re-encoding it, saving processing time and preserving original audio quality.
Customizing the Output
You can easily adjust this command to fit your specific needs:
- Adjust Blur Intensity: Increase the numbers in
boxblur=20:10for a stronger blur (e.g.,boxblur=40:10), or decrease them for a sharper background. - Change Resolution: If you want a 720p output
(1280x720), change
1920:1080to1280:720and scale the foreground withscale=-1:720.