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

Stefano Sabatini stefasab at gmail.com
Thu Sep 13 11:37:14 CEST 2012


---
 libavfilter/af_ashowinfo.c |    3 ++-
 libavfilter/audio.c        |    2 ++
 libavfilter/avcodec.c      |    2 ++
 libavfilter/avfilter.h     |    8 ++++++++
 libavfilter/buffer.c       |    1 +
 libavfilter/f_settb.c      |   10 ++++++----
 libavfilter/vf_showinfo.c  |    6 ++++--
 libavfilter/video.c        |    1 +
 8 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c
index 65f18f5..4598698 100644
--- a/libavfilter/af_ashowinfo.c
+++ b/libavfilter/af_ashowinfo.c
@@ -65,11 +65,12 @@ static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
                                  samplesref->audio->channel_layout);
 
     av_log(ctx, AV_LOG_INFO,
-           "n:%d pts:%s pts_time:%s pos:%"PRId64" "
+           "n:%d pts:%s pts_time:%s dur:%s dur_time:%s pos:%"PRId64" "
            "fmt:%s channels:%d chlayout:%s nb_samples:%d rate:%d "
            "checksum:%08X plane_checksum[%08X",
            showinfo->frame,
            av_ts2str(samplesref->pts), av_ts2timestr(samplesref->pts, &inlink->time_base),
+           av_ts2str(samplesref->duration), av_ts2timestr(samplesref->duration, &inlink->time_base),
            samplesref->pos,
            av_get_sample_fmt_name(samplesref->format),
            samplesref->audio->channels,
diff --git a/libavfilter/audio.c b/libavfilter/audio.c
index e7306b1..0b35050 100644
--- a/libavfilter/audio.c
+++ b/libavfilter/audio.c
@@ -139,6 +139,7 @@ AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
     }
 
     samplesref->pts = AV_NOPTS_VALUE;
+    samplesref->duration = AV_NOPTS_VALUE;
 
     return samplesref;
 
@@ -197,6 +198,7 @@ int ff_filter_samples_framed(AVFilterLink *link, AVFilterBufferRef *samplesref)
             return AVERROR(ENOMEM);
         }
         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 fb28a3a..3e96fdc 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_duration(src);
 
     switch (dst->type) {
     case AVMEDIA_TYPE_VIDEO:
@@ -121,6 +122,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_duration(dst, src->duration);
 
     switch (src->type) {
     case AVMEDIA_TYPE_VIDEO:
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 7cc6125..76454a6 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -181,6 +181,14 @@ typedef struct AVFilterBufferRef {
     int perms;                  ///< permissions, see the AV_PERM_* flags
 
     enum AVMediaType type;      ///< media type of buffer data
+
+    /**
+     * duration timestamp, expressed in link time base units. 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. An undefined value must be set to AV_NOPTS_VALUE.
+     */
+    int64_t duration;
 } AVFilterBufferRef;
 
 /**
diff --git a/libavfilter/buffer.c b/libavfilter/buffer.c
index fc65b82..8266550 100644
--- a/libavfilter/buffer.c
+++ b/libavfilter/buffer.c
@@ -186,6 +186,7 @@ void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *s
     // copy common properties
     dst->pts             = src->pts;
     dst->pos             = src->pos;
+    dst->duration        = src->duration;
 
     switch (src->type) {
     case AVMEDIA_TYPE_VIDEO: {
diff --git a/libavfilter/f_settb.c b/libavfilter/f_settb.c
index 82a49f4..d146e1e 100644
--- a/libavfilter/f_settb.c
+++ b/libavfilter/f_settb.c
@@ -106,12 +106,14 @@ static int config_output_props(AVFilterLink *outlink)
 inline static void rescale_ref_time(AVFilterBufferRef *ref,
                                     AVRational outtb, AVRational intb, void *log_ctx)
 {
-    int64_t orig_pts = ref->pts;
+    int64_t orig_pts = ref->pts, orig_duration = ref->duration;
     ref->pts = av_rescale_q(ref->pts, intb, outtb);
+    ref->duration = av_rescale_q(ref->duration, intb, outtb);
     av_log(log_ctx, AV_LOG_DEBUG,
-           "tb:%d/%d pts:%"PRId64" -> tb:%d/%d pts:%"PRId64"\n",
-           intb .num, intb .den, orig_pts,
-           outtb.num, outtb.den, ref->pts);
+           "tb:%d/%d pts:%"PRId64" duration:%"PRId64" -> "
+           "tb:%d/%d pts:%"PRId64" duration:%"PRId64"\n",
+           intb .num, intb .den, orig_pts, orig_duration,
+           outtb.num, outtb.den, ref->pts, ref->duration);
 }
 
 static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 9d20b48..f2219c2 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -63,11 +63,13 @@ static int end_frame(AVFilterLink *inlink)
     }
 
     av_log(ctx, AV_LOG_INFO,
-           "n:%d pts:%s pts_time:%s pos:%"PRId64" "
+           "n:%d pts:%s pts_time:%s dur:%s dur_time:%s pos:%"PRId64" "
            "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c "
            "checksum:%08X plane_checksum:[%08X",
            showinfo->frame,
-           av_ts2str(picref->pts), av_ts2timestr(picref->pts, &inlink->time_base), picref->pos,
+           av_ts2str(picref->pts), av_ts2timestr(picref->pts, &inlink->time_base),
+           av_ts2str(picref->duration), av_ts2timestr(picref->duration, &inlink->time_base),
+           picref->pos,
            av_pix_fmt_descriptors[picref->format].name,
            picref->video->sample_aspect_ratio.num, picref->video->sample_aspect_ratio.den,
            picref->video->w, picref->video->h,
diff --git a/libavfilter/video.c b/libavfilter/video.c
index 5294c1b..e0e9688 100644
--- a/libavfilter/video.c
+++ b/libavfilter/video.c
@@ -126,6 +126,7 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int lin
     picref->extended_data = picref->data;
 
     picref->pts = AV_NOPTS_VALUE;
+    picref->duration = AV_NOPTS_VALUE;
 
     return picref;
 
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list