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;