FileDocCategorySizeDatePackage
TwoSecondIntersectionFinder.javaAPI Docmp4parser 1.0-RC-173043Wed Dec 19 20:10:37 GMT 2012com.googlecode.mp4parser.authoring.builder

TwoSecondIntersectionFinder

public class TwoSecondIntersectionFinder extends Object implements FragmentIntersectionFinder
This FragmentIntersectionFinder cuts the input movie in 2 second snippets.

Fields Summary
private int
fragmentLength
Constructors Summary
public TwoSecondIntersectionFinder()


      
    
public TwoSecondIntersectionFinder(int fragmentLength)

        this.fragmentLength = fragmentLength;
    
Methods Summary
protected longgetDuration(com.googlecode.mp4parser.authoring.Track track)

        long duration = 0;
        for (TimeToSampleBox.Entry entry : track.getDecodingTimeEntries()) {
            duration += entry.getCount() * entry.getDelta();
        }
        return duration;
    
public long[]sampleNumbers(com.googlecode.mp4parser.authoring.Track track, com.googlecode.mp4parser.authoring.Movie movie)
{@inheritDoc}

        List<TimeToSampleBox.Entry> entries = track.getDecodingTimeEntries();

        double trackLength = 0;
        for (Track thisTrack : movie.getTracks()) {
            double thisTracksLength = getDuration(thisTrack) / thisTrack.getTrackMetaData().getTimescale();
            if (trackLength < thisTracksLength) {
                trackLength = thisTracksLength;
            }
        }

        int fragmentCount = (int) Math.ceil(trackLength / fragmentLength) - 1;
        if (fragmentCount < 1) {
            fragmentCount = 1;
        }

        long fragments[] = new long[fragmentCount];
        Arrays.fill(fragments, -1);
        fragments[0] = 1;

        long time = 0;
        int samples = 0;
        for (TimeToSampleBox.Entry entry : entries) {
            for (int i = 0; i < entry.getCount(); i++) {
                int currentFragment = (int) (time / track.getTrackMetaData().getTimescale() / fragmentLength) + 1;
                if (currentFragment >= fragments.length) {
                    break;
                }
                fragments[currentFragment] = samples++ + 1;
                time += entry.getDelta();
            }
        }
        long last = samples + 1;
        // fill all -1 ones.
        for (int i = fragments.length - 1; i >= 0; i--) {
            if (fragments[i] == -1) {
                fragments[i] = last;
            }
            last = fragments[i];
        }
        return fragments;