Find out rotation metadata from video in ffmpeg

1

1

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?

user2882101

Posted 2013-10-16T04:56:31.420

Reputation: 11

Answers

2

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

Legend:

-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)

Agile Bean

Posted 2013-10-16T04:56:31.420

Reputation: 129

1

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.

Alex Folland

Posted 2013-10-16T04:56:31.420

Reputation: 59

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 – 2016-12-05T20:31:16.007

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 – 2016-12-05T23:23:41.730

1The autorotate does not effect if the video stream is being copied. That can be done by specifying -c:v copy – Gyan – 2016-12-06T05:18:02.980

Yes, that's exactly why I said what I said. Copying the stream is ideal. Never transcode to apply a rotation filter. Instead, output a container format that supports rotation tag, like mp4 (mkv doesn't seem to support it; tried recently), and use something like -c copy -metadata:s:v:0 rotate=90 in the ffmpeg command line. – Alex Folland – 2016-12-12T14:51:14.810

1I 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 – 2016-12-12T15:01:50.340

Instead of assuming, I opted to answer the OP's final question, which was "How can I get that metadata of current degree rotation of my video?". – Alex Folland – 2016-12-12T16:28:32.273

"...in order to rotate the video correctly and only when needed" is the logical appendix given all the text above that question. – Gyan – 2016-12-12T17:38:08.373

1So write your own answer. – Alex Folland – 2016-12-13T01:14:26.840