[FFmpeg-user] Getting wrong timestamps with my decoding code, but showinfo filter shows correct timestamps

Andreas Sommer andreas.sommer87 at googlemail.com
Thu Jan 24 00:58:03 CET 2013

I think I found the problem: The "best effort timestamp" must be
multiplied with the video stream's time_base, not the AVFormatContext's
time_base, and obviously through the mentioned commit, the video time
base is different than the other one.



*From:* Andreas Sommer <andreas.sommer87 at googlemail.com>
*Sent:* 23.01.2013 18:12
*To:* ffmpeg-user at ffmpeg.org
*Subject:* Getting wrong timestamps with my decoding code, but showinfo
filter shows correct timestamps

> The following problem happens only with MOV files (.3g2 extension)
> that were encoded after the following change was introduced in
> movenc.c (commit b02493e476):
>             while(track->timescale < 10000)
>                 track->timescale *= 2;
> With my own decoding source code that uses libavformat:
>     bytesDecoded = avcodec_decode_video2(m_videoCodecContext,
> m_currentFrame, &frameFinished, &packet);
>     [...]
>     if (frameFinished)
>     {
>         int64_t  best_effort_timestamp=
> av_frame_get_best_effort_timestamp(m_currentFrame);
>         pts =best_effort_timestamp * (float)
> av_q2d(m_videoCodecContext->time_base);
>         printf("pts %f, %f, %f (fps=%f)\n", pts, (float) packet.dts,
> av_q2d(m_videoCodecContext->time_base), (float) packet.dts / pts);
>         [...]
> ..., I always get these values for the first frame:
> pts 25.600000, 512.000000, 0.050000 (fps=20.000000)
> so the first frame is at 25.6 seconds which is wrong. However if I use
> ffmpeg.exe from the same build, and test that video file with
> "ffmpeg.exe -i thatfile.3g2 -vf showinfo -an -y dummy.3g2 >log.txt
> 2>&1", I'm getting this info:
> [Parsed_showinfo_0 @ 00CA0B20] n:0 pts:476 pts_time:0.0464844
> rawpts:476 timebase:0.000098 pos:67 fmt:yuv420p sar:12/11 s:176x144
> i:P iskey:1 type:I checksum:EB50BAC2 plane_checksum:[D057F94B 29FD60B4
> 29FD60B4]
> Here the first frame is at roughly 0.05 seconds which is correct
> (don't know why pts=476 instead of 512, possibly audio sync or
> whatever, probably doesn't matter here). And look at the timebase here
> which is 0.000098 as compared to 0.05 with my source code. What am I
> doing wrong? Do I have to change the calculations for the pts variable
> to get the timestamp in seconds?
> Thanks a bunch
> Andreas

More information about the ffmpeg-user mailing list