繁体   English   中英

如何使用python脚本(在ubuntu中)获取任何视频文件(.avi .mp4 .flv .mkv等)的持续时间?

[英]How to get the duration of any video file (.avi .mp4 .flv .mkv etc) using python script (in ubuntu)?

我对使用UBUNTU中的python脚本查找视频文件(常用格式)的持续时间感兴趣。 我找到了代码:

def getLength(filename):
result = subprocess.Popen(["ffprobe", filename],
stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
return [x for x in result.stdout.readlines() if "Duration" in x]

但它在我的UBUNTU BOX上不起作用可能是由于缺少ffprobe或其他东西,我收到以下错误消息:

File "leng.py", line 8, in getLength
stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

我只想要持续时间,所以有没有更简单的方法或如何使上述代码起作用?是否有任何简单的方法?

只需安装ffmpeg与

sudo apt-get install ffmpeg

Ubuntu默认情况下带有avconv,而不是ffmpeg(ffmpeg只是avconv的包装器)。

似乎您都没有安装。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM