diff --git a/libavformat/mov.c b/libavformat/mov.c index 29828ea7e6..14550e6456 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3062,6 +3062,21 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->nb_frames= total_sample_count; if (duration) st->duration= FFMIN(st->duration, duration); + + // All samples have zero duration. They have higher chance be chose by + // mov_find_next_sample, which leads to seek again and again. + // + // It's AVERROR_INVALIDDATA actually, but such files exist in the wild. + // So only mark data stream as discarded for safety. + if (!duration && sc->stts_count && + st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { + av_log(c->fc, AV_LOG_WARNING, + "All samples in data stream index:id [%d:%d] have zero " + "duration, stream set to be discarded by default. Override " + "using AVStream->discard or -discard for ffmpeg command.\n", + st->index, st->id); + st->discard = AVDISCARD_ALL; + } sc->track_end = duration; return 0; }