avformat/yuv4mpegdec: fix seeking backwards

Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
Paul B Mahol 2018-04-25 18:30:46 +02:00
parent a12899ad9b
commit b2570afde3
2 changed files with 34 additions and 22 deletions

View File

@ -314,7 +314,16 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
static int yuv4_read_seek(AVFormatContext *s, int stream_index,
int64_t pts, int flags)
{
if (avio_seek(s->pb, pts * s->packet_size + s->internal->data_offset, SEEK_SET) < 0)
AVStream *st = s->streams[0];
int64_t pos;
pos = av_rescale_rnd(pts * s->packet_size,
st->time_base.num,
st->time_base.den * s->packet_size,
(flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
pos *= s->packet_size;
if (avio_seek(s->pb, pos + s->internal->data_offset, SEEK_SET) < 0)
return -1;
return 0;
}

View File

@ -1,45 +1,48 @@
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064
ret:-1 st:-1 flags:0 ts:-1.000000
ret: 0 st:-1 flags:1 ts: 1.894167
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
ret: 0 st: 0 flags:0 ts: 0.800000
ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:3041464 size:152064
ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
ret:-1 st: 0 flags:1 ts:-0.320000
ret: 0 st:-1 flags:0 ts: 2.576668
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.120000 pts: 0.120000 pos: 456274 size:152064
ret: 0 st:-1 flags:1 ts: 1.470835
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
ret: 0 st: 0 flags:0 ts: 0.360000
ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1368694 size:152064
ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
ret:-1 st: 0 flags:1 ts:-0.760000
ret: 0 st:-1 flags:0 ts: 2.153336
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.120000 pts: 0.120000 pos: 456274 size:152064
ret: 0 st:-1 flags:1 ts: 1.047503
ret:-EOF
ret:-1 st: 0 flags:0 ts:-0.040000
ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
ret: 0 st: 0 flags:0 ts:-0.040000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064
ret: 0 st: 0 flags:1 ts: 2.840000
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
ret: 0 st:-1 flags:0 ts: 1.730004
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
ret: 0 st:-1 flags:1 ts: 0.624171
ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:2433184 size:152064
ret:-1 st: 0 flags:0 ts:-0.480000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064
ret: 0 st: 0 flags:0 ts:-0.480000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064
ret: 0 st: 0 flags:1 ts: 2.400000
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
ret: 0 st:-1 flags:0 ts: 1.306672
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
ret: 0 st:-1 flags:1 ts: 0.200839
ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: 760414 size:152064
ret:-1 st: 0 flags:0 ts:-0.920000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064
ret: 0 st: 0 flags:0 ts:-0.920000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064
ret: 0 st: 0 flags:1 ts: 2.000000
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.080000 pts: 0.080000 pos: 304204 size:152064
ret: 0 st:-1 flags:0 ts: 0.883340
ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3345604 size:152064
ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
ret:-1 st:-1 flags:1 ts:-0.222493
ret: 0 st: 0 flags:0 ts: 2.680000
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.120000 pts: 0.120000 pos: 456274 size:152064
ret: 0 st: 0 flags:1 ts: 1.560000
ret:-EOF
ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
ret: 0 st:-1 flags:0 ts: 0.460008
ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1824904 size:152064
ret: 0 st: 0 flags:1 dts: 0.040000 pts: 0.040000 pos: 152134 size:152064
ret:-1 st:-1 flags:1 ts:-0.645825