On Tue, 1 May 2018 15:17:53 +0200
Paul B Mahol <one...@gmail.com> wrote:

> On 5/1/18, wm4 <nfx...@googlemail.com> wrote:
> > On Tue,  1 May 2018 11:47:04 +0200
> > Paul B Mahol <one...@gmail.com> wrote:
> >  
> >> Signed-off-by: Paul B Mahol <one...@gmail.com>
> >> ---
> >>  libavformat/yuv4mpegdec.c    | 23 ++++----------------
> >>  tests/ref/seek/lavf-yuv4mpeg | 52
> >> ++++++++++++++++++++------------------------
> >>  2 files changed, 28 insertions(+), 47 deletions(-)
> >>
> >> diff --git a/libavformat/yuv4mpegdec.c b/libavformat/yuv4mpegdec.c
> >> index 8662a42a4c..cf6da2a2ef 100644
> >> --- a/libavformat/yuv4mpegdec.c
> >> +++ b/libavformat/yuv4mpegdec.c
> >> @@ -306,28 +306,13 @@ static int yuv4_read_packet(AVFormatContext *s,
> >> AVPacket *pkt)
> >>          return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO);
> >>      }
> >>      pkt->stream_index = 0;
> >> -    pkt->pts = (off - s->internal->data_offset) / s->packet_size;
> >> +    pkt->pos = off;
> >> +    pkt->dts = pkt->pts = (off - s->internal->data_offset) /
> >> s->packet_size;
> >> +    pkt->flags |= AV_PKT_FLAG_KEY;
> >>      pkt->duration = 1;
> >>      return 0;
> >>  }
> >>
> >> -static int yuv4_read_seek(AVFormatContext *s, int stream_index,
> >> -                          int64_t pts, int flags)
> >> -{
> >> -    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;
> >> -}
> >> -
> >>  static int yuv4_probe(AVProbeData *pd)
> >>  {
> >>      /* check file header */
> >> @@ -343,6 +328,6 @@ AVInputFormat ff_yuv4mpegpipe_demuxer = {
> >>      .read_probe     = yuv4_probe,
> >>      .read_header    = yuv4_read_header,
> >>      .read_packet    = yuv4_read_packet,
> >> -    .read_seek      = yuv4_read_seek,
> >>      .extensions     = "y4m",
> >> +    .flags          = AVFMT_GENERIC_INDEX,
> >>  };
> >> diff --git a/tests/ref/seek/lavf-yuv4mpeg b/tests/ref/seek/lavf-yuv4mpeg  
> >
> > Seems like a bad idea. This will make seeking read and skip all data
> > when seeking to the middle of the stream, instead of just seeking there.  
> 
> How do you explain that this patch makes backsteeping with mpv magnitude 
> faster?
> 
> Without it, more far you are from start of file backstepping is linearly 
> slower.

I don't know how this interacts with mpv, but obviously it's unexpected
that O(1) demuxer level seeking is slower than O(n) seeking. You
probably have some sort of overflow or something in the seek routine
or elsewhere. Maybe it's an lavf internal fallback to something worse
if the seek fails (e.g. when trying to seek before the start of the
file). Obviously you should analyze this.

(mpv seeks before the start of the file because it can't reliable know
a pts is before the start.)
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to