[FFmpeg-devel] [PATCH] libavu: add pkt_timebase to AVFrame.

Hendrik Leppkes h.leppkes at gmail.com
Fri Jul 18 12:47:06 CEST 2014


Am 18.07.2014 12:04 schrieb "Benoit Fouet" <benoit.fouet at free.fr>:
>
> In order to easily correlate pkt_duration to its real duration, add the
> packet time base information to the frame structure.
>
> Fixes issue #3052

The code in avcodec doesn't know the timebase, unless the user tells it.

And if the user wants to tell it, there already is an avctx field for it
(pkt_timebase), no need to store it in the frame since its not going to
change in every frame.

As such, I'm not sure what this new field would solve.

> ---
>  libavcodec/utils.c |  6 ++++++
>  libavutil/frame.c  |  3 +++
>  libavutil/frame.h  | 11 +++++++++++
>  3 files changed, 20 insertions(+)
>
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 9fa8e16..2fe4aba 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -751,6 +751,7 @@ int ff_init_buffer_info(AVCodecContext *avctx,
AVFrame *frame)
>          frame->pkt_pts = pkt->pts;
>          av_frame_set_pkt_pos     (frame, pkt->pos);
>          av_frame_set_pkt_duration(frame, pkt->duration);
> +        av_frame_set_pkt_timebase(frame, avctx->time_base);
>          av_frame_set_pkt_size    (frame, pkt->size);
>
>          /* copy the replaygain data to the output frame */
> @@ -776,6 +777,7 @@ int ff_init_buffer_info(AVCodecContext *avctx,
AVFrame *frame)
>          frame->pkt_pts = AV_NOPTS_VALUE;
>          av_frame_set_pkt_pos     (frame, -1);
>          av_frame_set_pkt_duration(frame, 0);
> +        av_frame_set_pkt_timebase(frame, (AVRational){ 0, });
>          av_frame_set_pkt_size    (frame, -1);
>      }
>      frame->reordered_opaque = avctx->reordered_opaque;
> @@ -2063,6 +2065,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
>              avpkt->size = 0;
>          else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))
>              avpkt->pts = avpkt->dts = frame->pts;
> +        if (frame && av_frame_get_pkt_timebase(frame).num)
> +            avpkt->duration =
av_rescale_q(av_frame_get_pkt_duration(frame),
> +
av_frame_get_pkt_timebase(frame),
> +                                           avctx->time_base);
>
>          if (needs_realloc && avpkt->data) {
>              ret = av_buffer_realloc(&avpkt->buf, avpkt->size +
FF_INPUT_BUFFER_PADDING_SIZE);
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index fdfbc46..be60776 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -29,6 +29,7 @@
>
>  MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp)
>  MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration)
> +MAKE_ACCESSORS(AVFrame, frame, AVRational, pkt_timebase)
>  MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_pos)
>  MAKE_ACCESSORS(AVFrame, frame, int64_t, channel_layout)
>  MAKE_ACCESSORS(AVFrame, frame, int,     channels)
> @@ -98,6 +99,7 @@ static void get_frame_defaults(AVFrame *frame)
>      frame->pkt_pts               = AV_NOPTS_VALUE;
>      av_frame_set_best_effort_timestamp(frame, AV_NOPTS_VALUE);
>      av_frame_set_pkt_duration         (frame, 0);
> +    av_frame_set_pkt_timebase         (frame, (AVRational){ 0, });
>      av_frame_set_pkt_pos              (frame, -1);
>      av_frame_set_pkt_size             (frame, -1);
>      frame->key_frame           = 1;
> @@ -475,6 +477,7 @@ int av_frame_copy_props(AVFrame *dst, const AVFrame
*src)
>      dst->pkt_pos                = src->pkt_pos;
>      dst->pkt_size               = src->pkt_size;
>      dst->pkt_duration           = src->pkt_duration;
> +    dst->pkt_timebase           = src->pkt_timebase;
>      dst->reordered_opaque       = src->reordered_opaque;
>      dst->quality                = src->quality;
>      dst->best_effort_timestamp  = src->best_effort_timestamp;
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index a39c8d0..954b765 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -530,6 +530,15 @@ typedef struct AVFrame {
>       * Not to be accessed directly from outside libavutil
>       */
>      AVBufferRef *qp_table_buf;
> +
> +    /**
> +     * timebase of the corresponding packet.
> +     * Code outside libavcodec should access this field using:
> +     * av_frame_get_pkt_timebase(frame)
> +     * - encoding: unused
> +     * - decoding: Read by user.
> +     */
> +    AVRational pkt_timebase;
>  } AVFrame;
>
>  /**
> @@ -541,6 +550,8 @@ int64_t av_frame_get_best_effort_timestamp(const
AVFrame *frame);
>  void    av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val);
>  int64_t av_frame_get_pkt_duration         (const AVFrame *frame);
>  void    av_frame_set_pkt_duration         (AVFrame *frame, int64_t val);
> +AVRational av_frame_get_pkt_timebase      (const AVFrame *frame);
> +void    av_frame_set_pkt_timebase         (AVFrame *frame, AVRational
val);
>  int64_t av_frame_get_pkt_pos              (const AVFrame *frame);
>  void    av_frame_set_pkt_pos              (AVFrame *frame, int64_t val);
>  int64_t av_frame_get_channel_layout       (const AVFrame *frame);
> --
> 2.0.1.442.g7fe6834
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


More information about the ffmpeg-devel mailing list