You can try to use mp4parser which does some muxing to mp4, there are some people (as seen from within github repo "issues" part) who are using this to mux mp3 and mp4.

Another option you've got is to use FFmpeg, either compile your self or use something premade, I've used this.

Library it self is a bit bulky, plus you might need some playing around to get FFmpeg commands right in order to get optimum quality and mux speed.

It looks something like this:

try {

FFmpeg ffmpeg = FFmpeg.getInstance(this);

String cmd = "-i " + videoFilePath + " -i " + audioFilePath + " -shortest -threads 0 -preset ultrafast -strict -2 " + outputFilePath

ffmpeg.execute(cmd, mergeListener);

} catch (FFmpegCommandAlreadyRunningException e) {

e.printStackTrace();

}

And a listener:

ExecuteBinaryResponseHandler mergeListener = new ExecuteBinaryResponseHandler() {

@Override

public void onStart() {

//started

}

@Override

public void onFailure(String message) {

//failed

}

@Override

public void onFinish() {

File output = new File(outputFilePath);

//Do whatever with your muxed file

}

};

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐