[FFmpeg-devel] [PATCH] Keep track of stream duration and nb_frames when muxing

Baptiste Coudurier baptiste.coudurier
Tue Jan 19 20:18:53 CET 2010


On 01/19/2010 07:51 AM, Michael Niedermayer wrote:
> On Tue, Jan 19, 2010 at 01:41:57AM -0500, David Conrad wrote:
>> On Jan 19, 2010, at 12:25 AM, Baptiste Coudurier wrote:
>>
>>> Hi,
>>>
>>> On 1/18/10 9:18 PM, David Conrad wrote:
>>>> Hi,
>>>>
>>>> [...]
>>>>
>>>> @@ -2785,6 +2791,11 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){
>>>>       if(compute_pkt_fields2(s, st, pkt)<   0&&   !(s->oformat->flags&   AVFMT_NOTIMESTAMPS))
>>>>           return -1;
>>>>
>>>> +    if (!st->nb_frames)
>>>> +        st->start_time = pkt->pts;
>>>> +    st->duration = pkt->pts + pkt->duration;
>>>
>>> st->duration = FFMAX(st->duration, pkt->pts + pkt->duration);
>>>
>>> and same above, is more correct.
>>
>> Whoops, fixed
>>
>
>> commit 06137c90d1cbc7b0aba086b954d5781f4ef603bd
>> Author: David Conrad<lessen42 at gmail.com>
>> Date:   Tue Jan 19 00:08:14 2010 -0500
>>
>>      Update stream start_time, duration, and nb_frames in
>>      av_(interleaved)_write_frame()
>>
>> diff --git a/libavformat/utils.c b/libavformat/utils.c
>> index 64c5ec4..fea28a0 100644
>> --- a/libavformat/utils.c
>> +++ b/libavformat/utils.c
>> @@ -2668,8 +2668,14 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){
>>
>>   int av_write_frame(AVFormatContext *s, AVPacket *pkt)
>>   {
>> +    AVStream *st = s->streams[pkt->stream_index];
>>       int ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);
>>
>> +    if (!st->nb_frames)
>> +        st->start_time = pkt->pts;
>> +    st->duration = FFMAX(st->duration, pkt->pts + pkt->duration);
>> +    st->nb_frames++;
>> +
>
> PTS reordering will break this, youd need something like this
>
> if(pkt->pts != AV_NOPTS_VALUE){
>      int64_t end= st->start_time + st->duration;
>      st->start_time = FFMIN(st->start_time, pkt->pts);
>      st->duration= FFMAX(end, pkt->pts) - st->start_time
> }
>

That is not correct for st->duration. It's FFMAX pkt->pts + 
pkt->duration, but st->start_time indeed is correct.

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



More information about the ffmpeg-devel mailing list