From patchwork Wed Aug 31 19:40:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Cooper X-Patchwork-Id: 379 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp551936vsd; Wed, 31 Aug 2016 12:46:29 -0700 (PDT) X-Received: by 10.28.88.144 with SMTP id m138mr10786919wmb.79.1472672789512; Wed, 31 Aug 2016 12:46:29 -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 u1si1625192wju.85.2016.08.31.12.46.28; Wed, 31 Aug 2016 12:46:29 -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; 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 0627D689AD6; Wed, 31 Aug 2016 22:46:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C8128689A75 for ; Wed, 31 Aug 2016 22:46:12 +0300 (EEST) Received: by mail-pa0-f44.google.com with SMTP id fi15so21561456pac.1 for ; Wed, 31 Aug 2016 12:46:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=W1uv+oXDxWIviBDgtcg+oRhsyRCMz51abDPiCu+t/Qo=; b=EM/swVwlYuOjToE2nPgAAO6DQu0t85Dcd4/cW6INPqUEPyC33IiPSFulqTZLS+x80k J96TcncMPsZnpif6gyaliIdCE3K/reiq++1EgUl7f4CSQP879DB/Jve7qAjsPXnKQdyJ mZuIFuXrG27AHXIhMnf+xFpAFbaosAaqzj0rgPag6x1mq2rdlZC/8OGwwUOnWzv9cgBf x+hJjBfhBWGLQjjDIO1072Fbbyqx7GZYGnCS7UxSBOBEwywGwkHTMSyugZ76jGd8Ze+C muuSa86PbM41bwd1QmXs8DrRTb6XTIGOWeT0XUBT2vFj80k/lwktVQwxu9Hu/wb6KSjL jtHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=W1uv+oXDxWIviBDgtcg+oRhsyRCMz51abDPiCu+t/Qo=; b=B/hzS7hY80OHwT4trBjee55y6yL01p+cmcVqccxnQwl2uM5p0OWTRVPdFwO6gOyVFS ocXXN3xUxOQDu225N3uHnE/pqIw5O6Iude1/GfMhH0x9+/KvNc8ufIoRUJgyLNAUyyoG HPrAMpyTgzbU68RUBrmuX5SzlSiFdtXfCuBK7tO9byguCr9qNMK6YAP6gD5wAIZWX20S ZllZIZrUO26iw+5KQIyFTmfA5acHh0y7sLwnDTVBifsZ+Yc2rE4M9tVquxWSffjRNRf+ RanBH/kRp+KJeCVvjQxuKY4+omrVv7ME5KgSGKR1c869EuB20bJEBzwv0AMZ0JAf1p6N +TOQ== X-Gm-Message-State: AE9vXwOUcftKiJJYfCkP3TG5Ou3PY6dTEiFwe2N+jgZJSNYiuGMImli5FShGsuKqi4Icj/ig X-Received: by 10.66.145.73 with SMTP id ss9mr19853956pab.82.1472672445111; Wed, 31 Aug 2016 12:40:45 -0700 (PDT) Received: from pinkiepie.mtv.corp.google.com ([172.27.82.120]) by smtp.gmail.com with ESMTPSA id h86sm1598812pfh.46.2016.08.31.12.40.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Aug 2016 12:40:44 -0700 (PDT) From: Lucas Cooper To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Aug 2016 12:40:41 -0700 Message-Id: <1472672441-26784-1-git-send-email-bobobo@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <20160829225933.GI4692@nb4> References: <20160829225933.GI4692@nb4> Subject: [FFmpeg-devel] [PATCH] Add max value output option to psnr stats log. 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 Cc: Lucas Cooper MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This allows retroactive calculation/aggregation of PSNR from the stats log. --- doc/filters.texi | 10 ++++++++++ libavfilter/vf_psnr.c | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 8cef0a0..92a49e6 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10583,6 +10583,12 @@ standard output. Specifies which version of the stats file format to use. Details of each format are written below. Default value is 1. + +@item stats_add_max +Determines whether the max value is output to the stats log. +Default value is 0. +Requires stats_version >= 2. If this is set and stats_version < 2, +the filter will return an error. @end table The file printed if @var{stats_file} is selected, contains a sequence of @@ -10619,6 +10625,10 @@ frames for the component specified by the suffix. @item psnr_y, psnr_u, psnr_v, psnr_r, psnr_g, psnr_b, psnr_a Peak Signal to Noise ratio of the compared frames for the component specified by the suffix. + +@item max_avg, max_y, max_u, max_v +Maximum allowed value for each channel, and average over all +channels. @end table For example: diff --git a/libavfilter/vf_psnr.c b/libavfilter/vf_psnr.c index 3bec747..320f433 100644 --- a/libavfilter/vf_psnr.c +++ b/libavfilter/vf_psnr.c @@ -45,6 +45,7 @@ typedef struct PSNRContext { char *stats_file_str; int stats_version; int stats_header_written; + int stats_add_max; int max[4], average_max; int is_rgb; uint8_t rgba_map[4]; @@ -63,6 +64,7 @@ static const AVOption psnr_options[] = { {"stats_file", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, {"f", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, {"stats_version", "Set the format version for the stats file.", OFFSET(stats_version), AV_OPT_TYPE_INT, {.i64=1}, 1, 2, FLAGS }, + {"output_max", "Add raw stats (max values) to the output log.", OFFSET(stats_add_max), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, { NULL } }; @@ -182,6 +184,12 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, for (j = 0; j < s->nb_components; j++) { fprintf(s->stats_file, ",psnr_%c", s->comps[j]); } + if (s->stats_add_max) { + fprintf(s->stats_file, ",max_avg"); + for (j = 0; j < s->nb_components; j++) { + fprintf(s->stats_file, ",max_%c", s->comps[j]); + } + } fprintf(s->stats_file, "\n"); s->stats_header_written = 1; } @@ -196,6 +204,13 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, fprintf(s->stats_file, "psnr_%c:%0.2f ", s->comps[j], get_psnr(comp_mse[c], 1, s->max[c])); } + if (s->stats_version == 2 && s->stats_add_max) { + fprintf(s->stats_file, "max_avg:%d ", s->average_max); + for (j = 0; j < s->nb_components; j++) { + c = s->is_rgb ? s->rgba_map[j] : j; + fprintf(s->stats_file, "max_%c:%d ", s->comps[j], s->max[c]); + } + } fprintf(s->stats_file, "\n"); } @@ -210,6 +225,11 @@ static av_cold int init(AVFilterContext *ctx) s->max_mse = -INFINITY; if (s->stats_file_str) { + if (s->stats_version < 2 && s->stats_add_max) { + av_log(ctx, AV_LOG_ERROR, + "stats_add_max was specified but stats_version < 2.\n" ); + return AVERROR(EINVAL); + } if (!strcmp(s->stats_file_str, "-")) { s->stats_file = stdout; } else {