视频文件详细信息python3_如何使用python3.7提取视频文件的元数据?

该博客介绍了如何利用Python的hachoir库获取视频文件的元数据,包括时长、宽度和高度。通过运行hachoir-metadata命令并解析输出,可以提取到如创建和修改日期等额外信息。示例代码展示了如何解析这些属性。
摘要由CSDN通过智能技术生成

我没有找到一个很好的Python库,但是使用hachoir和{def get_media_properties(filename):

result = subprocess.Popen(['hachoir-metadata', filename, ' raw', ' level=3'],

stdout = subprocess.PIPE, stderr = subprocess.STDOUT)

results = result.stdout.read().decode('utf-8').split('\r\n')

properties = {}

for item in results:

if item.startswith('- duration: '):

duration = item.lstrip('- duration: ')

if '.' in duration:

t = datetime.datetime.strptime(item.lstrip('- duration: '), '%H:%M:%S.%f')

else:

t = datetime.datetime.strptime(item.lstrip('- duration: '), '%H:%M:%S')

seconds = (t.microsecond / 1e6) + t.second + (t.minute * 60) + (t.hour * 3600)

properties['duration'] = round(seconds)

if item.startswith('- width: '):

properties['width'] = int(item.lstrip('- width: '))

if item.startswith('- height: '):

properties['height'] = int(item.lstrip('- height: '))

return properties

hachoir也支持其他属性,但我只需要这三个属性。对于我测试的mov文件,它似乎还打印出了创建日期和修改日期。我使用的优先级是3,所以你可以尝试使用它来查看更多的内容。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值