Fix Blank Borders When Rotating FFmpeg Video
When you rotate a video by a custom angle in FFmpeg using the
rotate filter, the corners of the rotated frame often leave
empty, blank areas (usually black) because the rectangular frame
boundary remains aligned with the screen. This article explains how to
handle these blank areas by filling them with custom colors, making them
transparent, cropping the video to remove them, or filling them with a
blurred background.
Fill Blank Areas with a Custom Color
By default, FFmpeg fills the empty areas created by rotation with
black. You can change this to any color using the fillcolor
option within the rotate filter.
To fill the blank areas with white, use the following command:
ffmpeg -i input.mp4 -vf "rotate=30*PI/180:fillcolor=white" -c:a copy output.mp4You can use standard color names (like red,
blue, green) or hexadecimal color codes (like
0xFF5733).
Make Blank Areas Transparent
If you want the background to be transparent—for example, to overlay
the rotated video on top of another video later—you can set the
fillcolor to none. This requires converting
the video’s pixel format to one that supports an alpha channel, such as
rgba, and exporting to a container that supports
transparency (like WebM or QuickTime MOV).
ffmpeg -i input.mp4 -vf "format=rgba,rotate=30*PI/180:fillcolor=none" -c:v libvpx-vp9 -b:v 2M output.webmCrop the Video to Remove Blank Areas
To completely eliminate the blank borders, you can crop the video down to the largest fully-contained rectangle inside the rotated frame. This removes the outer edges of your original video but ensures there are no empty gaps.
You can chain the crop filter after the
rotate filter. For a 30-degree rotation, you would manually
calculate the safe inner rectangle dimensions and crop accordingly:
ffmpeg -i input.mp4 -vf "rotate=30*PI/180,crop=1280:720" -c:a copy output.mp4Adjust the crop dimensions (w:h) based on
your original video resolution and the rotation angle to ensure no blank
spaces remain visible.
Fill Blank Areas with a Blurred Background
For a professional look, you can place a scaled, highly blurred version of the original video in the background to fill the empty spaces, while keeping the rotated video in the foreground.
This is achieved using a complex filtergraph:
ffmpeg -i input.mp4 -filter_complex "[0:v]split[bg][fg];[bg]scale=1920:1080,boxblur=20[bg_blur];[fg]rotate=30*PI/180:fillcolor=none[fg_rotated];[bg_blur][fg_rotated]overlay=(W-w)/2:(H-h)/2:format=rgb" -c:a copy output.mp4In this command: 1. The input video is split into two streams:
bg (background) and fg (foreground). 2. The
background is scaled up and blurred using boxblur. 3. The
foreground is rotated with a transparent background. 4. The rotated
foreground is centered and overlaid on top of the blurred
background.