[Libav-user] Getting frame duration when decoding

Vahid Kowsari vahid at kowsari.com
Mon Jul 8 01:02:17 CEST 2013


Hi All,

I am decoding some MPEG-2 and H264 streams from file and have a problem
getting the correct duration of a frame. Some files are MPEG2 transport
streams while other are wrapped in mp4 or MOV container.

I use the following section of code
    pFrame is the input AVFrame after decoding

    AVStream *pStream = pCtx->pFormatCtx->streams[pCtx->activeVideoStream];
    double time_base = av_q2d(pStream->time_base);
    double duration = time_base * av_frame_get_pkt_duration(pFrame);
    duration +=  duration * (pFrame->repeat_pict / 2);

My problem is that for alot of streams this works while for others streams
the duration needs to be multipled by 2 for the timing to work
correctly...even though repeat_pic is 0. I checked interlace flag but in
the files that I had the problem, they are both interlaced.

What timebase is the correct timebase to use? The codec timebase or the
stream timebase?

How do I correctly get the duration of a frame regardless of the type of
file and the encoding parameters that were used?

Thanks much for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130707/a36adc9f/attachment.html>


More information about the Libav-user mailing list