[Libav-user] How to get precise frame timestamp

YIRAN LI mrfun.china at gmail.com
Wed Oct 30 07:01:26 CET 2013


Thanks Alex,

I just had a quick check, called
av_frame_get_best_effort_timestamp(pFrame); and seems
pFrame->best_effort_timestamp was filled with desired values (1st frame
having 0, 2nd having 1 and so on).

I'll read through the link you gave me later on.

Great Thanks!


2013/10/30 Alex Cohn <alexcohn at netvision.net.il>

> On Wed, Oct 30, 2013 at 5:51 AM, YIRAN LI <mrfun.china at gmail.com> wrote:
> >
> > Hi friends,
> >
> > Here I have a question about AVFrame pts needs your help.
> >
> > My application uses av_read_frame to get packets and then calls
>  avcodec_decode_video2 to get video frames. But recently I found one
> specific video file generates strange pts/dts.
> >
> > Below is a part of the log:
> >
> > 00:00:17.301  MAIN  timestamp_debug:  pkt.pts = -9223372036854775808,
> dts = 0
> > 00:00:17.301  MAIN  timestamp_debug:            frame.pkt_pts =
> -9223372036854775808, frame.pkt_dts = -9223372036854775808, frame.pts =
> -9223372036854775808
> > 00:00:17.301  1108  FFMPEG: looks like this file was encoded with
> (divx4/(old)xvid/opendivx) -> forcing low_delay flag
> >
> > 00:00:17.301  MAIN  timestamp_debug:  pkt.pts = -9223372036854775808,
> dts = 1
> > 00:00:17.301  MAIN  timestamp_debug:            frame.pkt_pts =
> -9223372036854775808, frame.pkt_dts = -9223372036854775808, frame.pts =
> -9223372036854775808
> > 00:00:17.301  MAIN  timestamp_debug:  pkt.pts = -9223372036854775808,
> dts = 2
> > 00:00:17.301  MAIN  timestamp_debug:            frame.pkt_pts =
> -9223372036854775808, frame.pkt_dts = -9223372036854775808, frame.pts =
> -9223372036854775808
> > 00:00:17.301  MAIN  timestamp_debug:  pkt.pts = -9223372036854775808,
> dts = 3
> > 00:00:17.301  MAIN  timestamp_debug:            frame.pkt_pts =
> -9223372036854775808, frame.pkt_dts = -9223372036854775808, frame.pts =
> -9223372036854775808
> > 00:00:17.301  MAIN  timestamp_debug:  pkt.pts = -9223372036854775808,
> dts = 4
> > 00:00:17.301  MAIN  timestamp_debug:  [a full frame : frame.pkt_pts =
> -9223372036854775808, frame.pkt_dts = 0], frame.pts = 0
> > 00:00:18.393  LVid236  timestamp_debug:  pkt.pts = -9223372036854775808,
> dts = 5
> > 00:00:18.408  LVid236  timestamp_debug:  [a full frame : frame.pkt_pts =
> -9223372036854775808, frame.pkt_dts = 1], frame.pts = 0
> > 00:00:18.439  LVid236  timestamp_debug:  pkt.pts = -9223372036854775808,
> dts = 6
> > 00:00:18.439  LVid236  timestamp_debug:  [a full frame : frame.pkt_pts =
> -9223372036854775808, frame.pkt_dts = 2], frame.pts = 0
> > 00:00:18.439  LSou259  FFMPEG: first_dts 0 not matching first dts 113424
> in the queue
> > 00:00:18.486  LVid236  timestamp_debug:  pkt.pts = -9223372036854775808,
> dts = 7
> > 00:00:18.486  LVid236  timestamp_debug:  [a full frame : frame.pkt_pts =
> -9223372036854775808, frame.pkt_dts = 3], frame.pts = 0
> > 00:00:18.517  LVid236  timestamp_debug:  pkt.pts = -9223372036854775808,
> dts = 8
> > 00:00:18.517  LVid236  timestamp_debug:  [a full frame : frame.pkt_pts =
> -9223372036854775808, frame.pkt_dts = 4], frame.pts = 0
> > 00:00:18.549  LSou259  FFMPEG: first_dts 0 not matching first dts 114675
> in the queue
> >
> > We can see that, it was until 4th packet is sent to decode function that
> we got the first full frame. and all frames had pts = 0
> >
> > So here I want to know, frame.pts, frame.pkt_dts, packet,dts. which is
> best to represent the time stamp of a video frame (I mean pts, but in this
> case, no pts is valid).
> >
> > For example, in this case, for the 1st frame, should I use frame.pkt_dts
> (that's 0), or pkt.pts (the last packet that generates this frame, in this
> case 4) as the time  position
> > of the frame?
> >
> > The file I used to test is here
> https://dl.dropboxusercontent.com/u/89678527/av_divx_24_yuv420p_mp3_44100_2_1.avi
> >
> > Thanks
>
>
> That's what best_effort_timestamp is for. See
> http://dranger.com/ffmpeg/tutorial05.html about different values of
> pts/dts.
>
> BR,
> Alex Cohn
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20131030/4bf490d7/attachment.html>


More information about the Libav-user mailing list