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

I have a set of images that I want to add one after another and create a movie. I will use Quicktime for java for this (I am on a mac).

I searched on the Internet, I found many examples showing how to play movies using qtj, but I can’t find code snippets or tutorials showing how I can create frame by frame using qtj?

+6
java video quicktime
source share
2 answers

I did this through QTJ with the MovieMaker class from processing (GPL). Processing is pure java, although it may hide it for beginners.

A small tutorial: Download the Processing, open it, go to Sketch → Show the Sketch folder, create a folder called “data” and put all your images inside this folder with the name “filename01.gif” through “filename09.gif”. Paste the following code into the editor and click 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 pixels to movie mm.addFrame(); index++; } else { mm.finish(); // Quit running the sketch once the file is written exit(); } } 

This will create a “drawing.mov” file from your images in the sketch folder. If you go to the file → application for export, and then open the sketch folder and go to the application.macosx / source or application.windows/source folder, there should be a .java file with the actual code, which should look like:

 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 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 will need to use core.jar and video.jar from the application folder to process in your class path, and then compile this Java code. Here is a link to the function and javadoc for the processing library. Here are the javadocs for the MovieMaker class . If you want, you can see the source in the MovieMaker class.

NTN

+7
source share

Here is a sample code related to export:

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

This shows how you can open one native QuickTime Movie for reading, and then pass the MovieExporter component to create a new QuickTime Movie from it.

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

 void importMedia() 

To export source code to a QuickTime movie, see

 void run() 

It should be possible to open the image file using the same approach, though if the file format of the input file is supported by QuickTime (e.g. BMP).

You can also write a sequence of image files using most of this code. The only thing you need to explore is the method you have to call to add additional frames to an existing movie. It may work using the same API, but most likely you will need to use a different call.

If you need to dig for another method, you can find it in the QT Java Reference Documentation located here:

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

This is a hack and most likely poor performance, but it can work.

And ... I have never tried this (I'm a QuickTime Windows guy by profession), therefore: sorry, no warranty =).


Change If you are looking for a way to write frames to a QT Movie using an existing input buffer instead of reading data from a file using the QT API, there must be an API for this as well. Just check the help documentation.


Change 2 . Actually, it might be worth looking at the C / C ++ API documentation here, since the naming of components and calls seems to be roughly in line with the same naming conventions (i.e. this can help dig for the Java API calls you need ), and the C / C ++ docs seem to be more detailed in terms of providing guides and How To as a starting point. C / C ++ docs can be found here:

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

The most interesting sections should be

  • Import and export
  • Compression and decompression

Good luck


+1
source share

All Articles