@@ -2159,6 +2159,8 @@ static int mov_read_chap(MOVContext *c, AVIOContext *pb, MOVAtom atom)
static int mov_read_trex(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
MOVTrackExt *trex;
+ AVStream *st = NULL;
+ int i;
if ((uint64_t)c->trex_count+1 >= UINT_MAX / sizeof(*c->trex_data))
return AVERROR_INVALIDDATA;
@@ -2174,6 +2176,23 @@ static int mov_read_trex(MOVContext *c, AVIOContext *pb, MOVAtom atom)
trex->duration = avio_rb32(pb);
trex->size = avio_rb32(pb);
trex->flags = avio_rb32(pb);
+ for (i = 0; i < c->fc->nb_streams; i++) {
+ if (c->fc->streams[i]->id == trex->track_id) {
+ st = c->fc->streams[i];
+ break;
+ }
+ }
+ if (st) {
+ /* If the stts atom was empty, we didn't set st->duration based
+ * on that atom, but we might have set it based on what's written
+ * in mdhd. For some files, the mdhd duration is 0 if the moov
+ * doesn't contain any samples, but for others, this is the
+ * total duration of the file, including fragments. So make
+ * sure duration is 0 at this point, if the moov didn't contain
+ * any samples. */
+ if (!st->nb_frames)
+ st->duration = 0;
+ }
return 0;
}