Rotate Video 90 Degrees Clockwise with FFmpeg
Rotating a video 90 degrees clockwise on the Linux command line is a frequent task that can be easily accomplished using the powerful, open-source multimedia framework FFmpeg. This article provides a straightforward, step-by-step guide on how to use the FFmpeg video filter transpose function to achieve this rotation, explains the syntax of the command, and offers a quick tip on how to handle the process without re-encoding the entire file if your media player supports metadata rotation.
To rotate a video 90 degrees clockwise, you will use the
transpose video filter. The basic command syntax requires
you to specify the input file, the video filter configuration, and the
output file. In FFmpeg’s transpose filter, a value of 1
corresponds to a 90-degree clockwise rotation.
Here is the exact command you need to run in your terminal:
ffmpeg -i input.mp4 -vf "transpose=1" output.mp4Understanding the Command Parameters
ffmpeg: Invokes the FFmpeg program.-i input.mp4: Specifies the path to your original, unrotated input video file.-vf "transpose=1": Applies the video filter graph. Thetranspose=1parameter tells FFmpeg to rotate the video 90 degrees clockwise and flip it vertically (which effectively results in a pure 90-degree clockwise rotation).output.mp4: Specifies the name and format of the new, rotated video file.
By default, this command will re-encode the video stream, ensuring that the rotation is hardcoded into the actual video frames. This guarantees that the video will play back correctly on any device or media player.
Alternative: Fast Rotation via Metadata
If you want an instantaneous result and your target media player reads orientation metadata (like most modern smartphones and VLC), you can change the rotation metadata instead of re-encoding the video. This method takes less than a second because it does not alter the actual video frames.
ffmpeg -i input.mp4 -metadata:s:v rotate="90" -codec copy output.mp4In this variation, the -codec copy flag instructs FFmpeg
to stream-copy the audio and video without re-encoding, while the
-metadata:s:v rotate="90" flag injects the 90-degree
clockwise orientation hint directly into the video stream.