I have a video clip recorded by a smartphone vertically, and I'm trying to rotate it 90 degrees clockwise using the usual ffmpeg command (because some players fail to read the EXIF rotation data and display it properly by autorotating). Its EXIF metadata includes "Width: 848; Height: 480; Rotation: 90" Normally, this command should do it:

ffmpeg -i input.mp4 -vf transpose=1 output.mp4

However, the actual result is just a horizontal flip while the concerning EXIF metadata becomes "Width: 848; Height: 480; Rotation: 0" I've tried all transpose values (0,1,2,3) and none could give me a video with "Width: 480; Height: 848; Rotation: 0"

Ideally, I would also like to preserve all original EXIF data like date and time, camera and GPS details, etc. which are all gone with the command above.

Any ideas?

Note: Using ffmpeg version 4.2.4-1ubuntu0.1 built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)

  • 1
    FFmpeg will automatically autorotate when re-encoding, if the rotation data is tagged correctly by the phone.
    – Gyan
    Commented Aug 21, 2020 at 9:55
  • @Gyan Thanks! I've just discovered that when I went on trying vflip rotation option as well. Any idea about keeping EXIF metadata like recording date and time, and location?
    – Sadi
    Commented Aug 21, 2020 at 9:59

1 Answer 1


It seems ffmpeg is also taking into account the original file's EXIF metadata "Rotation: 90" and autorotating before the re-encoding process. So, at the end I've managed to write a script which can be incorporated into the context menu of file managers like Dolphin, Nautilus, Thunar, etc. to rotate the video according to its EXIF rotation metadata, keeping EXIF timestamps, and copying EXIF GPS information - with the help of @Gyan

#!/usr/bin/env bash
# Requires ffmpeg and libimage-exiftool-perl packages
for filename in ${@}
    ffmpeg -i "$filename" -map_metadata 0 "${name}_rotated.${ext}"
    GPSLatitude="$(exiftool -GPSLatitude "$filename" | awk -F' : ' '{print $2}' | sed -e "s/ deg / /" -e "s/' / /" -e "s/\" / /")"
    GPSLongitude="$(exiftool -GPSLongitude "$filename" | awk -F' : ' '{print $2}' | sed -e "s/ deg / /" -e "s/' / /" -e "s/\" / /")"
    exiftool -GPSLatitude="$GPSLatitude" -GPSLongitude="$GPSLongitude" "${name}_rotated.${ext}" -overwrite_original
    mv "${name}_rotated.${ext}" "$filename"
  • 1
    Running the command twice will lead to an extra round of re-encoding. Run it once, without any filters.
    – Gyan
    Commented Aug 21, 2020 at 10:03
  • @Gyan Thanks! Does this mean using exiftool to change the rotation metadata to 0 first?
    – Sadi
    Commented Aug 21, 2020 at 10:17
  • 1
    No, just ffmpeg -i input.mp4 output.mp4 without changing the original rotation metadata.
    – Gyan
    Commented Aug 21, 2020 at 10:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .