2

Is there a way to extract the duration information from a video file's metadata (or maybe calculate the duration some other way) in python without invoking an external process. I've found a number of answers that reference using ffprobe but that isn't an option for me. I need this to be all self contained within the python app.

The file formats I need to process are .mp4, .mov, .mxf and preferably as many other common video file formats as possible.


Edit: I am using python 3.x so unfortunately it appears hachoir-metadata is not an option as it only operates with python 2.7

abagshaw
  • 6,162
  • 4
  • 38
  • 76
  • [pafy](https://pypi.python.org/pypi/pafy) may work for the `.mp4` files – chickity china chinese chicken Jul 26 '16 at 18:13
  • [This answer](http://stackoverflow.com/a/17190482/1248974) recommends a package that (according to [its website](https://bitbucket.org/haypo/hachoir/wiki/hachoir-parser)) supports all those but not `.mxf` – chickity china chinese chicken Jul 26 '16 at 18:20
  • hachoir-parser doesn't appear to support `.mp4` files either from what I've seen, am I missing something? – abagshaw Jul 26 '16 at 18:40
  • @downshift thanks, but I'm not exactly wanting to use a separate library for each file type. If worst comes to worst I might have to resort to that but I'd much rather find one library that works for all filetypes. – abagshaw Jul 26 '16 at 18:42
  • It may, at the bottom of it's website under [Supported file extensions](https://bitbucket.org/haypo/hachoir/wiki/hachoir-parser) it says `.mp4`. Also checkout [hachoir-metadata](https://bitbucket.org/haypo/hachoir/wiki/hachoir-metadata) under the same project. Ok, no worries, cheers & good luck! – chickity china chinese chicken Jul 26 '16 at 18:44
  • If you don't need to be especially accurate, you could find average compression ratios, and use file size, resolution, and frame rate to get an estimate. – Oscar Smith Jul 26 '16 at 18:53
  • How accurate could that get? What I don't understand is why the duration information I see when I view file properties can't simply be accessed by some simple python app. Isn't this already hardcoded in metadata? – abagshaw Jul 26 '16 at 19:02

0 Answers0