Skip to content Skip to sidebar Skip to footer

How Can I Script The Creation Of A Movie From A Set Of Images?

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

Solution 1:

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


Solution 2:

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) #

Solution 3:

Do you have to use python? There are other tools that are created just for these purposes. For example, to use ffmpeg or mencoder.


Post a Comment for "How Can I Script The Creation Of A Movie From A Set Of Images?"