[PATCH 2/5] Add a time_base field to AVFilterPad.

Stefano Sabatini stefano.sabatini-lala
Mon Jul 19 12:55:27 CEST 2010


This is required for allowing a filter to use a time base different
from AV_TIME_BASE_Q, as it was previously assumed.
---
 libavfilter/avfilter.c |   14 ++++++++++++++
 libavfilter/avfilter.h |   15 ++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index e81fa48..5b4e4e7 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -149,11 +149,15 @@ int avfilter_config_links(AVFilterContext *filter)
             if(avfilter_config_links(link->src))
                 return -1;
 
+            if (link_spad(link).time_base.num == 0 && link_spad(link).time_base.den == 0)
+                link_spad(link).time_base = AV_TIME_BASE_Q;
             if(!(config_link = link_spad(link).config_props))
                 config_link  = avfilter_default_config_output_link;
             if(config_link(link))
                 return -1;
 
+            if (link_dpad(link).time_base.num == 0 && link_dpad(link).time_base.den == 0)
+                link_dpad(link).time_base = link_spad(link).time_base;
             if((config_link = link_dpad(link).config_props))
                 if(config_link(link))
                     return -1;
@@ -240,6 +244,7 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
 {
     void (*start_frame)(AVFilterLink *, AVFilterPicRef *);
     AVFilterPad *dst = &link_dpad(link);
+    AVFilterPad *src = &link_spad(link);
 
     FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " "); ff_dprintf_picref(NULL, picref, 1);
 
@@ -263,6 +268,15 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
     else
         link->cur_pic = picref;
 
+    if (dst->time_base.num != src->time_base.num || dst->time_base.den != src->time_base.den) {
+        int64_t av_unused pts1 = picref->pts;
+        link->cur_pic->pts = av_rescale_q(picref->pts, src->time_base, dst->time_base);
+        FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0);
+        dprintf(NULL, " Converting PTS tb1:%d/%d pts1:%"PRId64" -> tb2:%d/%d pts2:%"PRId64"\n",
+                src->time_base.num, src->time_base.den, pts1,
+                dst->time_base.num, dst->time_base.den, link->cur_pic->pts);
+    }
+
     start_frame(link, link->cur_pic);
 }
 
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index f5f9bce..e7fdcc2 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -105,7 +105,14 @@ typedef struct AVFilterPicRef
     int w;                      ///< image width
     int h;                      ///< image height
 
-    int64_t pts;                ///< presentation timestamp in units of 1/AV_TIME_BASE
+    /**
+     * presentation timestamp. The time unit may change during
+     * filtering, as it is specified in the input and output pads of a
+     * link. The framework automatically rescale the timestamp when
+     * sending a picref through a link and the source and destination
+     * time units differ.
+     */
+    int64_t pts;
     int64_t pos;                ///< byte position in stream, -1 if unknown
 
     AVRational pixel_aspect;    ///< pixel aspect ratio
@@ -383,6 +390,12 @@ struct AVFilterPad
      * and another value on error.
      */
     int (*config_props)(AVFilterLink *link);
+
+    /**
+     * Define the time base used by the PTS of the frames/samples
+     * which will pass through this link.
+     */
+    AVRational time_base;
 };
 
 /** default handler for start_frame() for video inputs */
-- 
1.6.0.4


--Dxnq1zWXvFF0Q93v
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0003-Set-timebase-in-the-ffplay-input-and-output-filters.patch"




More information about the ffmpeg-devel mailing list