If I use:

ffmpeg -i in.mov -vf "transpose=1" out.mov

all .mov files are getting rotated, but what I need is to automatically detect just the rotated videos and change orientation for just those videos.

How can I automatically detect the rotation or orientation of the video during upload and rotate if needed, so that all .mov files play in the correct orientation? How can I get that metadata of current degree rotation of my video?


Applied to your question, in concrete terms, you can get the rotation by: ffprobe -loglevel error -select_streams v:0 -show_entries stream_tags=rotate -of default=nw=1:nk=1 -i in.mov


-loglevel error: only show the rotate field, no other info.

-select_streams v:0: process the first video stream (ignore if multiple video streams are present)

-show_entries stream_tags=rotate: returns the rotate information from the input video

-of default=nw=1:nk=1: use default output format and don't show anything else, i.e. no-wrappers (nw) and no key (nk)

| improve this answer | |

Use ffprobe, like this.

ffprobe -i in.mov

This should result in showing a "rotate:" field somewhere in the output if such a field is present in the file.

| improve this answer | |
  • FFmpeg nowadays autorotates the video i.e. if a rotation tag is present, it applies the filter and resets the tag, So the exercise is moot. – Gyan Dec 5 '16 at 20:31
  • This would be bad practice due to transcoding in the case of remultiplexing a video container file with a video stream that has a rotation flag. It is useful to know exactly what is happening to prevent transcoding. – Alex Folland Dec 5 '16 at 23:23
  • 1
    The autorotate does not effect if the video stream is being copied. That can be done by specifying -c:v copy – Gyan Dec 6 '16 at 5:18
  • 1
    I guess there's some lines crossed here. We don't know if the OP's target players respect the rotation tag. In fact, if they did, there would be no need for the OP to ask the Q. The OP is permanently baking in the correct orientation using the transpose filter. To that end, transcoding is required, and my point is recent ffmpeg versions automatically take care of it. – Gyan Dec 12 '16 at 15:01
  • 2
    So write your own answer. – Alex Folland Dec 13 '16 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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