title: Video Creation from a set of images with xuggler
body: <p>I have been looking for a solution everywhere! On this website and on others.
  I have found some interesting things, but they didn't solve my problem. I will explain it.</p>
  
  <p>I have one video, I grad each frame of it with xuggler. When I get all the frames I edit all of them with a color algorithm. Also, I store the audio in an mp3 file.</p>
  
  <p>Now I need to create a video from all the frames, this video, of course, should have the same characteristics as frame rate e duration. After that I have to merge the audio.</p>
  
  <p>I have done the first part, but I don't know how to create a video with the same characteristics. I am following this code: </p>
  
  <p><a href="http://www.javacodegeeks.com/2011/02/xuggler-tutorial-frames-capture-video.html" rel="nofollow noreferrer">http://www.javacodegeeks.com/2011/02/xuggler-tutorial-frames-capture-video.html</a></p>
  
  <p><a href="https://stackoverflow.com/questions/8327847/cant-encode-video-with-xuggler">Can&#39;t encode video with Xuggler</a></p>
  
  <p>But it takes the snapshot and it uses a strange loop:</p>
  
  <pre><code>for (int index = 0; index &lt; SECONDS_TO_RUN_FOR * FRAME_RATE; index++)
  </code></pre>
  
  <p>I can't figure out how to set the right characteristic. It should be easy because I know everything about the video! size, frame rate and number of frame.</p>
  
  <p>My code:</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
  
      final IMediaWriter writer = ToolFactory.makeWriter(outputFilename);
      writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4, 
                 720, 304);
      long nextFrameTime = 0;
      final long frameRate =25/1000;
      long startTime = System.nanoTime();
      while (indexVideo&lt;1597) {
          BufferedImage videoImage = null;
          try {
              videoImage = getVideoImage();
          } catch (AWTException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          }
          writer.encodeVideo(0, videoImage,nextFrameTime, 
                  TimeUnit.MILLISECONDS);
          nextFrameTime += frameRate;
  
  }
      writer.close();
  }
  
  private static BufferedImage getVideoImage() throws IOException, AWTException {
  
       File imgLoc = new File("D:/Gianfranco/Sample/"+indexVideo+".png");
       BufferedImage img;
      img = ImageIO.read(imgLoc);
      System.out.println(imgLoc.getName());
      indexVideo++;
      return img;
  
  }
  </code></pre>
  
  <p>Ca anyone help me out?</p>