From patchwork Mon Aug 30 08:16:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 29871 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp3737985iov; Mon, 30 Aug 2021 01:17:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxztN8Z5KCQpWjG9CG4n7OC/Ap1e53fEeS7O+Du7lOCBlb83FMVa67uDp2ZuwVhc+7lwCs X-Received: by 2002:a17:906:774f:: with SMTP id o15mr24150643ejn.200.1630311448376; Mon, 30 Aug 2021 01:17:28 -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 l7si9070424edb.31.2021.08.30.01.17.26; Mon, 30 Aug 2021 01:17:28 -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=jJ+fpam7; 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 859CE68A360; Mon, 30 Aug 2021 11:17:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08olkn2108.outbound.protection.outlook.com [40.92.46.108]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 422AA68A1D4 for ; Mon, 30 Aug 2021 11:17:00 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DmSAgbPP+oz3ZNnqJ3/S7x4Icf6DXhSJUQSNYCZJVoaZYKyj2ePyJ5lVh0G8nnZ027WuihV3hvkJNroJKxV3GNHMCL9jJBRcQULMbNCZnByvnVlqWO0ML5qjrsnlJzEeWg9bJeGgoDp540zLO34F8b2XT326D9eM00D3Sh4XnSp3FyXPCzT3QjEujN9TR3g15KD6qvM2z0fJE/xmLHE6jxt+sbBYQp08JCGEf230MYwjETq3E+MBFgzv6b7MZ+d4Xi1BZcTo1NKjuEtiTNhRK+jMSv/UOYsaMaMiLrzqAGyZeEFf9cbfSrzHLtxfDSrMeFFaw73bY1qhMz/RjZ4LVw== 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-SenderADCheck; bh=M++LZzAXzIr4CWwE7htwpzgAhSBf8XdZsImyZ4r1NKg=; b=SG49cXloHVU8V0g47iERx4seCEvCQf69yb7fS1KbzCHup7qj/YMrOwt93Jt7w/+aiAORNDWNXKBFuRSQQeoDmdV6FmtKs23GWU44w4556NPatup8qQ9o5U28la1AHvJ/zMACfQzPyXSkzoRMXmxesHtvi7k/XRo1gDoBhRm3/e9CHOGqNBzXTVfIDaKYbTrhzM+q7j5UudPYjOVl8qybGF321ATMAKwpBuA0Ipkp1+PBdefBtwRdZI5fMsurp9QUusH71fZS4ArhE/ptlIhKD+AhztbA8f+GWY5QCHJRg/j08JAERn6qnUbQW4Vgr9WyesTIi++AIQ201eVH3r4Hjg== 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=M++LZzAXzIr4CWwE7htwpzgAhSBf8XdZsImyZ4r1NKg=; b=jJ+fpam7iz2/uoTerQWWbluF8RAiN7GAHz5UCmjjshD17IQpPrckJ4M9aN086inqjW79O4OhXK8iqY2YeEmEDJQ5iV/RbRmkQUX1MsP/UCoq+XY4Dme6J/HPMHY5R2mfmc0NYxYu4xUWR++nFM3KFMuZswcThHqTR49wJ2A0VW2SFrdxwjHpg0uOMXUngWRb1gOtSw9RhdM6T5M8s2pFIYU+QPGcgAj+ezUek5Kl4g1uICMppUokxjjRQR640Vx3tKHpiX9RVsOW7ZsYBgVWgwVn5buhuBoHt7iHsbu5kRNO3tI98PDhBoPyM5Dnvxl0upvzsRcRjNGK2ZHaxKdR+w== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB5853.namprd04.prod.outlook.com (2603:10b6:208:a6::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.19; Mon, 30 Aug 2021 08:16: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.4457.024; Mon, 30 Aug 2021 08:16:58 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v2 6/8] avfilter/sbuffer: Add sbuffersrv and sbuffersink filters Thread-Index: AdeUpHY9YnLYcJe+Q/y5MTrjWNM3hg== Date: Mon, 30 Aug 2021 08:16:58 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [F1tKAGptf4TWyXAqapS78/GVcZpLj+aS] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 76d7b9c1-c296-42af-38a4-08d96b8e8970 x-ms-traffictypediagnostic: MN2PR04MB5853: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: sw6omXRbGHXloXHxAZAzMbvmI/dhrg4ChFpPw4cPpGc7S+5MWKSHUq5KrUZGG7xq+bRlgXclC+iKpmzqhBu6R5S4US7j5MOXHiIR6CB7De9NtyMosAXrAcFwUf/G/hZily2etAME0rQ6SRPkhaOXIIjiMHC9wA2LxglTO2kK0RTNlWxqEpD2r3meCtxJr5cNtpL72KQZIbnTnIkui587OpJW6zXomb5y0BjBpDp3nFrHgm3eK7BGDg9HapHpQ033rZReh7z3cPbzbB6UDT1o1dyiKf7EyQEoyN39CJylznCxrG32KpxuY4oXNXSXYlN5fB0O6WTgOvNyUii5BIM3ZvV1HzpYiFO63EGB05crErT/uoUUraiytlYJ4bBUaVkXKXv6QeFmBqYxfedOoiK+hGiDkFM+DNRRQdiROEiiUmBx+pQwwM+jbhepWhtyt7hs x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: FguNZGWTCbo2yRCk/UxrvM3OKQlIe/trGVyWmke+5jAhs3sMUBQE7NHKGQdPqOxP+/Ia2OwuEwthngTsgP3j3uvgNXQV20dXcKDPRqle92lFFGvPlQxzaG1RjYldX41B7xC+etw+EUvQgTDCF87fiw== 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: 76d7b9c1-c296-42af-38a4-08d96b8e8970 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Aug 2021 08:16:58.4657 (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: MN2PR04MB5853 Subject: [FFmpeg-devel] [PATCH v2 6/8] avfilter/sbuffer: Add sbuffersrv and sbuffersink filters 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: NdiutS8IQYaM Signed-off-by: softworkz --- v2 Update: - Implemented Andreas' suggestions - overlay_subs filter: - removed duplicated code - implemented direct (no pre-conversion) blending of graphical subtitle rects - Supported input formats: - all packed RGB formats (with and without alpha) - yuv420p, yuv422p, yuv444p configure | 2 +- libavfilter/allfilters.c | 10 ++++--- libavfilter/buffersink.c | 65 ++++++++++++++++++++++++++++++++++++++++ libavfilter/buffersink.h | 15 ++++++++++ libavfilter/buffersrc.c | 65 ++++++++++++++++++++++++++++++++++++++++ libavfilter/buffersrc.h | 1 + 6 files changed, 153 insertions(+), 5 deletions(-) diff --git a/configure b/configure index 9249254b70..fdb3bf1714 100755 --- a/configure +++ b/configure @@ -7715,7 +7715,7 @@ print_enabled_components(){ fi done if [ "$name" = "filter_list" ]; then - for c in asrc_abuffer vsrc_buffer asink_abuffer vsink_buffer; do + for c in asrc_abuffer vsrc_buffer ssrc_sbuffer asink_abuffer vsink_buffer ssink_sbuffer; do printf " &ff_%s,\n" $c >> $TMPH done fi diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 5b631b3617..5bd54db2c8 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -528,10 +528,12 @@ extern const AVFilter ff_avsrc_movie; * they are formatted to not be found by the grep * as they are manually added again (due to their 'names' * being the same while having different 'types'). */ -extern const AVFilter ff_asrc_abuffer; -extern const AVFilter ff_vsrc_buffer; -extern const AVFilter ff_asink_abuffer; -extern const AVFilter ff_vsink_buffer; +extern const AVFilter ff_asrc_abuffer; +extern const AVFilter ff_vsrc_buffer; +extern const AVFilter ff_ssrc_sbuffer; +extern const AVFilter ff_asink_abuffer; +extern const AVFilter ff_vsink_buffer; +extern const AVFilter ff_ssink_sbuffer; extern const AVFilter ff_af_afifo; extern const AVFilter ff_vf_fifo; diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 07c4812f29..20845eb10f 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -57,6 +57,10 @@ typedef struct BufferSinkContext { int *sample_rates; ///< list of accepted sample rates, terminated by -1 int sample_rates_size; + /* only used for subtitles */ + enum AVSubtitleType *subtitle_types; ///< list of accepted subtitle types, must be terminated with -1 + int subtitle_types_size; + AVFrame *peeked_frame; } BufferSinkContext; @@ -168,6 +172,15 @@ AVABufferSinkParams *av_abuffersink_params_alloc(void) return NULL; return params; } + +AVSBufferSinkParams *av_sbuffersink_params_alloc(void) +{ + AVSBufferSinkParams *params = av_mallocz(sizeof(AVSBufferSinkParams)); + + if (!params) + return NULL; + return params; +} #endif static av_cold int common_init(AVFilterContext *ctx) @@ -305,6 +318,31 @@ static int asink_query_formats(AVFilterContext *ctx) return 0; } +static int ssink_query_formats(AVFilterContext *ctx) +{ + BufferSinkContext *buf = ctx->priv; + AVFilterFormats *formats = NULL; + unsigned i; + int ret; + + if ((ret = ff_default_query_formats(ctx)) < 0) + return ret; + + ////CHECK_LIST_SIZE(pixel_fmts) + ////if (buf->pixel_fmts_size) { + //// for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++) + //// if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0) + //// return ret; + //// if ((ret = ff_set_common_formats(ctx, formats)) < 0) + //// return ret; + ////} else { + //// if ((ret = ff_default_query_formats(ctx)) < 0) + //// return ret; + ////} + + return 0; +} + #define OFFSET(x) offsetof(BufferSinkContext, x) #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM static const AVOption buffersink_options[] = { @@ -322,9 +360,16 @@ static const AVOption abuffersink_options[] = { { NULL }, }; #undef FLAGS +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM +static const AVOption sbuffersink_options[] = { + { "subtitle_types", "set the supported subtitle formats", OFFSET(subtitle_types), AV_OPT_TYPE_BINARY, .flags = FLAGS }, + { NULL }, +}; +#undef FLAGS AVFILTER_DEFINE_CLASS(buffersink); AVFILTER_DEFINE_CLASS(abuffersink); +AVFILTER_DEFINE_CLASS(sbuffersink); static const AVFilterPad avfilter_vsink_buffer_inputs[] = { { @@ -365,3 +410,23 @@ const AVFilter ff_asink_abuffer = { .inputs = avfilter_asink_abuffer_inputs, .outputs = NULL, }; + +static const AVFilterPad avfilter_ssink_sbuffer_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_SUBTITLE, + }, + { NULL } +}; + +AVFilter ff_ssink_sbuffer = { + .name = "sbuffersink", + .description = NULL_IF_CONFIG_SMALL("Buffer subtitle frames, and make them available to the end of the filter graph."), + .priv_class = &sbuffersink_class, + .priv_size = sizeof(BufferSinkContext), + .init = common_init, + .query_formats = ssink_query_formats, + .activate = activate, + .inputs = avfilter_ssink_sbuffer_inputs, + .outputs = NULL, +}; diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h index 69ed0f29a8..b439b586c5 100644 --- a/libavfilter/buffersink.h +++ b/libavfilter/buffersink.h @@ -129,6 +129,21 @@ typedef struct AVABufferSinkParams { */ attribute_deprecated AVABufferSinkParams *av_abuffersink_params_alloc(void); + +/** + * Deprecated and unused struct to use for initializing an sbuffersink context. + */ +typedef struct AVSBufferSinkParams { + const int *subtitle_type; +} AVSBufferSinkParams; + +/** + * Create an AVSBufferSinkParams structure. + * + * Must be freed with av_free(). + */ +attribute_deprecated +AVSBufferSinkParams *av_sbuffersink_params_alloc(void); #endif /** diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 4d0bb4f91d..eeef3e2390 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -39,6 +39,7 @@ #include "formats.h" #include "internal.h" #include "video.h" +#include "libavcodec/avcodec.h" typedef struct BufferSourceContext { const AVClass *class; @@ -63,6 +64,9 @@ typedef struct BufferSourceContext { uint64_t channel_layout; char *channel_layout_str; + /* subtitle only */ + enum AVSubtitleType subtitle_type; + int eof; } BufferSourceContext; @@ -130,6 +134,9 @@ int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *par if (param->channel_layout) s->channel_layout = param->channel_layout; break; + case AVMEDIA_TYPE_SUBTITLE: + s->subtitle_type = param->format; + break; default: return AVERROR_BUG; } @@ -197,6 +204,8 @@ int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFra CHECK_AUDIO_PARAM_CHANGE(ctx, s, frame->sample_rate, frame->channel_layout, frame->channels, frame->format, frame->pts); break; + case AVMEDIA_TYPE_SUBTITLE: + break; default: return AVERROR(EINVAL); } @@ -269,6 +278,7 @@ unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src) #define OFFSET(x) offsetof(BufferSourceContext, x) #define A AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM #define V AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM +#define S AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM static const AVOption buffer_options[] = { { "width", NULL, OFFSET(w), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, V }, @@ -298,6 +308,14 @@ static const AVOption abuffer_options[] = { AVFILTER_DEFINE_CLASS(abuffer); +static const AVOption sbuffer_options[] = { + { "time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, INT_MAX, S }, + { "subtitle_type", NULL, OFFSET(subtitle_type), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, S }, + { NULL }, +}; + +AVFILTER_DEFINE_CLASS(sbuffer); + static av_cold int init_audio(AVFilterContext *ctx) { BufferSourceContext *s = ctx->priv; @@ -347,6 +365,21 @@ static av_cold int init_audio(AVFilterContext *ctx) return ret; } +static av_cold int init_subtitle(AVFilterContext *ctx) +{ + BufferSourceContext *c = ctx->priv; + + if (c->subtitle_type == SUBTITLE_BITMAP) + av_log(ctx, AV_LOG_VERBOSE, "graphical subtitles - w:%d h:%d tb:%d/%d\n", + c->w, c->h, c->time_base.num, c->time_base.den); + else + av_log(ctx, AV_LOG_VERBOSE, "text subtitles - tb:%d/%d\n", + c->time_base.num, c->time_base.den); + + return 0; +} + + static av_cold void uninit(AVFilterContext *ctx) { BufferSourceContext *s = ctx->priv; @@ -381,6 +414,11 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_set_common_channel_layouts(ctx, channel_layouts)) < 0) return ret; break; + case AVMEDIA_TYPE_SUBTITLE: + if ((ret = ff_add_format (&formats, c->subtitle_type)) < 0 || + (ret = ff_set_common_formats (ctx , formats )) < 0) + return ret; + break; default: return AVERROR(EINVAL); } @@ -408,6 +446,9 @@ static int config_props(AVFilterLink *link) if (!c->channel_layout) c->channel_layout = link->channel_layout; break; + case AVMEDIA_TYPE_SUBTITLE: + link->format = c->subtitle_type; + break; default: return AVERROR(EINVAL); } @@ -474,3 +515,27 @@ const AVFilter ff_asrc_abuffer = { .outputs = avfilter_asrc_abuffer_outputs, .priv_class = &abuffer_class, }; + +static const AVFilterPad avfilter_ssrc_sbuffer_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_SUBTITLE, + .request_frame = request_frame, + .config_props = config_props, + }, + { NULL } +}; + +const AVFilter ff_ssrc_sbuffer = { + .name = "sbuffer", + .description = NULL_IF_CONFIG_SMALL("Buffer subtitle frames, and make them accessible to the filterchain."), + .priv_size = sizeof(BufferSourceContext), + .query_formats = query_formats, + + .init = init_subtitle, + .uninit = uninit, + + .inputs = NULL, + .outputs = avfilter_ssrc_sbuffer_outputs, + .priv_class = &sbuffer_class, +}; diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h index 08fbd18a47..929a2fa249 100644 --- a/libavfilter/buffersrc.h +++ b/libavfilter/buffersrc.h @@ -74,6 +74,7 @@ typedef struct AVBufferSrcParameters { /** * video: the pixel format, value corresponds to enum AVPixelFormat * audio: the sample format, value corresponds to enum AVSampleFormat + * subtitles: the subtitle format, value corresponds to enum AVSubtitleType */ int format; /**