Find out rotation metadata from video in ffmpeg
Solution 1
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)
Solution 2
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.
Solution 3
For me the field was called rotation
NOT rotate
. The only way I could extract it was like so:
ffprobe -v quiet -select_streams v:0 -show_streams rgb.mp4 | grep -i rotation=
Which outputs, for example rotation=-180
Related videos on Youtube
user2882101
Updated on September 18, 2022Comments
-
user2882101 over 1 year
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? -
Gyan over 7 yearsFFmpeg 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.
-
Francisco Pizarro over 7 yearsThis 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.
-
Gyan over 7 yearsThe autorotate does not effect if the video stream is being copied. That can be done by specifying
-c:v copy
-
Francisco Pizarro over 7 yearsYes, 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. -
Gyan over 7 yearsI 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.
-
Francisco Pizarro over 7 yearsInstead 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?".
-
Gyan over 7 years"...in order to rotate the video correctly and only when needed" is the logical appendix given all the text above that question.
-
Francisco Pizarro over 7 yearsSo write your own answer.