From patchwork Tue Dec 4 20:42:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 11278 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1B1A444D466 for ; Tue, 4 Dec 2018 22:47:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A479768A52D; Tue, 4 Dec 2018 22:47:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 92F6368A451 for ; Tue, 4 Dec 2018 22:47:32 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id q18so17391635wrx.9 for ; Tue, 04 Dec 2018 12:47:41 -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=EmUp+/EdVOtlUIORnry6zXHEFSbBGDchs/Wade2vA5c=; b=AKq7qYGqEKOjvTyZnetT0Eq/KirPMRp7HaMvHLHhESSSfY4h7SfA+8mOZ9xVoxuBpm vTK/NpNADSXawIDIqtt0jBMgpoJC1UvKboGD1HVVOAfxd6Af+03w/01UEXAzbwxmXqge QFNuQhlsexNVIb/+1AKLOOEXuIkAriIx8PGNGZKIQ4OY5R97xv1ucslCMYlsxdJbbZPV rZOdBIRV9/McM9lZIYnzsXKM/9KObscaqhz2Us7oBCZkAQ1Q4SR2RgVnX8KT/rl3v4Hf baBQTbuKeNYjR4L7xuBxEOCYw+wP7S+qCqxh42bvxl6CnHujJ/c/k+xSV6XteXppp/dG eGmA== 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=EmUp+/EdVOtlUIORnry6zXHEFSbBGDchs/Wade2vA5c=; b=ikll0BTyLm0HdCnzTAbfPCc4lOX+xASDn9MuNq4WjZxcTfAPkdNfoY7Zgpwkge916Q w0Dx2/gGGTIRdsX97E2i18qjk78LL6lTwdl8ZzFfgi5Hh+gfUFX6ry8vioqo4c5XPDbx Tt8Iriq9JisDV5MG67qM5anyvLPvcYTm5PAaNDcjNuH54yOLHBRoUnYRnvESokem7HbW OXhc4dOcmkk0VeZ05zmvackPWO3oJ5vgHIztxymj4iLbeg/bRH+p7nliy2lGgDiDrP72 HrLop9mFaNxDWqTUGX1ycG8uJBxw0LVKwY4XEkapkZrpcAomQWQ2n2GAd5ERH78TWCNE 4Hig== X-Gm-Message-State: AA+aEWYOMvFaRvUnVtRhzJVzkEQ7h3dfUr7vepKC6jRvEX2IohCT4in9 hHsuElRKdat4+pgl8deay9V417Tv X-Google-Smtp-Source: AFSGD/XVQGI3NpBfn8AGU0h222CnaAdJyHCb44M48AajwFBX+7RhMBWlbZouaK5t+yISwXwSP4NYBQ== X-Received: by 2002:adf:cc91:: with SMTP id p17mr20073005wrj.118.1543956140540; Tue, 04 Dec 2018 12:42:20 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id m4sm16645729wmi.3.2018.12.04.12.42.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 12:42:19 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 4 Dec 2018 21:42:11 +0100 Message-Id: <20181204204211.15289-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_showinfo: allow checksums calculation to be disabled 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" Fixes #6987. Signed-off-by: Paul B Mahol --- doc/filters.texi | 7 +++++ libavfilter/vf_showinfo.c | 56 ++++++++++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 41fbbc5329..a795531584 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -15304,6 +15304,13 @@ Keep the same colorspace property (default). Show a line containing various information for each input video frame. The input video is not modified. +This filter supports the following options: + +@table @option +@item checksums +Calculate checksums of each plane. By default enabled. +@end table + The shown line contains a sequence of key/value pairs of the form @var{key}:@var{value}. diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 37e73b60aa..9e84197a55 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -28,6 +28,7 @@ #include "libavutil/display.h" #include "libavutil/imgutils.h" #include "libavutil/internal.h" +#include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavutil/spherical.h" #include "libavutil/stereo3d.h" @@ -38,6 +39,21 @@ #include "internal.h" #include "video.h" +typedef struct ShowInfoContext { + const AVClass *class; + int calculate_checksums; +} ShowInfoContext; + +#define OFFSET(x) offsetof(ShowInfoContext, x) +#define VF AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM + +static const AVOption showinfo_options[] = { + { "checksum", "calculate checksums", OFFSET(calculate_checksums), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, VF }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(showinfo); + static void dump_spherical(AVFilterContext *ctx, AVFrame *frame, AVFrameSideData *sd) { AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data; @@ -141,13 +157,14 @@ static void update_sample_stats(const uint8_t *src, int len, int64_t *sum, int64 static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { AVFilterContext *ctx = inlink->dst; + ShowInfoContext *s = ctx->priv; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); uint32_t plane_checksum[4] = {0}, checksum = 0; int64_t sum[4] = {0}, sum2[4] = {0}; int32_t pixelcount[4] = {0}; int i, plane, vsub = desc->log2_chroma_h; - for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) { + for (plane = 0; plane < 4 && s->calculate_checksums && frame->data[plane] && frame->linesize[plane]; plane++) { uint8_t *data = frame->data[plane]; int h = plane == 1 || plane == 2 ? AV_CEIL_RSHIFT(inlink->h, vsub) : inlink->h; int linesize = av_image_get_linesize(frame->format, frame->width, plane); @@ -167,8 +184,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) av_log(ctx, AV_LOG_INFO, "n:%4"PRId64" pts:%7s pts_time:%-7s pos:%9"PRId64" " - "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c " - "checksum:%08"PRIX32" plane_checksum:[%08"PRIX32, + "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c ", inlink->frame_count_out, av_ts2str(frame->pts), av_ts2timestr(frame->pts, &inlink->time_base), frame->pkt_pos, desc->name, @@ -177,19 +193,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) !frame->interlaced_frame ? 'P' : /* Progressive */ frame->top_field_first ? 'T' : 'B', /* Top / Bottom */ frame->key_frame, - av_get_picture_type_char(frame->pict_type), - checksum, plane_checksum[0]); - - for (plane = 1; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) - av_log(ctx, AV_LOG_INFO, " %08"PRIX32, plane_checksum[plane]); - av_log(ctx, AV_LOG_INFO, "] mean:["); - for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) - av_log(ctx, AV_LOG_INFO, "%"PRId64" ", (sum[plane] + pixelcount[plane]/2) / pixelcount[plane]); - av_log(ctx, AV_LOG_INFO, "\b] stdev:["); - for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) - av_log(ctx, AV_LOG_INFO, "%3.1f ", - sqrt((sum2[plane] - sum[plane]*(double)sum[plane]/pixelcount[plane])/pixelcount[plane])); - av_log(ctx, AV_LOG_INFO, "\b]\n"); + av_get_picture_type_char(frame->pict_type)); + + if (s->calculate_checksums) { + av_log(ctx, AV_LOG_INFO, + "checksum:%08"PRIX32" plane_checksum:[%08"PRIX32, + checksum, plane_checksum[0]); + + for (plane = 1; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) + av_log(ctx, AV_LOG_INFO, " %08"PRIX32, plane_checksum[plane]); + av_log(ctx, AV_LOG_INFO, "] mean:["); + for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) + av_log(ctx, AV_LOG_INFO, "%"PRId64" ", (sum[plane] + pixelcount[plane]/2) / pixelcount[plane]); + av_log(ctx, AV_LOG_INFO, "\b] stdev:["); + for (plane = 0; plane < 4 && frame->data[plane] && frame->linesize[plane]; plane++) + av_log(ctx, AV_LOG_INFO, "%3.1f ", + sqrt((sum2[plane] - sum[plane]*(double)sum[plane]/pixelcount[plane])/pixelcount[plane])); + av_log(ctx, AV_LOG_INFO, "\b]"); + } + av_log(ctx, AV_LOG_INFO, "\n"); for (i = 0; i < frame->nb_side_data; i++) { AVFrameSideData *sd = frame->side_data[i]; @@ -285,4 +307,6 @@ AVFilter ff_vf_showinfo = { .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."), .inputs = avfilter_vf_showinfo_inputs, .outputs = avfilter_vf_showinfo_outputs, + .priv_size = sizeof(ShowInfoContext), + .priv_class = &showinfo_class, };