[Ffmpeg-devel] Timestamps Again

Michael Niedermayer michaelni
Sat Nov 5 10:54:40 CET 2005


Hi

On Sat, Nov 05, 2005 at 12:31:49PM +0800, Colin Ward wrote:
> 
>   *sigh*
> 
>   This pts business is really getting me down.  I have been fiddling 
> with this code on and off for weeks now and can make no progress. 
> Different file formats seems to act differently and all of the example 
> sources (ffmpeg.c, ffplay.c) do different things and are all very 
> complex.  So far I have found that the following piece of pseudocode 
> works the best:
> 
> 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);
> }
> 
> This results in pts being set to the presentation time in milliseconds. 
>  This works fine for avi, mp4, wmv and mpeg files that I tested but 
> fails for mov files (frame->pts is always zero and the calculated pts 
> always ends up being incremented by only one millisecond).
> 
> Can someone *please* help me with this.  Obtaining the presentation time 
> seems to be terribly difficult with ffmpeg and lots of people suffer 
> from this problem.  Once I have sorted out these problems once and for 
> all I would like to make some example code to be posted in an FAQ and, 
> even better, an avformat_get_pts() function that will do all of the hard 
> work that everybody has to currently re-implement every time they write 
> a video player that uses ffmpeg.

you should use AVPacket.pts/dts not AVFrame.pts

[...]
-- 
Michael





More information about the ffmpeg-devel mailing list