Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

video orientation detection in bash

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?

like image 743
Miati Avatar asked Dec 29 '14 22:12

Miati


1 Answers

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.

like image 103
John1024 Avatar answered Sep 20 '22 00:09

John1024