+ } else {
+ char *arg, *p = s->layout, *saveptr = NULL;
+ char *arg2, *p2, *saveptr2 = NULL;
+ char *arg3, *p3, *saveptr3 = NULL;
+ int inw, inh, size;
+
+ for (i = 0; i < s->nb_inputs; i++) {
+ AVFilterLink *inlink = ctx->inputs[i];
+ StackItem *item = &s->items[i];
+
+ if (!(arg = av_strtok(p, "|", &saveptr)))
+ return AVERROR(EINVAL);
+
+ p = NULL;
+
+ 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;
+
+ p2 = arg;
+ inw = inh = 0;
+
+ for (int j = 0; j < 2; j++) {
+ if (!(arg2 = av_strtok(p2, "_", &saveptr2)))
+ return AVERROR(EINVAL);
+
+ p2 = NULL;
+ p3 = arg2;
+ while ((arg3 = av_strtok(p3, "+", &saveptr3))) {
+ p3 = NULL;
+ if (sscanf(arg3, "w%d", &size) == 1) {
+ if (size == i || size < 0 || size >= s->nb_inputs)
+ return AVERROR(EINVAL);
+
+ if (!j)
+ inw += ctx->inputs[size]->w;
+ else
+ inh += ctx->inputs[size]->w;
+ } else if (sscanf(arg3, "h%d", &size) == 1) {
+ if (size == i || size < 0 || size >= s->nb_inputs)
+ return AVERROR(EINVAL);
+
+ if (!j)
+ inw += ctx->inputs[size]->h;
+ else
+ inh += ctx->inputs[size]->h;
+ } else if (sscanf(arg3, "%d", &size) == 1) {
+ if (size < 0)
+ return AVERROR(EINVAL);
+
+ if (!j)
+ inw += size;
+ else
+ inh += size;
+ } else {
+ return AVERROR(EINVAL);
+ }
+ }
+ }
+
+ 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 = FFMAX(width, inlink->w + inw);
+ height = FFMAX(height, inlink->h + inh);
+ }