[FFmpeg-devel] Samples frames and PTS inter/extrapolation

Nicolas George nicolas.george at normalesup.org
Sun Jul 1 11:23:08 CEST 2012


Hi.

I am considering the problem of computing the timestamps of frames when
samples have to be re-grouped in a different pattern. For example, if we
have frames with 384 samples as input and want 960 samples as output, we may
be in this situation:

384 + 384 + 384 + 384 = 320 + 64 + 384 + 384 + 128 + 256
in1   in2   in3   in4   prv   --------out---------   nxt

The code I wrote for lavfi two days ago does:

    out.pts = in1.pts + rescale(320, 1/sample_rate, time_base)

The corresponding code from libav does:

    out.pts = in4.pts - rescale(64 + 384 + 384, 1/sample_rate, time_base)

If the PTS do not match the number of samples exactly, it will give a
different result.

Since out.pts is the timestamp of the beginning of out, I believe using the
timestamp of the first input frame, the one that gave the beginning, is more
logical.

But if there is a constant error ratio between PTS and samples, the rescale
is wrong.

What I think may be right: interpolating between in1.pts and in2.pts:

    out.pts = in1.pts + rescale(320, 1/384, 1/(in2.pts-in1.pts)

If I do not have in2.pts (because in1 was large enough to provide the whole
frame and more; or if it is absurd or undefined), I can use
in1.pts+in1.duration.

If I do not have in1.duration, I can use in0.pts (i.e. extrapolate the
timestamps of the previous frame).

If I do not have anything (for the very first frame, for example), I can
resort to sample_rate and time_base.

Remarks? Or is it just not worth it?

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120701/1caece4e/attachment.asc>


More information about the ffmpeg-devel mailing list