How to Rotate Video in FFmpeg without Cropping

This article explains how to use the FFmpeg rotate filter to rotate a video by any arbitrary angle while dynamically adjusting the output frame size. By configuring the output width and height to match the rotated bounds, you can prevent the video from being cropped or having its corners cut off during the rotation process.

By default, the FFmpeg rotate filter retains the original input dimensions. When you rotate a video at an angle other than multiples of 180 degrees, this default behavior causes the corners of the video to be clipped. To prevent this, you must explicitly calculate and set the output width (ow) and height (oh) to fit the new bounding box of the rotated image.

FFmpeg provides two built-in functions specifically for this calculation: rotw(a) and roth(a), where a is the rotation angle in radians.

The FFmpeg Command

To rotate a video and automatically expand the canvas to fit the rotated frame, use the following filter syntax:

ffmpeg -i input.mp4 -vf "rotate=45*PI/180:ow='rotw(45*PI/180)':oh='roth(45*PI/180)'" output.mp4

How It Works

Handling the Background Color

When the output frame size expands, empty areas (corners) will be created around the rotated video. By default, FFmpeg fills these areas with black. If you want to change this background color, you can use the fillcolor (or c) option:

ffmpeg -i input.mp4 -vf "rotate=30*PI/180:ow='rotw(30*PI/180)':oh='roth(30*PI/180)':fillcolor=blue" output.mp4

Using this method ensures your video is fully visible at any angle, with the output dimensions automatically scaling to perfectly fit the newly rotated boundaries.