From patchwork Thu Nov 25 00:48:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soft Works X-Patchwork-Id: 31641 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp11417745iob; Wed, 24 Nov 2021 16:51:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEyl0PMciHlRmLZeaLYYLqpF13o2/vc79F9zaI20cwOgAIbPVUXDwU2pPetCWcNMzpg3tc X-Received: by 2002:a05:6402:4404:: with SMTP id y4mr32792605eda.321.1637801477714; Wed, 24 Nov 2021 16:51:17 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y7si5291933edd.161.2021.11.24.16.51.17; Wed, 24 Nov 2021 16:51:17 -0800 (PST) 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=n8vmBKNR; 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 2046368ACAE; Thu, 25 Nov 2021 02:48:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10olkn2034.outbound.protection.outlook.com [40.92.40.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8B62E68AE8D for ; Thu, 25 Nov 2021 02:48:52 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EjbIauiA0LvliadzXW8NjfZRDpK2bBBtEId4wOEsa8X2Xp2Hl/nkEGKB5730WSn7FGxLJwBhh8+cohiwcal21zunKna7okq34i8B3IK/GMKl/os0wAIecMsvnyAP1HYMRcGfpmxJBKWUnsj7PlzitNIFa4cIEVrfXJXNM/rTz7xgOe0uyy8lO2m+NQ960KFW/GIfa3tIlfhPP7KDwsKKX+PO5FvHmymuYwMbNEatn07kR/HYcnJl9hF1h2wMM0Q187ZsF/71PKSzmELLDmnW5AFC/a8DTNpk+hhMw9ERJ+KuAJ7Z7EP8q1UNziEGBfmxdbPDJbVt86YuHjvz4uekiw== 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=g0nyIZATYd688D8vTb4MlLQmTNMNOPE5mjqBuMAx82Q=; b=Mpy6XhWb+CtCJ1Sd+GWtlq7J0cXXNsMAbvJ5BpNP6dic3SV2bCOdXLBf0dEthzi1DtLfoBYbOj3+p8u+6DGpHYnfbGKCIlAsZozie5zXD2GhZ7i8a9mu7iIQRGfa1+SN2iR2rDrtQsHQ70xx/6yhGx33s/p9tk1al1nBy3MTLlc7dJH+wUcito1LafUiMqqmRf2i0IP2Mgvfy7w887Tb0+MvuS/jnkL00apsAKDSHpdZM8ABv19ndX/9NPoaZG6dtpFjGqjWIW7bbHFTF0HzXSI68t8ex7saiAk4gQiicOwf/cEMgVJsMTWYD1xJuVitOml/Ou7BEUE7dTQCkpL1dg== 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=g0nyIZATYd688D8vTb4MlLQmTNMNOPE5mjqBuMAx82Q=; b=n8vmBKNR4kW/9sUt5zSr6XuMf/mlBH3GmdATZoZkuQHUu9V8qq0nV6dlGiUpfRgxIoTzL3kY6PMmLz/I9PWu0IRBRJqFZcIc+lm4f7bwn3PcpE5wiMb3GSzLqASeordBmvPJLBszw1OtfJnx1JVQwR27Dtudx3H0Vo75WGu9SadspA6UTj3vJKv3YBqGASUoUaqDovlK92cVuCtohR4vhl+FZEPUV042kzDxb9Nd3jceJbiRN+UKFL4hUtvOktbIQ0RDrKLuA9LbJ6cc3AjFCDdQIxF1ucuRpstI4PXVBEGhiX8/0nwxJsGAdbWW30VmZKA6ueORmnhM8kSxQ9Nbpg== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0032.NAMP223.PROD.OUTLOOK.COM (2603:10b6:5:316::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22; Thu, 25 Nov 2021 00:48:50 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::8c05:4078:21a:53fb]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::8c05:4078:21a:53fb%5]) with mapi id 15.20.4734.020; Thu, 25 Nov 2021 00:48:50 +0000 From: Soft Works To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v15 16/16] fftools/ffmpeg: Use new frame-based subtitle encoding API Thread-Index: AQHX4ZY2WtVx4JUQ30ugYZxTsgqSWg== Date: Thu, 25 Nov 2021 00:48:50 +0000 Message-ID: References: <3815d024795f567ed6215bfcd4faae23dc1b7ecf.1637801132.git.softworkz@hotmail.com> <7c5e4813b96e3517e377b2d3d8031b9e083adfac.1637801132.git.softworkz@hotmail.com> <7ab9f75e090bd6e9155fd773714781d28af68049.1637801132.git.softworkz@hotmail.com> <54b962131be46bdf689d13a87ee1666a96bfffa8.1637801132.git.softworkz@hotmail.com> <965c49dd5c779fc4bcfea01c8871dafc7f38c5cf.1637801132.git.softworkz@hotmail.com> <50c59617deffcf7b56b2aa5c8ada46f744e2a97c.1637801133.git.softworkz@hotmail.com> 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: [FSRNnjxHO4UzmupHMVZPCUKX4B/rGeMA] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: fd662b3c-1691-4999-7525-08d9afad58cc x-ms-traffictypediagnostic: DM8P223MB0032: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 91giZPPaqXhxi5yQdVtx906doPHi8EMAs+oHPDzcXC9Vv70p69OyBLCJzBeQ+J7is2XgU/XVpjonAgH2XslBRTCv7pqR6IXlzfHqJ5+R/Bl8xxbnot9jJ8hRhpfMyQBJ60LWGFY2DfucQhH9Mw384rB5OgK0SAbIbeskXGSUzF+FynzRoPqzAqKtRQnhPMVFAyatFBYTfKLVA1d+EmCBP9LJ/34K44aIcewu6Bogurct98raaLjfLQWpLe4TGGDwoE5QdlPrJ9Q7hTarTN1hanYw+EcK0eVm1174LSs+mylfrtErwi/2JO6Olou54lqux1w7J+K2Ift0ELYI/ocjF6V/CWeDKrKdnnNNCyKzmKs3m8X/aOiNB0LuhMOLYyPpKCMBTcHq+tAm5x/p7EnHyx8CTtcNl4V+ifKsUTFXA3KWv0vk43NJeCkwpSyQXAF+eBJYJ2nPIRpEhZCFjeL8CGFN7GYnXwsZ7h/Og5cM3Sx6i5wJIrTy7S1mTi/UVGXluxruiOYzoshRQU8bwz8e4eQ0UOioSr6eXMAdkYAjjbSIBWB9WNnDlPBdkoCpgxDkuAc7OAnGgnuO/XSxvP3tag== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: PBy3yobQbGYeJuyAzH+0lTYAULyLvV0iji0Mhd7qNzq/luhD+yRg9TaiGRQV4ENUGCDzT2obMtpo6YKpbI89UOsQJ78wf+SoQqY5A6LgGIolXSPqub/KE+vxDAXN6XvTHuvQ0hNBwqgDsGShsuWLuYmr7zCKrWPETTISnhnIvhh02NyqLjxBxyPf56GUHTs41wXE876OIjsu+aFjC0MvGuK9oE5qP14yp+L6txq8XOiqmfHi4MlzTmddPFhJnXSbWTI/gV/1k2NEz5AAqMLd5Z6QCaRs35r17TwVL3TXOpQQMcEiiwSVZLwfIYUC+otDVDaK/KzjUBeZUBryG7nXEfnRrAm4S/UJpMuCNJNuusS+flLUiLGM+oSstnVsnnVFo6dkZKDZTU4NUBqBC3HQw1hYI3HaExNSDpj37xBVcMlimPsZvfb3S/JHoPlvibesslF0GHCX0ttr0K6rSNgWK1Puldm78UeqvgDPoK4VzmdXGvheuyAHHda2D6NFzgDv+Dq0Qh14WSutF0KS30nOQbd2LDVTA6715cUu0VukxFumqRDnwMyNnEQBRmaxYLMuDaVUDJKX4Avw50sDdljc8ag4sYH/9IPDQtYpEhzenOrBH+Pmyi42Gb52lHlqY7fC+pkDDxPMCNgiWXXfJyz5jcRPUT3id3O7ZW1alJkgs/GohwLMbT7+ouwFHyQpkjj3/OMrh16MHfloWkqOUM6prA== MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-3912-16-msonline-outlook-1fc6d.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: fd662b3c-1691-4999-7525-08d9afad58cc X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Nov 2021 00:48:50.3095 (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: DM8P223MB0032 Subject: [FFmpeg-devel] [PATCH v15 16/16] fftools/ffmpeg: Use new frame-based subtitle encoding API 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: YJzqmZHvA4wC Signed-off-by: softworkz --- fftools/ffmpeg.c | 60 ++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index c697c12777..603b4c23e0 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -896,10 +896,9 @@ error: static void do_subtitle_out(OutputFile *of, OutputStream *ost, AVFrame *frame) { const int subtitle_out_max_size = 1024 * 1024; - int subtitle_out_size, nb, i; + int nb, i; AVCodecContext *enc; AVPacket *pkt = ost->pkt; - AVSubtitle out_sub = { 0 }; int64_t pts; if (!frame) @@ -917,12 +916,14 @@ static void do_subtitle_out(OutputFile *of, OutputStream *ost, AVFrame *frame) enc = ost->enc_ctx; if (!subtitle_out) { - subtitle_out = av_malloc(subtitle_out_max_size); + subtitle_out = av_mallocz(subtitle_out_max_size); if (!subtitle_out) { av_log(NULL, AV_LOG_FATAL, "Failed to allocate subtitle_out\n"); exit_program(1); } } + else + memset(subtitle_out, 0, subtitle_out_max_size); /* Note: DVB subtitle need one packet to draw them and one other packet to clear them */ @@ -947,44 +948,43 @@ static void do_subtitle_out(OutputFile *of, OutputStream *ost, AVFrame *frame) frame->subtitle_end_time -= frame->subtitle_start_time; frame->subtitle_start_time = 0; - av_frame_get_subtitle(&out_sub, frame); - for (i = 0; i < nb; i++) { - const unsigned save_num_rects = out_sub.num_rects; + int ret, got_packet = 0; + const unsigned save_num_rects = frame->num_subtitle_areas; + + pkt->data = subtitle_out; + pkt->size = subtitle_out_max_size; ost->frames_encoded++; if (i == 1) - out_sub.num_rects = 0; + frame->num_subtitle_areas = 0; - subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, subtitle_out_max_size, &out_sub); + ret = avcodec_encode_subtitle2(enc, pkt, frame, &got_packet); if (i == 1) - out_sub.num_rects = save_num_rects; + frame->num_subtitle_areas = save_num_rects; - if (subtitle_out_size < 0) { - av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n"); - exit_program(1); - } - - //av_packet_unref(pkt); - pkt->data = subtitle_out; - pkt->size = subtitle_out_size; - pkt->pts = av_rescale_q(frame->subtitle_pts, AV_TIME_BASE_Q, ost->mux_timebase); - pkt->duration = av_rescale_q(frame->subtitle_end_time, (AVRational){ 1, 1000 }, ost->mux_timebase); - if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { - /* XXX: the pts correction is handled here. Maybe handling - it in the codec would be better */ - if (i == 0) - pkt->pts += av_rescale_q(frame->subtitle_start_time, (AVRational){ 1, 1000 }, ost->mux_timebase); - else - pkt->pts += av_rescale_q(frame->subtitle_end_time, (AVRational){ 1, 1000 }, ost->mux_timebase); + if (ret < 0) { + av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed: %d\n", ret); + exit_program(ret); + } + + if (got_packet) { + pkt->pts = av_rescale_q(frame->subtitle_pts, AV_TIME_BASE_Q, ost->mux_timebase); + pkt->duration = av_rescale_q(frame->subtitle_end_time, (AVRational){ 1, 1000 }, ost->mux_timebase); + if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { + /* XXX: the pts correction is handled here. Maybe handling + it in the codec would be better */ + if (i == 0) + pkt->pts += av_rescale_q(frame->subtitle_start_time, (AVRational){ 1, 1000 }, ost->mux_timebase); + else + pkt->pts += av_rescale_q(frame->subtitle_end_time, (AVRational){ 1, 1000 }, ost->mux_timebase); + } + pkt->dts = pkt->pts; + output_packet(of, pkt, ost, 0); } - pkt->dts = pkt->pts; - output_packet(of, pkt, ost, 0); } - - avsubtitle_free(&out_sub); } static void do_video_out(OutputFile *of,