5

I was just wondering if anybody knows how to take an mp4 audio file and overlay it onto an mp4 video file using mp4parser on Android. I have been able to append one video with another, now I just need to overlay a raw mp4 that I have over the combined file.

Any help would be appreciated!

Thor
  • 6,607
  • 13
  • 62
  • 96
Matt Kula
  • 268
  • 2
  • 8

1 Answers1

4

The following code muxes two audio languages and a video. It should be easy to adopt it to your needs:

public static void main(String[] args) throws IOException {

    String audioDeutsch = MuxMp4SourcesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-deutsch-audio.mp4";
    String audioEnglish = MuxMp4SourcesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-english-audio.mp4";
    String video = MuxMp4SourcesExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-video.mp4";


    Movie countVideo = MovieCreator.build(new FileInputStream(video).getChannel());
    Movie countAudioDeutsch = MovieCreator.build(new FileInputStream(audioDeutsch).getChannel());
    Movie countAudioEnglish = MovieCreator.build(new FileInputStream(audioEnglish).getChannel());

    Track audioTrackDeutsch = countAudioDeutsch.getTracks().get(0);
    audioTrackDeutsch.getTrackMetaData().setLanguage("deu");
    Track audioTrackEnglish = countAudioEnglish.getTracks().get(0);
    audioTrackEnglish.getTrackMetaData().setLanguage("eng");

    countVideo.addTrack(audioTrackDeutsch);
    countVideo.addTrack(audioTrackEnglish);

    Container out = new DefaultMp4Builder().build(countVideo);
    FileOutputStream fos = new FileOutputStream(new File("output.mp4"));
    out.writeContainer(fos.getChannel());
    fos.close();

}
Sebastian Annies
  • 2,438
  • 1
  • 20
  • 38
  • Audio Is overwriting when using this code.. ANy help ?? – Ahmad Arslan May 15 '14 at 09:11
  • 1
    @Sebastian The audio tracks are added one after the other . Is there anyway I can add two audio tracks and they have to run at the same time and obviously the video. Let's say I have a video and a voice audio and also a background music. Now I want to have these two audio run parallely at the same time with the video. Can you help how we can achieve this ? – ROCKY Apr 25 '15 at 20:14
  • Above mentioned code mixes the video with the first audio track added. I want to play two audio track parallel with video file. Can anyone help me for that – Amit Thaper Mar 14 '16 at 11:19
  • @SebastainAnnies Is it possible to combine two video files into one using `mp4parser` in java –  Jul 01 '16 at 08:36