From patchwork Sat May 1 13:07:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 27551 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:cc:0:0:0:0 with SMTP id m12csp418849pxt; Sat, 1 May 2021 06:08:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzj9cakQa8A8SM+9uhXBW3G58s7lLAPN7g4kOC/fdutQPQ+nl3ZBNbnorQI3x0+Sz3AokOE X-Received: by 2002:a17:906:d0c5:: with SMTP id bq5mr6912921ejb.340.1619874498419; Sat, 01 May 2021 06:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619874498; cv=none; d=google.com; s=arc-20160816; b=Q6yw4SfH6i/rTb9OhuUu0uUKuhRfs1Tn4USUpDm9BoJDl8pHdqOioQk9WtgGt8T9PE B1naE62jsO5sv3Hpi/OLwR26Ory2A2UpgxmrH9GAswQi8T7HRolrnK5stFL2rYcSqHug 7L1dGopVPyk0uKLbi0X0YZNogAB01v3Fn25XT1rNGXxtYru/I1nq1sEVsO7cAfYeXqW8 VP+a9oMoCtjySVqA/IeRqxA2JJ/nrGIiJ1xkzfvZH55cjJN2mXBS1mbhcTwMZaJhpEw9 fzj97aVbz1zo4ch82lB0Rq4qKO4Yf7MaWfmt1CM13FT5H83SSny1Dtb7SXwLY5QxIiIX 7cQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=P108VCGyaCz5esC63MmHAdLRqYCxra/idXe7dECtjS8=; b=qrCj6GNOtI4rJZAxdpKM2Cj7uetW/jMBd2alwpOMo7lHo05muTDbsj47zp+6FrWysX Ho8AfRdgqVjiyxo1gRiKE7kSEyRCT6OhEdwvPMGy7UvhElmGqYT6AuOVUt2YxzS0sn7N bwbJzLi1NcxrL/D1yy1qK9xvEtX9BHkjDDyeUK29zp3UKOs6QekptnqrViWz3L2wSpoA Hy8fAAQtW3L2hgzuPaj4SDXGkQO7+w0GEGRhfH1bqacQvQPLJzss7LOczdEg7Joe9zhC 5CP+nqnxn0b/TMp+bFOiblw7apLYC7lcQ4FZ7TAfkw5WhJmfGG4IZ87AQuC3lYQs5VyP Us8g== ARC-Authentication-Results: i=1; mx.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a20si5898459ejf.345.2021.05.01.06.08.17; Sat, 01 May 2021 06:08:18 -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; 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 023DB6881C2; Sat, 1 May 2021 16:08:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 804B7680A0D for ; Sat, 1 May 2021 16:08:06 +0300 (EEST) Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4FXV0P681mzQk2l for ; Sat, 1 May 2021 15:08:05 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id 4QoCQJkhgAM6 for ; Sat, 1 May 2021 15:08:02 +0200 (CEST) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 May 2021 18:37:45 +0530 Message-Id: <20210501130745.629-1-ffmpeg@gyani.pro> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.26 / 15.00 / 15.00 X-Rspamd-Queue-Id: CF5EF17EF X-Rspamd-UID: 86c152 Subject: [FFmpeg-devel] [PATCH] ffprobe: add option to control optional fields display X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cuv4gqzJpbl6 --- doc/ffprobe.texi | 6 ++++++ fftools/ffprobe.c | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi index d7fab4ff40..59a397a225 100644 --- a/doc/ffprobe.texi +++ b/doc/ffprobe.texi @@ -335,6 +335,12 @@ Show information about all pixel formats supported by FFmpeg. Pixel format information for each format is printed within a section with name "PIXEL_FORMAT". +@item -show_optional_fields @var{value} +Some writers viz. JSON and XML, omit the printing of fields with invalid or non-applicable values, +while other writers always print them. This option enables one to control this behaviour. +Valid values are @code{always}/@code{1}, @code{never}/@code{0} and @code{auto}/@code{-1}. +Default is @var{auto}. + @item -bitexact Force bitexact output, useful to produce output which is not dependent on the specific build. diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 7b28f6b3ce..b07032bd88 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -117,6 +117,11 @@ static int use_byte_value_binary_prefix = 0; static int use_value_sexagesimal_format = 0; static int show_private_data = 1; +#define SHOW_OPTIONAL_FIELDS_AUTO -1 +#define SHOW_OPTIONAL_FIELDS_NEVER 0 +#define SHOW_OPTIONAL_FIELDS_ALWAYS 1 +static int show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO; + static char *print_format; static char *stream_specifier; static char *show_data_hash; @@ -745,8 +750,10 @@ static inline int writer_print_string(WriterContext *wctx, const struct section *section = wctx->section[wctx->level]; int ret = 0; - if ((flags & PRINT_STRING_OPT) - && !(wctx->writer->flags & WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS)) + if (show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER || + (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO + && (flags & PRINT_STRING_OPT) + && !(wctx->writer->flags & WRITER_FLAG_DISPLAY_OPTIONAL_FIELDS))) return 0; if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) { @@ -3244,6 +3251,17 @@ static void ffprobe_show_pixel_formats(WriterContext *w) writer_print_section_footer(w); } +static int opt_show_optional_fields(void *optctx, const char *opt, const char *arg) +{ + if (!av_strcasecmp(arg, "always")) show_optional_fields = SHOW_OPTIONAL_FIELDS_ALWAYS; + else if (!av_strcasecmp(arg, "never")) show_optional_fields = SHOW_OPTIONAL_FIELDS_NEVER; + else if (!av_strcasecmp(arg, "auto")) show_optional_fields = SHOW_OPTIONAL_FIELDS_AUTO; + + if (show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO && av_strcasecmp(arg, "auto")) + show_optional_fields = parse_number_or_die("show_optional_fields", arg, OPT_INT, SHOW_OPTIONAL_FIELDS_AUTO, SHOW_OPTIONAL_FIELDS_ALWAYS); + return 0; +} + static int opt_format(void *optctx, const char *opt, const char *arg) { iformat = av_find_input_format(arg); @@ -3631,6 +3649,7 @@ static const OptionDef real_options[] = { { "show_library_versions", 0, { .func_arg = &opt_show_library_versions }, "show library versions" }, { "show_versions", 0, { .func_arg = &opt_show_versions }, "show program and library versions" }, { "show_pixel_formats", 0, { .func_arg = &opt_show_pixel_formats }, "show pixel format descriptions" }, + { "show_optional_fields", HAS_ARG, { .func_arg = &opt_show_optional_fields }, "show optional fields" }, { "show_private_data", OPT_BOOL, { &show_private_data }, "show private data" }, { "private", OPT_BOOL, { &show_private_data }, "same as show_private_data" }, { "bitexact", OPT_BOOL, {&do_bitexact}, "force bitexact output" },