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

Baptiste Coudurier baptiste.coudurier
Tue Jun 8 04:22:42 CEST 2010


Hi Michael,

On 06/07/2010 07:14 PM, Michael Niedermayer wrote:
> 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

I agree, and I started to, but ffmpeg.c does not use it yet, and for y4m,
the new API is the same because every frame is a keyframe, so a 
timestamp request will always succeed given it's within the file duration.

-- 
Baptiste COUDURIER
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org



More information about the ffmpeg-devel mailing list