我想给一个没有音频的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();
}