42

I have a video file. I open it with MediaInfo utility and I can see a video stream in this file having attribute Rotation 90 (along with other attributes such as CodecID, bitrate etc).

Now I have another video file which does not have that attribute Rotation 90, it does not have the Rotation attribute at all.

Can I use ffmpeg.exe so that it produces output file with Rotation 90 attribute added and with no other changes? I don't really want to do any transform, just want to set the Rotation attribute.

I've tried the -metadata option to no avail.

1 Answer 1

92

This works with recent FFmpeg:

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

This will stream copy the bitstreams, so no encoding is performed. Only the metadata of the first video stream (v:0) is changed here and the player will show the video in a rotated way. (Not all players will support this.)

Additional notes:

  • If you want to "physically" rotate the video, you have to use the transpose filter. Filtering will require re-encoding, so you will have to remove -c copy.

  • If you omit -c copy, and want to encode instead of only re-muxing, then ffmpeg will automatically rotate the video if there is any existing rotate metadata. You can disable this behavior with -noautorotate.

16
  • I have compiled latest code of ffmpeg and there is no error in running this command but still video is not rotating.pls help
    – Mohit
    Jan 8, 2014 at 5:56
  • 1
    @MohitChauhan Please note that this does not actually rotate the video. It just sets the rotation flag, which causes some players to show it in a rotated way. If you have an issue with a command, please ask a question on Super User and show the command and its full console output.
    – slhck
    Jan 8, 2014 at 6:50
  • @davor While this is an Apple-exclusive feature I only know QuickTime. But then again I don't use Windows or Linux so I cannot give an authoritative answer, sorry.
    – slhck
    Jan 18, 2014 at 15:24
  • 1
    @slhck This is very interesting. Any suggestion for players that actually support this? I am currently trying VLC and XBMC, and none seem to support this. Tried with MKV/MOV/MP4 containers. WMP12 and QuickTime do support this. Jan 18, 2014 at 15:25
  • 1
    I just tried this on an x265 video (converted from an x264 source of vertical video on an older iPhone) and it worked beautifully. Plays perfectly with VLC 2.2.1 on OS X. Oct 30, 2015 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.