title: How to concatenate/merge two videos in a new video file in Java?
body: <p>I am creating a video using <a href="https://github.com/artclarke/humble-video" rel="nofollow noreferrer">humble-video</a>'s <a href="https://github.com/artclarke/humble-video/blob/master/humble-video-demos/src/main/java/io/humble/video/demos/RecordAndEncodeVideo.java" rel="nofollow noreferrer">RecordAndEncodeVideo.java</a>. </p>
  
  <p>I Now want to combine two videos first is the recorded video and second is the pre-stored video of same frame-rate and resolution on my <code>system</code>. Due to limitation, I want to do this by using humble-video <strong>apis</strong> in java. If anyone have used it please guide me how to do it. </p>
  
  <p>here is the code which i tried:</p>
  
  <pre><code>  public static void combineVideo() throws InterruptedException, IOException {
      final Demuxer demuxer = Demuxer.make();
      demuxer.open("a.mp4", null, false, true, null, null);
      final Muxer muxer = Muxer.make("b.mp4", null, null);
      final MuxerFormat format = muxer.getFormat();
      final MediaPacket packet = MediaPacket.make();
      muxer.open(null, null);
      while (demuxer.read(packet) &gt;= 0) {
          muxer.write(packet, false);
      }
      muxer.close();
      demuxer.close();
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I want to concatenate two video files and save as a new Video File. I know this had been asked in the previous questions <strong>e.g-</strong></p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/13514317/how-to-concat-or-merge-two-or-more-video-files-in-android">how-to-concat-or-merge-two-or-more-video-files-in-android</a></li>
  <li><a href="https://stackoverflow.com/questions/26401514/merge-multiple-video-file-in-a-file?rq=1">merge-multiple-video-file-in-a-file</a></li>
  </ol>
  
  <p>But most of the answer links to the resources or libraries which are not available. Can anyone guide me to some resources. Any code snippet may be helpful. </p>