简体   繁体   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)?

I am interested in finding the duration of a video file (of commonly used formats) using a python script in UBUNTU. 我对使用UBUNTU中的python脚本查找视频文件(常用格式)的持续时间感兴趣。 I found the code: 我找到了代码:

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]

but it does not work on my UBUNTU BOX may be because of absence of ffprobe or something and i get the following error: 但它在我的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

I only want the duration so is there any easier method or how to make the above code work Is there any simple way? 我只想要持续时间,所以有没有更简单的方法或如何使上述代码起作用?是否有任何简单的方法?

只需安装ffmpeg与

sudo apt-get install ffmpeg

Ubuntu comes with avconv by default and not ffmpeg (ffmpeg is just a wrapper for avconv). Ubuntu默认情况下带有avconv,而不是ffmpeg(ffmpeg只是avconv的包装器)。

It seems you don't have either installed. 似乎您都没有安装。

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

相关问题 使用python将任何格式的视频(flv,3gp,MXF等)转换为django中的MP4 - convert the videos of any format(flv,3gp,MXF etc.,) to MP4 in django using python 是否有 python package 从 AVI、MP4 和 MKV 读取和更新元数据? - Is there a python package to Read and update metadata from AVI, MP4 and MKV? Python .avi 到 .mp4 - Python .avi to .mp4 用“Name - SXXEYY”.mkv(或 avi,mp4)转换文件名“Name - XXxYY”.mkv(或 avi,mp4) - Transform filename "Name - XXxYY".mkv(or avi,mp4) with "Name - SXXEYY".mkv(or avi,mp4) 如何使用Python OpenCV从多个帧生成mp4(而非avi)文件? - How to generate a mp4(not a avi) file from a number of frames using Python OpenCV? 使用imageio包将mp4视频转换为avi视频 - Convert mp4 video to avi video using imageio package Python - 如何将.mkv 视频转换为.mp4 视频 - Python - How to convert .mkv videos to .mp4 videos 如何在python中将任何视频格式转换为mp4格式 - How to convert any video format to mp4 format in python 哪种方法是从 x(MOV、AVI 等)到 x 类型(MP4、MP2 等)的视频转换的最佳和最快的方法 - Which approach is the best and fastest for video conversion from x (MOV, AVI etc) to x type (MP4, MP2 etc) 使用python分别获取Mp4文件的视频和音频比特率? - Get video and audio bitrate of an Mp4 file separately with python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM