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

Michael Niedermayer michaelni
Tue Jan 19 23:27:17 CET 2010


On Tue, Jan 19, 2010 at 11:18:53AM -0800, Baptiste Coudurier wrote:
> 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, 

indeed, more precissely:

st->duration= FFMAX(end, pkt->pts + pkt->duration) - st->start_time


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

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
-------------- 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/20100119/037174f6/attachment.pgp>



More information about the ffmpeg-devel mailing list