Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get a video file's orientation in Python

I would like to load a video file's frames into a numpy array. I want the frames to be properly upright, which means I need to read the orientation metadata in the video file, and rotate the loaded frames accordingly.

I have a means of loading the frames (opencv's python bindings), so all I need is a way to read the video file's orientation metadata.

I'm trying to read a .MOV file recorded off my iPhone, in python running on an Ubuntu 14.04 machine.

Stuff I've looked at:

  • opencv: no way of inspecting video orientation
  • hachoir-metadata: doesn't display orientation metadata
  • enzyme: only works on .mkv files, AFAICT.
  • ffmpeg: no longer available as a stand-alone executable on Ubuntu's repositories. This is a dealbreaker since I'd rather just hand-specify the rotation rather than go through the trouble of compiling ffmpeg from source just to get video orientation.
  • PIL, pyexiv: AFAICT, only loads image files.

I'm running the code on an Ubuntu 14.04 machine, so I'm looking for libraries or command-line programs available on that platform.

Any pointers would be greatly appreciated.

like image 367
SuperElectric Avatar asked Oct 31 '22 12:10

SuperElectric


2 Answers

We use MediaInfo (libmediainfo)

it is running both on Windows and Ubuntu, and you can get all you need (codec, aspect, fps, bitrate, orientation...).

like image 153
Eyal Ch Avatar answered Nov 15 '22 03:11

Eyal Ch


use qtrotate. It's just one file, and it works on .Mov files

https://github.com/danielgtaylor/qtrotate

like image 39
scanner Avatar answered Nov 15 '22 04:11

scanner