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

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


---
 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(-)

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;
 
 /**
diff --git a/libavfilter/buffer.c b/libavfilter/buffer.c
index 30663b5..abb1659 100644
--- a/libavfilter/buffer.c
+++ b/libavfilter/buffer.c
@@ -170,6 +170,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: *dst->video = *src->video; break;
diff --git a/libavfilter/f_settb.c b/libavfilter/f_settb.c
index ff93f1e..16185d8 100644
--- a/libavfilter/f_settb.c
+++ b/libavfilter/f_settb.c
@@ -102,12 +102,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 1c65563..d79105b 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -62,11 +62,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:%"PRId64" 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),
+           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,
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list