From patchwork Tue Nov 7 19:34:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 5899 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp4526338jah; Tue, 7 Nov 2017 11:42:41 -0800 (PST) X-Google-Smtp-Source: ABhQp+QCLfYOsymeJn5qJ/nhuyqyXPpEUqSE1S/KyN1gmOjK8gnPVj4UWBYKhAdv5hJ5AILSNXLn X-Received: by 10.223.202.1 with SMTP id o1mr16091499wrh.205.1510083761432; Tue, 07 Nov 2017 11:42:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510083761; cv=none; d=google.com; s=arc-20160816; b=T8m2x+/CE+K+lBu3KiV406TWoodbmIVTSJSPR2yEFN7/8TAdZXuLIyn2eqjw29bxoS WSYxixiPppOZCWuHTjkOJqxER0y1YGvW+4nM1Iy2rKf2FTJp5NxMTklhVX33Cd0GBO2G bX+jff4+eD3x3CMBRPIRyzX3aclM26Ro8hxnsLAlL/WTjvPrfkln5ZfAQhZXOaeJbHah LNaMADJxz9lhG/6kxjg8qn4MF6d/60f0Fpi0KiVNVszalOCCErV5S7CKRRZIYCijCg1N +oX5X5WC8uzSFGkZP7zn3pBNC7BBv3vTs7lTY9mIFQ34nS+F3cI3Eqke63fCeEqfnBvJ 96aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=erMpRrmPA04Is9oV08taN9W5OkA4jage79prJ7nbNoo=; b=W/rYAuFk9qjkiAWYeObfIPKIfbmMA+M6mdWjeFhc5BnnA5hMUO42Ykczl86e9wDpFO AhW2c20SOUQqWQTGZo4SwuQSjB/hHGJoQOXEaLLd+FJfE6TkT8cOufIZRJC6Z8bcQ3QP ajCE23tn+Cl6B74yKmsq1XCVgcY9rWCYCFUSjeVWUTJ/yTZ7Gej8OSXwcZM5aK4+WLoj g/1/jQ0lc86Shk0oFtlbkv9OIb169xKjN4YcgBEOxoPxqPhdwEk45lKEjfFJaXSNaxcD qju1Ctnn7jNiqJCmpAc+WpZdy0f9nhCMzbhWui/+gJ+8Y2lEZ1OMyknj0Yzkqzwuvyw3 7Qgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=NAlyC6jv; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e6si1709388wrd.79.2017.11.07.11.42.38; Tue, 07 Nov 2017 11:42:41 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=NAlyC6jv; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7CD4D689DA2; Tue, 7 Nov 2017 21:42:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D078689D74 for ; Tue, 7 Nov 2017 21:42:18 +0200 (EET) Received: by mail-wm0-f67.google.com with SMTP id t139so6341353wmt.1 for ; Tue, 07 Nov 2017 11:42:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=txU8MfvBSKyHJmcrFWu+l4pPUGzUREWTJ/KM5jShGew=; b=NAlyC6jvlHQZTdesQQxy+KSo2B4+vq5rShMuSGFQVew2BQG1Wnny1BFo7Ms0griKzU uPSmGxuAP5TBUKA5ZBH3ifJ1/saaNPoVqzLgOWAm2R8Fa1SF9xxlaLOw3JnYPzcOTmOL s1lT4MRrRJ9sVxo9UTI2seAF1te7FqfoEvmAqlepznBHiLrJa+KO2R+A4NXMWabkK8Lg UO7c80RmBBVDzWhMg+MScLm7rAJDMZz322mgfdYCDyJDwo1R9S2YI2N239wfViUmpi39 0bBRxWPSEsOMmewEjgYCsSYaGkHgbG8kOvsbZ+sZB0nt89NNLiwYEHlmxclpjyOIQPVs jPLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=txU8MfvBSKyHJmcrFWu+l4pPUGzUREWTJ/KM5jShGew=; b=JrGfHr+eGZwplFabnBZrCUjez5NMfr0+qb3GPeA7XRj39ASCAm/ouemz71zolYNCHR HoNawrwjSLH7VT6DdsD9C4KBnRWK8JVo2pjKwALftkHqM0eds9/NZ+tsr0U3yeXKHQ2z P+6ysYiiR6sPv9CDahMjRFAEfirEjV0EBP2XZZflSdWCTXjhlGUAO0XVpzgEQn9H+5rc 2AFhospeRcSE+b0JlHvT/hbMv9b46jlEbFIiagiXwJ6+6SZ2GxF7rlMxnisNArxh0qwf 4spIcEPZNpFn4hi3op3ngT0uPIJ7pUMkUM7cxfgzn4qWocOZCOO80wHofha1qvcRDIDc YcVA== X-Gm-Message-State: AJaThX5cDaBtB+LCXRp1FZ4JekjAFjuMWJhu2+ULyIBO5DPVNQrBEZAW a6eVwA6RK/pK9Sqt14rfoKmcWw== X-Received: by 10.80.170.107 with SMTP id p40mr336726edc.158.1510083329540; Tue, 07 Nov 2017 11:35:29 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id k5sm1921886edc.61.2017.11.07.11.35.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 11:35:28 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Nov 2017 20:34:41 +0100 Message-Id: <20171107193441.28526-1-onemda@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_tile: add skip option 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: Paul B Mahol --- doc/filters.texi | 5 +++++ libavfilter/vf_tile.c | 53 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 2ba6e04166..a6d537485b 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -14439,6 +14439,11 @@ refer to the pad video filter. Specify the color of the unused area. For the syntax of this option, check the "Color" section in the ffmpeg-utils manual. The default value of @var{color} is "black". + +@item skip +Set the number of frames to skip from input before rendering output frame. +The default value is @code{0}, meaning skip @var{nb_frames} frames. If it is more +than @var{nb_frames} its is set to @var{nb_frames}. @end table @subsection Examples diff --git a/libavfilter/vf_tile.c b/libavfilter/vf_tile.c index e9d246fc73..089872831f 100644 --- a/libavfilter/vf_tile.c +++ b/libavfilter/vf_tile.c @@ -37,11 +37,13 @@ typedef struct TileContext { unsigned w, h; unsigned margin; unsigned padding; + unsigned skip; unsigned current; unsigned nb_frames; FFDrawContext draw; FFDrawColor blank; AVFrame *out_ref; + AVFrame *prev_out_ref; uint8_t rgba_color[4]; } TileContext; @@ -58,6 +60,8 @@ static const AVOption tile_options[] = { { "padding", "set inner border thickness in pixels", OFFSET(padding), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1024, FLAGS }, { "color", "set the color of the unused area", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS }, + { "skip", "set how many frames to skip for each render", OFFSET(skip), + AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS }, { NULL } }; @@ -90,6 +94,10 @@ static av_cold int init(AVFilterContext *ctx) return AVERROR(EINVAL); } + if (!tile->skip) + tile->skip = tile->nb_frames; + tile->skip = FFMIN(tile->skip, tile->nb_frames); + return 0; } @@ -120,19 +128,19 @@ static int config_props(AVFilterLink *outlink) outlink->h = tile->h * inlink->h + total_margin_h; outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; outlink->frame_rate = av_mul_q(inlink->frame_rate, - av_make_q(1, tile->nb_frames)); + av_make_q(1, tile->skip)); ff_draw_init(&tile->draw, inlink->format, 0); ff_draw_color(&tile->draw, &tile->blank, tile->rgba_color); return 0; } -static void get_current_tile_pos(AVFilterContext *ctx, unsigned *x, unsigned *y) +static void get_tile_pos(AVFilterContext *ctx, unsigned *x, unsigned *y, unsigned current) { TileContext *tile = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; - const unsigned tx = tile->current % tile->w; - const unsigned ty = tile->current / tile->w; + const unsigned tx = current % tile->w; + const unsigned ty = current / tile->w; *x = tile->margin + (inlink->w + tile->padding) * tx; *y = tile->margin + (inlink->h + tile->padding) * ty; @@ -144,7 +152,7 @@ static void draw_blank_frame(AVFilterContext *ctx, AVFrame *out_buf) AVFilterLink *inlink = ctx->inputs[0]; unsigned x0, y0; - get_current_tile_pos(ctx, &x0, &y0); + get_tile_pos(ctx, &x0, &y0, tile->current); ff_fill_rectangle(&tile->draw, &tile->blank, out_buf->data, out_buf->linesize, x0, y0, inlink->w, inlink->h); @@ -160,8 +168,13 @@ static int end_last_frame(AVFilterContext *ctx) while (tile->current < tile->nb_frames) draw_blank_frame(ctx, out_buf); + tile->current = tile->nb_frames - tile->skip; + if (tile->current) { + av_frame_free(&tile->prev_out_ref); + tile->prev_out_ref = av_frame_clone(out_buf); + } ret = ff_filter_frame(outlink, out_buf); - tile->current = 0; + tile->out_ref = NULL; return ret; } @@ -176,7 +189,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) AVFilterLink *outlink = ctx->outputs[0]; unsigned x0, y0; - if (!tile->current) { + if (!tile->out_ref) { tile->out_ref = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!tile->out_ref) { av_frame_free(&picref); @@ -194,7 +207,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) 0, 0, outlink->w, outlink->h); } - get_current_tile_pos(ctx, &x0, &y0); + if (tile->prev_out_ref) { + unsigned x1, y1, i; + + for (i = tile->skip; i < tile->nb_frames; i++) { + get_tile_pos(ctx, &x1, &y1, i); + get_tile_pos(ctx, &x0, &y0, i - tile->skip); + ff_copy_rectangle2(&tile->draw, + tile->out_ref->data, tile->out_ref->linesize, + tile->prev_out_ref->data, tile->prev_out_ref->linesize, + x0, y0, x1, y1, inlink->w, inlink->h); + + } + } + + get_tile_pos(ctx, &x0, &y0, tile->current); ff_copy_rectangle2(&tile->draw, tile->out_ref->data, tile->out_ref->linesize, picref->data, picref->linesize, @@ -215,11 +242,18 @@ static int request_frame(AVFilterLink *outlink) int r; r = ff_request_frame(inlink); - if (r == AVERROR_EOF && tile->current) + if (r == AVERROR_EOF && tile->current && tile->out_ref) r = end_last_frame(ctx); return r; } +static av_cold void uninit(AVFilterContext *ctx) +{ + TileContext *tile = ctx->priv; + + av_frame_free(&tile->prev_out_ref); +} + static const AVFilterPad tile_inputs[] = { { .name = "default", @@ -243,6 +277,7 @@ AVFilter ff_vf_tile = { .name = "tile", .description = NULL_IF_CONFIG_SMALL("Tile several successive frames together."), .init = init, + .uninit = uninit, .query_formats = query_formats, .priv_size = sizeof(TileContext), .inputs = tile_inputs,