final long trackId = trackBox.getTrackHeaderBox().getTrackId();
samples = new SampleList(trackBox);
SampleTableBox stbl = trackBox.getMediaBox().getMediaInformationBox().getSampleTableBox();
handler = trackBox.getMediaBox().getHandlerBox().getHandlerType();
mihd = trackBox.getMediaBox().getMediaInformationBox().getMediaHeaderBox();
decodingTimeEntries = new ArrayList<TimeToSampleBox.Entry>();
compositionTimeEntries = new ArrayList<CompositionTimeToSample.Entry>();
sampleDependencies = new ArrayList<SampleDependencyTypeBox.Entry>();
decodingTimeEntries.addAll(stbl.getTimeToSampleBox().getEntries());
if (stbl.getCompositionTimeToSample() != null) {
compositionTimeEntries.addAll(stbl.getCompositionTimeToSample().getEntries());
}
if (stbl.getSampleDependencyTypeBox() != null) {
sampleDependencies.addAll(stbl.getSampleDependencyTypeBox().getEntries());
}
if (stbl.getSyncSampleBox() != null) {
syncSamples = stbl.getSyncSampleBox().getSampleNumber();
}
sampleDescriptionBox = stbl.getSampleDescriptionBox();
final List<MovieExtendsBox> movieExtendsBoxes = trackBox.getParent().getBoxes(MovieExtendsBox.class);
if (movieExtendsBoxes.size() > 0) {
for (MovieExtendsBox mvex : movieExtendsBoxes) {
final List<TrackExtendsBox> trackExtendsBoxes = mvex.getBoxes(TrackExtendsBox.class);
for (TrackExtendsBox trex : trackExtendsBoxes) {
if (trex.getTrackId() == trackId) {
List<Long> syncSampleList = new LinkedList<Long>();
long sampleNumber = 1;
for (MovieFragmentBox movieFragmentBox : trackBox.getIsoFile().getBoxes(MovieFragmentBox.class)) {
List<TrackFragmentBox> trafs = movieFragmentBox.getBoxes(TrackFragmentBox.class);
for (TrackFragmentBox traf : trafs) {
if (traf.getTrackFragmentHeaderBox().getTrackId() == trackId) {
List<TrackRunBox> truns = traf.getBoxes(TrackRunBox.class);
for (TrackRunBox trun : truns) {
final TrackFragmentHeaderBox tfhd = ((TrackFragmentBox) trun.getParent()).getTrackFragmentHeaderBox();
boolean first = true;
for (TrackRunBox.Entry entry : trun.getEntries()) {
if (trun.isSampleDurationPresent()) {
if (decodingTimeEntries.size() == 0 ||
decodingTimeEntries.get(decodingTimeEntries.size() - 1).getDelta() != entry.getSampleDuration()) {
decodingTimeEntries.add(new TimeToSampleBox.Entry(1, entry.getSampleDuration()));
} else {
TimeToSampleBox.Entry e = decodingTimeEntries.get(decodingTimeEntries.size() - 1);
e.setCount(e.getCount() + 1);
}
} else {
if (tfhd.hasDefaultSampleDuration()) {
decodingTimeEntries.add(new TimeToSampleBox.Entry(1, tfhd.getDefaultSampleDuration()));
} else {
decodingTimeEntries.add(new TimeToSampleBox.Entry(1, trex.getDefaultSampleDuration()));
}
}
if (trun.isSampleCompositionTimeOffsetPresent()) {
if (compositionTimeEntries.size() == 0 ||
compositionTimeEntries.get(compositionTimeEntries.size() - 1).getOffset() != entry.getSampleCompositionTimeOffset()) {
compositionTimeEntries.add(new CompositionTimeToSample.Entry(1, l2i(entry.getSampleCompositionTimeOffset())));
} else {
CompositionTimeToSample.Entry e = compositionTimeEntries.get(compositionTimeEntries.size() - 1);
e.setCount(e.getCount() + 1);
}
}
final SampleFlags sampleFlags;
if (trun.isSampleFlagsPresent()) {
sampleFlags = entry.getSampleFlags();
} else {
if (first && trun.isFirstSampleFlagsPresent()) {
sampleFlags = trun.getFirstSampleFlags();
} else {
if (tfhd.hasDefaultSampleFlags()) {
sampleFlags = tfhd.getDefaultSampleFlags();
} else {
sampleFlags = trex.getDefaultSampleFlags();
}
}
}
if (sampleFlags != null && !sampleFlags.isSampleIsDifferenceSample()) {
//iframe
syncSampleList.add(sampleNumber);
}
sampleNumber++;
first = false;
}
}
}
}
}
// Warning: Crappy code
long[] oldSS = syncSamples;
syncSamples = new long[syncSamples.length + syncSampleList.size()];
System.arraycopy(oldSS, 0, syncSamples, 0, oldSS.length);
final Iterator<Long> iterator = syncSampleList.iterator();
int i = oldSS.length;
while (iterator.hasNext()) {
Long syncSampleNumber = iterator.next();
syncSamples[i++] = syncSampleNumber;
}
}
}
}
}
MediaHeaderBox mdhd = trackBox.getMediaBox().getMediaHeaderBox();
TrackHeaderBox tkhd = trackBox.getTrackHeaderBox();
setEnabled(tkhd.isEnabled());
setInMovie(tkhd.isInMovie());
setInPoster(tkhd.isInPoster());
setInPreview(tkhd.isInPreview());
trackMetaData.setTrackId(tkhd.getTrackId());
trackMetaData.setCreationTime(DateHelper.convert(mdhd.getCreationTime()));
trackMetaData.setLanguage(mdhd.getLanguage());
/* System.err.println(mdhd.getModificationTime());
System.err.println(DateHelper.convert(mdhd.getModificationTime()));
System.err.println(DateHelper.convert(DateHelper.convert(mdhd.getModificationTime())));
System.err.println(DateHelper.convert(DateHelper.convert(DateHelper.convert(mdhd.getModificationTime()))));*/
trackMetaData.setModificationTime(DateHelper.convert(mdhd.getModificationTime()));
trackMetaData.setTimescale(mdhd.getTimescale());
trackMetaData.setHeight(tkhd.getHeight());
trackMetaData.setWidth(tkhd.getWidth());
trackMetaData.setLayer(tkhd.getLayer());