From patchwork Fri Sep 2 20:42:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 401 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp1646934vsd; Fri, 2 Sep 2016 13:42:55 -0700 (PDT) X-Received: by 10.194.236.68 with SMTP id us4mr20419925wjc.12.1472848975335; Fri, 02 Sep 2016 13:42:55 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v207si6058726wmv.86.2016.09.02.13.42.54; Fri, 02 Sep 2016 13:42:55 -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=@gmail.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; dmarc=fail (p=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 A0D92689CC7; Fri, 2 Sep 2016 23:42:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D2F8689BE6 for ; Fri, 2 Sep 2016 23:42:38 +0300 (EEST) Received: by mail-wm0-f66.google.com with SMTP id w207so4275444wmw.0 for ; Fri, 02 Sep 2016 13:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=W0LnQ/2QATtrGjafhL9FqW8MuaguwBg9E64SXJnfBtc=; b=d1zVIPlts46/RB00Q6FtwAAnnCkEwobnrQybZ4tWaCCbrIKSF8NIv1+gDR6xaGUWRp nLQOB5Gfz+Df2p2Cwkr69c4ia4keAj2qqtq9qw/PuIgQ/VpFGanbFEFsYRZP1hiDJPOX Fx4YjXOr2/0aHh7sPavFF+6BHVrnj87cAL0MrEbO+J3rVfi6mih3/CdkMpQ1KfFCXkV9 OaVcPv39CAYwZBI8qq02iokV5MvS9UsewwZQ52TQe7mo36u1WjDIXPG5XDp4ZlZb7Rm/ bkOhhCvGQ1v9w+8VmCUGHBuJcUJ71um2qCB0b4PD7+cv7hZzdoXzCpjHoULYLiplN8CM w47A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=W0LnQ/2QATtrGjafhL9FqW8MuaguwBg9E64SXJnfBtc=; b=af+jNgkFJIgB78GcrRFgToMf6YV2KatCaju5oHV7u0KA6rY2LTJPYiuv+425FoKRS2 t+x6KmIEyylMuFlPNoqqJt/yJUm0KvtPj+Y4IBZD854HeY3lhK7krhA6j/nWJMd3ku8c sKGlGDH5rzQjFXB71mlejyZw8KIxUf4Xfo8p4WJH8YXc3ICO/mNnfixNpeG74gWEtYCI wJa6NvuLuxeJ8yLxov4sA4vt7FFIxakuYno8j5qI/tjJTCB4lIGYP4unsNw3ODbPWC5B tgfaxyq4q+xJT5VbbUjKvtT9uqWyCDs4kEo+IK6pNXCTpeZ/DQoQJlQlGebZSSDWT10T hkzg== X-Gm-Message-State: AE9vXwMFFmneuhVlrQCfhJlc3/M0HaMHriKk8XFhPy8h7DiZ9C/DJiAjP4Q94wlPLNACOg== X-Received: by 10.28.183.135 with SMTP id h129mr5230829wmf.2.1472848965565; Fri, 02 Sep 2016 13:42:45 -0700 (PDT) Received: from computer.gigaset.lan (236-208.dsl.iskon.hr. [89.164.236.208]) by smtp.gmail.com with ESMTPSA id d80sm5254306wmd.14.2016.09.02.13.42.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Sep 2016 13:42:43 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Sep 2016 22:42:09 +0200 Message-Id: <1472848930-1985-1-git-send-email-onemda@gmail.com> X-Mailer: git-send-email 2.5.0 Subject: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_palettegen: add mode for generating palette for each input frame 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 --- libavfilter/vf_palettegen.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_palettegen.c b/libavfilter/vf_palettegen.c index fccc5ca..3018b06 100644 --- a/libavfilter/vf_palettegen.c +++ b/libavfilter/vf_palettegen.c @@ -53,6 +53,7 @@ struct hist_node { enum { STATS_MODE_ALL_FRAMES, STATS_MODE_DIFF_FRAMES, + STATS_MODE_SINGLE_FRAMES, NB_STATS_MODE }; @@ -80,9 +81,10 @@ typedef struct { static const AVOption palettegen_options[] = { { "max_colors", "set the maximum number of colors to use in the palette", OFFSET(max_colors), AV_OPT_TYPE_INT, {.i64=256}, 4, 256, FLAGS }, { "reserve_transparent", "reserve a palette entry for transparency", OFFSET(reserve_transparent), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS }, - { "stats_mode", "set statistics mode", OFFSET(stats_mode), AV_OPT_TYPE_INT, {.i64=STATS_MODE_ALL_FRAMES}, 0, NB_STATS_MODE, FLAGS, "mode" }, + { "stats_mode", "set statistics mode", OFFSET(stats_mode), AV_OPT_TYPE_INT, {.i64=STATS_MODE_ALL_FRAMES}, 0, NB_STATS_MODE-1, FLAGS, "mode" }, { "full", "compute full frame histograms", 0, AV_OPT_TYPE_CONST, {.i64=STATS_MODE_ALL_FRAMES}, INT_MIN, INT_MAX, FLAGS, "mode" }, { "diff", "compute histograms only for the part that differs from previous frame", 0, AV_OPT_TYPE_CONST, {.i64=STATS_MODE_DIFF_FRAMES}, INT_MIN, INT_MAX, FLAGS, "mode" }, + { "single", "compute new histogram for each frame", 0, AV_OPT_TYPE_CONST, {.i64=STATS_MODE_SINGLE_FRAMES}, INT_MIN, INT_MAX, FLAGS, "mode" }, { NULL } }; @@ -480,8 +482,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) { AVFilterContext *ctx = inlink->dst; PaletteGenContext *s = ctx->priv; - const int ret = s->prev_frame ? update_histogram_diff(s->histogram, s->prev_frame, in) - : update_histogram_frame(s->histogram, in); + int ret = s->prev_frame ? update_histogram_diff(s->histogram, s->prev_frame, in) + : update_histogram_frame(s->histogram, in); + int64_t in_pts = in->pts; if (ret > 0) s->nb_refs += ret; @@ -493,6 +496,22 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) av_frame_free(&in); } + if (s->stats_mode == STATS_MODE_SINGLE_FRAMES) { + AVFrame *out; + int i; + + out = get_palette_frame(ctx); + out->pts = in_pts; + ret = ff_filter_frame(ctx->outputs[0], out); + for (i = 0; i < HIST_SIZE; i++) + av_freep(&s->histogram[i].entries); + av_freep(&s->refs); + s->nb_refs = 0; + s->nb_boxes = 0; + memset(s->boxes, 0, sizeof(s->boxes)); + memset(s->histogram, 0, sizeof(s->histogram)); + } + return ret; } @@ -507,7 +526,7 @@ static int request_frame(AVFilterLink *outlink) int r; r = ff_request_frame(inlink); - if (r == AVERROR_EOF && !s->palette_pushed && s->nb_refs) { + if (r == AVERROR_EOF && !s->palette_pushed && s->nb_refs && s->stats_mode != STATS_MODE_SINGLE_FRAMES) { r = ff_filter_frame(outlink, get_palette_frame(ctx)); s->palette_pushed = 1; return r;