Skip to content

Instantly share code, notes, and snippets.

@RenegadeEagle
Created October 29, 2014 22:14
Show Gist options
  • Save RenegadeEagle/3752b204e5974c2ab65a to your computer and use it in GitHub Desktop.
Save RenegadeEagle/3752b204e5974c2ab65a to your computer and use it in GitHub Desktop.
public static void combineVideos(){
List<Movie> movies = new LinkedList<Movie>();
File videos = new File("/root/Videos/");
File[] directoryListing = videos.listFiles();
for (File child : directoryListing) {
try {
movies.add(MovieCreator.build(child.getAbsolutePath()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//All our videos have been added cool.
List<Track> videoTracks = new LinkedList<Track>();
List<Track> audioTracks = new LinkedList<Track>();
Movie newMovie = new Movie();
for (Movie m : movies) {
for (Track track : m.getTracks()) {
if (track.getHandler().equals("vide")) {
videoTracks.add(track);
}
if (track.getHandler().equals("soun")) {
audioTracks.add(track);
}
}
}
try {
newMovie.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
newMovie.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Container out = new DefaultMp4Builder().build(newMovie);
try {
FileChannel fc = new RandomAccessFile(String.format("output.mp4"), "rw").getChannel();
out.writeContainer(fc);
fc.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment