public long[] getSampleDurations() { long[] scaled = new long[source.getSampleDurations().length]; for (int i = 0; i < source.getSampleDurations().length; i++) { scaled[i] = source.getSampleDurations()[i] / timeScaleDivisor; } return scaled; }
public long[] getSampleDurations() { long[] scaled = new long[source.getSampleDurations().length]; for (int i = 0; i < source.getSampleDurations().length; i++) { scaled[i] = source.getSampleDurations()[i] * timeScaleFactor; } return scaled; }
public long[] getSampleDurations() { return source.getSampleDurations(); }
public synchronized long[] getSampleDurations() { return origTrack.getSampleDurations(); }
public long[] getSampleDurations() { return parent.getSampleDurations(); }
public synchronized long[] getSampleDurations() { long[] decodingTimes = new long[toSample - fromSample]; System.arraycopy(origTrack.getSampleDurations(), fromSample, decodingTimes, 0, decodingTimes.length); return decodingTimes; }
public AppendTrack(Track... tracks) throws IOException { super(appendTracknames(tracks)); this.tracks = tracks; for (Track track : tracks) { sampleEntries.addAll(track.getSampleEntries()); } for (Track track : tracks) { //System.err.println("Track " + track + " is about to be appended"); lists.addAll(track.getSamples()); } int numSamples = 0; for (Track track : tracks) { numSamples += track.getSampleDurations().length; } decodingTimes = new long[numSamples]; int index = 0; // should use system arraycopy but this works too (yes it's slow ...) for (Track track : tracks) { long[] durs = track.getSampleDurations(); System.arraycopy(durs, 0, decodingTimes, index, durs.length); index += durs.length; } }
public static void main(String[] args) throws IOException { Movie movie = MovieCreator.build(DumpAmf0TrackToPropertyFile.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/example.f4v"); for (Track track : movie.getTracks()) { if (track.getHandler().equals("data") ) { long time = 0; Iterator<Sample> samples = track.getSamples().iterator(); Properties properties = new Properties(); File f = File.createTempFile(DumpAmf0TrackToPropertyFile.class.getSimpleName(), "" + track.getTrackMetaData().getTrackId()); for (long decodingTime : track.getSampleDurations()) { ByteBuffer sample = samples.next().asByteBuffer(); byte[] sampleBytes = new byte[sample.limit()]; sample.reset(); sample.get(sampleBytes); properties.put("" + time, new String(Base64.encodeBase64(sampleBytes, false, false))); time += decodingTime; } FileOutputStream fos = new FileOutputStream(f); System.err.println(properties); properties.store(fos, ""); } } }
private static long[] getTimes(Track track, long[] syncSamples, long targetTimeScale) { long[] syncSampleTimes = new long[syncSamples.length]; int currentSample = 1; // first syncsample is 1 long currentDuration = 0; int currentSyncSampleIndex = 0; while (currentSample <= syncSamples[syncSamples.length - 1]) { if (currentSample == syncSamples[currentSyncSampleIndex]) { syncSampleTimes[currentSyncSampleIndex++] = (currentDuration * targetTimeScale) / track.getTrackMetaData().getTimescale(); } currentDuration += track.getSampleDurations()[currentSample - 1]; currentSample++; } return syncSampleTimes; }
private static long[] getTimes(Track track, Movie m) { long[] syncSamples = track.getSyncSamples(); long[] syncSampleTimes = new long[syncSamples.length]; int currentSample = 1; // first syncsample is 1 long currentDuration = 0; int currentSyncSampleIndex = 0; final long scalingFactor = calculateTracktimesScalingFactor(m, track); while (currentSample <= syncSamples[syncSamples.length - 1]) { if (currentSample == syncSamples[currentSyncSampleIndex]) { syncSampleTimes[currentSyncSampleIndex++] = currentDuration * scalingFactor; } currentDuration += track.getSampleDurations()[-1 + currentSample++]; } return syncSampleTimes; }
double time = trackToTime.get(nextChunksTrack); for (int j = startSample; j < startSample + numberOfSampleInNextChunk; j++) { time += (double) nextChunksTrack.getSampleDurations()[j] / nextChunksTrack.getTrackMetaData().getTimescale();
private static long findNextSyncSample(Track track, double cutHere) { long currentSample = 0; double currentTime = 0; long[] durations = track.getSampleDurations(); long[] syncSamples = track.getSyncSamples(); for (int i = 0; i < durations.length; i++) { long delta = durations[i]; if ((syncSamples == null || syncSamples.length > 0 || Arrays.binarySearch(syncSamples, currentSample + 1) >= 0) && currentTime > cutHere) { return i; } currentTime += (double) delta / (double) track.getTrackMetaData().getTimescale(); currentSample++; } return currentSample; }
private static double correctTimeToSyncSample(Track track, double cutHere, boolean next) { double[] timeOfSyncSamples = new double[track.getSyncSamples().length]; long currentSample = 0; double currentTime = 0; for (int i = 0; i < track.getSampleDurations().length; i++) { long delta = track.getSampleDurations()[i]; if (Arrays.binarySearch(track.getSyncSamples(), currentSample + 1) >= 0) { // samples always start with 1 but we start with zero therefore +1 timeOfSyncSamples[Arrays.binarySearch(track.getSyncSamples(), currentSample + 1)] = currentTime; } currentTime += (double) delta / (double) track.getTrackMetaData().getTimescale(); currentSample++; } double previous = 0; for (double timeOfSyncSample : timeOfSyncSamples) { if (timeOfSyncSample > cutHere) { if (next) { return timeOfSyncSample; } else { return previous; } } previous = timeOfSyncSample; } return timeOfSyncSamples[timeOfSyncSamples.length - 1]; }
private static double correctTimeToSyncSample(Track track, double cutHere, boolean next) { double[] timeOfSyncSamples = new double[track.getSyncSamples().length]; long currentSample = 0; double currentTime = 0; for (int i = 0; i < track.getSampleDurations().length; i++) { long delta = track.getSampleDurations()[i]; if (Arrays.binarySearch(track.getSyncSamples(), currentSample + 1) >= 0) { // samples always start with 1 but we start with zero therefore +1 timeOfSyncSamples[Arrays.binarySearch(track.getSyncSamples(), currentSample + 1)] = currentTime; } currentTime += (double) delta / (double) track.getTrackMetaData().getTimescale(); currentSample++; } double previous = 0; for (double timeOfSyncSample : timeOfSyncSamples) { if (timeOfSyncSample > cutHere) { if (next) { return timeOfSyncSample; } else { return previous; } } previous = timeOfSyncSample; } return timeOfSyncSamples[timeOfSyncSamples.length - 1]; }
private static double correctTimeToSyncSample(Track track, double cutHere, boolean next) { double[] timeOfSyncSamples = new double[track.getSyncSamples().length]; long currentSample = 0; double currentTime = 0; for (int i = 0; i < track.getSampleDurations().length; i++) { long delta = track.getSampleDurations()[i]; if (Arrays.binarySearch(track.getSyncSamples(), currentSample + 1) >= 0) { // samples always start with 1 but we start with zero therefore +1 timeOfSyncSamples[Arrays.binarySearch(track.getSyncSamples(), currentSample + 1)] = currentTime; } currentTime += (double) delta / (double) track.getTrackMetaData().getTimescale(); currentSample++; } double previous = 0; for (double timeOfSyncSample : timeOfSyncSamples) { if (timeOfSyncSample > cutHere) { if (next) { return timeOfSyncSample; } else { return previous; } } previous = timeOfSyncSample; } return timeOfSyncSamples[timeOfSyncSamples.length - 1]; }
protected void createTfdt(long startSample, Track track, TrackFragmentBox parent) { TrackFragmentBaseMediaDecodeTimeBox tfdt = new TrackFragmentBaseMediaDecodeTimeBox(); tfdt.setVersion(1); long startTime = 0; long[] times = track.getSampleDurations(); for (int i = 1; i < startSample; i++) { startTime += times[i - 1]; } tfdt.setBaseMediaDecodeTime(startTime); parent.addBox(tfdt); }
long[] syncSamples = t.getSyncSamples(); long timescale = t.getTrackMetaData().getTimescale(); long tts = t.getSampleDurations()[0]; for (long syncSample : syncSamples) { long time = 1000 * tts * (syncSample - 1) / timescale;
/** * {@inheritDoc} */ public long[] sampleNumbers(Track track) { long[] segmentStartSamples = new long[]{1}; long[] sampleDurations = track.getSampleDurations(); long[] syncSamples = track.getSyncSamples(); long timescale = track.getTrackMetaData().getTimescale(); double time = 0; for (int i = 0; i < sampleDurations.length; i++) { time += (double) sampleDurations[i] / timescale; if (time >= fragmentLength && (syncSamples == null || Arrays.binarySearch(syncSamples, i + 1) >= 0)) { if (i > 0) { segmentStartSamples = Mp4Arrays.copyOfAndAppend(segmentStartSamples, i + 1); } time = 0; } } return segmentStartSamples; } }
protected void createStts(Track track, SampleTableBox stbl) { TimeToSampleBox.Entry lastEntry = null; List<TimeToSampleBox.Entry> entries = new ArrayList<TimeToSampleBox.Entry>(); for (long delta : track.getSampleDurations()) { if (lastEntry != null && lastEntry.getDelta() == delta) { lastEntry.setCount(lastEntry.getCount() + 1); } else { lastEntry = new TimeToSampleBox.Entry(1, delta); entries.add(lastEntry); } } TimeToSampleBox stts = new TimeToSampleBox(); stts.setEntries(entries); stbl.addBox(stts); }
/** * Changes the time scale of the source track to the target time scale and makes sure * that any rounding errors that may have summed are corrected exactly before the syncSamples. * * @param source the source track * @param targetTimeScale the resulting time scale of this track. * @param syncSamples at these sync points where rounding error are corrected. */ public ChangeTimeScaleTrack(Track source, long targetTimeScale, long[] syncSamples) { this.source = source; this.timeScale = targetTimeScale; double timeScaleFactor = (double) targetTimeScale / source.getTrackMetaData().getTimescale(); ctts = adjustCtts(source.getCompositionTimeEntries(), timeScaleFactor); decodingTimes = adjustTts(source.getSampleDurations(), timeScaleFactor, syncSamples, getTimes(source, syncSamples, targetTimeScale)); }