[FFmpeg-devel] [PATCH 1/5] Move timestamp correction code from ffplay to cmdutils

Alexander Strange astrange
Mon Sep 13 05:05:06 CEST 2010


On Tue, Jul 27, 2010 at 8:52 AM, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Mon, Jul 26, 2010 at 01:16:06PM -0700, Alexander Strange wrote:
>> ---
>> ?cmdutils.c | ? 27 +++++++++++++++++++++++++++
>> ?cmdutils.h | ? 24 ++++++++++++++++++++++++
>> ?ffplay.c ? | ? 31 ++++++-------------------------
>> ?3 files changed, 57 insertions(+), 25 deletions(-)
>>
>> diff --git a/cmdutils.c b/cmdutils.c
>> index 978b73c..cd0b194 100644
>> --- a/cmdutils.c
>> +++ b/cmdutils.c
>
>
>>
>> - ? ? ? ? ? ?is->last_dts_for_fault_detection=
>> - ? ? ? ? ? ?is->last_pts_for_fault_detection= INT64_MIN;
>> + ? ? ? ? ? ?init_pts_correction(&is->pts_ctx);
>
>> @@ -663,3 +663,30 @@ int read_file(const char *filename, char **bufptr, size_t *size)
>> ? ? ?fclose(f);
>> ? ? ?return 0;
>> ?}
>> +
>> +void init_pts_correction(PtsCorrectionContext *ctx)
>> +{
>> + ? ?ctx->num_faulty_pts = ctx->num_faulty_dts = 0;
>> + ? ?ctx->last_pts = ctx->last_dts = AV_NOPTS_VALUE;
>
> INT64_MIN is correct, AV_NOPTS_VALUE is wrong, the code depends on it being
> the smallest integer, it does not check == AV_NOPTS_VALUE

Fixed. Not sure where that came from.

>> +}
>> +
>> +int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts)
>> +{
>> + ? ?int64_t pts = AV_NOPTS_VALUE;
>> +
>> + ? ?if (dts != AV_NOPTS_VALUE) {
>> + ? ? ? ?ctx->num_faulty_dts += dts <= ctx->last_dts;
>> + ? ? ? ?ctx->last_dts = dts;
>> + ? ?}
>> + ? ?if (reordered_pts != AV_NOPTS_VALUE) {
>> + ? ? ? ?ctx->num_faulty_pts += reordered_pts <= ctx->last_pts;
>> + ? ? ? ?ctx->last_pts = reordered_pts;
>> + ? ?}
>> + ? ?if ((ctx->num_faulty_pts<ctx->num_faulty_dts || dts == AV_NOPTS_VALUE)
>> + ? ? ? && reordered_pts != AV_NOPTS_VALUE)
>> + ? ? ? ?pts = reordered_pts;
>> + ? ?else
>> + ? ? ? ?pts = dts;
>> +
>> + ? ?return pts;
>> +}
>
> you are loosing the decoder_reorder_pts code here

Merged the next patch into this one.

>> diff --git a/cmdutils.h b/cmdutils.h
>> index d48abab..f2ad34a 100644
>> --- a/cmdutils.h
>> +++ b/cmdutils.h
>> @@ -220,4 +220,28 @@ int read_yesno(void);
>> ? */
>> ?int read_file(const char *filename, char **bufptr, size_t *size);
>>
>> +typedef struct {
>> + ? ?int64_t num_faulty_pts; /// Number of incorrect PTS values so far
>> + ? ?int64_t num_faulty_dts; /// Number of incorrect DTS values so far
>> + ? ?int64_t last_pts; ? ? ? /// PTS of the last frame
>> + ? ?int64_t last_dts; ? ? ? /// DTS of the last frame
>> +} PtsCorrectionContext;
>> +
>> +/**
>> + * Resets the state of the PtsCorrectionContext.
>> + */
>> +void init_pts_correction(PtsCorrectionContext *ctx);
>> +
>> +/**
>> + * Attempts to guess proper monotonic timestamps for decoded video frames
>> + * which might have incorrect times.
>> + *
>> + * @param pts The pts field of the decoded AVPacket, as passed through
>> + * AVCodecContext.reordered_opaque
>> + * @param dts The dts field of the decoded AVPacket
>
>> + * @return Whichever of pts or dts is more correct; will not be less than
>> + * or equal to the previous value. May be AV_NOPTS_VALUE.
>
> this is impossible, mpeg-ps/ts have timestamp discontinuities and thus the
> values may very well be less than previous

Changed the comment.

Note right now the function only returns one of the input values (so
@return mentions that), but I think it might need to do more in the
case of files that come out with duplicate pts, like that
mpeg+mpeg2video+ac3++non_monotone_timestamps.mpg. But I don't want to
hide too many future bugs in lavf, so I'm not sure that's a good idea
now.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Move-timestamp-correction-code-from-ffplay-to-cmduti.patch
Type: application/octet-stream
Size: 5826 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100912/dd998ef9/attachment.obj>



More information about the ffmpeg-devel mailing list