title: How to merge audio and video file in android
body: <p>Thanks for the great <a href="https://github.com/sannies/mp4parser" rel="noreferrer">mp4parser</a> lib, i have few queries related to audio video muxing.</p>
  
  <p>We used the below code in android and tried, but we are not getting the expected output, We have kept a working mp4 file in the specific directory and trying but no luck.</p>
  
  <p>Here we get the merged audio and video, but audio gets appended to video. And the appended audio will not play but simply it increases the width of video.</p>
  
  <p>Any help from geeks.</p>
  
  <p>Here is the code,</p>
  
  <pre><code>    File sdCard = Environment.getDataDirectory();
  
      String videofilepath = Environment.getExternalStorageDirectory().toString()+"/video.mp4";
      String audiofilepath = Environment.getExternalStorageDirectory().toString()+"/audio.aac";
      File file=new File(videofilepath);
  
      H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(videofilepath));
      AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl(audiofilepath));
  
      Movie movie = new Movie();
      movie.addTrack(h264Track);
      movie.addTrack(aacTrack);
  
  
      Container mp4file = new DefaultMp4Builder().build(movie);
  
      FileChannel fc = new FileOutputStream(new File(Environment.getExternalStorageDirectory().toString() + "/video.mp4")).getChannel();
      mp4file.writeContainer(fc);
      fc.close();
  </code></pre>