我正在尝试将 MP3 音频文件混合到 MP4 视频中。 经过几个小时的搜索,我得出的结论是,我需要将 MP3 文件转换为 AAC 格式,以便适合 MP4 容器。
但我找不到任何有关如何将 MP3 文件转换为 AAC 格式的文档。 那么您对如何将 MP3 音频转换为 AAC 音频有什么建议吗?
此外,我需要在最终视频的特定时间插入多个音频。
最佳答案
您可以尝试使用mp4parser它对 mp4 进行一些混流,有些人(从 github 存储库“问题”部分中可以看出)正在使用它来混流 mp3 和 mp4。
你的另一个选择是使用 FFmpeg,要么自己编译,要么使用预制的东西,我用过 this 。 库本身有点庞大,而且您可能需要一些尝试才能正确使用 FFmpeg 命令,以获得最佳质量和复用器速度。
它看起来像这样:
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();
}
还有一个听众:
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
}
};
关于Android - 将 mp3 音频添加到 mp4 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34896885/