Get duration from multiple video files?

寵の児 提交于 2019-12-23 04:29:17

问题


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?


回答1:


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

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




回答2:


There is no "best" way, just a best way for your use case. os.stat doesn't have it because video duration is not part of any posix file system, (files systems don't care about the contents of a file, Whats is the duration of a text file? what is the resolution of an executable?) If you don't like ffprobe, try mediainfo, or mp4box, or any other tool that can read media files.



来源:https://stackoverflow.com/questions/53144494/get-duration-from-multiple-video-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!