Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 in all this is that I am looking for something easy and simple to install. Ideally, using the standard OS X installation procedure:

  • download .dmg
  • click
  • move into the application folder

I do not want to expend a lot of effort to install the video editing program. Just something simple that works.


Questions

  1. 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.

  2. 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.

like image 847
Pietro Speroni Avatar asked Jun 03 '09 14:06

Pietro Speroni


2 Answers

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

like image 88
Shawn Chin Avatar answered Sep 27 '22 20:09

Shawn Chin


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) #
like image 20
Daniyar Avatar answered Sep 27 '22 19:09

Daniyar