Get total length of videos in a particular directory in python

后端 未结 4 2042
后悔当初
后悔当初 2020-12-03 23:55

I have downloaded a bunch of videos from coursera.org and have them stored in one particular folder. There are many individual videos in a particular folder (Coursera breaks

4条回答
  •  温柔的废话
    2020-12-04 00:15

    This link shows how to get the length of a video file https://stackoverflow.com/a/3844467/735204

    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]
    

    If you're using that function, you can then wrap it up with something like

    import os
    
    for f in os.listdir('.'):
        print "%s: %s" % (f, getLength(f))
    

提交回复
热议问题