Continuously Rotate Video with FFmpeg

This article demonstrates how to create a continuous spinning effect in a video using the FFmpeg rotate filter. By tying the rotation angle to the timeline variable t, you can make a video spin smoothly for its entire duration. Below, you will find the standard command, an explanation of the mathematical parameters used for rotation speed, and options to prevent the edges of the video from being clipped.

The Basic Command

To rotate a video continuously around its center, run the following FFmpeg command:

ffmpeg -i input.mp4 -vf "rotate=2*PI*t:ow='hypot(iw,ih)':oh='hypot(iw,ih)':c=black" -c:a copy output.mp4

How It Works

  • rotate=2*PI*t: The rotate filter calculates angles in radians. 2*PI radians equals a full 360-degree rotation. The variable t represents the current timestamp in seconds. Multiplying 2*PI by t forces the video to complete exactly one full revolution per second.
  • ow and oh: By default, the output width (ow) and output height (oh) match the input video dimensions, which will cut off the corners as the video turns. Setting both to 'hypot(iw,ih)' calculates the hypotenuse of the input width (iw) and input height (ih), ensuring the canvas is large enough that corners are never cropped.
  • c=black: Fills the empty background area exposed by the rotation with black. You can change this to any supported color (such as white or blue), or set it to none if exporting to a format that supports transparency (like ProRes 4444 or VP9 with alpha).
  • -c:a copy: Copies the original audio stream directly to the output file without re-encoding.

Controlling Speed and Direction

You can easily modify the spinning behavior by changing the angle expression:

  • Spin Slower: Halve the speed to one revolution every two seconds:

    -vf "rotate=PI*t:ow='hypot(iw,ih)':oh='hypot(iw,ih)'"
  • Spin Faster: Double the speed to two revolutions per second:

    -vf "rotate=4*PI*t:ow='hypot(iw,ih)':oh='hypot(iw,ih)'"
  • Reverse Direction: Add a negative sign to spin counter-clockwise:

    -vf "rotate=-2*PI*t:ow='hypot(iw,ih)':oh='hypot(iw,ih)'"

Keeping the Original Video Dimensions

If you want the output resolution to remain identical to the input resolution and do not mind the corners being clipped during rotation, omit the ow and oh parameters:

ffmpeg -i input.mp4 -vf "rotate=2*PI*t:c=black" -c:a copy output.mp4