[FFmpeg-devel] [PATCH] y4m seek and duration

Michael Niedermayer michaelni
Tue Jun 8 04:14:45 CEST 2010


On Sun, Jun 06, 2010 at 05:11:48PM -0700, Baptiste Coudurier wrote:
> Hi,
>
> $subject.
>
>
> -- 
> Baptiste COUDURIER
> Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
> FFmpeg maintainer                                  http://www.ffmpeg.org

>  yuv4mpeg.c |   35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 9766b335f6795309d6f9abf48b01e73dca85a85d  y4m_seek_and_duration.patch
> Index: libavformat/yuv4mpeg.c
> ===================================================================
> --- libavformat/yuv4mpeg.c	(revision 23501)
> +++ libavformat/yuv4mpeg.c	(working copy)
> @@ -327,6 +327,7 @@
>          aspectd = 1;
>      }
>  
> +    s->data_offset = url_ftell(s->pb);
>      st = av_new_stream(s, 0);
>      if(!st)
>          return AVERROR(ENOMEM);
> @@ -340,6 +341,20 @@
>      st->sample_aspect_ratio= (AVRational){aspectn, aspectd};
>      st->codec->chroma_sample_location = chroma_sample_location;
>  
> +    if (!url_is_streamed(s->pb)) {
> +        int frame_size = avpicture_get_size(st->codec->pix_fmt,
> +                                            st->codec->width, st->codec->height);
> +        if (frame_size < 0) {
> +            av_log(s, AV_LOG_ERROR, "could not get frame size\n");
> +            return -1;
> +        }
> +        frame_size += sizeof(Y4M_FRAME_MAGIC);
> +        if ((url_fsize(s->pb) - s->data_offset) % frame_size)
> +            av_log(s, AV_LOG_WARNING, "partial file\n");
> +        st->nb_frames = (url_fsize(s->pb) - s->data_offset) / frame_size;
> +        st->duration = st->nb_frames;
> +    }
> +
>      return 0;
>  }
>  
> @@ -389,6 +404,25 @@
>          return 0;
>  }
>  
> +static int yuv4_read_seek(AVFormatContext *s, int stream_index,
> +                          int64_t ts, int flags)
> +{
> +    AVStream *st = s->streams[0];
> +    unsigned frame_size;
> +
> +    if (url_is_streamed(s->pb))
> +        return -1;
> +
> +    frame_size = avpicture_get_size(st->codec->pix_fmt,
> +                                    st->codec->width, st->codec->height);
> +    frame_size += sizeof(Y4M_FRAME_MAGIC);
> +    if (s->data_offset + (ts+1)*frame_size > url_fsize(s->pb))
> +        return -1;
> +
> +    url_fseek(s->pb, s->data_offset + ts*frame_size, SEEK_SET);
> +    return 0;
> +}

the patch looks ok but shouldnt we implement the new seeking api in new
demuxers?
it could help find issues with the new api

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Incandescent light bulbs waste a lot of energy as heat so the EU forbids them.
Their replacement, compact fluorescent lamps, much more expensive, dont fit in
many old lamps, flicker, contain toxic mercury, produce a fraction of the light
that is claimed and in a unnatural spectrum rendering colors different than
in natural light. Ah and we now need to turn the heaters up more in winter to
compensate the lower wasted heat. Who wins? Not the environment, thats for sure
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100608/3e1bf2fd/attachment.pgp>



More information about the ffmpeg-devel mailing list