static long[] adjustTts( long[] sourceArray, double timeScaleFactor, long[] syncSample, long[] syncSampleTimes) { long summedDurations = 0; long[] scaledArray = new long[sourceArray.length]; for (int i = 1; i <= sourceArray.length; i++) { long duration = sourceArray[i - 1]; long x = Math.round(timeScaleFactor * duration); int ssIndex; if ((ssIndex = Arrays.binarySearch(syncSample, i + 1)) >= 0) { // we are at the sample before sync point if (syncSampleTimes[ssIndex] != summedDurations) { long correction = syncSampleTimes[ssIndex] - (summedDurations + x); LOG.finest( String.format( "Sample %d %d / %d - correct by %d", i, summedDurations, syncSampleTimes[ssIndex], correction)); x += correction; } } summedDurations += x; scaledArray[i - 1] = x; } return scaledArray; }
/** * Adjusting the composition times is easy. Just scale it by the factor - that's it. There is no * rounding error summing up. * * @param source * @param timeScaleFactor * @return */ static List<CompositionTimeToSample.Entry> adjustCtts( List<CompositionTimeToSample.Entry> source, double timeScaleFactor) { if (source != null) { List<CompositionTimeToSample.Entry> entries2 = new ArrayList<CompositionTimeToSample.Entry>(source.size()); for (CompositionTimeToSample.Entry entry : source) { entries2.add( new CompositionTimeToSample.Entry( entry.getCount(), (int) Math.round(timeScaleFactor * entry.getOffset()))); } return entries2; } else { return null; } }