How to get the duration of a video in Python?
Question: I need to get the video duration in Python. The video formats that I need to
get are [MP4](http://en.wikipedia.org/wiki/MPEG-4_Part_14), Flash video,
[AVI](http://en.wikipedia.org/wiki/Audio_Video_Interleave), and MOV... I have
a shared hosting solution, so I have no
[FFmpeg](http://en.wikipedia.org/wiki/FFmpeg) support.


Answer: You'll probably need to invoke an external program.
[`ffprobe`](http://ffmpeg.org/ffprobe.html) can provide you with that
information:

    
    
    import subprocess
    
    def getLength(filename):
      result = subprocess.Popen(["ffprobe", filename],
        stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
      return [x for x in result.stdout.readlines() if "Duration" in x]
    

