0

I am using moviepy to automatically create a movie from lots of videos. Some of these videos will be portrait, and some landscape. I need to be able to grab the orientation of each video from its metadata, and then rotate it in moviepy if it returns 'portrait'.

I have found this code, which extracts metadata using ffprobe, and outputs height and width, but I don't know how to get the orientation.

Several people have mentioned mediainfo, but I don't know how to extract the information from the terminal result.

There are two PyPI module, ffprobe and mediainfo, which are both python wrappers for their respective tools, but the usage information is practically nonexistent.

I have found several questions, but they do not answer my question in enough detail:

how to get a video file's orientation in Python

I know SO isn't "writemycode.com" but this isn't documented anywhere, and I have looked thoroughly.

Community
  • 1
  • 1
Tom Burrows
  • 2,225
  • 2
  • 29
  • 46
  • See [this answer](http://stackoverflow.com/a/41306388/1109017). – llogan Dec 23 '16 at 18:46
  • Thanks, that is helpful! Just another quick question... All my program needs to know is whether the video to be imported is landscape or portrait. AFAIK the best way to tell this is to get the height and width, and if the height is higher than the width, then it is portrait. However, using [this](https://gist.github.com/oldo/dc7ee7f28851922cca09) program to get the data, it always outputs width as higher, even if in Finder > Get Info > Dimensions height is higher. – Tom Burrows Dec 24 '16 at 10:03
  • @LordNeckbeard is there a way to get the **real** dimensions? – Tom Burrows Dec 24 '16 at 10:05
  • Sure. See examples 2 & 3 in http://stackoverflow.com/a/28863962/1109017 – llogan Dec 24 '16 at 19:39
  • @LordNeckbeard Sorry, that isn't what I meant. I run it on a video where height should be bigger than width, but it still returns width bigger than height. Does this make sense? – Tom Burrows Dec 24 '16 at 21:01
  • @LordNeckbeard https://www.dropbox.com/s/i7xqd48kd1lpq8j/shepmovie.mp4?dl=0 is the file. It should return 352 × 640 but if I run 'ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of default=noprint_wrappers=1 /Users/myname/Documents/movie.mp4' it returns 'width=640 height=352'. Thanks – Tom Burrows Dec 24 '16 at 22:34
  • 1
    The width x height **is** 640x352, but there is rotate metadata which tells the player to rotate the video. If you re-encode the video with `ffmpeg` it will automatically physically rotate the video, according to the rotate metadata, and then strip the metadata so it will end up being 352x640 (unless you tell it not to with `-noautorotate`). – llogan Dec 24 '16 at 22:39

0 Answers0