From patchwork Wed Oct 13 04:49:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31091 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp5559582ioa; Tue, 12 Oct 2021 21:50:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9bNYxh8wqfXnhxEr92eK3edw2gJEeWt6lIh+Wz+FEUnm8iRvzQsfwGwVASu/ZnNSMoH7T X-Received: by 2002:a05:6402:11cf:: with SMTP id j15mr6182498edw.232.1634100622126; Tue, 12 Oct 2021 21:50:22 -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 h1si17923743edk.285.2021.10.12.21.50.21; Tue, 12 Oct 2021 21:50:22 -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=@hotmail.com header.s=selector1 header.b=tfNtsmGh; arc=fail (body hash mismatch); 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=hotmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 593DE68A8F5; Wed, 13 Oct 2021 07:50:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12olkn2082.outbound.protection.outlook.com [40.92.21.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CDBDD68803D for ; Wed, 13 Oct 2021 07:50:04 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BgT/Wr4etRC9+6+4oSsTNI7ceCAr1E2N1NeSRomDRqGAV8oMRR3IyNHDyfodD7zULzQhIYoO0LK4cNZLgcFUJf9VgmzGq3oBiQVLxxcBLihm6FVb+WMqEAOvZ3rDS0X3a+l+lZtryDDZTIAew9BW2VYMiPH2vVSgCGUfqHUPKdsMwuJoUktx5Y9gH3ftY8en0dDM6DxL0RID/BStAfaVzUEKphRxaLWSz/glDR7wgFp701DepspExe4kUXAq7Ehehf6xfqQ/G4jI1A67GyxRXT9RYTkbFc4AI2bhSYNx+RAjDlxhd/H7oN4LvuqPSN9LK0F6JJ7TQ9zAb+UibwmaPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ADUYUzvTJlUhyRSWpOl/t7DiPwP3a8csnclRYHNUpCg=; b=mDeXIVr7yI/+TivXV3rAxLcAvS+/XRsY7YRQPSw6NacGURhDDBBVSfakcgS1Clo6/tYU2FjdfMb378hX6cFJsLQmAJ5X5R6Z1iPRLamyHINrpXccnyY/E9DoZdR0PKlrAhs6Wvc/3zFZLP2st1oI34SzeK97kdigYTXeMZD1jJVL/4ud+spNthH6pFnHyjbzS1X7+6FG0MNlR2ntbZEWKvvNoHmYFJqctGqjnpFc4Nd7WC1/4UPva2kpxrOLsM0A7BPlgWKBNiUxCUQPxyJDbKB+ujDAOeJB7MYLvx0mR4tTXPAtQCtROQyrQ15JOyQ6or2wVo3SleWiHLm/GpmfWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ADUYUzvTJlUhyRSWpOl/t7DiPwP3a8csnclRYHNUpCg=; b=tfNtsmGh93APJ3q0RMqMaLhSUXC+RT7deZyvYjJ8XtD3g0PQ0y0y6y+D7HDnRMdHqCbVXaYXPOJlEnxds+kuSfoavmFn7YExVT4jepp1aLTly5RWN4JKRLJ3CqWrR7axZXttZLdeyDg+CttZRoLczaCy9xhh6XDEHJXt3act91a9NXXvybhNsHQ4s1d65tcNN+7ol6DKoPqMo2jdMIapIaS+JZ+f1EtOwo88jM5zVoSAW3Gucwm/+5oGwn/dF3YSUgvn1W8KwQMEM5qjFFAMkUODqJlRXOsuQ0ZGZRn42fuu+PxcA4pL1/LRpMavPuc0u5llhEEJZwb6nm7b1GtpWw== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB6205.namprd04.prod.outlook.com (2603:10b6:208:d5::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.19; Wed, 13 Oct 2021 04:49:58 +0000 Received: from MN2PR04MB5981.namprd04.prod.outlook.com ([fe80::ecfe:2528:2012:22cb]) by MN2PR04MB5981.namprd04.prod.outlook.com ([fe80::ecfe:2528:2012:22cb%5]) with mapi id 15.20.4587.026; Wed, 13 Oct 2021 04:49:57 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH 2/5] fftools/cmdutils: Print filter input/output formats in help output Thread-Index: AQHXv+3FjFYbef1VDEW/18uDaAl0Jw== Date: Wed, 13 Oct 2021 04:49:57 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [tqs80TBnBAKVMI6s221HJzmtWt/hiMz6] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 049aa640-5df2-4fb2-d466-08d98e04e85f x-ms-traffictypediagnostic: MN2PR04MB6205: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 2UW/cG5yHbFDn8u6+W4VCBkBfim7a2OwE4eiKM+33xd9RJ0XgydsbvFTd7uF+3rOs15NSiNTb0A8uB/fhPRcKN4g2fJc6g4ong/czLIEZKOu/1oiMLR6uZ9TeoU8pAGWJ++IunAzYNizQ0lVNr4B49MbF66d1xtkK4NZK1gkGS2y3D2Jmg3Hc83XHG2oB6BWyjJ/Ge7lxKY4W1NElbS9Nle/rGRD0CWzc+utTMG7wyplIPEkp/xxB5S8OyQOvIkEKww8TJpccK2xFOUXQzBIuITxnxB172sWPwouXHl5hi9Jmfzd+WOpWeJsuLel17RbEFH6TgApNWlkpE9EiNOEmkP+GvEzReGxU5w2QJO9qcjQQi6LENP+dtaXrpabQomVo63ZVw76QiM5U9vHdIiTPQLGNX3gQjFK5uIso/9q51E3CQ4G1ADU+kvw0RPgYhgk x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: FJBBzKd/AQPoze6z48NIKiN8QEgKfCB0bY/rPPj4Bv0RR8zZ9xJlsayFkQ2YTaBZnVuCazqBaSFPbNwQSP71r5RLyR3kj0mv318NO5g5+014Hq+bMntNtA5BAlCSJKOdsXHUWXF/GQH6hVh37Sh80Q== x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-529c7.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR04MB5981.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 049aa640-5df2-4fb2-d466-08d98e04e85f X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Oct 2021 04:49:57.8524 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6205 Subject: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print filter input/output formats in help output 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: 2oU7iMkPo5zG Exmaple command: ffmpeg -h filters=overlay Output: Filter overlay Overlay a video source on top of the input. slice threading supported Inputs: #0: main (video) [yuv420p, yuvj420p, yuva420p, nv12, nv21] #1: overlay (video) [yuva420p] Outputs: #0: default (video) [yuv420p, yuvj420p, yuva420p, nv12, nv21] overlay AVOptions: x [...] Signed-off-by: softworkz --- fftools/cmdutils.c | 89 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index aa706c33ab..a112998574 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -33,6 +33,7 @@ #include "compat/va_copy.h" #include "libavformat/avformat.h" #include "libavfilter/avfilter.h" +#include #include "libavdevice/avdevice.h" #include "libswscale/swscale.h" #include "libswresample/swresample.h" @@ -1922,11 +1923,38 @@ static void show_help_muxer(const char *name) } #if CONFIG_AVFILTER +static void print_link_formats(enum AVMediaType mediaType, AVFilterFormats* formats) +{ + if (formats == NULL) + return; + + printf(" ["); + + for (unsigned i = 0; i < formats->nb_formats; i++) { + if (formats->formats[i] >= 0) { + if (i > 0) + printf(", "); + if (mediaType == AVMEDIA_TYPE_VIDEO) { + printf("%s", av_get_pix_fmt_name(formats->formats[i])); + } else if (mediaType == AVMEDIA_TYPE_AUDIO) { + printf("%s", av_get_sample_fmt_name(formats->formats[i])); + // TODO: Uncomment once subtitle filtering is added + ////} else if (mediaType == AVMEDIA_TYPE_SUBTITLE) { + //// printf("%s", av_get_subtitle_fmt_name(formats->formats[i])); + } + } + } + + printf("]"); +} + static void show_help_filter(const char *name) { #if CONFIG_AVFILTER const AVFilter *f = avfilter_get_by_name(name); - int i, count; + unsigned i, count; + int got_formats = 0; + AVFilterContext *filter_context; if (!name) { av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n"); @@ -1943,12 +1971,50 @@ static void show_help_filter(const char *name) if (f->flags & AVFILTER_FLAG_SLICE_THREADS) printf(" slice threading supported\n"); + filter_context = avfilter_alloc(f, "filter"); + if (!filter_context) { + av_log(NULL, AV_LOG_ERROR, "Failed create filtercontext\n"); + return; + } + + if (filter_context->nb_outputs == 0) { + filter_context->outputs= av_calloc(1, sizeof(AVFilterLink*)); + filter_context->outputs[0] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink)); + } + + if (filter_context->nb_inputs == 0) { + filter_context->inputs= av_calloc(1, sizeof(AVFilterLink*)); + filter_context->inputs[0] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink)); + } + + for (i = 0; i < filter_context->nb_inputs; i++) + filter_context->inputs[i] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink)); + + for (i = 0; i < filter_context->nb_outputs; i++) + filter_context->outputs[i] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink)); + + if (filter_context->filter->nb_inputs) + filter_context->inputs[0]->type = avfilter_pad_get_type(f->inputs, 0); + + if (filter_context->filter->nb_outputs) + filter_context->outputs[0]->type = avfilter_pad_get_type(f->outputs, 0); + + if (filter_context->nb_inputs > 0 || filter_context->nb_outputs > 0) + got_formats = !avfilter_query_formats(filter_context); + printf(" Inputs:\n"); count = avfilter_filter_pad_count(f, 0); for (i = 0; i < count; i++) { - printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i), - media_type_string(avfilter_pad_get_type(f->inputs, i))); + const enum AVMediaType media_type = avfilter_pad_get_type(f->inputs, i); + + printf(" #%d: %s (%s)", i, avfilter_pad_get_name(f->inputs, i), + media_type_string(media_type)); + + if (got_formats && (i < filter_context->nb_inputs)) + print_link_formats(media_type, filter_context->inputs[i]->outcfg.formats); + printf("\n"); } + if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS) printf(" dynamic (depending on the options)\n"); else if (!count) @@ -1957,8 +2023,13 @@ static void show_help_filter(const char *name) printf(" Outputs:\n"); count = avfilter_filter_pad_count(f, 1); for (i = 0; i < count; i++) { - printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i), - media_type_string(avfilter_pad_get_type(f->outputs, i))); + const enum AVMediaType media_type = avfilter_pad_get_type(f->outputs, i); + printf(" #%d: %s (%s)", i, avfilter_pad_get_name(f->outputs, i), + media_type_string(media_type)); + + if (got_formats && i < filter_context->nb_outputs) + print_link_formats(media_type, filter_context->outputs[i]->incfg.formats); + printf("\n"); } if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS) printf(" dynamic (depending on the options)\n"); @@ -1970,6 +2041,14 @@ static void show_help_filter(const char *name) AV_OPT_FLAG_AUDIO_PARAM); if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE) printf("This filter has support for timeline through the 'enable' option.\n"); + + if (filter_context->nb_inputs == 0) + filter_context->nb_inputs = 1; + if (filter_context->nb_outputs == 0) + filter_context->nb_outputs = 1; + + avfilter_free(filter_context); + #else av_log(NULL, AV_LOG_ERROR, "Build without libavfilter; " "can not to satisfy request\n");