title: How to combine an AVI and a WAV file using only client side JAVA?
body: <p>My program is doing a screen capture video, into an AVI file while also recording the microphone's voice into a WAV file. After it is finished, I would like to combine the two into a single file (so basically add the WAV file as the audio to the video).</p>
  
  <p>I do the screen capturing with the following code(the ScreenRecorder class is from org.monte.screenrecorder ):</p>
  
  <pre><code>GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().
      getDefaultScreenDevice().getDefaultConfiguration();
  
  Format fileFormat = new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI);
  Format screenFormat = new Format(MediaTypeKey, MediaType.VIDEO, 
                      EncodingKey, ENCODING_AVI_MJPG,
                      CompressorNameKey, ENCODING_AVI_MJPG,
                      DepthKey, (int)24, 
                      FrameRateKey, Rational.valueOf(15),
                      QualityKey, 1.0f,
                      KeyFrameIntervalKey, (int) (15 * 60));
  Format mouseFormat = new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,"black",
  FrameRateKey, Rational.valueOf(30));
  screenRecorder = new ScreenRecorder(gc, fileFormat, screenFormat, mouseFormat, null);   
  </code></pre>
  
  <p>For the audio recording I do it like this (so you can see all the formats, parameters etc.):</p>
  
  <pre><code>float sampleRate = 44100;
  int sampleSizeInBits = 16;
  int channels = 2;
  boolean signed = true;
  boolean bigEndian = true;    
  AudioFormat format new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
  DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
  
  // checks if system supports the data line
  if (!AudioSystem.isLineSupported(info)) {
      System.out.println("Line not supported");
      System.exit(0);
  }
  line = (TargetDataLine) AudioSystem.getLine(info);
  line.open(format);
  line.start();   // start capturing
  
  System.out.println("Start capturing...");
  
  AudioInputStream ais = new AudioInputStream(line);
  
  System.out.println("Start recording...");
  
  // start recording
  AudioSystem.write(ais, fileType, wavFile);
  </code></pre>
  
  <p>I tried the following solutions, to no avail:
  JMF ( javax.media.Manager, it dies at createRealizedProcessor )
  Xuggle ( com.xuggle.mediatool and com.xuggle.xuggler )</p>
  
  <p>I'm pretty sure that they don't work because they don't like the input formats. </p>
  
  <p>Yes, I can easily do this merge with FFMPEG from command line or on a server, but it is not good for me, I need a client side JAVA solution (can't really ask the users to install FFMPEG so I can call it with Runtime.getRuntime().exec or something).</p>