简体   繁体   English

什么是一个很好的Python库来操纵视频文件的帧?

[英]What's a good Python library to manipulate frames of a video file?

I'm looking for a Python video processing library, similar to PIL , where I can iterate through all the frames of a source video, access the pixel data for each frame, draw onto each frame and save the result as a new video file. 我正在寻找一个类似于PIL的Python视频处理库,我可以遍历源视频的所有帧,访问每个帧的像素数据,绘制到每个帧并将结果保存为新的视频文件。

I've found a couple of similar questions, but they are pretty old now: 我发现了几个类似的问题,但它们现在已经很老了:

They recommend PyMedia and PyFFMPEG . 他们推荐PyMediaPyFFMPEG PyMedia seems rather out of date (but may still work?) and PyFFMPEG, while more recent, has almost no documentation. PyMedia似乎已经过时了(但可能仍然有效?)和PyFFMPEG,而最近几乎没有文档。

I've had no luck installing either these on Ubuntu 10.10, before I press on, is there: 我没有运气在Ubuntu 10.10上安装这些,在我按下之前,有:

a) A better library I should look at? a)我应该看一个更好的图书馆?

b) Good instructions on how to get either of these up and running? b)关于如何启动和运行其中任何一个的良好说明?

I've often needed the same thing and as far as I know, there is no good solution with bindings in Python. 我经常需要相同的东西,据我所知,Python中的绑定没有很好的解决方案。

Also it is not as simple as it may seem to manipulate frames of a video file. 此外,它并不像操作视频文件的帧那样简单。 A modern file format for video does not store the frames one frame after the other but instead uses "delta frames", in which only the changes from one frame to the other is stored. 用于视频的现代文件格式不是一帧接一帧地存储帧,而是使用“增量帧”,其中仅存储从一帧到另一帧的改变。 Other considerations such as video with variable frame rate makes the problem even harder. 诸如具有可变帧速率的视频之类的其他考虑因素使问题更加困难。

In the past I've used the following command to generate images from video. 在过去,我使用以下命令从视频生成图像。

ffmpeg -i /path/to/file.mpg -an -r 30 -s 320x240 tmp%06d.jpg

Where 30 is the target frame rate, 320x240 the image dimension and tmp%06d.jpg the pattern to use to store the generated jpegs. 其中30是目标帧速率,320x240是图像尺寸,tmp%06d.jpg是用于存储生成的jpeg的模式。 Then you can use PIL to manipulate each frame and mencoder or ffmpeg to stich the images back again into a movie: 然后你可以使用PIL来操作每个帧和mencoder或ffmpeg来将图像再次放回到电影中:

ffmpeg -r 30 -i tmp%06d.jpg output.mpg

Obviously, you'll lose the audio track. 显然,你将失去音轨。

I've been looking at using py.processing for similar work. 我一直在寻找使用py.processing进行类似的工作。 It does everything you're asking, but is a hybrid with Processing. 它可以满足您的所有要求,但却与Processing混合使用。 You're not writing python code per se. 你本身并不是在编写python代码。 Anyway, It makes it quite easy to work with, but there is a lot of program/interpretation overhead so it can be slow to do realtime modification of the movies. 无论如何,它使得它很容易使用,但是有很多程序/解释开销,因此对电影进行实时修改可能会很慢。 You said you wanted to edit to file so that should be workable. 你说你想要编辑到文件,这应该是可行的。

I recommend scikit-video for you which is the most straightforward python video processing library I have ever met. 我推荐scikit-video ,这是我见过的最简单的python视频处理库。

This is the official introduction to scikit-video from its project website: 这是其项目网站上scikit-video的官方介绍:

Scikit-video is designed for easy video processing using Python. Scikit-video旨在使用Python轻松进行视频处理。 It is modeled in the spirit of other successful scikits such as scikit-learn and scikit-image. 它以其他成功的scikits精神为模型,如scikit-learn和scikit-image。 The developers of scikit-video know libraries exist for manipulating videos, such as PyFFmpeg, MoviePy, PyAV, imageIO, and opencv. scikit-video知识库的开发者存在用于操纵视频,例如PyFFmpeg,MoviePy,PyAV,imageIO和opencv。 However, no libraries have been found to provide an all-in-one solution for research-level video processing tools. 但是,没有找到任何图书馆为研究级视频处理工具提供一体化解决方案。

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

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