Blurred background
vertical video in ffmpeg.
The full filter graph, what every single part of it does, how to batch it across a folder, and the three mistakes that produce broken output.
Complete filter graph
ffmpeg -y -i input.mp4 -filter_complex "\
[0:v]scale=1080:1920:force_original_aspect_ratio=increase,\
crop=1080:1920,boxblur=40:4,setsar=1[bg];\
[0:v]scale=1080:-2[fg];\
[bg][fg]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p[v]" \
-map "[v]" -map 0:a? -c:v libx264 -preset veryfast -crf 20 \
-c:a copy -movflags +faststart output.mp4
Every part, explained
| Fragment | What it does |
|---|---|
[0:v] | The video stream of input 0. Used twice — once for background, once for foreground. |
force_original_aspect_ratio=increase | Scales up until the frame covers the canvas, overflowing on one axis rather than fitting inside it. |
crop=1080:1920 | Trims that overflow to exact canvas size, producing a full-bleed background. |
boxblur=40:4 | Radius 40, 4 passes. Repeated box blur approximates gaussian at a fraction of the cost. |
setsar=1 | Forces square pixels. Without it, mismatched sample aspect ratios between layers break the overlay. |
scale=1080:-2 | Foreground at full width; height computed automatically and rounded even for H.264. |
overlay=(W-w)/2:(H-h)/2 | Centres foreground over background on both axes using canvas and layer dimensions. |
format=yuv420p | Mandatory for social platforms. Without it ffmpeg may emit yuv444p, which most uploaders reject. |
-map 0:a? | Includes audio only if present. The ? prevents a silent source from failing the job. |
-movflags +faststart | Moves the MP4 index to the front so the file streams before it finishes downloading. |
Processing a whole folder
macOS / Linux
mkdir -p out
for f in *.mp4; do
ffmpeg -y -i "$f" -filter_complex "\
[0:v]scale=1080:1920:force_original_aspect_ratio=increase,\
crop=1080:1920,boxblur=40:4,setsar=1[bg];\
[0:v]scale=1080:-2[fg];\
[bg][fg]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p[v]" \
-map "[v]" -map 0:a? -c:v libx264 -preset veryfast -crf 20 \
-c:a copy -movflags +faststart "out/${f%.mp4}-vertical.mp4"
done
Windows (PowerShell)
mkdir out -Force
Get-ChildItem *.mp4 | ForEach-Object {
ffmpeg -y -i $_.Name -filter_complex "[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,boxblur=40:4,setsar=1[bg];[0:v]scale=1080:-2[fg];[bg][fg]overlay=(W-w)/2:(H-h)/2:format=auto,format=yuv420p[v]" -map "[v]" -map 0:a? -c:v libx264 -preset veryfast -crf 20 -c:a copy -movflags +faststart "out/$($_.BaseName)-vertical.mp4"
}
Three mistakes that break output
Missing yuv420p
The file encodes fine and plays locally, then fails to upload with an unhelpful error. Always end the chain with format=yuv420p.
Hardcoded height
Works for exactly-16:9 sources, silently stretches everything else. Use -2 and let ffmpeg compute it.
Missing setsar=1
Sources with non-square pixels produce a distorted or failed overlay. Cheap to add, annoying to debug.
Speeding it up
The blur is the expensive filter. If you're processing at volume:
- Blur a smaller layer. Scale down, blur, then scale back up — visually near-identical, meaningfully cheaper, since the result is heavily blurred anyway.
- Keep
-preset veryfast. The blurred region conceals most encoding artefacts, so slower presets buy very little here. - Don't touch the audio.
-c:a copyskips audio re-encoding entirely.
# cheaper background: downscale → blur → upscale
[0:v]scale=270:480,boxblur=10:4,scale=1080:1920,setsar=1[bg];
Common questions
What does boxblur=40:4 mean?
Radius 40 pixels, applied over 4 passes. Multiple passes of box blur approximate a gaussian blur at much lower computational cost.
Why use -2 instead of a fixed height?
It tells ffmpeg to compute the height from the width while preserving aspect ratio and rounding to an even number, which H.264 requires. A fixed height distorts any source that isn't exactly 16:9.
Can I use GPU acceleration?
Yes — h264_nvenc, h264_qsv, or h264_videotoolbox can replace libx264 for encoding. The blur filter itself still runs on CPU unless you use the CUDA filter chain.
How do I make the blur stronger?
Increase the boxblur radius. Values between 30 and 50 work well; beyond that the background loses all structure and stops reading as related to the foreground.