I managed to get a set of images loaded using Python.
I'd like my script to take this series of images (in whatever format I need them), and create a video from them. The big limit in all this is that I am looking for something easy and simple to install. Ideally, using the standard OS X installation procedure:
I do not want to expend a lot of effort to install the video editing program. Just something simple that works.
What format should I aim for? I need my video to be playable on Linux, Mac, and Windows systems. The images are graphs, so we are speaking of discreet images, not photographs. It should be pretty easy to compress it. There will be about 1000 images, so this will be a short movie.
What tools should I use to produce the actual video? I need to either do it directly from Python using a library designed for this purpose, or by scripting command-line tools called from Python.
If you're not averse to using the command-line, there's the convert
command from the ImageMagick package. It's available for Mac, Linux, Windows. See http://www.imagemagick.org/script/index.php.
It supports a huge number of image formats and you can output your movie as an mpeg file:
convert -quality 100 *.png outvideo.mpeg
or as animated gifs for uploading to webpages:
convert -set delay 3 -loop 0 -scale 50% *.png animation.gif
More options for the convert
command available here: ImageMagick v6 Examples -
Animation Basics
You may use OpenCV. And it can be installed on Mac. Also, it has a python interface.
I have slightly modified a program taken from here, but don't know if it compiles, and can't check it.
import opencv
from opencv.cv import *
from opencv.highgui import *
isColor = 1
fps = 25 # or 30, frames per second
frameW = 256 # images width
frameH = 256 # images height
writer = cvCreateVideoWriter("video.avi",-1,
fps,cvSize(frameW,frameH),isColor)
#-----------------------------
#Writing the video file:
#-----------------------------
nFrames = 70; #number of frames
for i in range(nFrames):
img = cvLoadImage("image_number_%d.png"%i) #specify filename and the extension
# add the frame to the video
cvWriteFrame(writer,img)
cvReleaseVideoWriter(writer) #
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With