我没有找到一个很好的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,所以你可以尝试使用它来查看更多的内容。在