本文介绍了mpeg-2库以提取视频时长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近冒险涉足与音频和视频相关的编码,而且我对这两者都不了解.

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库以提取视频时长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 13:50