[FFmpeg-devel] [PATCH] avformat/yuv4mpegdec: use generic code for seeking

wm4 nfxjfg at googlemail.com
Tue May 1 16:05:28 EEST 2018


On Tue,  1 May 2018 11:47:04 +0200
Paul B Mahol <onemda at gmail.com> wrote:

> Signed-off-by: Paul B Mahol <onemda at 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.


More information about the ffmpeg-devel mailing list