获取多个视频文件的时长? [英] Get duration from multiple video files?

查看:712
本文介绍了获取多个视频文件的时长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从指定目录中的每个视频文件中提取视频时长元数据,然后查看总时长.

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

我需要从多达数千个视频中提取数据.在Windows中,当在资源管理器中选择文件并进入详细信息时,我可以手动查看许多文件的总持续时间.对于1500 mp4文件,大约需要20秒才能进行计算并查看总时间.它比用FFprobe进行迭代时得到的当前速度要快得多.

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.

我目前使用FFprobe获得结果的速度有多快.

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

最快的方法是什么?

推荐答案

我解决了mutagen模块的问题,因为它可以非常快速地处理文件.

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

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

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

这篇关于获取多个视频文件的时长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆