Last active
November 5, 2015 13:22
-
-
Save dominicthomas/0d6323d0102b36738124 to your computer and use it in GitHub Desktop.
Code used to append 4 mp4 files using mp4parser - Code uses example path to file strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
final Movie intro = MovieCreator.build(new FileDataSourceImpl(file1)); | |
final Movie main = MovieCreator.build(new FileDataSourceImpl(file2)); | |
final Movie resultClip = MovieCreator.build(new FileDataSourceImpl(file3)); | |
final Movie end = MovieCreator.build(new FileDataSourceImpl(file4)); | |
final Movie[] movies = new Movie[]{intro, main, resultClip, end}; | |
final List<Track> videoTracks = new LinkedList<>(); | |
final List<Track> audioTracks = new LinkedList<>(); | |
for (Movie m : movies) { | |
for (Track track : m.getTracks()) { | |
if (track.getHandler().equals("soun")) { | |
audioTracks.add(track); | |
} | |
if (track.getHandler().equals("vide")) { | |
videoTracks.add(track); | |
} | |
} | |
} | |
final Movie output = new Movie(); | |
if (videoTracks.size() > 0) { | |
output.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()]))); | |
} | |
if (audioTracks.size() > 0) { | |
output.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()]))); | |
} | |
final Container container = new DefaultMp4Builder().build(output); | |
final RandomAccessFile randomAccessFile = new RandomAccessFile(finalOutput, "rw"); | |
final FileChannel fileChannel = randomAccessFile.getChannel(); | |
container.writeContainer(fileChannel); | |
randomAccessFile.close(); | |
fileChannel.close(); | |
Timber.d("SUCCESS!"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment