From patchwork Mon Aug 30 08:16:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 29867 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp3737482iov; Mon, 30 Aug 2021 01:16:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBe8YdG5z7f6nN5MrymVOFLc7qji9duKIpZR/K5D7zE4ngCG0z1rtcDzQCa+tzfikZYnNL X-Received: by 2002:a05:6402:358e:: with SMTP id y14mr15800180edc.296.1630311400270; Mon, 30 Aug 2021 01:16:40 -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 j4si3181485ejj.357.2021.08.30.01.16.38; Mon, 30 Aug 2021 01:16:40 -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=FWQ5u4TU; 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 2664268A1F0; Mon, 30 Aug 2021 11:16:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10olkn2052.outbound.protection.outlook.com [40.92.40.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 57625688181 for ; Mon, 30 Aug 2021 11:16:29 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aYss6YOZGUOMGi5XIStYds7at/Hpd6uTYOLqJPd4VxXjJ5zo3qDLEwb3rp8ZmpmyEXB2Q+Ij/EzhIb9Et+f551GckoLSCfOdNr5sJWzaAuKXF0XiF3lmCdH5HkuWxW2K0K+iXZKtnD4WtdsSmlLeYw5Kry9T4CIsq5EAHnVG1r2tXSMbS2hvntfaoBULnTP5ySa2L2zE0wdSMHg0BioqQsImPZcpDW7i2DD8fRNWsZswiUFK5BBMqkwH8CoODZT8afuAd53b3bPli/HteJui9tDrblP3gHCF5jU4yORUsY3OeLFVEgDliUdXw/S6dd1bgjBCVQ2OXv2eY1Xwyo9SOQ== 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=J2pPSyLvneqeWTRFVt31F2VRPFXYUFLyIqwyG2Mn9K0=; b=IhppVlyeAvvwkccCjJVLJBtqBFgzpAyWVQNooyPIXiqQlagiLTjmL/E5K3q0Ere3zUojce1E0rTjTdVECsakGWs7InirtYEQnq1zlUv2AaIHvoNPSmPr3E52MdYaogzYtUt8xr2lGUr3uTlKcoInXYHUGFcX5GXSmYsVNVgXrRmysv14QubhYRU8rmQ780IwD1VtzGQn5dAgT1z+4IfdKCdW394Q0V82SuuDqxRmC9Wpm3QwlaDv2cwjvVipZ87QBZJ8HMLrKZ0Y5Gjy2D0bkqZ4pHV0NuBvqF4FgrmdkgppJeYx0HqVAUVBQCjyElxDNv91dAPXN4yJHuelWjDdWA== 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=J2pPSyLvneqeWTRFVt31F2VRPFXYUFLyIqwyG2Mn9K0=; b=FWQ5u4TUCt9r2cuWb1gJvXluBVE7Caq2V7SKqNj8rmM+ewe4w3Kw0gCRpVopEBPJ8gnZH22YKEmQfIW4+di1eqvPsu6hUMtNnofUoMDZj//0ejA8qhI3n2GAe1kjgKGRqlknosCDRXsWc3C94EMsx8fdCZkrNXB/rTaHCvI1BfoY3hTmqjzCRP6f0Fz6RzRCibnm1Sdo8dluW/CpombXdHqvgGkWuGDzGaz4SIzRqL+Vhdl+4qjfF/joYXRLL/1nYBzXjJ7C/b3BttYkYvRVBZu9jLNWE46yL41WIZvVYRHE5Gd+BCmkcVL25345tcNuuMl9HR7FO+6Veru9dY6Eeg== Received: from MN2PR04MB5981.namprd04.prod.outlook.com (2603:10b6:208:da::10) by MN2PR04MB6191.namprd04.prod.outlook.com (2603:10b6:208:de::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Mon, 30 Aug 2021 08:16:27 +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:27 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v2 2/8] avfilter/subtitles: Add subtitles.c Thread-Index: AdedcjHqoNWdqt5YTeuSX/XxFkJE7A== Date: Mon, 30 Aug 2021 08:16:27 +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: [s64LF3HAQS9yRJirhKS5gdPk3d/SwYV9] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 457f235d-8e2e-4351-b41f-08d96b8e7716 x-ms-traffictypediagnostic: MN2PR04MB6191: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: GbJ4k86kQVU++QLkY60Apb7D7QuD3b2c+6D9Pg+lXYS7Ql8iBH6+AC+Mm6zzrw+SrRL0N/cGsZ7Dh5XuXaOyPsGMWIKz5yTS5rnBoXazR8nuQxsn6QCf0HUtTcg0ltLBMtUMZufQ2NO46cg5t+91XqanEpEPhQTGGYa3GwgFwsaIaQAv4UVjxnvNlQPI3b2BiwtjG0W9JRYqAw1PN2UZCCTYhmff4smZvJXA3zROBLnwEXEQPQoULgJ/JmcfREbHxkmzxuUyucz5f1CqTblNO0KPTzTJfSMRUiXoecaxUWUvFn+O5DFu/k8U3mpJHPPOve0vpuxbxbLJRjRkVBHOn3wT+UlFw3hbCNGmUaVGPp3QDDj8y91a/aXjJ8YbWkSrXxEnzUBTjVkHV/Ptq5aEC5hvbhknC1Y7OeV1CoSc9d0VbrIYB6yEhDPVPWeffGCe x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: Nv+HqZVo5f+KTVZn7riT3iziB1vMXUXkAMpCpOJ2l/Tg/YyiaCK6sLDbqLpY6LXcpUHpgHMiQfL2BmXegTFT6nj6edXq1tYYQCZOc7+nNQvOIks/TTULz6+uTh+/db0XwDTyeiz+7JjPddmhP5ipag== 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: 457f235d-8e2e-4351-b41f-08d96b8e7716 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Aug 2021 08:16:27.6600 (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: MN2PR04MB6191 Subject: [FFmpeg-devel] [PATCH v2 2/8] avfilter/subtitles: Add subtitles.c 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: qCMFtbuNAqNO 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 libavfilter/Makefile | 1 + libavfilter/f_interleave.c | 3 ++ libavfilter/internal.h | 1 + libavfilter/subtitles.c | 61 ++++++++++++++++++++++++++++++++++++++ libavfilter/subtitles.h | 44 +++++++++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 libavfilter/subtitles.c create mode 100644 libavfilter/subtitles.h diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 102ce7beff..82a7394adb 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -19,6 +19,7 @@ OBJS = allfilters.o \ framequeue.o \ graphdump.o \ graphparser.o \ + subtitles.o \ video.o \ OBJS-$(HAVE_THREADS) += pthread.o diff --git a/libavfilter/f_interleave.c b/libavfilter/f_interleave.c index 2845d72b79..aefa9a11cb 100644 --- a/libavfilter/f_interleave.c +++ b/libavfilter/f_interleave.c @@ -32,6 +32,7 @@ #include "filters.h" #include "internal.h" #include "audio.h" +#include "subtitles.h" #include "video.h" typedef struct InterleaveContext { @@ -170,6 +171,8 @@ static av_cold int init(AVFilterContext *ctx) inpad.get_buffer.video = ff_null_get_video_buffer; break; case AVMEDIA_TYPE_AUDIO: inpad.get_buffer.audio = ff_null_get_audio_buffer; break; + case AVMEDIA_TYPE_SUBTITLE: + inpad.get_buffer.subtitle = ff_null_get_subtitles_buffer; break; default: av_assert0(0); } diff --git a/libavfilter/internal.h b/libavfilter/internal.h index a0aa32af4d..85519a1076 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -85,6 +85,7 @@ struct AVFilterPad { union { AVFrame *(*video)(AVFilterLink *link, int w, int h); AVFrame *(*audio)(AVFilterLink *link, int nb_samples); + AVFrame *(*subtitle)(AVFilterLink *link, int format); } get_buffer; /** diff --git a/libavfilter/subtitles.c b/libavfilter/subtitles.c new file mode 100644 index 0000000000..90ec479e51 --- /dev/null +++ b/libavfilter/subtitles.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 softworkz + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" + +#include "subtitles.h" +#include "avfilter.h" +#include "internal.h" + + +AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format) +{ + return ff_get_subtitles_buffer(link->dst->outputs[0], format); +} + +AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format) +{ + AVFrame *frame = NULL; + + // TODO: + //frame = ff_frame_pool_get(link->frame_pool); + + frame = av_frame_alloc(); + if (!frame) + return NULL; + + frame->format = format; + frame->type = AVMEDIA_TYPE_SUBTITLE; + + return frame; +} + +AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format) +{ + AVFrame *ret = NULL; + + if (link->dstpad->get_buffer.subtitle) + ret = link->dstpad->get_buffer.subtitle(link, format); + + if (!ret) + ret = ff_default_get_subtitles_buffer(link, format); + + return ret; +} diff --git a/libavfilter/subtitles.h b/libavfilter/subtitles.h new file mode 100644 index 0000000000..d3d5491652 --- /dev/null +++ b/libavfilter/subtitles.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 softworkz + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFILTER_SUBTITLES_H +#define AVFILTER_SUBTITLES_H + +#include "avfilter.h" +#include "internal.h" + +/** default handler for get_subtitles_buffer() for subtitle inputs */ +AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format); + +/** get_subtitles_buffer() handler for filters which simply pass subtitles along */ +AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format); + +/** + * Request a subtitles buffer with a specific set of permissions. + * + * @param link the output link to the filter from which the buffer will + * be requested + * @param format The subtitles format. + * @return A reference to the subtitles. This must be unreferenced with + * avfilter_unref_buffer when you are finished with it. +*/ +AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format); + +#endif /* AVFILTER_SUBTITLES_H */