I an creating an app witch merge videos and add mp3 audio overlay.
With merging videos i have no problems, but audio not playing in output video.
Here is my code:
Movie[] inMovies = new Movie[count];
for (int i = count - 1; i >= 0; i--) {
File file = new File(lv1List.get(i));
if (file.exists()) {
try {
inMovies[counter] = MovieCreator.build(file.getAbsolutePath());
counter++;
} catch (Exception e) {
Log.d("mp4parse", e.getMessage());
}
}
}
List<Track> videoTracks = new LinkedList<Track>();
List<Track> audioTracks = new LinkedList<Track>();
for (Movie m : inMovies) {
for (Track t : m.getTracks()) {
if (t.getHandler().equals("vide")) {
videoTracks.add(t);
}
}
}
try {
MP3TrackImpl aacTrack = new MP3TrackImpl(new FileDataSourceImpl(audiopath));
CroppedTrack aacTrackShort = new CroppedTrack(aacTrack, 1, aacTrack.getSamples().size());
audioTracks.add(aacTrackShort);
} catch (Exception e) {
e.printStackTrace();
}
Movie result = new Movie();
try {
if (audioTracks.size() > 0) {
result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
}
if (videoTracks.size() > 0) {
result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
}
} catch (Exception e) {
e.printStackTrace();
}
try {
Container out = new DefaultMp4Builder().build(result);
String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + "/MERGEDoutput" + Long.toString(System.currentTimeMillis()) + ".mp4";
FileOutputStream fos = new FileOutputStream(new File(filename));
out.writeContainer(fos.getChannel());
fos.close();
} catch (Exception e) {
}
Output video has not sound. Input mp3 is usual music track.