用于提取视频时长的 mpeg-2 库 [英] mpeg-2 library to extract video duration
问题描述
我最近开始涉足与音频和视频相关的编码,但我对其中任何一个都知之甚少.
I have recently ventured out into dealing with audio and video related coding and i have limited knowledge about neither one of them.
碰巧我现在有一个处理 mpeg-2 视频的项目.是否有任何可用的 python 库来提取 mpeg-2 视频本身的持续时间?
It happens that i have a project that is dealing with mpeg-2 video now. Is there any python library that available out there to extract the duration of the mpeg-2 video itself?
推荐答案
我不知道任何纯 python 实现.但也许 opencv 绑定适合你:
I don't know any pure python implementations. But maybe the opencv bindings works for you:
import cv
cvcapture = cv.CaptureFromFile("movie.mpg")
cv.GetCaptureProperty(cvcapture,cv.CV_CAP_PROP_FRAME_COUNT)
否则,您可以使用 pyffmpeg.当心:根据我的经验,帧数通常不是很准确.Opencv 2.6 运行良好,但早期版本有时只是垃圾.
Otherwise, maye you can use pyffmpeg. Beware: It is my experience that the frame count is often not very accurate. Opencv 2.6 works very well, but ealier versions gives sometimes just garbage.
啊,抱歉我的错误:这仅提供帧数.对于持续时间:将其与帧速率相乘:
Ah, sorry my mistake: This gives you the frame count only. For the duration: Multiply this with the frame rate:
cv.GetCaptureProperty(cvcapture,cv.CV_CAP_PROP_FPS)
这篇关于用于提取视频时长的 mpeg-2 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!