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.

I've found a couple of similar questions, but they are pretty old now:

  • Best video manipulation library for Python?
  • python video library
  • They recommend PyMedia and PyFFMPEG. PyMedia seems rather out of date (but may still work?) and PyFFMPEG, while more recent, has almost no documentation.

    I've had no luck installing either these on Ubuntu 10.10, before I press on, is there:

    a) A better library I should look at?

    b) Good instructions on how to get either of these up and running?


    I've often needed the same thing and as far as I know, there is no good solution with bindings in 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. Then you can use PIL to manipulate each frame and mencoder or ffmpeg to stich the images back again into a movie:

    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. It does everything you're asking, but is a hybrid with Processing. You're not writing python code per se. 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.

    This is the official introduction to scikit-video from its project website:

    Scikit-video is designed for easy video processing using Python. It is modeled in the spirit of other successful scikits such as scikit-learn and scikit-image. The developers of scikit-video know libraries exist for manipulating videos, such as PyFFmpeg, MoviePy, PyAV, imageIO, and opencv. However, no libraries have been found to provide an all-in-one solution for research-level video processing tools.

    链接地址: http://www.djcxy.com/p/41224.html

    上一篇: 用动态语言编码视频的好库?

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