[FFmpeg-user] understanding DTS PTS

Andy Sheen sheen.andy at googlemail.com
Wed Mar 4 11:21:33 CET 2009



Alexandre Ferrieux wrote:
> Andy Sheen wrote:
>> Bouke wrote:
>>> ----- Original Message ----- 
>>> From: "Alexandre Ferrieux" <alexandre.ferrieux at orange-ftgroup.com>
>>> To: "FFmpeg user questions and RTFMs" <ffmpeg-user at mplayerhq.hu>
>>> Sent: Wednesday, March 04, 2009 9:25 AM
>>> Subject: Re: [FFmpeg-user] understanding DTS PTS
>>>
>>>
>>>> Marc Mason wrote:
>>>>> John wrote:
>>>>>
>>>>>> I am going through the ffmpeg tutorials and am having trouble making
>>>>>> sense of this statement in tutorial 5.
>>>>>>
>>>>>> <quote>
>>>>>> However, ffmpeg reorders the packets so that the DTS of the packet
>>>>>> being processed by avcodec_decode_video() will always be the same as
>>>>>> the PTS of the frame it returns.
>>>>>> </quote>
>>>>>>
>>>>>> What reordering is it talking about? From the example
>>>>>>
>>>>>> PTS: 1 4 2 3
>>>>>> DTS: 1 2 3 4
>>>>>> Stream: I P B B
>>>>>>
>>>>>> The frames are being read in I P B B. When P is being processed by
>>>>>> avcodec_decode_video() its DTS is 2. P's PTS cannot be 2. What frame
>>>>>> reordering is ffmpeg supposed to be doing? Thanks...
>>>>> Suppose we have 4 frames, and we decide to encode them the following 
>>>>> way: F1=I F2=B F3=B F4=P
>>>>>
>>>>> To encode F2 and F3, we need F4 (B frames).
>>>>>
>>>>> The presentation order (PTS) is F1, F2, F3, F4.
>>>>>
>>>>> But since the decoder needs F4 to decode F2 and F3, we can send them in 
>>>>> a different order : F1, F4, F2, F3 (the decoding order).
>>>>>
>>>>> The decoder will receive frames in the following order.
>>>>>
>>>>> F1 DTS=1 PTS=1
>>>>> F4 DTS=2 PTS=4
>>>>> F2 DTS=3 PTS=2
>>>>> F3 DTS=4 PTS=3
>>>> OK, but what purpose does the DTS serve then ?
>>>>
>>>> -Alex
>>> Tell the decoder when to display the frames (thus, in the correct order)
>>>
>> Err.. DTS == DECODE time stamp, PTS == PRESENTATION time stamp. The DTS 
>> is used by the decoder to decide when to decode the frame, and PTS is 
>> used to decide when to put it up on screen.
> 
> 
> Isn't "when to decode" equal to "as soon as available" ?
> In what respect does DTS differ from simply the order of arrival ?
> 

Because you need to manage the buffers in use. If frames were decoded as 
soon as they arrive, you cannot predict the number of buffers you need 
to will use. The "arrival time" of an image is dependent on the number 
of bits used to encode it and the way it has been muxed. Neither are 
deterministic, so you need a deterministic method to say when to decode it

This management is very important for hardware decoders where there is 
limited memory in the system.

> -Alex
> 

Andy




More information about the ffmpeg-user mailing list