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 .
publicclassMp4ParserAudioMuxerimplementsAudioMuxer {
@Overridepublicbooleanmux(String videoFile, String audioFile, String outputFile) {
Movie video;
try {
video = newMovieCreator().build(videoFile);
} catch (RuntimeException e) {
e.printStackTrace();
returnfalse;
} catch (IOException e) {
e.printStackTrace();
returnfalse;
}
Movie audio;
try {
audio = newMovieCreator().build(audioFile);
} catch (IOException e) {
e.printStackTrace();
returnfalse;
} catch (NullPointerException e) {
e.printStackTrace();
returnfalse;
}
Track audioTrack = audio.getTracks().get(0);
video.addTrack(audioTrack);
Container out = newDefaultMp4Builder().build(video);
FileOutputStream fos;
try {
fos = newFileOutputStream(outputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
returnfalse;
}
BufferedWritableFileByteChannel byteBufferByteChannel =
newBufferedWritableFileByteChannel(fos);
try {
out.writeContainer(byteBufferByteChannel);
byteBufferByteChannel.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
returnfalse;
}
returntrue;
}
}
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"