From patchwork Mon Dec 19 07:34:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 39727 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp3819100pzb; Sun, 18 Dec 2022 23:34:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf6OOwYwjffW2w05mLRwJ/NauW1tH7l37Y2KRFKJM+IILkUjyWDiD1chVn4ypv3jgTLX/h0h X-Received: by 2002:aa7:c047:0:b0:46d:6efb:b47a with SMTP id k7-20020aa7c047000000b0046d6efbb47amr33324980edo.41.1671435274261; Sun, 18 Dec 2022 23:34:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671435274; cv=none; d=google.com; s=arc-20160816; b=Rhv9qEJM4JXqwSBLmpk5LUIbF6YqqRB2DowcO10rHyXiLiy7usaPvi6wC8vrZy/F+q sKjtTNaFF2cPuie4+7imx58TmRbNTpj6hMYNxdGSJvPjmMf2EdUG3+ecJcVyUm9PKB9k 3D3b0aAkSKnwobD2tKsENO6Vj1+kaCmMmvrckbypZmrRuqhhyCf08QhF9bYuVU9620l4 AruH9ugH+AZ3kJ49TFBTOPqlGOi9oMIo2E73Ahgit881ErGswT1b58Z2cw8wP42samsd h6Mmm3MiB4deiEt2orbjyG49uggQwz2MIIGzTvf0srbvuLosx/Dv7YiHyDJZlzIK7k67 dObw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=LAFxX8wzL83jcyyGDa64spEokJOqZAQCTaicxhi3kt0=; b=mW15A/Hcq2INZD97OheHArS+QfdSoTqu6O1X1bdLtS+IGCzioBQR6aeZOfa+pL1Xkf /DuI9fnI9NojiojOvzmTohv0cYjsTMB0pafBn/6UAB9B8cXHafFSn6t1MlSQbIxjab9S Usl0BA2MQeTBQX1GmWHjiqD0jHKqbCoE9X82UeB5CP2V3QL5H1AX/OO9QHX4TYdevojs bOBWChaWwHdQZmcl7892ypq+JB6h9QRGwz4ayqsOZpRWUnPS46CypK6ONEkMcMl6pBYX +qHsbY76HpmAjKOfQFYYvTfe4h7c22qmKuxdUss//j/bBkAE0PlyO4ePD/A5ztAWLgbL Rp+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Q0JGRbMf; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l9-20020a056402028900b004595af54eacsi7374861edv.226.2022.12.18.23.34.33; Sun, 18 Dec 2022 23:34:34 -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=@gmail.com header.s=20210112 header.b=Q0JGRbMf; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5214868B32D; Mon, 19 Dec 2022 09:34:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D46A768A49E for ; Mon, 19 Dec 2022 09:34:17 +0200 (EET) Received: by mail-lf1-f52.google.com with SMTP id o6so7505327lfi.5 for ; Sun, 18 Dec 2022 23:34:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3PYtyLQ9HIgj1Yzp/rYxBGUyaX95lPSWVHTdR5/AuiA=; b=Q0JGRbMfyshSKvTzHZ843ZSr1DccfFD3H2KJ5zUT3UDjXhXMS7yVQjPig1ER1/7ZNQ 8n5fcXP1txHtXqqBk02NY+pkupcWSENbsFUVWjAKzFx4k464zwYW/yTW2nXyGKA0UP7A hLBGEILGXxZUax/8Is4jf0vGQwvtLFC1iJ67LuFDl7DeprwiSM6trIV7V88//P4ANLGx TvwrwvifAxuZ48YPk1Bvf29qKhjsvL4dSgHO3H235tXAORus9HeylXR0UMxxbkgVyzjj qo5NWGn39AYpuh34z5ed7xp3Xklb1Cg7llxCcp3GCKtO8PuDRKPY7kvtz2t7LbBZNVRY L3YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3PYtyLQ9HIgj1Yzp/rYxBGUyaX95lPSWVHTdR5/AuiA=; b=KxpPp7ecqKA6Gbg+MV9ZwqVihrERdyQ0C9PvqiEHakPvcAQE0d+7pSEIvjpiQ2wJeO UuFNzIrQ5FJ0OdQFmDH+npcq+fS8IW5KQyl4XWeuI7FbzjAOEW/GBFZzCDcQgGDYTpUJ H2F8XXfYtk7JptOrBCv+PT4WeFpy/jtcfBDhe/qxUjcbvEVRoVPTVWCkbtJ63Fbjc3FC stpdP3TNJf85p0Pc46l/B4XTpEpArbBH1FPCAaB0iQzzy9cq3a2JbDKCvTNHyKmljy0f gzHDIk0kgHRZ+poF3uFHoys0g7JQ0400WB7D4Pe+jKLW5yng8SxV4KDKL2wJy+9z3rIO dBmQ== X-Gm-Message-State: ANoB5plw7NAAcfweRH9UCRBFfohFy670k8U8/QYg7fIQ7mKo1X7TJL4k i3gazVG6JmPvlw4uP5Bp5l66hpe2Nuk= X-Received: by 2002:ac2:4c51:0:b0:4a4:8a04:4b37 with SMTP id o17-20020ac24c51000000b004a48a044b37mr15644598lfk.32.1671435257186; Sun, 18 Dec 2022 23:34:17 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id r7-20020a19ac47000000b004b58ebf0399sm1029165lfc.132.2022.12.18.23.34.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Dec 2022 23:34:16 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Dec 2022 09:34:06 +0200 Message-Id: <20221219073408.11501-2-jeebjp@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221219073408.11501-1-jeebjp@gmail.com> References: <20221219073408.11501-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 1/3] ffmpeg: refactor post-decoding steps for subtitles into a function 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: yytIfZlUDGgB From: Jan Ekström This enables us to later call this when generating additional subtitles for splitting purposes. Co-authored-by: Andrzej Nadachowski Signed-off-by: Jan Ekström --- fftools/ffmpeg.c | 49 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 881d6f0af2..eaf0a40328 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2187,27 +2187,15 @@ fail: return err < 0 ? err : ret; } -static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, - int *decode_failed) +static int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_output) { - AVSubtitle subtitle; + int ret = 0; int free_sub = 1; - int ret = avcodec_decode_subtitle2(ist->dec_ctx, - &subtitle, got_output, pkt); - - check_decode_result(NULL, got_output, ret); - - if (ret < 0 || !*got_output) { - *decode_failed = 1; - if (!pkt->size) - sub2video_flush(ist); - return ret; - } if (ist->fix_sub_duration) { int end = 1; if (ist->prev_sub.got_output) { - end = av_rescale(subtitle.pts - ist->prev_sub.subtitle.pts, + end = av_rescale(subtitle->pts - ist->prev_sub.subtitle.pts, 1000, AV_TIME_BASE); if (end < ist->prev_sub.subtitle.end_display_time) { av_log(NULL, AV_LOG_DEBUG, @@ -2219,7 +2207,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, } FFSWAP(int, *got_output, ist->prev_sub.got_output); FFSWAP(int, ret, ist->prev_sub.ret); - FFSWAP(AVSubtitle, subtitle, ist->prev_sub.subtitle); + FFSWAP(AVSubtitle, *subtitle, ist->prev_sub.subtitle); if (end <= 0) goto out; } @@ -2228,20 +2216,20 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, return ret; if (ist->sub2video.frame) { - sub2video_update(ist, INT64_MIN, &subtitle); + sub2video_update(ist, INT64_MIN, subtitle); } else if (ist->nb_filters) { if (!ist->sub2video.sub_queue) ist->sub2video.sub_queue = av_fifo_alloc2(8, sizeof(AVSubtitle), AV_FIFO_FLAG_AUTO_GROW); if (!ist->sub2video.sub_queue) report_and_exit(AVERROR(ENOMEM)); - ret = av_fifo_write(ist->sub2video.sub_queue, &subtitle, 1); + ret = av_fifo_write(ist->sub2video.sub_queue, subtitle, 1); if (ret < 0) exit_program(1); free_sub = 0; } - if (!subtitle.num_rects) + if (!subtitle->num_rects) goto out; ist->frames_decoded++; @@ -2251,15 +2239,34 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, || ost->enc_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) continue; - do_subtitle_out(output_files[ost->file_index], ost, &subtitle); + do_subtitle_out(output_files[ost->file_index], ost, subtitle); } out: if (free_sub) - avsubtitle_free(&subtitle); + avsubtitle_free(subtitle); return ret; } +static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, + int *decode_failed) +{ + AVSubtitle subtitle; + int ret = avcodec_decode_subtitle2(ist->dec_ctx, + &subtitle, got_output, pkt); + + check_decode_result(NULL, got_output, ret); + + if (ret < 0 || !*got_output) { + *decode_failed = 1; + if (!pkt->size) + sub2video_flush(ist); + return ret; + } + + return process_subtitle(ist, &subtitle, got_output); +} + static int send_filter_eof(InputStream *ist) { int i, ret; From patchwork Mon Dec 19 07:34:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 39728 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp3819165pzb; Sun, 18 Dec 2022 23:34:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf6H4EV6Lcu+8YIkoh6fpbr0Kwyv9jhU8dkwLGtEWAKlZcjd6e7FnguN/gt3Kv1iGQuXxeva X-Received: by 2002:a17:906:3a01:b0:7ad:aed7:a5da with SMTP id z1-20020a1709063a0100b007adaed7a5damr50663408eje.28.1671435281915; Sun, 18 Dec 2022 23:34:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671435281; cv=none; d=google.com; s=arc-20160816; b=cNmQpO224dtymsGWkAbvF+5igaqfgqYv+pp0BsGMbADP+loU9Hm+2ch6o4JLYSNDi3 n4mE6jW/BdF5wlzDLyj//XATs/uuf7HyFP8/vNuxZGrsV8lQYI+TDypI8wx2WAz8/i7p PgZHQyf5oCUsf05QlFCu1nJXCsVbGksIfvAD53j/r3dKuQPqfuBKJZ0FYa6Tc13SOp4t qjSyL3j4Um2TjQVRnvBcIgfhoZBxGbyw2fFqJoG5CfJvrdOmjH9OMPx7EqsBFVM/fYB0 /4FbLNp97uOhC5Mtb/0776iL02CX4MlPGBoJ9NBCXO3PIK+Xu4upVxfKMhoqWqk85gh7 j7pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=gxE1Z4inxNxg5QL1IyGobKuuKz0QV/xZZKVnI1177/Y=; b=Y2kbp6NHHizSyKksf+26jOINTgmTazLEQImpDm0dsyus5HZmpZn7ttTtMYeb4HYAxQ PWJ4lkz5LEBEpUIKqJCHCuAcY0/m/a5aO6a++WH7YAOkBs3o8oq5S4RnTaaynIPFhbco VhJnh/NT59UepI5QS7qqfKvYcKBI2sxguD/UoiC0PMk5WJMwqwitMMzrCBSqbsnHRGZb AlKjBLHp0tNGhcUnduXNwdaX2Jj2ozs5Dx+IU7sRgXDinzBYStNEzr7/oH2o1UhVbL01 ZT0xyhHgvnTAPp+zwRQvCE0/ebFvZuNketlUkb4m1yzj+l4SNveik/CWaza910Qz5KSm NQhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=dgewsN0a; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ty16-20020a170907c71000b007c0a96378easi7550915ejc.704.2022.12.18.23.34.41; Sun, 18 Dec 2022 23:34:41 -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=@gmail.com header.s=20210112 header.b=dgewsN0a; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 60B5D68B3E7; Mon, 19 Dec 2022 09:34:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 99DCE68B1F1 for ; Mon, 19 Dec 2022 09:34:18 +0200 (EET) Received: by mail-lf1-f52.google.com with SMTP id b3so12415565lfv.2 for ; Sun, 18 Dec 2022 23:34:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=GEP0D+wR/tbBLZZEgn3HvS7SVm90vZn7SNSMd64TtVc=; b=dgewsN0a0c7ORsgzRsUyDetfY2teZiyROF2w4oOuIXlUmKMR94YuX+zFrZcBpXltHx TKYHZQWQVYwaSTwY7W5Rdd0HAF8lRaxTIi5UvVPNAmvyYnysbYaa+53VZSn4PXcA4D44 RWhLEU+GoLK+lYaQzDLZpOOs19jY903I+kmczrrp4uXlC3Jh9MJDnaJsssr+NnJqCWsb fhtcU0cVrzwtkjFXa5z/5pMJRUEAdazAgVVJkZz/qL9xIgvFxZ8dSlPkHUUFOaaCvnaH fBlwBfT6iEzQr6bBgoQhYVo2IQ1k/Kqhafc/6SolbEkHzsw54ErnP8wiwg7sT/9I/6Os mdRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GEP0D+wR/tbBLZZEgn3HvS7SVm90vZn7SNSMd64TtVc=; b=VNvirGDJk4L65dMhgdMcjGv/NeSGHyDW7xBFyy2G4n/zWzmMlulvWhundEw/Bqp3Fb ar8+7F5RDIDsZihcGVv2mOiCNYuXWZ/n/hJcfnbPdxNMHVpcmHL/ZhGPY3xXAN1vumJf L3dwcTeAedu6ByO+GZaqeGi6E9VT0VXULQlJdGS+cgQBcUeBSMWUArUzRwoxPMSwZuBF TZCFUStYcvd+oNLt0TKaCZ2U152mdGeH2Z/E3tam5vJYyrZJj6zqepfcs4kd3i6Tzz5k DSvQ0AmIrYW1i9IiTu4K/sI6StnvHmE3sW4wJvi50i7yKEryzhdzOmZDSwyZNBCMrvDO 4E5w== X-Gm-Message-State: ANoB5pkLrATjHGhoigO37UvQS9TfH1p9PoyQo4JJ8bhHVYrzNzr90eeI OBGoQdIPqmpijmelnJ8Xy9nG+9brlec= X-Received: by 2002:a05:6512:2344:b0:4b5:a70f:8efc with SMTP id p4-20020a056512234400b004b5a70f8efcmr20632865lfu.64.1671435257922; Sun, 18 Dec 2022 23:34:17 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id r7-20020a19ac47000000b004b58ebf0399sm1029165lfc.132.2022.12.18.23.34.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Dec 2022 23:34:17 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Dec 2022 09:34:07 +0200 Message-Id: <20221219073408.11501-3-jeebjp@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221219073408.11501-1-jeebjp@gmail.com> References: <20221219073408.11501-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 2/3] ffmpeg: move decoded frame counter from after post-processing to decode 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: 0RQzQ5aGsSH7 From: Jan Ekström This way we can call process_subtitles without causing the decoded frame counter to get bumped. Additionally, this now takes into mention all of the decoded subtitle frames without fix_sub_duration latency/buffering, or filtering out decoded reset/end subtitles without any rendered rectangles, which matches the original intent in 4754345027eb85cfa51aeb88beec68d7b036c11e . Signed-off-by: Jan Ekström --- fftools/ffmpeg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index eaf0a40328..3b94eaaa58 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2232,8 +2232,6 @@ static int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_out if (!subtitle->num_rects) goto out; - ist->frames_decoded++; - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { if (!check_output_constraints(ist, ost) || !ost->enc_ctx || ost->enc_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) @@ -2264,6 +2262,8 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, return ret; } + ist->frames_decoded++; + return process_subtitle(ist, &subtitle, got_output); } From patchwork Mon Dec 19 07:34:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 39729 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp3819229pzb; Sun, 18 Dec 2022 23:34:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf7iU/8S9BALKRrIoOSeJ6XrlWLrp1FWu86Ix+ji2jiHRdP7aDMX5T0HuSqk+6z1agoGAgNE X-Received: by 2002:a05:6402:5389:b0:461:fc07:b9a7 with SMTP id ew9-20020a056402538900b00461fc07b9a7mr50476260edb.2.1671435289928; Sun, 18 Dec 2022 23:34:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671435289; cv=none; d=google.com; s=arc-20160816; b=uPl551NXvR7eSmi9Zp/VR/Z4mGzQF+9+mx6xS7Sppirfp4/lU+DKBUB9KMAEKE4urU DOFHpa75ga6r2gW4o+jyN7p1M9UNYkU48NQ7tfSX6kyfpmb6nJRelBoejlKicHYgGYRw hA9KgbgcNiSmiWujNYNiO2OEeNRli0Reoo++YjX2X9Ylp2A9uzFVJIdOix+7Ken2SX9s +p1Plh9TWIY+T/8crzx2f5Ja993UYwv6FYG+NhTKqWj3GGymq7rdrzEKY3rGgq39Bbcu h6FY8oPsYGjTRh14hgl+lPNXJ2nX1UjfU14Zg592TwF4Dbxw897StrD9P1hgMaBjk4Bw ++rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=3sNJcO5nCipzkXf66q8QvzccdXQkBnvxTNl70VPyk2M=; b=VC/7vwUwk87BmKig/9PxddLDsF3m2wF7//QluIRLoR8znjAUix3EXswjvlf+Q/k+NK RAcJY4R+kqIAX242O8YlkxVSt2XFa+IqInZziSilm+8P3o8eLWUJdSZ8upW1VrsfAbjR /ymFEI5P6cLs+1XMp/EFL9x9JQvr+nNi8iOpJxnDF6aRiyexC4Fl8vTcI+cGWeRRx/sR WKrzeIAhbdJ7itrhFcOVDP1lwq47Ihb7UUAeNdrOSjVkeCuWKg7D72525uJjznsZKsBp wywZunu0otqFecd9zx6mM+vw5FCi8i+tUIpud/QLwjxzxZTTd6JY6+T//tTLSzNuo/1w xZNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Qgn5zWuL; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q20-20020a056402033400b0043dc00e0740si7686273edw.373.2022.12.18.23.34.49; Sun, 18 Dec 2022 23:34:49 -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=@gmail.com header.s=20210112 header.b=Qgn5zWuL; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6158C68B460; Mon, 19 Dec 2022 09:34:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6215868A8C1 for ; Mon, 19 Dec 2022 09:34:19 +0200 (EET) Received: by mail-lf1-f43.google.com with SMTP id c1so12374369lfi.7 for ; Sun, 18 Dec 2022 23:34:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=KpLWpzBX42NKrvxzQ0vgpdR8ff9t1MU2QUluDoU3FJY=; b=Qgn5zWuL6wfUyJ8RLWa05NdJw+P6B3cxQp7z1wDxmhNevhyYRu+bfVcvFbycIla8c/ 74YRZHvGNFQu5Fb/L5EP5eXSwJhuaF66jMhteZjz6vKXtJDKt6wGh7fXy7LIvMuPyVLU R39I+3C0DUuPFkZiUxWOQKyt/tJqoq20y3gN1L0ZNiYUbSFgn6wpl+ScK3+sKniFR1Ou Xm0ZZUdRUUYdxQNhjIxX2Y7N2FUlI8kzrH3yW302joPMfsuXCtnbbOqtHO1wNkfocAEq DdxxWuNtbGs9FK96IMFjBXNi89r4IclZM+ss2C7FRNz/B5yIWqdBN7Zjoq0H9YIZAbCq 2Kwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KpLWpzBX42NKrvxzQ0vgpdR8ff9t1MU2QUluDoU3FJY=; b=FgDQYxcLLJ7uKd/F2h0wxanBxGmSfa5B+d2rbUgg6xjzpMPHVUnX6EohEQpJly4wXT 3fR4OYDMRC0bYLsbCkgldTkEvowjU+yx7yJmyH/AFmPdOLeRnaqPXwrkljL743QT/MP3 JcyX8qqazrhWGqKc5LJiI1rTYT43OlQBnTiRgZIrjZNMlSMSV/vb3rtLs1OqodVc7C9e m85J/35SaFCBTYJQe4k7GTgEB5CPduWeOgzY+szTuUgJoVz3QXRCJ1HSz/kH563ueY6t 5TBX/WlmUQIIDiXjM6350cc4UKrGgcmWrUNjIeiJ5CnH3sGqKVQIafYmTTHtm1StkOTP UNSQ== X-Gm-Message-State: ANoB5pnmk54P67OeRIwEbE2jUp2jWbCYYcZPvx/W27SdXi9bo9ajs6to lTRMizMK9wJY4heKryFqhMiX/FSp0MM= X-Received: by 2002:a05:6512:33c5:b0:4a4:68b7:f86d with SMTP id d5-20020a05651233c500b004a468b7f86dmr22802943lfg.17.1671435258617; Sun, 18 Dec 2022 23:34:18 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id r7-20020a19ac47000000b004b58ebf0399sm1029165lfc.132.2022.12.18.23.34.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Dec 2022 23:34:18 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Dec 2022 09:34:08 +0200 Message-Id: <20221219073408.11501-4-jeebjp@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221219073408.11501-1-jeebjp@gmail.com> References: <20221219073408.11501-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 3/3] ffmpeg: add video heartbeat capability to fix_sub_duration 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: tlUcfsOLzz3u From: Jan Ekström Splits the currently handled subtitle at random access point packets that can be configured to follow a specific output stream. This way the subtitle - which is known to be shown at this time can be split and passed to muxer before its full duration is yet known. This is also a drawback, as this essentially outputs multiple subtitles from a single input subtitle that continues over multiple random access points. Thus this feature should not be utilized in cases where subtitle output latency does not matter. Co-authored-by: Andrzej Nadachowski Co-authored-by: Bernard Boulay Signed-off-by: Jan Ekström --- doc/ffmpeg.texi | 14 ++ fftools/ffmpeg.c | 141 ++++++++++++++++++ fftools/ffmpeg.h | 8 + fftools/ffmpeg_mux_init.c | 4 + fftools/ffmpeg_opt.c | 5 + tests/fate/ffmpeg.mak | 14 ++ .../fate/ffmpeg-fix_sub_duration_heartbeat | 48 ++++++ 7 files changed, 234 insertions(+) create mode 100644 tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 0367930a3b..d5f231e635 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1339,6 +1339,20 @@ List all hardware acceleration components enabled in this build of ffmpeg. Actual runtime availability depends on the hardware and its suitable driver being installed. +@item -fix_sub_duration_heartbeat[:@var{stream_specifier}] +Set a specific output video stream as the heartbeat stream according to which +to split and push through currently in-progress subtitle upon receipt of a +random access packet. + +This lowers the latency of subtitles for which the end packet or the following +subtitle has not yet been received. As a drawback, this will most likely lead +to duplication of subtitle events in order to cover the full duration, so +when dealing with use cases where latency of when the subtitle event is passed +on to output is not relevant this option should not be utilized. + +Requires @option{-fix_sub_duration} to be set for the relevant input subtitle +stream for this to have any effect. + @end table @section Audio Options diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 3b94eaaa58..1fde4bf0f5 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -119,6 +119,7 @@ typedef struct BenchmarkTimeStamps { int64_t sys_usec; } BenchmarkTimeStamps; +static int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt); static BenchmarkTimeStamps get_benchmark_time_stamps(void); static int64_t getmaxrss(void); static int ifilter_has_all_input_formats(FilterGraph *fg); @@ -870,6 +871,13 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base)); } + if ((ret = trigger_fix_sub_duration_heartbeat(ost, pkt)) < 0) { + av_log(NULL, AV_LOG_ERROR, + "Subtitle heartbeat logic failed in %s! (%s)\n", + __func__, av_err2str(ret)); + exit_program(1); + } + ost->data_size_enc += pkt->size; if (enc->codec_type == AVMEDIA_TYPE_VIDEO) @@ -1817,6 +1825,16 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p opkt->duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->mux_timebase); + { + int ret = trigger_fix_sub_duration_heartbeat(ost, pkt); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, + "Subtitle heartbeat logic failed in %s! (%s)\n", + __func__, av_err2str(ret)); + exit_program(1); + } + } + of_output_packet(of, opkt, ost, 0); ost->streamcopy_started = 1; @@ -2246,6 +2264,129 @@ out: return ret; } +static int copy_av_subtitle(AVSubtitle *dst, AVSubtitle *src) +{ + int ret = AVERROR_BUG; + AVSubtitle tmp = { + .format = src->format, + .start_display_time = src->start_display_time, + .end_display_time = src->end_display_time, + .num_rects = 0, + .rects = NULL, + .pts = src->pts + }; + + if (!src->num_rects) + goto success; + + if (!(tmp.rects = av_calloc(src->num_rects, sizeof(*tmp.rects)))) + return AVERROR(ENOMEM); + + for (int i = 0; i < src->num_rects; i++) { + AVSubtitleRect *src_rect = src->rects[i]; + AVSubtitleRect *dst_rect; + + if (!(dst_rect = tmp.rects[i] = av_mallocz(sizeof(*tmp.rects[0])))) { + ret = AVERROR(ENOMEM); + goto cleanup; + } + + tmp.num_rects++; + + dst_rect->type = src_rect->type; + dst_rect->flags = src_rect->flags; + + dst_rect->x = src_rect->x; + dst_rect->y = src_rect->y; + dst_rect->w = src_rect->w; + dst_rect->h = src_rect->h; + dst_rect->nb_colors = src_rect->nb_colors; + + if (src_rect->text) + if (!(dst_rect->text = av_strdup(src_rect->text))) { + ret = AVERROR(ENOMEM); + goto cleanup; + } + + if (src_rect->ass) + if (!(dst_rect->ass = av_strdup(src_rect->ass))) { + ret = AVERROR(ENOMEM); + goto cleanup; + } + + for (int j = 0; j < 4; j++) { + // SUBTITLE_BITMAP images are special in the sense that they + // are like PAL8 images. first pointer to data, second to + // palette. This makes the size calculation match this. + size_t buf_size = src_rect->type == SUBTITLE_BITMAP && j == 1 ? + AVPALETTE_SIZE : + src_rect->h * src_rect->linesize[j]; + + if (!src_rect->data[j]) + continue; + + if (!(dst_rect->data[j] = av_memdup(src_rect->data[j], buf_size))) { + ret = AVERROR(ENOMEM); + goto cleanup; + } + dst_rect->linesize[j] = src_rect->linesize[j]; + } + } + +success: + *dst = tmp; + + return 0; + +cleanup: + avsubtitle_free(&tmp); + + return ret; +} + +static int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts) +{ + int ret = AVERROR_BUG; + int got_output = 1; + AVSubtitle *prev_subtitle = &ist->prev_sub.subtitle; + AVSubtitle subtitle; + + if (!ist->fix_sub_duration || !prev_subtitle->num_rects || + signal_pts <= prev_subtitle->pts) + return 0; + + if ((ret = copy_av_subtitle(&subtitle, prev_subtitle)) < 0) + return ret; + + subtitle.pts = signal_pts; + + return process_subtitle(ist, &subtitle, &got_output); +} + +static int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt) +{ + int64_t signal_pts = av_rescale_q(pkt->pts, ost->mux_timebase, + AV_TIME_BASE_Q); + + if (!ost->fix_sub_duration_heartbeat || !(pkt->flags & AV_PKT_FLAG_KEY)) + // we are only interested in heartbeats on streams configured, and + // only on random access points. + return 0; + + for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { + int ret = AVERROR_BUG; + + if (!ist->decoding_needed || + ist->dec_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) + continue; + + if ((ret = fix_sub_duration_heartbeat(ist, signal_pts)) < 0) + return ret; + } + + return 0; +} + static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, int *decode_failed) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 5527dbe49b..896297fef6 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -224,6 +224,8 @@ typedef struct OptionsContext { int nb_reinit_filters; SpecifierOpt *fix_sub_duration; int nb_fix_sub_duration; + SpecifierOpt *fix_sub_duration_heartbeat; + int nb_fix_sub_duration_heartbeat; SpecifierOpt *canvas_sizes; int nb_canvas_sizes; SpecifierOpt *pass; @@ -625,6 +627,12 @@ typedef struct OutputStream { int sq_idx_encode; int sq_idx_mux; + + /* + * bool on whether this stream should be utilized for splitting + * subtitles utilizing fix_sub_duration at random access points. + */ + unsigned int fix_sub_duration_heartbeat; } OutputStream; typedef struct OutputFile { diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 0280759b05..1e0abf1fca 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -57,6 +57,7 @@ static const char *const opt_name_disposition[] = {"disposition", static const char *const opt_name_enc_time_bases[] = {"enc_time_base", NULL}; static const char *const opt_name_filters[] = {"filter", "af", "vf", NULL}; static const char *const opt_name_filter_scripts[] = {"filter_script", NULL}; +static const char *const opt_name_fix_sub_duration_heartbeat[] = {"fix_sub_duration_heartbeat", NULL}; static const char *const opt_name_fps_mode[] = {"fps_mode", NULL}; static const char *const opt_name_force_fps[] = {"force_fps", NULL}; static const char *const opt_name_forced_key_frames[] = {"forced_key_frames", NULL}; @@ -342,6 +343,9 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample, oc, st); + MATCH_PER_STREAM_OPT(fix_sub_duration_heartbeat, i, ost->fix_sub_duration_heartbeat, + oc, st); + if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx) ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 3df02b7d7f..d187da88a0 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1648,6 +1648,11 @@ const OptionDef options[] = { { "autoscale", HAS_ARG | OPT_BOOL | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(autoscale) }, "automatically insert a scale filter at the end of the filter graph" }, + { "fix_sub_duration_heartbeat", OPT_VIDEO | OPT_BOOL | OPT_EXPERT | + OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(fix_sub_duration_heartbeat) }, + "set this video output stream to be a heartbeat stream for " + "fix_sub_duration, according to which subtitles should be split at " + "random access points" }, /* audio options */ { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames }, diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak index d87639c596..a983ace3bd 100644 --- a/tests/fate/ffmpeg.mak +++ b/tests/fate/ffmpeg.mak @@ -117,6 +117,20 @@ fate-ffmpeg-fix_sub_duration: CMD = fmtstdout srt -fix_sub_duration \ -real_time 1 -f lavfi \ -i "movie=$(TARGET_SAMPLES)/sub/Closedcaption_rollup.m2v[out0+subcc]" +# Basic test for fix_sub_duration_heartbeat, which causes a buffered subtitle +# to be pushed out when a video keyframe is received from an encoder. +FATE_SAMPLES_FFMPEG-$(call FILTERDEMDECENCMUX, MOVIE, MPEGVIDEO, \ + MPEG2VIDEO, SUBRIP, SRT, LAVFI_INDEV \ + MPEGVIDEO_PARSER CCAPTION_DECODER \ + MPEG2VIDEO_ENCODER NULL_MUXER PIPE_PROTOCOL) \ + += fate-ffmpeg-fix_sub_duration_heartbeat +fate-ffmpeg-fix_sub_duration_heartbeat: CMD = fmtstdout srt -fix_sub_duration \ + -real_time 1 -f lavfi \ + -i "movie=$(TARGET_SAMPLES)/sub/Closedcaption_rollup.m2v[out0+subcc]" \ + -map 0:v -fix_sub_duration_heartbeat:v:0 \ + -c mpeg2video -b:v 2M -g 30 -sc_threshold 1000000000 \ + -f null - + FATE_STREAMCOPY-$(call REMUX, MP4 MOV, EAC3_DEMUXER) += fate-copy-trac3074 fate-copy-trac3074: CMD = transcode eac3 $(TARGET_SAMPLES)/eac3/csi_miami_stereo_128_spx.eac3\ mp4 "-codec copy -map 0" "-codec copy" diff --git a/tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat b/tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat new file mode 100644 index 0000000000..957a410921 --- /dev/null +++ b/tests/ref/fate/ffmpeg-fix_sub_duration_heartbeat @@ -0,0 +1,48 @@ +1 +00:00:00,968 --> 00:00:01,001 +{\an7}( + +2 +00:00:01,001 --> 00:00:01,168 +{\an7}( + +3 +00:00:01,168 --> 00:00:01,368 +{\an7}( inaudibl + +4 +00:00:01,368 --> 00:00:01,568 +{\an7}( inaudible radio chat + +5 +00:00:01,568 --> 00:00:02,002 +{\an7}( inaudible radio chatter ) + +6 +00:00:02,002 --> 00:00:03,003 +{\an7}( inaudible radio chatter ) + +7 +00:00:03,003 --> 00:00:03,103 +{\an7}( inaudible radio chatter ) + +8 +00:00:03,103 --> 00:00:03,303 +{\an7}( inaudible radio chatter ) +>> + +9 +00:00:03,303 --> 00:00:03,503 +{\an7}( inaudible radio chatter ) +>> Safety rema + +10 +00:00:03,504 --> 00:00:03,704 +{\an7}( inaudible radio chatter ) +>> Safety remains our numb + +11 +00:00:03,704 --> 00:00:04,004 +{\an7}( inaudible radio chatter ) +>> Safety remains our number one +