diff --git a/libavformat/utils.c b/libavformat/utils.c index d59a02d951..a4218db8ed 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1863,10 +1863,10 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, filesize = avio_size(s->pb); pos_max = filesize - 1; do{ - pos_max -= step; + pos_max = FFMAX(0, pos_max - step); ts_max = ff_read_timestamp(s, stream_index, &pos_max, pos_max + step, read_timestamp); step += step; - }while(ts_max == AV_NOPTS_VALUE && pos_max >= step); + }while(ts_max == AV_NOPTS_VALUE && pos_max > 0); if (ts_max == AV_NOPTS_VALUE) return -1; diff --git a/tests/ref/seek/lavf-ogg b/tests/ref/seek/lavf-ogg index 2898d10a7d..583526ef59 100644 --- a/tests/ref/seek/lavf-ogg +++ b/tests/ref/seek/lavf-ogg @@ -1,35 +1,53 @@ ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 ret: 0 st:-1 flags:0 ts:-1.000000 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 -ret:-1 st:-1 flags:1 ts: 1.894167 -ret:-1 st: 0 flags:0 ts: 0.788345 +ret: 0 st:-1 flags:1 ts: 1.894167 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st: 0 flags:0 ts: 0.788345 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 ret: 0 st: 0 flags:1 ts:-0.317506 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 -ret:-1 st:-1 flags:0 ts: 2.576668 -ret:-1 st:-1 flags:1 ts: 1.470835 -ret:-1 st: 0 flags:0 ts: 0.365011 +ret: 0 st:-1 flags:0 ts: 2.576668 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st:-1 flags:1 ts: 1.470835 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st: 0 flags:0 ts: 0.365011 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 ret: 0 st: 0 flags:1 ts:-0.740839 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 -ret:-1 st:-1 flags:0 ts: 2.153336 -ret:-1 st:-1 flags:1 ts: 1.047503 +ret: 0 st:-1 flags:0 ts: 2.153336 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st:-1 flags:1 ts: 1.047503 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 ret: 0 st: 0 flags:0 ts:-0.058322 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 -ret:-1 st: 0 flags:1 ts: 2.835828 -ret:-1 st:-1 flags:0 ts: 1.730004 -ret:-1 st:-1 flags:1 ts: 0.624171 +ret: 0 st: 0 flags:1 ts: 2.835828 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st:-1 flags:0 ts: 1.730004 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st:-1 flags:1 ts: 0.624171 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 ret: 0 st: 0 flags:0 ts:-0.481655 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 -ret:-1 st: 0 flags:1 ts: 2.412494 -ret:-1 st:-1 flags:0 ts: 1.306672 -ret:-1 st:-1 flags:1 ts: 0.200839 +ret: 0 st: 0 flags:1 ts: 2.412494 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st:-1 flags:0 ts: 1.306672 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st:-1 flags:1 ts: 0.200839 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 ret: 0 st: 0 flags:0 ts:-0.904989 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 -ret:-1 st: 0 flags:1 ts: 1.989184 -ret:-1 st:-1 flags:0 ts: 0.883340 +ret: 0 st: 0 flags:1 ts: 1.989184 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st:-1 flags:0 ts: 0.883340 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 ret: 0 st:-1 flags:1 ts:-0.222493 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 -ret:-1 st: 0 flags:0 ts: 2.671678 -ret:-1 st: 0 flags:1 ts: 1.565850 -ret:-1 st:-1 flags:0 ts: 0.460008 +ret: 0 st: 0 flags:0 ts: 2.671678 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st: 0 flags:1 ts: 1.565850 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 +ret: 0 st:-1 flags:0 ts: 0.460008 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 ret: 0 st:-1 flags:1 ts:-0.645825 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364