views:

1442

answers:

3

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?

+1  A: 

There is an export related piece of sample code here:

http://developer.apple.com/samplecode/ImportExport/listing1.html

It shows how a single native QuickTime Movie can be opened for reading and then be passed on to a MovieExporter component to create a new QuickTime Movie from it.

For the code to import a file for as source for writing, see

void importMedia()

For the code to export the source to a QuickTime Movie, see

void run()

It should be possible to open an image file using the same approach, though, as long as the file format of the input file is supported by QuickTime (like f.e. BMP).

You should be able to write a sequence of image files using most of this code as well. The only point which you will have to investigate is which method you'll have to call to append additional frames to an existing Movie. It might work using the same API, but most likely you'll need to use another call.

If you have to dig for another method you should be able to find it in the QT Java Reference Documentation located here:

http://developer.apple.com/Java/Reference/1.4/Java14API_QTJ/

It's a hack and most likely poor in performance, but it might actually work.

And... I never tried this (I am a QuickTime for Windows guy by trade) so: sorry, no warranty = ).


Edit: If you are looking for a way to write frames to a QT Movie using an existing input buffer instead of reading the data from file using the QT API, there should be APIs for this as well. Just check out the reference documentation.


Edit 2: Actually it might be worthwhile to check out the C/C++ API Documentation here, as naming of components and calls seems to follow roughly the same naming conventions (i.e. this might help to dig for the calls of the Java API you need) and the C/C++ Docs seem to be more thorough in terms of providing Guides and How To's as a starting point. The C/C++ Docs can be found here:

http://developer.apple.com/referencelibrary/QuickTime/index.html

The most interesting sections should be

  1. Import & Export
  2. Compression & Decompression

Have Fun!


Bjoern
+4  A: 

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

Peter Nore
A: 

hi! I have a problem with the code above. When I copy it and try to run it, it doesn´t work...it says:

java.lang.NullPointerException at processing.core.PApplet.registerNoArgs(Unknown Source) at processing.core.PApplet.registerDispose(Unknown Source) at processing.video.MovieMaker.(Unknown Source) at processing.video.MovieMaker.(Unknown Source)

I think the problem has to be with the first parametre in MovieMaker, the one refering to PApplet...the example uses "this" but it doesn´t work. I´ve also tried PApplet p = new PApplet(); but it cause an error because you have to use parametres but there´s no such information in the documentation. I haven´t found information about nf() method in loadImages...what is its use? it´s for catching every file o the current folder? if not...how can I do that?

here is part of my code:

public class ProgramaMovieMaker extends PApplet {

MovieMaker mm; PImage[] imageFrames; int index; PApplet p = new PApplet();

public void setup () {

int width = 320; int height = 240; String nombre = "ejemplo.mov";

int numFrames = 3; imageFrames = new PImage[numFrames]; for( int i = 1; i < imageFrames.length; i++ ) { imageFrames[i] = loadImage("filename" + nf(i+1,2) + ".gif");
}

mm = new MovieMaker(this, width, height, nombre, 30, MovieMaker.H263, MovieMaker.HIGH);

}

public void draw () {

size(320,240); 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" ); } }

public static void main(String args[]) {

ProgramaMovieMaker programa = new ProgramaMovieMaker();

programa.setup();
programa.draw();

System.exit(0); }

}

THANKS A LOT FOR YOUR TIME AND SORRY ABOUT MY ENGLISH!!!

pipe