[Ffmpeg-devel] Timestamps on Decoding

Paul Curtis pfc
Sun Oct 23 19:47:38 CEST 2005

Rich Felker wrote:

> Using DTS as PTS is blatently incorrect whenever there are B frames. 
> It will actually put the timestamps OUT OF ORDER!

In using the mpeg container, with MPEG2 video and MPEG2 audio, I have
not found an out of order frame yet. The encoder (MainActor) defaults to
IBBPBBPBBPBBPBBPBB (18 frames between I, every third frame P) ... so my
code must be doing something more than you assume.

> It will make invalid files.

> If your files have no B frames, it's fine. If they do, all hell will 
> break loose and your files might randomly work with some broken 
> players, but the files you output will actually be highly invalid and
>  will not play in compliant players.

I'm encoding using the Helix SDK. So far, I have encoded seven files
with lengths from 25 seconds to 3 hours. Both mplayer (with w32codecs)
and the Real 'realplay' show no errors, and played every one.

> Unfortunately, the most common format (AVI) only has DTS and not PTS,
>  and there's no general way to convert DTS to PTS without processing 
> the codec-specific data in the frames themselves. The process of 
> getting PTS values (the way the decoder does it) involves reordering 
> the frames to display (presentation) order, which is fine if you're 
> decoding them and just intending to display them. But if you want to 
> keep them in decode order for remuxing into another container, it 
> requires lots of awkward buffering, and quite frankly I don't know a 
> proper way to do it... :(

I am lucky in that I have control over the input format (always 'mpeg') 
and the streams. It allows me to make assumptions that oridnarily would 
cause invalid files to be created. I will test with other containers and 
streams to verify which ones work properly.


More information about the ffmpeg-devel mailing list