diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c index aafefbbe65..553ddb0b03 100644 --- a/libavformat/oggparseopus.c +++ b/libavformat/oggparseopus.c @@ -130,16 +130,13 @@ static int opus_packet(AVFormatContext *avf, int idx) duration += d; last_pkt = next_pkt = next_pkt + os->psize; for (; seg < os->nsegs; seg++) { - if (os->segments[seg] < 255) { - int d = opus_duration(last_pkt, os->segments[seg]); - if (d < 0) { - duration = os->granule; - break; - } - duration += d; - last_pkt = next_pkt + os->segments[seg]; - } next_pkt += os->segments[seg]; + if (os->segments[seg] < 255 && next_pkt != last_pkt) { + int d = opus_duration(last_pkt, next_pkt - last_pkt); + if (d > 0) + duration += d; + last_pkt = next_pkt; + } } os->lastpts = os->lastdts = os->granule - duration;