How to Rotate Video by Custom Angle in FFmpeg
This guide demonstrates how to use the rotate filter in
FFmpeg to rotate a video by any custom angle. You will learn the core
command syntax, how to convert degrees to radians, and how to adjust the
output frame size to prevent the edges of your rotated video from being
cropped.
The Core Rotation Syntax
FFmpeg’s rotate filter (-vf "rotate=...")
expects the rotation angle to be specified in radians
rather than degrees.
To rotate a video by a custom angle in degrees, you must convert the
degrees to radians using the formula: degrees * (PI / 180).
FFmpeg conveniently provides the PI constant to use
directly inside the command.
Basic Rotation (with cropping)
To rotate a video clockwise by 45 degrees using the default video dimensions:
ffmpeg -i input.mp4 -vf "rotate=45*(PI/180)" output.mp4Note: This basic command keeps the original video width and height. Because the video is rotated within the original boundaries, the corners of the frame will be cropped.
Rotating Without Cropping (Fit to Screen)
To prevent the corners of the video from being cut off, you must
dynamically recalculate the output frame size. You can achieve this by
setting the output width (ow) and output height
(oh) using FFmpeg’s built-in rotw (rotated
width) and roth (rotated height) functions.
Rotation with expanded frame
To rotate a video clockwise by 33 degrees and expand the frame to fit the entire rotated image:
ffmpeg -i input.mp4 -vf "rotate=33*(PI/180):ow='rotw(33*(PI/180))':oh='roth(33*(PI/180))'" output.mp4Rotating Counter-Clockwise
To rotate the video counter-clockwise, simply use a negative angle value. For example, to rotate 15 degrees counter-clockwise:
ffmpeg -i input.mp4 -vf "rotate=-15*(PI/180):ow='rotw(-15*(PI/180))':oh='roth(-15*(PI/180))'" output.mp4Customizing the Background Color
When you rotate a video and expand the frame, empty triangular areas are created in the corners. By default, FFmpeg fills these areas with black.
You can change this background color using the fillcolor
option (or c). For example, to fill the background with
red:
ffmpeg -i input.mp4 -vf "rotate=45*(PI/180):ow='rotw(45*(PI/180))':oh='roth(45*(PI/180))':fillcolor=red" output.mp4To make the background completely transparent (requires an output format that supports transparency, like VP9 or ProRes):
ffmpeg -i input.mp4 -vf "rotate=45*(PI/180):ow='rotw(45*(PI/180))':oh='roth(45*(PI/180))':fillcolor=none" output.mp4