Android 如何在不创建新视频的情况下向现有视频添加音频

How to add audio to an existing video without creating a new video in Android

我想做一个配音应用程序。我将从 user's microphone 获取音频。我有一个 mp4 视频。我想将 用户的音频覆盖为 mp4 视频 。我该怎么做?
我搜索了很多,我认为 mp4 解析器 库会帮助我,但很难理解我。
我没有找到一个很好的例子。
有没有人给我解释清楚?

如果您的 MP4 已通过 h.264 编码,您可以轻松使用 MP4parser.

try {
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl(baseDir + "/video.h264"));
AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl( baseDir + "/aac_sample.aac" ));

Movie movie = new Movie();
movie.addTrack(h264Track);
movie.addTrack(aacTrack);
Container mp4file = new DefaultMp4Builder().build(movie);

FileChannel fc = new FileOutputStream(new File(baseDir +"/output.mp4")).getChannel();
mp4file.writeContainer(fc);
fc.close();

} catch (FileNotFoundException e) {
  e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
}

未测试。有帮助吗