how to get a video file's orientation in Pytho

2019-06-27 07:23发布

问题:

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.

回答1:

We use MediaInfo (libmediainfo)

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



回答2:

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

https://github.com/danielgtaylor/qtrotate