- if (flags & 0x001) data_offset = avio_rb32(pb);
- if (flags & 0x004) first_sample_flags = avio_rb32(pb);
- if (flags & 0x800) {
- MOVStts *ctts_data;
- if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data))
- return -1;
- ctts_data = av_realloc(sc->ctts_data,
- (entries+sc->ctts_count)*sizeof(*sc->ctts_data));
+
+ /* Always assume the presence of composition time offsets.
+ * Without this assumption, for instance, we cannot deal with a track in fragmented movies that meet the following.
+ * 1) in the initial movie, there are no samples.
+ * 2) in the first movie fragment, there is only one sample without composition time offset.
+ * 3) in the subsequent movie fragments, there are samples with composition time offset. */
+ if (!sc->ctts_count && sc->sample_count)
+ {
+ /* Complement ctts table if moov atom doesn't have ctts atom. */
+ ctts_data = av_malloc(sizeof(*sc->ctts_data));