From patchwork Wed Dec 28 01:52:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 1953 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp1741549vsb; Tue, 27 Dec 2016 17:53:07 -0800 (PST) X-Received: by 10.28.220.197 with SMTP id t188mr29688399wmg.57.1482889987593; Tue, 27 Dec 2016 17:53:07 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2si48259394wmr.165.2016.12.27.17.53.04; Tue, 27 Dec 2016 17:53:07 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4E6BA689D7A; Wed, 28 Dec 2016 03:52:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe01-3.mx.upcmail.net (vie01a-dmta-pe01-3.mx.upcmail.net [62.179.121.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A2073689A84 for ; Wed, 28 Dec 2016 03:52:53 +0200 (EET) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1cM3QG-0002zR-0a for ffmpeg-devel@ffmpeg.org; Wed, 28 Dec 2016 02:52:56 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id RDsu1u01Z0S5wYM01Dsvgd; Wed, 28 Dec 2016 02:52:55 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 28 Dec 2016 02:52:54 +0100 Message-Id: <20161228015254.17232-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_pad: Add eval=frame support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Michael Niedermayer --- libavfilter/vf_pad.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index dfc873cd39..9739a0fdf6 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -75,11 +75,18 @@ static int query_formats(AVFilterContext *ctx) return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0)); } +enum EvalMode { + EVAL_MODE_INIT, + EVAL_MODE_FRAME, + EVAL_MODE_NB +}; + typedef struct PadContext { const AVClass *class; 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; ///< width expression string char *h_expr; ///< height expression string @@ -88,6 +95,8 @@ typedef struct PadContext { uint8_t rgba_color[4]; ///< color for the padding area FFDrawContext draw; FFDrawColor color; + + int eval_mode; ///< expression evaluation mode } PadContext; static int config_input(AVFilterLink *inlink) @@ -163,6 +172,8 @@ static int config_input(AVFilterLink *inlink) s->y = ff_draw_round_to_sub(&s->draw, 1, -1, s->y); s->in_w = ff_draw_round_to_sub(&s->draw, 0, -1, inlink->w); s->in_h = ff_draw_round_to_sub(&s->draw, 1, -1, inlink->h); + s->inlink_w = inlink->w; + s->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, s->w, s->h, s->x, s->y, @@ -290,8 +301,35 @@ static int frame_needs_copy(PadContext *s, AVFrame *frame) static int filter_frame(AVFilterLink *inlink, AVFrame *in) { PadContext *s = inlink->dst->priv; + AVFilterLink *outlink = inlink->dst->outputs[0]; AVFrame *out; - int needs_copy = frame_needs_copy(s, in); + int needs_copy; + if(s->eval_mode == EVAL_MODE_FRAME && ( + in->width != s->inlink_w + || in->height != s->inlink_h + || in->format != outlink->format + || in->sample_aspect_ratio.den != outlink->sample_aspect_ratio.den || in->sample_aspect_ratio.num != outlink->sample_aspect_ratio.num)) { + int ret; + + inlink->dst->inputs[0]->format = in->format; + inlink->dst->inputs[0]->w = in->width; + inlink->dst->inputs[0]->h = in->height; + + inlink->dst->inputs[0]->sample_aspect_ratio.den = in->sample_aspect_ratio.den; + inlink->dst->inputs[0]->sample_aspect_ratio.num = in->sample_aspect_ratio.num; + + + if ((ret = config_input(inlink)) < 0) { + s->inlink_w = -1; + return ret; + } + if ((ret = config_output(outlink)) < 0) { + s->inlink_w = -1; + return ret; + } + } + + needs_copy = frame_needs_copy(s, in); if (needs_copy) { av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n"); @@ -364,6 +402,9 @@ static const AVOption pad_options[] = { { "x", "set the x offset expression for the input image position", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS }, { "y", "set the y offset expression for the input image position", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS }, { "color", "set the color of the padded area border", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS }, + { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_INIT}, 0, EVAL_MODE_NB-1, FLAGS, "eval" }, + { "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags = FLAGS, .unit = "eval" }, + { "frame", "eval expressions during initialization and per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" }, { NULL } };