[Ffmpeg-devel] Re: Timestamps Again

Michael Niedermayer michaelni
Sun Nov 6 14:48:38 CET 2005


Hi

On Sun, Nov 06, 2005 at 10:54:56AM +0800, Colin Ward wrote:
> 
> On 05/11/05, you wrote:
> > 
> 
>   [Snip]
> 
> >> static double pts;
> >> 
> >> avcodec_decode_video(context, &frame, ...)
> >> 
> >> if ((frame->pts == 0) || (frame->pts == AV_NOPTS_VALUE))
> >> {
> >>   pts += (av_q2d(context->time_base) * 1000);
> >> }
> >> else
> >> {
> >>   pts = ((frame->pts * av_q2d(context->time_base)) * 1000);
> >> }
> 
>   [Snip]
> 
> > you should use AVPacket.pts/dts not AVFrame.pts
> 
>   Ok, I just tried that but it results in crazy pts times being calculated
> (ie. starting with a 7 figure millisecond count).  This is with an MPEG
> file that I know has a start time of zero and for which the method above
> works fine.

well, the timestamps you get are whats stored in the file with missing
timesamps filled in, search for timestamp discontinuities and mpeg if
you want to know the details about this mess


> 
>   Also, the calculations above are using
> AVFormatContext.streams[video_stream]->codec->time_base - is this correct? 
> Or should I be using AVFormatContext.streams[video_stream]->time_base? 
> These two time_base variables are *different* when playing the MPEG file
> mentioned above.

AVPacket timestamps should use AVStream.time_base, AVFrame timestamps should
use AVCodecContext.time_base


> 
>   Also, what is the actual difference between AVPacket.pts and AVFrame.pts?

AVPacket.pts is the timestamp from the container format, AVFrame.pts is the
timestamp from the codec, later is often wrong or missing


>  If you are decoding a video that has B/P frames and the frames are out of
> order, wouldn't you have to get the pts from AVFrame?  Because after
> calling avcodec_decode_video() the AVFrame returned would be in
> presentation order, whereas the AVPacket wouldn't be, because the file
> would contain IIP whereas the presentation order is IPI.

you either have to use AVPacket.dts or reorder AVPacket.pts through 
AVFrame.opaque


> 
>   And what is dts?

search the archives, IIRC this has been explained many times

[...]
-- 
Michael





More information about the ffmpeg-devel mailing list