[FFmpeg-devel] [PATCH 2/4] vf_pad: reinit on input parameter changes.

Michael Niedermayer michaelni at gmx.at
Mon Jul 16 20:17:33 CEST 2012


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavfilter/vf_pad.c |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c
index aeff424..9bca4a2 100644
--- a/libavfilter/vf_pad.c
+++ b/libavfilter/vf_pad.c
@@ -78,6 +78,7 @@ typedef struct {
     int w, h;               ///< output dimensions, a value of 0 will result in the input size
     int x, y;               ///< offsets of the input area with respect to the padded area
     int in_w, in_h;         ///< width and height for the padded input video, which has to be aligned to the chroma values in order to avoid chroma issues
+    int inlink_w, inlink_h;
 
     char w_expr[256];       ///< width  expression string
     char h_expr[256];       ///< height expression string
@@ -183,6 +184,8 @@ static int config_input(AVFilterLink *inlink)
     pad->y    = ff_draw_round_to_sub(&pad->draw, 1, -1, pad->y);
     pad->in_w = ff_draw_round_to_sub(&pad->draw, 0, -1, inlink->w);
     pad->in_h = ff_draw_round_to_sub(&pad->draw, 1, -1, inlink->h);
+    pad->inlink_w = inlink->w;
+    pad->inlink_h = inlink->h;
 
     av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X\n",
            inlink->w, inlink->h, pad->w, pad->h, pad->x, pad->y,
@@ -262,9 +265,28 @@ static int does_clip(PadContext *pad, AVFilterBufferRef *outpicref, int plane, i
 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     PadContext *pad = inlink->dst->priv;
+    AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
     int plane;
 
+    if(   inpicref->video->w != pad->inlink_w
+       || inpicref->video->h != pad->inlink_h
+       || inpicref->format   != outlink->format
+       || av_cmp_q(inpicref->video->sample_aspect_ratio, outlink->sample_aspect_ratio)
+    ) {
+        int ret;
+
+        inlink->dst->inputs[0]->format = inpicref->format;
+        inlink->dst->inputs[0]->w      = inpicref->video->w;
+        inlink->dst->inputs[0]->h      = inpicref->video->h;
+        inlink->dst->inputs[0]->sample_aspect_ratio = inpicref->video->sample_aspect_ratio;
+
+        if ((ret = config_input(inlink)) < 0)
+            av_assert0(0); //what to do here ?
+        if ((ret = config_output(outlink)) < 0)
+            av_assert0(0); //what to do here ?
+    }
+
     for (plane = 0; plane < 4 && outpicref->data[plane] && pad->draw.pixelstep[plane]; plane++) {
         int hsub = pad->draw.hsub[plane];
         int vsub = pad->draw.vsub[plane];
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list