So after receiving only a few recommendations for a Java package to use to create video files, I decided I would try to modify the JPEGImagesToMovie file that comes as a sample with the JMF. I managed to get everything compiling and seems like it should run. The new class should take a Vector of BufferedImages, then instead of reading from a file and converting to a byte array like before, I convert directly from a BufferedImage to a byte array. The problem lies in the fact that the Processor won't configure (it locks up or something of the like). Can anyone see any obvious flaws that would be causing this?
Also I'm still completely open to suggestions for a better/easier/simpler framework to work with.
EDIT: Here's some code that I actually did something to. Cleaned up a little here for readability.
class ImageDataSource extends PullBufferDataSource {
ImageSourceStream streams[];
ImageDataSource(int width, int height, int frameRate, Vector images) {
streams = new ImageSourceStream[1];
streams[0] = new ImageSourceStream(width, height, frameRate, images);
}
/**
* The source stream to go along with ImageDataSource.
*/
class ImageSourceStream implements PullBufferStream {
Vector images;
int width, height;
VideoFormat format;
int nextImage = 0; // index of the next image to be read.
boolean ended = false;
public ImageSourceStream(int width, int height, int frameRate, Vector images) {
this.width = width;
this.height = height;
this.images = images;
format = new VideoFormat(null,
new Dimension(width, height),
Format.NOT_SPECIFIED,
Format.byteArray,
(float)frameRate);
}
/**
* This is called from the Processor to read a frame worth
* of video data.
*/
public void read(Buffer buf) throws IOException {
// Check if we've finished all the frames.
if (nextImage >= images.size()) {
// We are done. Set EndOfMedia.
System.err.println("Done reading all images.");
buf.setEOM(true);
buf.setOffset(0);
buf.setLength(0);
ended = true;
return;
}
BufferedImage imageFile = (BufferedImage)images.elementAt(nextImage);
nextImage++;
byte data[] = ImageToByteArray.convertToBytes(imageFile);
// Check the input buffer type & size.
if (buf.getData() instanceof byte[])
data = (byte[])buf.getData();
// Check to see the given buffer is big enough for the frame.
buf.setData(data);
buf.setOffset(0);
buf.setLength((int)data.length);
buf.setFormat(format);
buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
}
One thing I wasn't sure of is what to use as the encoding for the VideoFormat.