Rotate videos with FFmpeg

There are actually two ways you can rotate videos with FFmpeg:

  • You can rotate the video “physically” with the -vf transpose option. This will re-encode the video, thus it might degrade the video quality slightly.
  • Or you can just change the metadata in the file to rotate the video presentation. This will tell media players how to play the video correctly.

If you can, you should always change the metadata instead of rotating the video itself. That way you will maintain the original video quality and properties.

Alternative 1: Rotating by changing the metadata

Videos, especially those captured by mobile phones in portrait mode, often have a metadata field called rotation. This lets media players know that a video in portrait mode should be displayed vertically and not horizontally. Without the metadata, there would be no way to tell.

In this example, the phone was held upright in portrait mode and hence it has a 90° rotation tag in the metadata. You can inspect the metadata of a video with Mediainfo.

If you still want to rotate the video you can easily alter the metadata with FFmpeg.

You will have to experiment to find the right angle. Remember you can try a 10-second preview by adding -t 10.

ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=90 output.mp4

Valid metadata degrees are usually 90, 180, 270 or 360. Replace rotate=90 with the number that is correct for you.

Alternative 2: Completely rotating the video

To completely or physically rotate the video you will have to use the transpose video filter. This will turn or rotate every pixel in the video.

Here is an example:

ffmpeg -i input.mp4 -vf "transpose=1" -c copy output.mp4

You can change -vf "transpose=1" with any of the following alternatives depending on how you want to rotate the video:

  • 90° Clockwise
    • -vf "transpose=1"
  • 90° Clockwise
    • -vf "transpose=clock"
  • 90° Counterclockwise and vertical flip (inverted)
    • -vf "transpose=0"
  • 90° Counterclockwise and vertical flip (inverted)
    • -vf "transpose=clock_flip"
  • 90° Clockwise and vertical flip (Inverted)
    • -vf "transpose=3"
  • 90° Clockwise and vertical flip (Inverted)
    • -vf "transpose=clock_flip"
  • 90° Counterclockwise
    • -vf "transpose=2"
  • 90° Counterclockwise
    • -vf "transpose=cclock"
  • 180° Clockwise
    • -vf "transpose=2,transpose=2"
  • 180° Clockwise
    • -vf "transpose=cclock,transpose=cclock"
  • 180° Clockwise horizontal flip (inverted)
    • -vf "transpose=0,transpose=2"
  • 180° Clockwise horizontal flip (inverted)
    • -vf "transpose=cclock_flip,transpose=cclock"


Sources: https://www.ffmpeg.org/ffmpeg-all.html#transpose-1

Leave a Reply

Your email address will not be published. Required fields are marked *