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

FindCommonSync

public class FindCommonSync extends Object

Fields Summary
Constructors Summary
Methods Summary
public static java.util.ListasSortedList(java.util.Collection c)

        List<T> list = new ArrayList<T>(c);
        java.util.Collections.sort(list);
        return list;
    
public static voidmain(java.lang.String[] args)

        HashMap<Integer, Integer> common = new HashMap<Integer, Integer>();
        boolean first = true;
        for (String arg : args) {
            Movie invideo = MovieCreator.build(new FileInputStream(arg).getChannel());
            List<Track> tracks = invideo.getTracks();

            for (Track t : tracks) {
                String type = t.getMediaHeaderBox().getType();
                String ctype = t.getSampleDescriptionBox().getSampleEntry().getType();
                System.out.println("Track of type " + type + " (" + ctype + ")");
                if (type.equals("vmhd")) {
                    HashMap<Integer, Integer> previous = (HashMap<Integer, Integer>) common.clone();
                    common.clear();
                    System.out.println("Found video track in " + arg);
                    long[] syncSamples = t.getSyncSamples();
                    long timescale = t.getTrackMetaData().getTimescale();
                    long tts = t.getDecodingTimeEntries().get(0).getDelta();
                    for (long syncSample : syncSamples) {
                        long time = 1000 * tts * (syncSample - 1) / timescale;
                        int inttime = (int) time;
                        if (first || previous.containsKey(inttime)) {
                            common.put(inttime, 1);
                        }
                    }
                    first = false;
                }
            }
        }
        // Print the common times
        Set<Integer> keys = common.keySet();

        List<Integer> inorder = asSortedList(keys);
        Integer previous = 0;
        int wrong = 0;
        for (Integer sync : inorder) {
            Integer delta = sync - previous;
            System.out.println("Common sync point: " + (double) sync / 1000.0 + " delta: " + (double) delta / 1000.0);
            if (delta > 3000) {
                System.out.println("WARNING WARNING! > 3sek");
                wrong++;
            }
            previous = sync;
        }
        int commonCount = inorder.size();
        System.out.println("Durations that are too long: " + wrong + "/" + commonCount);