From patchwork Thu Oct 21 03:19:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31186 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp127394ioa; Wed, 20 Oct 2021 20:20:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZoGtZXwGVI2/xPf97sXOzFB/FFC+u64KQpjmEx7IOQ9SUZS6G8YiVRxH1hyIGzmEw03+E X-Received: by 2002:a50:ef10:: with SMTP id m16mr3994806eds.224.1634786420843; Wed, 20 Oct 2021 20:20:20 -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 v5si7766536edi.595.2021.10.20.20.20.16; Wed, 20 Oct 2021 20:20:20 -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=qqkTNmPM; 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 6D03B68A7D4; Thu, 21 Oct 2021 06:19:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11olkn2034.outbound.protection.outlook.com [40.92.20.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 64CB368A5FC for ; Thu, 21 Oct 2021 06:19:29 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W7G5TfG7Uh4cd+8WKwFK3hfs2fBJegS0kAehpK3ONHESQyfUEQLKf/hGsiHpw+Nsw2V+5RsWaKhahEmAV7/YsCDb8JFNtLnuBqoYMJRrOAtjirN90agS18A1xrdjdLlpuW308I/f96sisWGkb7dkO+hKeOzOVypURG+7+ryb60JI9Yfck7rHLKfsjum8lkNnLXEytCM/FGlyocGKR9Lgdnp7uLSUu0pp4eH0RMbLjs5R0+IZc4cQyZmmcOMDWhIs5XGkSPB6zvF5diFT6RqKiTqogyp+yKBU6/0daz39Cneicw/cHEcWc9tFKjye65ZZFJ1zOPhF0jBOal05Hrgagw== 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=bDL97GB4jejrgjmRzhDsP7shYz99S7YBdbklbSFNiW8=; b=J/eW81Df1iHX8PQtcC9CzlAgZAIp857/TSM7Cs4JMQ/eBYflWAp3RoVgrD9tMTsicSClILs4L/u94Dp81fU/fIE2eaewOUOx5jNkXG1pWp/db48meknPIurfYKAuTXTbzL3DKWH4zrkJ+TxaklaOQ0ozBaL+HNhK2BrCW7mKQbGT1j2NGlpLfvfNKXGw162c8Vo5nvAWaKeNk9CvR/XP0lGMKiDvY+X0yV7XWbo1qOcB8MgC1n0hJnWqjR8UQKqWjcACSQHsVaPMeHxGnCH2FA6pmHRPkfO3P76tU9VwmrcP9ak0flITj7WfX9Xq4p0ip2Yl9u05MVgF+gRUwd5r8Q== 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=bDL97GB4jejrgjmRzhDsP7shYz99S7YBdbklbSFNiW8=; b=qqkTNmPMuYGlhQ9TdNjj6d4sCrNdQSMC+rzWR5+oA4jD/Djp4EssUTqGvs2ypIQIJK8UC+hiZObfBTj7BEMILCs6eKskP59Nk55vfZp9sRdyk4IclM6q7jgoghYdZKy8Q2x3t72ywcNzp0ZgI699AllowiJFuAMEXnpNOXayCCgPDP56UBp3tUHfs9I5lCLnBU8uqtceuP8o9vnui/CpFjaTJIHsZKWCONlP2FQUO6mfb/NP0/01c+TcQ998jkBLqnSmmxBkbHOVWMSrHrBeqKQ0OPiKrsY2Lp18g8VZVCzHKim1vp58IU9AUXR8eaH2nf3A0PzL62+0pQA9P2E48A== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB6238.namprd04.prod.outlook.com (2603:10b6:208:e4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18; Thu, 21 Oct 2021 03:19:18 +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.4608.018; Thu, 21 Oct 2021 03:19:18 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v14 05/14] avfilter/avfilter: Handle subtitle frames Thread-Index: AQHXxipvM15Dpqu6DkKxAyggORWVIQ== Date: Thu, 21 Oct 2021 03:19:18 +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: [mPmE6+//9bhry4s5iA5f2qSNbeIIr1h3] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ef8dfa6e-893b-4dd9-a4e2-08d9944191cd x-ms-traffictypediagnostic: MN2PR04MB6238: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: HipOdKxyT7d3AfLfvcc40Gx8rhFyQUmKKZrsLrAY4NCQg8T8kPiRf0R8/ABTc34mfpDdoYVzL931eKqgVFeJHyjgnQ9X0xO6bDXX4qi77/yCboKloPXYtsWjSfR81tcyr/1K1s/Q2lejELnX3yDgy3K4EncXZakWDPW1ed1Qt5jNTMewcnrcZYtyi/OdwgZbRjq+dtxNebM7IOd18/fjnfb8UzuR0Dp85D2gRiuhF8qzmPWWFTQr26QEC9Dw4EkSQXIOUH3SeXHGi221GUeKlzp207nMjIszSr+ypOI5x3tdrfIi4NLg0p22Mb+ueihAza+XRJ5npD/uazdFOGdF+AqpYo2Y7k65Uq3CS9VWvS0HhiIbPzMSUwvlyiXfGXR89FKpbcdSKQ28phlB9uoFrJVVbt/1GODAXaNSDb/MUi/01T46luorMo0s27TOVC0YlDdMvnLrMMBwv+2mgJ1ThGlr9x5K+LuN9XjFBAx42o1JzlnfBj3ihCHY3m7Yx7EuNMVrfrCxD9383nkdPQWAAnXkeX2y0v6g+kR08aqGjNc= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: E6NHBhyC5TC16TJnItMvK7wRRlj9Oj7akIu6OaGRcpA3tpBp8gITfZIbpl0r4Z8yVQi1Xx5coDhehxAy+vqMT9XLkCJfBtV+z+4htNjAJI+DtqDoRZ8ihEL3ctHjmbm70urNd7Lzzrnh5kZCWgmHnqsiouoXP8A+eIg3jvY84T/C44TZ79GrZ4/h5hIFZifB7jXHxMdFXxkRVMefVoQRyL4vHL3uC6jDF5FcS8idLhSb+rgRUkVXUP4sN2d9sxDEApWs8ohud7NzTQdpfw8yhnqC466U/P2zascrSBCmDQ3r/BetejIg9S0fUHTHwA8Nqj+xEbggaXeYZwdPXnm+5sp6dZRzA2JcJWR4Nfx1gEvvH2hiJ/OzKrXG3XzBPy5uk+WHMLNOWngu2GJam/thYUzFjcYKTgaw0DxcCFTFJSxzNMoGUCJdI5unU35MvItDAlpfxey2G+CIhgNYu1SnFphTM2ZJYd3aHbw4ACwo1djNrUnEuGag/oTVHDy3DO5oq+Niw8HnOgbOsdeGBxfb3r94LloquOCkXPFBatt4xiYQ5yiMTg43egHbqeZRTcfo1WcRO2ceG3O4NAvEtEMMQsFNoJBCTP2QJvoZL1NGMYjBCX+0rM9LF9N+1gfZK9kLU02z7SOI0tnwaqkteQ9PQMlGAudTyJahrR3ETd3DXVBX4EtzBNEgc9j1eeatI67j9Xs4ESzzagLSfuIfaksAqg== 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: ef8dfa6e-893b-4dd9-a4e2-08d9944191cd X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Oct 2021 03:19:18.8754 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-userprincipalname: softworkz@hotmail.com X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6238 Subject: [FFmpeg-devel] [PATCH v14 05/14] avfilter/avfilter: Handle subtitle frames 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: g2vbVbNCCTQ4 Signed-off-by: softworkz --- libavfilter/avfilter.c | 8 +++++--- libavfilter/avfilter.h | 11 +++++++++++ libavfilter/avfiltergraph.c | 5 +++++ libavfilter/formats.c | 22 ++++++++++++++++++++++ libavfilter/formats.h | 3 +++ libavfilter/internal.h | 18 +++++++++++++++--- 6 files changed, 61 insertions(+), 6 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index df5b8f483c..75d5e86539 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -56,7 +56,8 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end) ref->linesize[0], ref->linesize[1], ref->linesize[2], ref->linesize[3], ref->pts, ref->pkt_pos); - if (ref->width) { + switch(ref->type) { + case AVMEDIA_TYPE_VIDEO: ff_tlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c", ref->sample_aspect_ratio.num, ref->sample_aspect_ratio.den, ref->width, ref->height, @@ -64,12 +65,13 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end) ref->top_field_first ? 'T' : 'B', /* Top / Bottom */ ref->key_frame, av_get_picture_type_char(ref->pict_type)); - } - if (ref->nb_samples) { + break; + case AVMEDIA_TYPE_AUDIO: ff_tlog(ctx, " cl:%"PRId64"d n:%d r:%d", ref->channel_layout, ref->nb_samples, ref->sample_rate); + break; } ff_tlog(ctx, "]%s", end ? "\n" : ""); diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index f7208754a7..ee2f5b594d 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -45,6 +45,7 @@ #include "libavutil/log.h" #include "libavutil/samplefmt.h" #include "libavutil/pixfmt.h" +#include "libavutil/subfmt.h" #include "libavutil/rational.h" #include "libavfilter/version.h" @@ -327,6 +328,12 @@ typedef struct AVFilter { * and outputs use the same sample rate and channel count/layout. */ const enum AVSampleFormat *samples_list; + /** + * Analogous to pixels, but delimited by AV_SUBTITLE_FMT_NONE + * and restricted to filters that only have AVMEDIA_TYPE_SUBTITLE + * inputs and outputs. + */ + const enum AVSubtitleType *subs_list; /** * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list. */ @@ -335,6 +342,10 @@ typedef struct AVFilter { * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list. */ enum AVSampleFormat sample_fmt; + /** + * Equivalent to { sub_fmt, AV_SUBTITLE_FMT_NONE } as subs_list. + */ + enum AVSubtitleType sub_fmt; } formats; int priv_size; ///< size of private data to allocate for the filter diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index b8b432e98b..96f35a792c 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -311,6 +311,8 @@ static int filter_link_check_formats(void *log, AVFilterLink *link, AVFilterForm return ret; break; + case AVMEDIA_TYPE_SUBTITLE: + return 0; default: av_assert0(!"reached"); } @@ -441,6 +443,9 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) if (!link) continue; + if (link->type == AVMEDIA_TYPE_SUBTITLE) + continue; + neg = ff_filter_get_negotiation(link); av_assert0(neg); for (neg_step = 1; neg_step < neg->nb_mergers; neg_step++) { diff --git a/libavfilter/formats.c b/libavfilter/formats.c index ba62f73248..46dbbd2975 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavcodec/avcodec.h" #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" @@ -431,6 +432,12 @@ int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout) return 0; } +int ff_add_subtitle_type(AVFilterFormats **avff, int64_t fmt) +{ + ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats); + return 0; +} + AVFilterFormats *ff_make_formats_list_singleton(int fmt) { int fmts[2] = { fmt, -1 }; @@ -450,6 +457,13 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type) return NULL; fmt++; } + } else if (type == AVMEDIA_TYPE_SUBTITLE) { + if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_BITMAP) < 0) + return NULL; + if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_ASS) < 0) + return NULL; + if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_TEXT) < 0) + return NULL; } return ret; @@ -724,6 +738,10 @@ int ff_default_query_formats(AVFilterContext *ctx) type = AVMEDIA_TYPE_AUDIO; formats = ff_make_format_list(f->formats.samples_list); break; + case FF_FILTER_FORMATS_SUBFMTS_LIST: + type = AVMEDIA_TYPE_SUBTITLE; + formats = ff_make_format_list(f->formats.subs_list); + break; case FF_FILTER_FORMATS_SINGLE_PIXFMT: type = AVMEDIA_TYPE_VIDEO; formats = ff_make_formats_list_singleton(f->formats.pix_fmt); @@ -732,6 +750,10 @@ int ff_default_query_formats(AVFilterContext *ctx) type = AVMEDIA_TYPE_AUDIO; formats = ff_make_formats_list_singleton(f->formats.sample_fmt); break; + case FF_FILTER_FORMATS_SINGLE_SUBFMT: + type = AVMEDIA_TYPE_SUBTITLE; + formats = ff_make_formats_list_singleton(f->formats.sub_fmt); + break; default: av_assert2(!"Unreachable"); /* Intended fallthrough */ diff --git a/libavfilter/formats.h b/libavfilter/formats.h index a884d15213..94754ebd88 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -180,6 +180,9 @@ int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts); av_warn_unused_result int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout); +av_warn_unused_result +int ff_add_subtitle_type(AVFilterFormats **avff, int64_t fmt); + /** * Add *ref as a new reference to f. */ diff --git a/libavfilter/internal.h b/libavfilter/internal.h index fc09ef574c..192b0ae196 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -149,9 +149,11 @@ static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_act enum FilterFormatsState { /** - * The default value meaning that this filter supports all formats - * and (for audio) sample rates and channel layouts/counts as long - * as these properties agree for all inputs and outputs. + * The default value meaning that this filter supports + * - For video: all formats + * - For audio: all sample rates and channel layouts/counts + * - For subtitles: all subtitle formats + * as long as these properties agree for all inputs and outputs. * This state is only allowed in case all inputs and outputs actually * have the same type. * The union is unused in this state. @@ -162,8 +164,10 @@ enum FilterFormatsState { FF_FILTER_FORMATS_QUERY_FUNC, ///< formats.query active. FF_FILTER_FORMATS_PIXFMT_LIST, ///< formats.pixels_list active. FF_FILTER_FORMATS_SAMPLEFMTS_LIST, ///< formats.samples_list active. + FF_FILTER_FORMATS_SUBFMTS_LIST, ///< formats.subs_list active. FF_FILTER_FORMATS_SINGLE_PIXFMT, ///< formats.pix_fmt active FF_FILTER_FORMATS_SINGLE_SAMPLEFMT, ///< formats.sample_fmt active. + FF_FILTER_FORMATS_SINGLE_SUBFMT, ///< formats.sub_fmt active. }; #define FILTER_QUERY_FUNC(func) \ @@ -175,16 +179,24 @@ enum FilterFormatsState { #define FILTER_SAMPLEFMTS_ARRAY(array) \ .formats.samples_list = array, \ .formats_state = FF_FILTER_FORMATS_SAMPLEFMTS_LIST +#define FILTER_SUBFMTS_ARRAY(array) \ + .formats.subs_list = array, \ + .formats_state = FF_FILTER_FORMATS_SUBFMTS_LIST #define FILTER_PIXFMTS(...) \ FILTER_PIXFMTS_ARRAY(((const enum AVPixelFormat []) { __VA_ARGS__, AV_PIX_FMT_NONE })) #define FILTER_SAMPLEFMTS(...) \ FILTER_SAMPLEFMTS_ARRAY(((const enum AVSampleFormat[]) { __VA_ARGS__, AV_SAMPLE_FMT_NONE })) +#define FILTER_SUBFMTS(...) \ + FILTER_SUBFMTS_ARRAY(((const enum AVSubtitleType[]) { __VA_ARGS__, AV_SUBTITLE_FMT_NONE })) #define FILTER_SINGLE_PIXFMT(pix_fmt_) \ .formats.pix_fmt = pix_fmt_, \ .formats_state = FF_FILTER_FORMATS_SINGLE_PIXFMT #define FILTER_SINGLE_SAMPLEFMT(sample_fmt_) \ .formats.sample_fmt = sample_fmt_, \ .formats_state = FF_FILTER_FORMATS_SINGLE_SAMPLEFMT +#define FILTER_SINGLE_SUBFMT(sub_fmt_) \ + .formats.sub_fmt = sub_fmt_, \ + .formats_state = FF_FILTER_FORMATS_SINGLE_SUBFMT #define FILTER_INOUTPADS(inout, array) \ .inout = array, \