mp4parser icon indicating copy to clipboard operation
mp4parser copied to clipboard

how to add mp3 audio to mp4 video?

Open songdings opened this issue 7 years ago • 4 comments

how to add mp3 audio to mp4 video?

songdings avatar Nov 10 '16 07:11 songdings

You can search in some issues, Sannies already explained that mp3 can not be added to mp4 directly. We have to decode mp3.

In my case, I just need to mux mp3 to mp4 in android. Follow is my solution. Dont waste your time if you need to do this in anywhere else (desktop...).

https://github.com/google/ringdroid help to convert from mp3 to m4a (totally in java, no native library, Apache License, I think some one can write sample project about mux mp3 to mp4 in android use it and mp4parser). And then you can mux m4a and mp4 as usual:

Movie audioTrack = null;
Movie outputVideo = null;
try {
    outputVideo = MovieCreator.build("mp4Dir");
} catch (Exception e) {
    e.printStackTrace();
}
try {
    audioTrack = MovieCreator.build("m4aDir");
} catch (IOException e) {
    e.printStackTrace();
}
List<Track> nuTracks = new ArrayList<>();
for (Track track : outputVideo.getTracks()) {
    if (track.getHandler().equals("vide")) {
        nuTracks.add(track);
    }
}
for (Track track : audioTrack.getTracks()) {
    if (track.getHandler().equals("soun")) {
        nuTracks.add(track);
    }
}
outputVideo.setTracks(nuTracks);
Container out = new DefaultMp4Builder().build(outputVideo);
try {
    FileOutputStream fos = new FileOutputStream(new File("outputDir");
    FileChannel fc = fos.getChannel();
    out.writeContainer(fc);
    fos.close();
} catch (Exception e) {
    e.printStackTrace();
}

I dont know if it is suitable for use or not, but in my case it is good (I do not need to care about performance, I like pure java and Apache License)

cuong0993 avatar Nov 12 '16 16:11 cuong0993

@cuong0993 Nice, good job. your method is working and fix. i use isoparser-1.1.9.jar and fix. this version support on all android api level? and how to create or download 1.9.27 version ?

not found new version in link: http://repo1.maven.org/maven2/com/googlecode/mp4parser/isoparser/ last version is: 1.1.9

farzadno avatar Sep 14 '17 13:09 farzadno

Anyone have any idea the compressed video file how to get? I am compressing video and it is successful but unable to get the final compressed file. Any help would be great.

binaykumarrana avatar Nov 29 '17 07:11 binaykumarrana

Step 1: Add video to iDealshare VideoGo, Step 2:Click "Effect" button and switch to "Audio" category and the original video audio will appear in the box under Add icon, and then click Add icon (a "+"sign on the lower left side) to import the MP3 audio that you want to add to video. Step 3: Click Convert button. Step by step guide: https://www.idealshare.net/add-mp3-to-mp4.html

idealitystarts avatar Sep 29 '19 01:09 idealitystarts