Rotate Video by Arbitrary Angle in FFmpeg
This guide explains how to rotate a video to an arbitrary angle, such
as 45 degrees, using FFmpeg's rotate video filter. You will
learn the correct command syntax, how to convert standard degrees to
radians, how to prevent edge-clipping by adjusting output dimensions,
and how to change the background fill color of the exposed frame
area.
Basic Rotation Command
The rotate filter in FFmpeg expects angles expressed in
radians rather than degrees. To rotate a video by 45 degrees clockwise,
you must convert the degree value by multiplying it by
PI/180 (or using the direct radian value
PI/4).
ffmpeg -i input.mp4 -vf "rotate=45*(PI/180)" -c:a copy output.mp4To rotate counter-clockwise, supply a negative value:
ffmpeg -i input.mp4 -vf "rotate=-45*(PI/180)" -c:a copy output.mp4Preventing Frame Cropping
By default, the rotate filter maintains the original
video's width and height. Rotating a rectangular frame within its
original dimensions causes the corners of the rotated image to be cut
off.
To expand the canvas so the entire rotated video remains visible,
configure the output width (ow) and output height
(oh) parameters using the helper functions
rotw() and roth():
ffmpeg -i input.mp4 -vf "rotate=45*(PI/180):ow='rotw(45*PI/180)':oh='roth(45*PI/180)'" -c:a copy output.mp4Customizing the Background Color
When the output canvas expands, empty space appears around the
corners of the rotated frame. By default, FFmpeg fills this space with
black. You can change this background using the c (color)
option:
ffmpeg -i input.mp4 -vf "rotate=45*(PI/180):ow='rotw(45*PI/180)':oh='roth(45*PI/180)':c=white" -c:a copy output.mp4For transparency (when encoding to formats that support alpha
channels, such as ProRes 4444 or VP9), set the fill color to
none:
ffmpeg -i input.mp4 -vf "rotate=45*(PI/180):ow='rotw(45*PI/180)':oh='roth(45*PI/180)':c=none" -c:v prores_ks -profile:v 4 -c:a copy output.movAnimating the Rotation
The rotate filter also evaluates expressions dynamically
across time. To continuously spin a video at a fixed rate, incorporate
the time variable t:
ffmpeg -i input.mp4 -vf "rotate=2*PI*t/10:ow='rotw(2*PI*t/10)':oh='roth(2*PI*t/10)'" -c:a copy output.mp4In this command, 2*PI*t/10 completes one full 360-degree
rotation every 10 seconds.