Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i create a movie from a set of images using qtj and java?

I have a set of images i want to add one after another and create a movie. I will be using Quicktime for java for this(I'm on a mac).

I searched the web i have found lots of examples that show how to play movies using qtj, but i can't find any code snippets or tutorials showing how i can create a movie frame by frame using qtj?

like image 234
Hamza Yerlikaya Avatar asked Mar 13 '09 11:03

Hamza Yerlikaya


Video Answer


1 Answers

I've done this through QTJ with the MovieMaker class from processing libraries (GPL). Processing is pure java, though it can hide it for beginners.

Small tutorial: Download Processing, open it, go to Sketch -> Show Sketch Folder, create a folder called "data", and put all your images inside that folder, named "filename01.gif" through "filename09.gif". Paste the following code into the editor, and hit play:

/**
 * Makes a QuickTime movie out of an array of images.
 */

import processing.video.*;

MovieMaker mm;
PImage[] imageFrames;
int index;

void setup() {
  size(320, 240);
  int numFrames = 9;
  imageFrames = new PImage[numFrames];
  for( int i = 0; i < imageFrames.length; i++ )
  {
    imageFrames[i] = loadImage( "filename" + nf(i+1,2) + ".gif" );
  }
  // Save uncompressed, at 15 frames per second
  mm = new MovieMaker(this, width, height, "drawing.mov");
  // Or, set specific compression and frame rate options
  //mm = new MovieMaker(this, width, height, "drawing.mov", 30, 
  //                    MovieMaker.ANIMATION, MovieMaker.HIGH);
}

void draw() {
  if( index < imageFrames.length )
  {
    // show the image
    image( imageFrames[index], 0, 0 );
    // Add window's pixels to movie
    mm.addFrame();
    index++;
  }
  else
  {
    mm.finish();
    // Quit running the sketch once the file is written
    exit();    
  }
}

This will create a file "drawing.mov" from your images in the sketch folder. If you go to file --> export application, and then open the sketch folder and navigate to the folder application.macosx/source or application.windows/source, there should be a .java file that has the actual code, which should look like this:

import processing.core.*; 
import processing.xml.*; 

import processing.video.*; 

import java.applet.*; 
import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.io.*; 
import java.net.*; 
import java.text.*; 
import java.util.*; 
import java.util.zip.*; 
import java.util.regex.*; 

public class movie2 extends PApplet {

/**
 * Makes a QuickTime movie out of an array of images.
 */



MovieMaker mm;
PImage[] imageFrames;
int index;

public void setup() {
  size(320, 240);
  int numFrames = 9;
  imageFrames = new PImage[numFrames];
  for( int i = 0; i < imageFrames.length; i++ )
  {
    imageFrames[i] = loadImage( "filename" + nf(i+1,2) + ".gif" );
  }
  // Save uncompressed, at 15 frames per second
  mm = new MovieMaker(this, width, height, "drawing.mov");
  // Or, set specific compression and frame rate options
  //mm = new MovieMaker(this, width, height, "drawing.mov", 30, 
  //                    MovieMaker.ANIMATION, MovieMaker.HIGH);
}

public void draw() {
  if( index < imageFrames.length )
  {
    // show the image
    image( imageFrames[index], 0, 0 );
    // Add window's pixels to movie
    mm.addFrame();
    index++;
  }
  else
  {
    mm.finish();
    // Quit running the sketch once the file is written
    //exit();    
    println( "done" );
  }
}

  static public void main(String args[]) {
    PApplet.main(new String[] { "--bgcolor=#e0dfe3", "movie2" });
  }
}

To use pure java, you'll need to use core.jar and video.jar from the processing application folder on your classpath, and then compile this java code. Here's a function reference and a javadoc for the processing library. Here are the javadocs for the MovieMaker class. If you want, you can see the source to the MovieMaker class.

HTH

like image 162
Myer Avatar answered Sep 20 '22 11:09

Myer