Skip to content

Commit

Permalink
Fix handling of unknown duration in FMP4.
Browse files Browse the repository at this point in the history
Issue: 186
  • Loading branch information
ojw28 committed Dec 5, 2014
1 parent 6f1832f commit c8e5988
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ private static Track parseTrak(ContainerAtom trak) {
/**
* Parses a tkhd atom (defined in 14496-12).
*
* @return A {@link Pair} consisting of the track id and duration.
* @return A {@link Pair} consisting of the track id and duration (in the timescale indicated in
* the movie header box). The duration is set to -1 if the duration is unspecified.
*/
private static Pair<Integer, Long> parseTkhd(ParsableByteArray tkhd) {
tkhd.setPosition(ATOM_HEADER_SIZE);
Expand All @@ -473,7 +474,23 @@ private static Pair<Integer, Long> parseTkhd(ParsableByteArray tkhd) {

int trackId = tkhd.readInt();
tkhd.skip(4);
long duration = version == 0 ? tkhd.readUnsignedInt() : tkhd.readUnsignedLongToLong();

boolean durationUnknown = true;
int durationPosition = tkhd.getPosition();
int durationByteCount = version == 0 ? 4 : 8;
for (int i = 0; i < durationByteCount; i++) {
if (tkhd.data[durationPosition + i] != -1) {
durationUnknown = false;
break;
}
}
long duration;
if (durationUnknown) {
tkhd.skip(durationByteCount);
duration = -1;
} else {
duration = version == 0 ? tkhd.readUnsignedInt() : tkhd.readUnsignedLongToLong();
}

return Pair.create(trackId, duration);
}
Expand Down

0 comments on commit c8e5988

Please sign in to comment.