Combine Audio With Video - Android
I am developing an app to capture video and download audio. I am able to save these files separately but could not find a way to combine these files to make a new video with audio.
Solution 1:
I think MP4Parser library is apt for this scenario. I'd found the below sample code to merge audio and video into single mp4 file in this link Video Recording And Processing In Android .
public class Mp4ParserAudioMuxer implements AudioMuxer {
@Override
public boolean mux(String videoFile, String audioFile, String outputFile) {
Movie video;
try {
video = new MovieCreator().build(videoFile);
} catch (RuntimeException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
Movie audio;
try {
audio = new MovieCreator().build(audioFile);
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (NullPointerException e) {
e.printStackTrace();
return false;
}
Track audioTrack = audio.getTracks().get(0);
video.addTrack(audioTrack);
Container out = new DefaultMp4Builder().build(video);
FileOutputStream fos;
try {
fos = new FileOutputStream(outputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
BufferedWritableFileByteChannel byteBufferByteChannel =
new BufferedWritableFileByteChannel(fos);
try {
out.writeContainer(byteBufferByteChannel);
byteBufferByteChannel.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
}
If you are thinking of doing it via ffmpeg, you can use static ffmpeg binaries or you need to build it.
Post a Comment for "Combine Audio With Video - Android"