JpegImagesToMovie.java - How does processor use read(Buffer buf)
up vote
1
down vote
favorite
I am looking at the JMF code source, written out as an answer on this thread by user Mavie. As I try to trace the code, from the function doIt --> ImageDataSource --> ImageSourceStream, I'm not too clear how the program reads the list of image files from the vector.
As far as I know, this part of the code read(Buffer buf) reads the image data file, but this function does not seem to be called by the processor from within the code itself.
I have managed to get the code running perfectly fine, but do not understand the logical flow. How/Where does the processor call this function to read and generate the video?
read(Buffer buf) - part of the entire source code
/**
* 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;
}
String imageFile = (String) images.elementAt(nextImage);
nextImage++;
//System.err.println(" - reading image file: " + imageFile);
// Open a random access file for the next image.
RandomAccessFile raFile;
raFile = new RandomAccessFile(imageFile, "r");
byte data = null;
// 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.
if (data == null || data.length < raFile.length()) {
data = new byte[(int) raFile.length()];
buf.setData(data);
}
// Read the entire JPEG image from the file.
raFile.readFully(data, 0, (int) raFile.length());
//System.err.println(" read " + raFile.length() + " bytes.");
buf.setOffset(0);
buf.setLength((int) raFile.length());
buf.setFormat(format);
buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
// Close the random access file.
raFile.close();
}
java jmf
add a comment |
up vote
1
down vote
favorite
I am looking at the JMF code source, written out as an answer on this thread by user Mavie. As I try to trace the code, from the function doIt --> ImageDataSource --> ImageSourceStream, I'm not too clear how the program reads the list of image files from the vector.
As far as I know, this part of the code read(Buffer buf) reads the image data file, but this function does not seem to be called by the processor from within the code itself.
I have managed to get the code running perfectly fine, but do not understand the logical flow. How/Where does the processor call this function to read and generate the video?
read(Buffer buf) - part of the entire source code
/**
* 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;
}
String imageFile = (String) images.elementAt(nextImage);
nextImage++;
//System.err.println(" - reading image file: " + imageFile);
// Open a random access file for the next image.
RandomAccessFile raFile;
raFile = new RandomAccessFile(imageFile, "r");
byte data = null;
// 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.
if (data == null || data.length < raFile.length()) {
data = new byte[(int) raFile.length()];
buf.setData(data);
}
// Read the entire JPEG image from the file.
raFile.readFully(data, 0, (int) raFile.length());
//System.err.println(" read " + raFile.length() + " bytes.");
buf.setOffset(0);
buf.setLength((int) raFile.length());
buf.setFormat(format);
buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
// Close the random access file.
raFile.close();
}
java jmf
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am looking at the JMF code source, written out as an answer on this thread by user Mavie. As I try to trace the code, from the function doIt --> ImageDataSource --> ImageSourceStream, I'm not too clear how the program reads the list of image files from the vector.
As far as I know, this part of the code read(Buffer buf) reads the image data file, but this function does not seem to be called by the processor from within the code itself.
I have managed to get the code running perfectly fine, but do not understand the logical flow. How/Where does the processor call this function to read and generate the video?
read(Buffer buf) - part of the entire source code
/**
* 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;
}
String imageFile = (String) images.elementAt(nextImage);
nextImage++;
//System.err.println(" - reading image file: " + imageFile);
// Open a random access file for the next image.
RandomAccessFile raFile;
raFile = new RandomAccessFile(imageFile, "r");
byte data = null;
// 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.
if (data == null || data.length < raFile.length()) {
data = new byte[(int) raFile.length()];
buf.setData(data);
}
// Read the entire JPEG image from the file.
raFile.readFully(data, 0, (int) raFile.length());
//System.err.println(" read " + raFile.length() + " bytes.");
buf.setOffset(0);
buf.setLength((int) raFile.length());
buf.setFormat(format);
buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
// Close the random access file.
raFile.close();
}
java jmf
I am looking at the JMF code source, written out as an answer on this thread by user Mavie. As I try to trace the code, from the function doIt --> ImageDataSource --> ImageSourceStream, I'm not too clear how the program reads the list of image files from the vector.
As far as I know, this part of the code read(Buffer buf) reads the image data file, but this function does not seem to be called by the processor from within the code itself.
I have managed to get the code running perfectly fine, but do not understand the logical flow. How/Where does the processor call this function to read and generate the video?
read(Buffer buf) - part of the entire source code
/**
* 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;
}
String imageFile = (String) images.elementAt(nextImage);
nextImage++;
//System.err.println(" - reading image file: " + imageFile);
// Open a random access file for the next image.
RandomAccessFile raFile;
raFile = new RandomAccessFile(imageFile, "r");
byte data = null;
// 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.
if (data == null || data.length < raFile.length()) {
data = new byte[(int) raFile.length()];
buf.setData(data);
}
// Read the entire JPEG image from the file.
raFile.readFully(data, 0, (int) raFile.length());
//System.err.println(" read " + raFile.length() + " bytes.");
buf.setOffset(0);
buf.setLength((int) raFile.length());
buf.setFormat(format);
buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
// Close the random access file.
raFile.close();
}
java jmf
java jmf
edited Nov 10 at 4:31
Andrew Thompson
152k27161335
152k27161335
asked Nov 9 at 16:17
Jones Lee
112
112
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229470%2fjpegimagestomovie-java-how-does-processor-use-readbuffer-buf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown