-3

I want to get the video length metadata of .mp4 files, using either a module that comes with Python or a module available on PyPi and doesn't require external software. I've searched all over the internet, and all I could find was either modules that don't support .mp4 files, outdated and non-functioning modules, and modules that require external software.

It only has to be able to run on Windows*

Treehee
  • 117
  • 1
  • 2
  • 11
  • Possible duplicate of [How to get the duration of a video in Python?](https://stackoverflow.com/questions/3844430/how-to-get-the-duration-of-a-video-in-python) – EsotericVoid Aug 28 '17 at 15:19
  • It's already asked here [How to get the duration of a video in Python?](https://stackoverflow.com/questions/3844430/how-to-get-the-duration-of-a-video-in-python) – Masoud Masoumi Moghadam Aug 28 '17 at 15:49
  • And it doesn't have an answer that fits my specifications. – Treehee Aug 28 '17 at 16:22

1 Answers1

4

You could use moviepy.

First, install it using pip:

$ pip install --user moviepy

Then, from python, make sure you have the ffmpeg binary installed (only required once, but harmless if you call it multiple times):

>>> import imageio
>>> imageio.plugins.ffmpeg.download()

Then you can use VideoFileClip to query and manipulate the file:

>>> clip = VideoFileClip('/path/to/file.mp4')
>>> duration_in_sec = clip.duration
>>> duration_in_sec
14.0
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Like I said, no external software* – Treehee Aug 28 '17 at 16:21
  • If you're ruling out pip, the most recognized source for external libraries, you won't get very far. Your question is like "How can I drive without a vehicle?" – Nathan Smith Aug 28 '17 at 16:27
  • I'm not ruling out pip. I'm ruling out non-pip stuff like ffmpeg – Treehee Aug 28 '17 at 19:13
  • Oh sorry, I didn't notice the download function call. I thought you were ruling out the use of pip libraries. If you edit the question, I can take back my downvote. At the same time, I'm wondering if the reason python itself doesn't is unable to do this has something to do with codecs... Still, you'd think you could read the metadata easily enough. Hmm... – Nathan Smith Aug 28 '17 at 21:26