[FFmpeg-devel] [PATCH 3/3] lavc: adjust timestamp in case of skiping initial samples

Nicolas George nicolas.george at normalesup.org
Fri Jul 13 00:18:54 CEST 2012


Le quintidi 25 messidor, an CCXX, Michael Niedermayer a écrit :
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  libavcodec/utils.c |    6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index e435c05..db0d870 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1656,6 +1656,12 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
>              } else {
>                  av_samples_copy(frame->extended_data, frame->extended_data, 0, avctx->internal->skip_samples,
>                                  frame->nb_samples - avctx->internal->skip_samples, avctx->channels, frame->format);
> +                if(avctx->pkt_timebase.num && avctx->sample_rate) {
> +                    if(frame->pkt_pts!=AV_NOPTS_VALUE)
> +                        frame->pkt_pts += av_rescale_q(avctx->internal->skip_samples,(AVRational){1, avctx->sample_rate}, avctx->pkt_timebase);
> +                    if(frame->pkt_dts!=AV_NOPTS_VALUE)
> +                        frame->pkt_dts += av_rescale_q(avctx->internal->skip_samples,(AVRational){1, avctx->sample_rate}, avctx->pkt_timebase);
> +                }
>                  frame->nb_samples -= avctx->internal->skip_samples;
>                  avctx->internal->skip_samples = 0;
>              }

Altering the pkt_?ts fields feels a bit like lying: the packet did not have
that altered timestamp. Maybe best_effort_timestamp would be a better
choice:

frame->best_effort_timestamp = guess_correct_pts(avctx, frame->pkt_pts, frame->pkt_dts);
if (frame->best_effort_timestamp != AV_NOPTS_VALUE &&
    avctx->pkt_timebase.num && avctx->sample_rate)
    frame->best_effort_timestamp += av_rescale_q(avctx->internal->skip_samples,
                                                 (AVRational){1, avctx->sample_rate},
						 avctx->pkt_timebase);

But I do not strongly object to your solution either.

Thanks for the work.

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/20120713/7c8b2081/attachment.asc>


More information about the ffmpeg-devel mailing list