public class MovieEncoder
extends java.lang.Object
implements javax.media.datasink.DataSinkListener, javax.media.ControllerListener, java.io.Serializable
Usage of this class depends on the existence of the Java Media Framework (JMF) which can be acquired from javasoft.com. The class was tested on JMF 2.1.1.
This class encodes BufferedImages into quicktime movies. It has three main functions:
First, you call getEncodingFormats(), which returns an array of available formats. You specify a frame rate and a prototypical image.
Then, you call the constructor -- specify the frame rate, file, an encoding format chosen from the array in getEncodingFormats, and again provide a prototypical image. You'll want to ensure that future images encoded into the MovieEncoder will have the same size and format as the prototype image. If not, they'll be converted and cropped accordingly, which will take more time. You should expect the constructor to take a few seconds to start up -- JMF is not speedy.
Then you drop images into the MovieEncoder to add to the Quicktime movie as frames, using the add(BufferedImage) method. If there was an error and the movie could not be written, this method (and all subsequent add(...) calls) will return false.
When you're all finished, you call the stop() method to clean up and complete writing the file.
Note: Sun's JMF spawns threads in the background which it never cleans up. Thus if you use this class, you'll need to call System.exit(0) to quit your program rather than just dropping out of main().
Constructor and Description |
---|
MovieEncoder(float frameRate,
java.io.File file,
java.awt.image.BufferedImage typicalImage,
javax.media.Format encodeFormat)
Creates an object which will write out a move of the specified
format, and written to the provided file.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(java.awt.image.BufferedImage i)
Adds an image to the movie.
|
void |
controllerUpdate(javax.media.ControllerEvent evt)
Controller Listener.
|
void |
dataSinkUpdate(javax.media.datasink.DataSinkEvent evt)
Event handler for the file writer.
|
static javax.media.Format[] |
getEncodingFormats(float fps,
java.awt.image.BufferedImage typicalImage)
Returns null and prints an error out to stderr if an error occurred while trying to
get the formats
|
boolean |
stop()
Stops the writer and finishes uprocessor.
|
public MovieEncoder(float frameRate, java.io.File file, java.awt.image.BufferedImage typicalImage, javax.media.Format encodeFormat)
public static javax.media.Format[] getEncodingFormats(float fps, java.awt.image.BufferedImage typicalImage)
public void controllerUpdate(javax.media.ControllerEvent evt)
controllerUpdate
in interface javax.media.ControllerListener
public void dataSinkUpdate(javax.media.datasink.DataSinkEvent evt)
dataSinkUpdate
in interface javax.media.datasink.DataSinkListener
public boolean add(java.awt.image.BufferedImage i)
public boolean stop()