Rotate Video Continuously Over Time with FFmpeg

This article provides a step-by-step guide on how to continuously spin or rotate a video over time using FFmpeg’s powerful rotate filter. You will learn the exact command-line syntax to apply time-based mathematical expressions for a seamless spinning effect, as well as how to adjust the output canvas size to prevent the edges of your video from being cropped during rotation.

The Basic Spinning Command

To make a video spin continuously, you must use FFmpeg’s rotate video filter. This filter accepts mathematical expressions that update dynamically for every frame. By using the variable t (which represents the current time in seconds), you can increase the rotation angle as the video plays.

Here is the basic command to rotate a video 360 degrees (2 * PI radians) every 10 seconds:

ffmpeg -i input.mp4 -vf "rotate='2*PI*t/10'" output.mp4

Understanding the Formula

Preventing Cropping (Expanding the Canvas)

By default, the rotate filter keeps the original dimensions of the input video. Because a rotating rectangle is wider diagonally than it is horizontally or vertically, the corners of your video will get cut off during the spin.

To prevent this cropping, you must expand the output frame size to accommodate the diagonal length of the video. You can calculate this automatically using the hypotenuse function hypot(iw, ih) (where iw is input width and ih is input height).

Use this command to spin the video without cutting off the corners:

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

Parameter Breakdown for the Advanced Command: