How to Use the Rotate Filter in FFmpeg

This guide explains how to use the FFmpeg rotate filter to rotate videos by any angle. You will learn the basic syntax for common rotations (like 90, 180, and 270 degrees), how to handle custom angles using radians or degrees, and how to prevent the video frame from being clipped during rotation.

Understanding the Rotate Filter Syntax

The rotate filter in FFmpeg rotates a video by an angle expressed in radians. By default, the output video maintains the original width and height, which means the corners of a rotated video may be cropped, and empty areas will be filled with a black background.

The basic syntax is:

ffmpeg -i input.mp4 -vf "rotate=ANGLE" output.mp4

Because FFmpeg expects radians, you can specify angles using the constant PI. For example: * 90 degrees clockwise: PI/2 * 180 degrees: PI * 270 degrees clockwise (90 counter-clockwise): 3*PI/2

Alternatively, you can convert degrees to radians directly in the command by multiplying the degrees by PI/180:

ffmpeg -i input.mp4 -vf "rotate=45*PI/180" output.mp4

Rotating Without Clipping the Video (Auto-Sizing)

When you rotate a video by an angle that is not a multiple of 180 degrees, the corners will be cut off unless you expand the output frame. To prevent clipping, you must recalculate the output width (ow) and output height (oh) using the rotw (rotated width) and roth (rotated height) functions.

Use the following command to rotate a video by 45 degrees and automatically fit the entire rotated image into the frame:

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

Changing the Background Color

By default, the empty spaces created by rotating a video are filled with black. You can change this background color using the fillcolor option (or c for short). You can specify color names (like red, blue, white) or hex codes:

ffmpeg -i input.mp4 -vf "rotate=45*PI/180:fillcolor=red" output.mp4

To make the background transparent (useful if you are outputting to a format that supports alpha channels, like ProRes or WebM), use the color value none:

ffmpeg -i input.mp4 -vf "rotate=45*PI/180:fillcolor=none" output.mp4

Creating a Dynamic Spinning Effect

The rotate filter allows you to use the variable t (time in seconds) or n (frame number) to create a continuous rotation effect over time.

To rotate the video by 1 radian per second, use:

ffmpeg -i input.mp4 -vf "rotate=t" output.mp4