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

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐