如何使用python查看视频的长度
2021-07-14 16:04
标签:rate pipe 使用 probe file imp desktop ret str 如何使用python查看视频的长度 标签:rate pipe 使用 probe file imp desktop ret str 原文地址:https://www.cnblogs.com/traditional/p/9538205.htmlimport subprocess
import re
def get_length(filename):
result = subprocess.Popen(["ffprobe", filename],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for x in result.stdout.readlines():
if b"Duration" in x:
print(x)
x = re.search(rb"Duration.+?\d{2}:(\d{2}):\d{2}", x)
return int(x.group(1))
print(get_length(r"C:\Users\Administrator\Desktop\1.mp4"))
‘‘‘
b‘ Duration: 00:17:25.00, start: 0.000000, bitrate: 507 kb/s\r\n‘
17
‘‘‘
上一篇:C#退出模式