[FFmpeg-devel] pts handling (reordered_opaque) and frame duration calculation

Reinhard Nissl rnissl
Wed Apr 1 19:46:06 CEST 2009


a few weeks ago I added code to xine-lib's FFmpeg interface to
make use of reordered_opaque. It worked like a charm for the
H.264 samples I used for testing.

Now I got reports that A/V sync seems to be broken for other
codecs (e. g. XviD). After some investigation I found out that I
always get back 0 from frame->reordered_opaque, no matter what I
set avctx->reordered_opaque to before calling avcodec_decode_video().

Is reordered_opaque only supported by certain codecs?

In that case, how can I check whether a certain codec supports it?

Regarding frame duration calculation: some months ago I added
code to xine-lib's FFmpeg interface which takes into account
avctx->time_base. I used that code to calculate frame duration in
pts units:

	* avctx->time_base.num
	/ avctx->time_base.den

But this seems to be no longer correct for recent FFmpeg and
H.264. After looking through the changes to h264.c, I see that
time_base.den has been doubled and ticks_per_frame has been set
to 2 too. So I changed the calculation to:

	* avctx->ticks_per_frame
	* avctx->time_base.num
	/ avctx->time_base.den

This works for my samples, but I doubt that this is correct in
general, as I came across the following comment while looking
through the ML for the first mentioned issue:

	frame_duration = (1 + repeat_pict) * time_base

Does this mean that my calculation should look like that to be
correct in general?

	* (1 + frame->repeat_pict)
	* avctx->ticks_per_frame
	* avctx->time_base.num
	/ avctx->time_base.den

Thanks in advance.

Dipl.-Inform. (FH) Reinhard Nissl
mailto:rnissl at gmx.de

More information about the ffmpeg-devel mailing list