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();
}









share|improve this question




























    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();
    }









    share|improve this question


























      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();
      }









      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 4:31









      Andrew Thompson

      152k27161335




      152k27161335










      asked Nov 9 at 16:17









      Jones Lee

      112




      112





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Schultheiß

          Liste der Kulturdenkmale in Wilsdruff

          Android Play Services Check