[FFmpeg-devel] [PATCH] lavfi: add duration field to AVFilterBufferRef

Stefano Sabatini stefasab at gmail.com
Mon Jul 30 19:19:01 CEST 2012


On date Monday 2012-07-30 19:13:43 +0200, Stefano Sabatini encoded:
> ---
>  libavfilter/audio.c       |    1 +
>  libavfilter/avcodec.c     |    2 ++
>  libavfilter/avfilter.h    |    7 +++++++
>  libavfilter/buffer.c      |    1 +
>  libavfilter/f_settb.c     |   10 ++++++----
>  libavfilter/vf_showinfo.c |    6 ++++--
>  6 files changed, 21 insertions(+), 6 deletions(-)

Consider this more than an RFC than a proper patch.
 
> diff --git a/libavfilter/audio.c b/libavfilter/audio.c
> index f3eebbf..16d0d32 100644
> --- a/libavfilter/audio.c
> +++ b/libavfilter/audio.c
> @@ -179,6 +179,7 @@ int ff_filter_samples_framed(AVFilterLink *link, AVFilterBufferRef *samplesref)
>          buf_out = ff_default_get_audio_buffer(link, dst->min_perms,
>                                                samplesref->audio->nb_samples);
>          buf_out->pts                = samplesref->pts;
> +        buf_out->duration           = samplesref->duration;
>          buf_out->audio->sample_rate = samplesref->audio->sample_rate;
>  
>          /* Copy actual data into new samples buffer */
> diff --git a/libavfilter/avcodec.c b/libavfilter/avcodec.c
> index 8d61fbc..8ab1123 100644
> --- a/libavfilter/avcodec.c
> +++ b/libavfilter/avcodec.c
> @@ -32,6 +32,7 @@ int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
>      dst->pts    = src->pts;
>      dst->pos    = av_frame_get_pkt_pos(src);
>      dst->format = src->format;
> +    dst->duration = av_frame_get_pkt_duration(src);
>  
>      switch (dst->type) {
>      case AVMEDIA_TYPE_VIDEO:
> @@ -110,6 +111,7 @@ int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src)
>      dst->pts     = src->pts;
>      dst->format  = src->format;
>      av_frame_set_pkt_pos(dst, src->pos);
> +    av_frame_set_pkt_duration(dst, src->duration);
>  
>      switch (src->type) {
>      case AVMEDIA_TYPE_VIDEO:
> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index b7155a0..772d811 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -174,6 +174,13 @@ typedef struct AVFilterBufferRef {
>      int perms;                  ///< permissions, see the AV_PERM_* flags
>  
>      enum AVMediaType type;      ///< media type of buffer data
> +
> +    /**
> +     * duration timestamp. The time unit may change during filtering,
> +     * as it is specified in the link and the filter code may need to
> +     * rescale the duration accordingly.
> +     */
> +    int64_t duration;
>  } AVFilterBufferRef;

The big question here is if we should set the duration only in video
properties (in this case copying frame->pkt_duration into
ref->video->duration should be fine) or if we should keep the duration
field in the general properties (as in the patch).

For audio buffers we could compute the duration from nb_samples, in
this case a duration field may still be useful if we want to specify
"special" audio buffers where the duration doesn't match nb_samples
(which may be a very bad idea due to the added complexity).
-- 
FFmpeg = Forgiving & Fancy MultiPurpose Enchanting Gymnast


More information about the ffmpeg-devel mailing list