sannies / mp4parser

A Java API to read, write and create MP4 files
Apache License 2.0
2.76k stars 571 forks source link

Obtain MP4 with two audio files mixed #189

Open JuGon83 opened 8 years ago

JuGon83 commented 8 years ago

I am wondering if is it possible.

I have two MP4 audio files and one MP4 video file. I need to combine them to reproduce the video and the two sounds at same time (Parallel, Not concatenate), in order to get an only MP4 file.

For example, I have an MP4 audio file with voice, another with music, and another with video. I need that they play all together like a videoclip.

I have been trying to add several tracks to movie with MP4Parser with:

video.addTrack(audioTrack1); video.addTrack(audioTrack2);

But when I play it, I only can hear one of them. Maybe MP4Parser is working correctly and I didn't understand its functionality, for this cause I need a suggest about it.

Is it possible to do this with MP4Parser or I am wrong and it is impossible?

If it is possible, please could you tell me how?

Thank you in advance.

pajama commented 7 years ago

I'm facing this as well, but I think it is my playback solution only supporting playing back one audio track. Would love to know if there is a good way to merge the audio into one track.

chasfirr commented 1 year ago

i found the solution for mixing twoi audios : val movie = Movie() val rec1 = list[0] val rec2 = list[1] val mov1 = MovieCreator.build(rec1).tracks[0] val mov2 = MovieCreator.build(rec2).tracks[0] //movie.addTrack(mov1) //movie.addTrack(mov2) movie.addTrack(AppendTrack(mov1, mov2)) val builder = DefaultMp4Builder().build(movie) val outX = Environment.getExternalStorageDirectory().absolutePath + "/" + Environment.DIRECTORYMUSIC + "/outX${System.currentTimeMillis()}.m4a" val fileChannel = FileOutputStream(outX).channel builder.writeContainer(fileChannel) fileChannel.close()

i am using AppendTrack to append multiple audios