diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index e73209cdb3..59b0058074 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1993,7 +1993,9 @@ static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size, co /* check packet sync byte */ if ((*data)[0] != 0x47) { /* find a new packet start */ - avio_seek(pb, -raw_packet_size, SEEK_CUR); + uint64_t pos = avio_tell(pb); + avio_seek(pb, -FFMIN(raw_packet_size, pos), SEEK_CUR); + if (mpegts_resync(s) < 0) return AVERROR(EAGAIN); else