Search code examples
pythonwindowsffmpegffprobe

Get duration from multiple video files?


I want to extract video duration metadata from every video file in a specified directory and then view the total duration.

I need to extract the data from as much as thousands of videos overall. In Windows I can view the total duration for many files manually when selecting them in the explorer and going into details. For 1500 mp4 files it takes about 20 seconds to make the calculations and view the total time. It's relatively much faster then what I'm currently getting when iterating with FFprobe.

How fast I am currently getting the result with FFprobe.

for filename in dirFiles:
   print(subprocess.check_output(['ffprobe', '-i', filename, '-show_entries','format=duration', '-sexagesimal' ,'-v', 'quiet', '-of', 'csv=%s' % ("p=0")]))

What is the faster way to do this?


Solution

  • I solved the problem with mutagen module as it handles files quite fast.

    mp4 = mutagen.mp4.MP4(filename) duration+=mp4.info.length