From patchwork Thu Nov 25 17:52: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: 31675 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp1098516iob; Thu, 25 Nov 2021 09:55:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9cH8kOdFIcjqYMcaaygR7oifegtueRtbSVKbRsKY0vBnSGEBUsgWe8iT2tUWK3KaLbzGc X-Received: by 2002:a50:f09b:: with SMTP id v27mr42027513edl.53.1637862936361; Thu, 25 Nov 2021 09:55:36 -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 dy17si7194107edb.209.2021.11.25.09.55.36; Thu, 25 Nov 2021 09:55:36 -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=nmrspKXM; 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 CD68E68A94A; Thu, 25 Nov 2021 19:53:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10olkn2013.outbound.protection.outlook.com [40.92.41.13]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7189E68AB64 for ; Thu, 25 Nov 2021 19:52:59 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F0XgPYehWP9OhHZEB7IU5OMSNrJwcP7i5iy72yF1EzBfMVHi6aYfB+QmM2jLP7+C3/Mkc/q8r1e2mLJ3ba0IyKYU+ET+WuEs5kXiGCts3klQyPo9y8e1h9WU5efDm5F986nOSORPmJfyiXd2/pObcBNLtS5DxUcg0rkV7DXx4xf/o0whMYbRxdagfZVk/OCb6Fkh+4OSB1+EYde8Phq/Wa0nOBDPIQk82LTQGgbTfjckli9FtgzU48gqQRHnwN9YULq+6/HwhXNSkSrThXS+gVsn4xfjPw25M8fvhMFkcuE8OIROslVKLH7//hwUnFdl4JnLOvT4agv1hz8O6RHZtA== 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=WB1mDAKsQOvGHDGPPYk0dmQ9SMkQmjzN8U8d4BBEvBX4lbpmXoFq0e4qkk0nPCTEqd/8nCWJ/UJT99ZJASIEmazWW5fbse2Yt93p58NI3SWkRp690bpSiqnh2HhzJ7icrpoeNO8QJd8Etdkw71pd3hwMCnhloYniAGwaOYIMlAT5y8WSGjIFvB+gZgdn3YNTDsr1j0PH5yVTO/v72d1ZoeRZyswrQ/iJxs+W164+kvKPF7Wg1cBa2uqQODksEKgxltoizomhEDFfkwqriG4ZWPmyEKJ72Yh/YW5cfQ/ohiM1XunQP68hu4T4JFc5BMv5L8dilKUUGEh/5/PPIDEaNw== 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=nmrspKXMGT/hi3OPYL/nbCdED3zRLbcn1SvZk+w/BEAE+IgJEmA4hGHpPlMWMphQLF8twMXdXBrDVatLIJYeRvpGwYturYpHgFqIYJ+RwbHt3CBU+dR79GhrOcNrcVHza9qBUmvSqayJz5447kOWS2EPqkN4Kbyvj1y6P2T5n1LFjR6cSorXyhw65dNq7wA14oMrLU10Icw2PvkE6NhS+GfidoZTMVKD/TinuYwbs66SxZiYQMlrbtBqwfsLwfQNlNrm2rt68uvoBwgigMoc8nU2de/aLLqIwXNvYT8gzWc7S0Uj33lxD7UKIwKfohM67pt+j0E/Pv7e6GXcQ4X5YA== Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::20) by DM8P223MB0286.NAMP223.PROD.OUTLOOK.COM (2603:10b6:8:b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Thu, 25 Nov 2021 17:52:57 +0000 Received: from DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775]) by DM8P223MB0365.NAMP223.PROD.OUTLOOK.COM ([fe80::9c8d:fc63:9488:9775%5]) with mapi id 15.20.4734.022; Thu, 25 Nov 2021 17:52:57 +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: AQHX4iVHA8QgwsRZGkST3xouISLj6w== Date: Thu, 25 Nov 2021 17:52:57 +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: [yXooeTYYM0f4fLyq/Xu63NDwCya5hOHv] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a74743b1-40d7-4c3a-71d4-08d9b03c6a2e x-ms-traffictypediagnostic: DM8P223MB0286: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: neWe1zNrdun/JQR6GpAs8IYVUX1unNU/Y9A3IilHttry/4QgakrFxdUMLgouptY2Xy47Xvla3UKEofVHkuCZqFTw9KHivzHfrbdgJUfvUavuOsWDy03nPUMdjNqHLQoNzzdc8/ku7CQUIMW98WVEk7hPeal1KE3cKUU+U3cT9iscwH7jk4pi9gDccCmpve2Jn1Hq9w0kB1UYla1V5pQ/15B7HpUrbW3ofEuTniRBQ8RR6HTFHKx3UZ52QVY1Wzx8bjC5+9OyZS2UX//u15FzTcAQC8hSOFwNyiLxyttPGjwbItQMzYcgR5+0WiU7ObFzh0TnNIwo8/SPN/wwgfnf/ocAljqG9dt0UaBRqlNDj2naIaLCUwrKDZU7xlI4hBoB83SZxR0r9ENAAiI36g0/920FWsWM2mv9mtKsNRMKDMQYOg5OlE3rLAQFzp/RXNASOKw9vw3pJKQJXxPpFQdtV7ShOOwAH05/8p4Zyw7VyaZdweu0Guz+qtL5ujB8iBuIOdlcMqPRaK+W6pRKJfAV8XoZ6bo4Y5VBj1Q36zEoeekUhHbESkhdWMT3sCKudR3/zQm1lhgjR/P8U6b54BfOqQ== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: d+YCt8+BYqSpxi2zLMfYGiFUI3czPA9tWb8T3pLd+4TjQ9ugXqbZeuRmiStyybOwmv001IX+/eUa4M9+mm36lvGrWPCRCg2LkUBOvKHzsJROriI/4QR9xrHQDNpNBtz6woacsJFSLZBpQZgcLwlRFzzk9PxC3MAlXlQ5Zuxzb+ixwdqAMV9jQgbcC2K3Op7gJoJ9OVAjLNZLH8CCf9ZwBzxJMIrhNS0rIBdcCfqtwNiia9HKRTiK+ZtNXO6jfPI8o1Z+DKVGHCSVOtwEHaqyTgEQKAIz9Pt/4yoWHFh+DEApcDqmk4nvJhYoKQS6FWN2R8kHp8tDEF+awYId0bheZp+mhSSqqj/wzbGRcLoRPeu+8F86vaiaNzjrdtiFYaS3PO8XbF4mnmQIi8cShZNJXrGJETIPuuRG4+OwZWz74vHbWS/j1pV8GGDnng+5H7U1L3sohZISWZm3wcYWql8V4YW8VJA/TK0uoBTnbRvk8go3Ev4WVbeCSur/f0HhPhkR+OODyrQAwEot+5lQ3Qmn86vH2dgVITgV6z/qI2bfM4Svl42qRZ12WgxF1kdmiu18pmars+5VdzyTQ9ePIfyp82bNgImL6pkXd9PMHVqBQDGN19QO+Iy2HIbA+VAYZpK20dP0WeVBqaZC0FhL9z6CzYtVbiSQib+tq5zYxyZL0TvJWQe2pGLjnH055IkR8+6fVlHYj9zU5YIzHzRWvYE1pQ== 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: a74743b1-40d7-4c3a-71d4-08d9b03c6a2e X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Nov 2021 17:52:57.4784 (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: DM8P223MB0286 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: sAFOUlTGNi2X 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,