FileDocCategorySizeDatePackage
AppendExample.javaAPI Docmp4parser 1.0-RC-172147Wed Dec 19 20:10:38 GMT 2012com.googlecode.mp4parser

AppendExample

public class AppendExample extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        String audioDeutsch = AppendExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-deutsch-audio.mp4";
        String audioEnglish = AppendExample.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/count-english-audio.mp4";

        Movie[] inMovies = new Movie[]{MovieCreator.build(new FileInputStream(audioDeutsch).getChannel()),
                MovieCreator.build(new FileInputStream(audioEnglish).getChannel())};

        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("soun")) {
                    audioTracks.add(t);
                }
                if (t.getHandler().equals("vide")) {
                    videoTracks.add(t);
                }
            }
        }

        Movie result = new Movie();

        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()])));
        }

        IsoFile out = new DefaultMp4Builder().build(result);

        FileChannel fc = new RandomAccessFile(String.format("output.mp4"), "rw").getChannel();
        fc.position(0);
        out.getBox(fc);
        fc.close();