From patchwork Tue Jun 28 19:01:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Venkat X-Patchwork-Id: 36517 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp2832930pzh; Tue, 28 Jun 2022 12:01:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s2uBFlYr+bZNyWGvOA1+nBYZCfpnVt45zzuG0YD+niKsFCL9AiYoPcAABJMI6EchKRkJZ7 X-Received: by 2002:a05:6402:3490:b0:435:9802:96ac with SMTP id v16-20020a056402349000b00435980296acmr25083826edc.40.1656442903303; Tue, 28 Jun 2022 12:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656442903; cv=none; d=google.com; s=arc-20160816; b=apPZkPRuxXXQReHbI9bXQ1TMN793+m2Dmn0R/5n+7cihSMrTxgclOFuKwg0L13FDXL amW3/b4ZSkF3X+mKNHAmiEPHlIwdycOmT9z45RCGZQEVxyhl9KMWdUqzH45huL2hKX3m BrJffr+ApUYXTPc2IDBTh71xgnACWBqGcVRg0rMJNIsFmqQMkrIwpsaWA4UQDWjVEwC8 Smm9WDAbMcWu481Mi2H8D9CI/e+uii+6JNElWbUpgzvTPBBs70I/Mr1Gpxh9ugUitadV nKH5zMqguCnP+QKVlde72OHXEmYq+QcPlBPTaxsQ6vMgWoOjMjJpTdBMRVa21Y+2l1Rq z2Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:from:mime-version:message-id:date :dkim-signature:delivered-to; bh=MZAcQ5sWviVUC3J5eo/tcoOHnoL92SFcH7waue2v0ts=; b=r3RmvXDIbel3lYsgqpfT+CFb/C3tf20JJ/Eth8aL3joy7Ox3xOsIiJzeETktVqeR29 pbkC2uLcj8NmsmFH6LD6Uowx/7uMOXQ5sgKGY9vefbClNLLoSvoU6QvJIiQw6j3q78Bj YwmXTd3vFfEj6rBZZ1sz8e6GO5r3vIWVE5Cm/z663zIhqGxXpQj7un9dYsybL3Hb11ZA GsX3G4N3gYsGfXbe0Pd1zItji8VlTVoiwky+4erJZE4S2R0Gh3CJhpuLMEGd693e1C2p CVD4Nby9tvuj2HP0/bZAOXjIAFxfSAfsWk5zTe9rsDAfESb6n0hTNugZqpWDZAGvgkiK 07hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20210112 header.b=AdSn9x+o; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gx19-20020a1709068a5300b007277c6ea3d5si497973ejc.380.2022.06.28.12.01.42; Tue, 28 Jun 2022 12:01:43 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20210112 header.b=AdSn9x+o; 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 3025E68B980; Tue, 28 Jun 2022 22:01:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B6A2C68B98E for ; Tue, 28 Jun 2022 22:01:33 +0300 (EEST) Received: by mail-yb1-f202.google.com with SMTP id r6-20020a5b06c6000000b006693f6a6d67so11648073ybq.7 for ; Tue, 28 Jun 2022 12:01:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=uUWuEJL8cqFrL5aE0BhkHto8jM4I/S5Od8TEVe2Qhc8=; b=AdSn9x+oNZ+27bWI+CjGqUexzwYDUJ+0Pk+9dW5kVWh/82tVoIByrTLEb11FEFQa1K OBktO8PNC3LQlnMykRqYDwWbZ6wkhW34onOONh+2KFTE9HIfVOweHDQ/4VJk5ooQR+Ob ag6d6uml3qJGy1WE/6SA5rNxxwr/iaq4C/DHOq0arh0PAeiHmYpYpILdyvT6syFW3tmT wKO42MEp+/GRueB7tiCcLxQJuZsZLSPF3HZ7GL143xhuKbLrm/4qFz4MoSLigiYUKCRf qdNg0s7GzqCqF/c5cJA3owi8HHETHrbbW/CwTB/XWCLBlkFvXCt2ZlujA7OS1QYb0+gZ dxWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=uUWuEJL8cqFrL5aE0BhkHto8jM4I/S5Od8TEVe2Qhc8=; b=7EZxix6U1KX9L5SMtzJiwLUndecY8BPPmJBFwblGwXLBl0LgJc2ZePsJUWFfuJHNRj A4IpwS55Sxuu+1n7C2j+5BISBoiBs7zIuAPkyYN5ICfMYF4bUl5Q+uQWpyIW4m4Qd5Xv vMSF5KqSQpis4UDCbgUX+t7NEp+DAbLC3WSERO98C6bQPbsPnDNHeo7hG9COeY06VxYn V9a9ZaceokVt9f89UGFjaGvDXFL9qWNDhNF+U0kLcP4kgCqel+cK1oDsdKFNpBJWYb+z RDyVgAomnDdQ0KEh6NeVYUFVHErxfLRkzsWAOLWlA1srIV/4cB0eHgSGPfhgHlOO7kPl aDlQ== X-Gm-Message-State: AJIora9pfZwLLhQeK1iDX4nq57v4ycUWY6URfzsfYvWuz/Ls51KwxH9I +OG+9Z1AguGIMI7Ti4zUJ8mJYGmWffofre2w0OHK++ihvJThVuRqaejmDDDKKHeamHgnkUr/sDb JMkTQMi+1Qzx3fRkIFT7IMm7B2O6U5Btpk93SkZ8Yucag4tH83h3RED6Ka8YVUM/Xgyxs X-Received: from vigneshv3.mtv.corp.google.com ([2620:0:1000:2511:a3d:b3a0:5148:b682]) (user=vigneshv job=sendgmr) by 2002:a25:f50b:0:b0:668:27cd:ed38 with SMTP id a11-20020a25f50b000000b0066827cded38mr21101536ybe.606.1656442892276; Tue, 28 Jun 2022 12:01:32 -0700 (PDT) Date: Tue, 28 Jun 2022 12:01:29 -0700 Message-Id: <20220628190129.2959644-1-vigneshv@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog From: Vignesh Venkatasubramanian To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avfilter/xstack: Add support for fixed size grid X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Vignesh Venkatasubramanian Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: GsqmCPph/mQV Add a short hand parameter for making a fixed size grid. The existing xstack layout parameter syntax gets tedious if all one wants is a matrix like grid of the input streams. Add a grid option to the xstack filter that simplifies this use case by simply specifying the number of rows and columns instead of specific x/y co-ordinate for each stream. Also updating the filter documentation to explain the new option. Signed-off-by: Vignesh Venkatasubramanian --- doc/filters.texi | 19 +++++++++-- libavfilter/vf_stack.c | 73 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index e525e87b3c..9d800a0fd6 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -24381,8 +24381,23 @@ the output video frame will be filled. Similarly, videos can overlap each other if their position doesn't leave enough space for the full frame of adjoining videos. -For 2 inputs, a default layout of @code{0_0|w0_0} is set. In all other cases, -a layout must be set by the user. +For 2 inputs, a default layout of @code{0_0|w0_0} is set. In all other cases, a +layout or a grid must be set by the user. Either grid or layout option can be +specified at a time. Specifying both will result in an error. + +@item grid +Specify a fixed size grid of inputs. +This option is used to create a fixed size grid of the input streams. The +option is of the form x (e.g. 2x4). There must be * + input streams and they will be arranged as a grid with rows and + columns. When using this option, all the input streams must have the +same width and height. + +Either grid or layout option can be specified at a time. Specifying both will +result in an error. + +If grid is set, then inputs option is ignored and is implicitly set to +*. @item shortest If set to 1, force the output to terminate when the shortest input diff --git a/libavfilter/vf_stack.c b/libavfilter/vf_stack.c index aa32a1bf5e..b38a193355 100644 --- a/libavfilter/vf_stack.c +++ b/libavfilter/vf_stack.c @@ -48,6 +48,9 @@ typedef struct StackContext { int is_vertical; int is_horizontal; int nb_planes; + char *grid; + int nb_grid_rows; + int nb_grid_columns; uint8_t fillcolor[4]; char *fillcolor_str; int fillcolor_enable; @@ -85,14 +88,6 @@ static av_cold int init(AVFilterContext *ctx) if (!strcmp(ctx->filter->name, "hstack")) s->is_horizontal = 1; - s->frames = av_calloc(s->nb_inputs, sizeof(*s->frames)); - if (!s->frames) - return AVERROR(ENOMEM); - - s->items = av_calloc(s->nb_inputs, sizeof(*s->items)); - if (!s->items) - return AVERROR(ENOMEM); - if (!strcmp(ctx->filter->name, "xstack")) { if (strcmp(s->fillcolor_str, "none") && av_parse_color(s->fillcolor, s->fillcolor_str, -1, ctx) >= 0) { @@ -100,7 +95,21 @@ static av_cold int init(AVFilterContext *ctx) } else { s->fillcolor_enable = 0; } - if (!s->layout) { + if (s->grid && s->layout) { + av_log(ctx, AV_LOG_ERROR, "Both layout and grid were specified. Only one is allowed.\n"); + return AVERROR(EINVAL); + } + if (s->grid) { + if (sscanf(s->grid, "%dx%d", &s->nb_grid_rows, &s->nb_grid_columns) != 2) { + av_log(ctx, AV_LOG_ERROR, "grid string is not of the form rowsxcolumns.\n"); + return AVERROR(EINVAL); + } + s->nb_inputs = s->nb_grid_rows * s->nb_grid_columns; + } else { + s->nb_grid_rows = 0; + s->nb_grid_columns = 0; + } + if (!s->layout && !s->grid) { if (s->nb_inputs == 2) { s->layout = av_strdup("0_0|w0_0"); if (!s->layout) @@ -112,6 +121,15 @@ static av_cold int init(AVFilterContext *ctx) } } + s->frames = av_calloc(s->nb_inputs, sizeof(*s->frames)); + if (!s->frames) + return AVERROR(ENOMEM); + + s->items = av_calloc(s->nb_inputs, sizeof(*s->items)); + if (!s->items) + return AVERROR(ENOMEM); + + for (i = 0; i < s->nb_inputs; i++) { AVFilterPad pad = { 0 }; @@ -244,6 +262,42 @@ static int config_output(AVFilterLink *outlink) width += ctx->inputs[i]->w; } } + } else if (s->nb_grid_rows > 0 && s->nb_grid_columns > 0) { + int inw = 0, inh = 0; + int k = 0; + for (i = 0; i < s->nb_grid_rows; i++, inh += height) { + inw = 0; + for (int j = 0; j < s->nb_grid_columns; j++, k++, inw += width) { + AVFilterLink *inlink = ctx->inputs[k]; + StackItem *item = &s->items[k]; + + if (ctx->inputs[k]->w != width) { + av_log(ctx, AV_LOG_ERROR, "Input %d width %d does not match input %d width %d.\n", k, ctx->inputs[k]->w, 0, width); + return AVERROR(EINVAL); + } + + if (ctx->inputs[k]->h != height) { + av_log(ctx, AV_LOG_ERROR, "Input %d height %d does not match input %d height %d.\n", k, ctx->inputs[k]->h, 0, height); + return AVERROR(EINVAL); + } + + if ((ret = av_image_fill_linesizes(item->linesize, inlink->format, inlink->w)) < 0) { + return ret; + } + + item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); + item->height[0] = item->height[3] = inlink->h; + + if ((ret = av_image_fill_linesizes(item->x, inlink->format, inw)) < 0) { + return ret; + } + + item->y[1] = item->y[2] = AV_CEIL_RSHIFT(inh, s->desc->log2_chroma_h); + item->y[0] = item->y[3] = inh; + } + } + width *= s->nb_grid_columns; + height *= s->nb_grid_rows; } else { char *arg, *p = s->layout, *saveptr = NULL; char *arg2, *p2, *saveptr2 = NULL; @@ -436,6 +490,7 @@ const AVFilter ff_vf_vstack = { static const AVOption xstack_options[] = { { "inputs", "set number of inputs", OFFSET(nb_inputs), AV_OPT_TYPE_INT, {.i64=2}, 2, INT_MAX, .flags = FLAGS }, { "layout", "set custom layout", OFFSET(layout), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, .flags = FLAGS }, + { "grid", "set fixed size grid layout", OFFSET(grid), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, .flags = FLAGS }, { "shortest", "force termination when the shortest input terminates", OFFSET(shortest), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS }, { "fill", "set the color for unused pixels", OFFSET(fillcolor_str), AV_OPT_TYPE_STRING, {.str = "none"}, .flags = FLAGS }, { NULL },