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.
Answer from Changed My Name Again on Stack OverflowA python library for processing/editing videos?
What's a good Python library to manipulate frames of a video file? - Stack Overflow
Python Mode for Processing
I recommend pyprocessing instead. It isn't as complete in functionality, but you don't need java or the Processing environment. It's OpenGL and Pyglet based (so multi platform).
https://code.google.com/p/pyprocessing/
More on reddit.comI wrote a lightweight Python library for GPU-accelerated Image & Video Processing
Hi, I'm looking to do some weird projects with video editing, and wanna try something that lets me mess with videos. I'm planning to mess with individual pixels pretty often, (e.g. edit a video of a cat so that each pixel's color becomes inverted with probability 50%, wouldn't that look cool?)
I wanted to see if yall had experience with any libraries like that that you can recommend. thanks =)
(P.S. i can also do javascript/java/c++, if you know anything good there)
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 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.
» pip install vidgear