Reputation: 1399
I wanted to add audio to a mp4 file,that video doesn't have any audio ,will be added by user selected audio ,How can i achive this?
Upvotes: 3
Views: 4391
Reputation: 517
if your MP4 has been encoded by h.264 , you can easily use 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();
}
Upvotes: 4