I need to detect whether videos are recorded in portrait or landscape mode, then transpose those into the correct orientation, in a scripted fashion.
if [ "$v_orient" == "landscape" ]
then
ffmpeg -i file.mp4 -vf "transpose=1" file.ogv
else
ffmpeg -i file.mp4 file.ogv
fi
I've looked in ffmpeg online documentation and googled around,
I've attempted exiftool
exiftool -Rotation -Rotate file.mp4
However, this outputs Rotate: 90 for both landscape & portrait videos I have.
How can I detect the video orientation in bash?
ffprobe
is part of the ffmpeg
package and it will report on video metadata.
ffprobe somevideo.mp4
grep
can be used to select just the rotation information. On a rotated video, I see this output:
$ ffprobe somevideo.mp4 2>&1 | grep rotate
rotate : 90
On unrotated videos that I tried, the above command produced no output.
This command depends on video file's metadata. If you have a source that does not produce a reliable rotate
tag, you may need to look for other tags.
Old cameras that do not have accelerometers (gravity sensors) cannot tell if they are held in portrait or landscape orientation and hence cannot produce any useful tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With