Skip to content

Instantly share code, notes, and snippets.

@cmlewis
Last active October 9, 2022 22:00
Show Gist options
  • Save cmlewis/f950d876171a11703f89 to your computer and use it in GitHub Desktop.
Save cmlewis/f950d876171a11703f89 to your computer and use it in GitHub Desktop.
Rotate videos 90 or 180 degrees using ffmpeg
Rotate videos 90 or 180 degrees using ffmpeg.
rem For the transpose parameter you can pass:
rem 0 = 90CounterCLockwise and Vertical Flip (default)
rem 1 = 90Clockwise
rem 2 = 90CounterClockwise
rem 3 = 90Clockwise and Vertical Flip
rem To rotate 180 degrees, instead use "transpose=2,transpose=2"
rem Using -codec:a copy will simply copy the audio instead of reencoding it.
ffmpeg -i in.mp4 -vf "transpose=1" -codec:a copy out.mp4
@johannish
Copy link

This will re-encode the video, always resulting in a quality loss (though usually imperceptible). Since the MP4 container format supports a "rotation" flag, which most players respect, you can set it for lossless rotation:

ffmpeg -i $INPUTVIDEO -metadata:s:v rotate="-90" -codec copy $OUTPUTVIDEO

see https://gist.github.com/ViktorNova/1dd68a2ec99781fd9adca49507c73ee2

OR using exiftool:

exiftool -rotation=270 FILE.mp4

see https://exiftool.org/forum/index.php?topic=10806.0

If the player you're using doesn't support this metadata flag, or if you're using another container like mkv, then ffmpeg with -vf transpose=1 is a fine alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment