From patchwork Fri Jul 29 13:35:36 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: 37038 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp892325pzb; Fri, 29 Jul 2022 06:36:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s6CIwcbiVKbAmEUWjqylBCJeeRHq7rH3mHkkQQj9VQPUVAM5zeStpU/PWcheuk0Wo+eHMw X-Received: by 2002:a17:906:84f7:b0:72b:47ba:33b6 with SMTP id zp23-20020a17090684f700b0072b47ba33b6mr2696218ejb.699.1659101762376; Fri, 29 Jul 2022 06:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659101762; cv=none; d=google.com; s=arc-20160816; b=s4xu98b4KQKmeshPyRCiUk0cuWjpZG4DzVe0BQ3xENN9L5Sj+maXqHBRT7jy8OXkJO sYJqjyggWTokve0asYyZXdDbD4a9HMXJSuWH2RBNaWsV0E9HsTw7Fijh74jOPNJjOpf5 YxQoaIsvE/Xo6LBXVMoFKVOFg6mZcPMO33zsC8NTHkU/QhHVrqS+RUY9KeU/CriiBveJ mH14vYzyhsUUbp38ZeXqWXqrkj++vj3lU/H4ItZULYPNCkJfwkGMjWbj6te/sZJQv+/w n4mJA+HxM9sLap1IkXCvp+DjyFNhESZ0SGW3t+TYwyc2iMCf+HoLfHIpRd3oLvFRylzf GW8w== 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=GSIyH/oKEj16H2tkJ1Bk1wLm9wi/li7QBN2e7uscKPU=; b=vV6x+pPBQ+BepGDe0d9xV5Li8Daq0GKc/gsOgN4JsIBZ5CzBSa1k2BQPXOaFFXLSiU WWTl6E6GsRx1vK/m+fONacFPZgPp7DmE8+h/4HyWhHZy1ZLDeEqfeF3fIIuzEvRryPj5 bB8gSlKYyaAQoO5kbtDAmxZsOPwNms5Zi58Svz7O73jhOBJEahXqyszi2A9uzPeforrC 59KN4qjzw+iWLF1NIPNOgTOkVICUEI+tA8rmT7XW7E/s4q4mMSQjxexHj25oj2hes+BA RSEe/DRLyMLoaQwcKqMBgFcVYYQrkZ6kIWSojTtyQmn7q5GTWwHDKTkjmdSafeWvbLBf XqiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=D9l4HAJJ; 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 c13-20020a05640227cd00b0043d0b75fda2si2613393ede.345.2022.07.29.06.35.54; Fri, 29 Jul 2022 06:36:02 -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=@gmail.com header.s=20210112 header.b=D9l4HAJJ; 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 7441068B9F6; Fri, 29 Jul 2022 16:35:50 +0300 (EEST) 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 F0E9968B8A3 for ; Fri, 29 Jul 2022 16:35:43 +0300 (EEST) Received: by mail-lf1-f43.google.com with SMTP id u3so4587370lfl.3 for ; Fri, 29 Jul 2022 06:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=uegzU56TyZnyqZfD7NKFgTr3fiPeQkYG4NHmHPyGDkg=; b=D9l4HAJJ8DV57gSTd1Imeinfd3N89HPNQruYqch/3RNbcRpEA8+Gine7cgA8apfZx5 Bhoyyr6WkRGIOfaZyDrxaOp3tKn2tbMOwsnwz4BqTHeoMQK6AHPSlmbCkH6fyFgSdNtX 8Tm+yJXVoBw6EdEbA2wJuQzg1ygFjS7SoftibQhzauP7J1IIUrIcR2/jLxKuIiRV7bqt jlkfSE7bHTBe3KQ7qCSvOibuk0yrKTqTBuxAJtarZbx4Flv26Gv+nBID7VWqpQmOC+V0 adc2LMZ4SfllJ8mUSGkYmo+WZAWOf3GeMISewd/CR6bgUAsrPsMPkwmu5bBBJ0cHsosv fSgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uegzU56TyZnyqZfD7NKFgTr3fiPeQkYG4NHmHPyGDkg=; b=fzNtvSmH7hfxwoBr6x/wVlrvHhB7G2y7Topzjo7eca7qWy3h/zAMb5OD0PN8OZg5d6 96T3XFP57sU654a1smJWyTn50g+z1TtCc/Y5/vjJO9hfvlTg8TA4J5NokydY9rgJGXbw z1sl0zAqCpou4vJxlWp5x+/1Tq5zFMW4x7RXG+pWixFizoDQLK0JCHfEsPa7sHwB+h/S 3EzEv6TuAid/PFj06uhjXql6W3p+cyh9JjDa3bxgJ1YxFYHlr2AElWgBbldqUWKe4ozc j4/NNnIb7quy6EB7TyX4DyCOoMtB/GOV2WPnjCYBX9t/c1nA3xkCChibpjvB1lLzExp4 9MIg== X-Gm-Message-State: AJIora/nH220WABMstbutKr4Xkm0uMLq25skKv3kByUYIan60V5TjTiG UTsl+ipO96DrFrVggSoE99IIKXsU/Us= X-Received: by 2002:a05:6512:2290:b0:48a:9b0c:e12a with SMTP id f16-20020a056512229000b0048a9b0ce12amr1432490lfu.616.1659101742998; Fri, 29 Jul 2022 06:35:42 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id a3-20020a19e303000000b0048a68fe3745sm667589lfh.34.2022.07.29.06.35.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 06:35:42 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 Jul 2022 16:35:36 +0300 Message-Id: <20220729133537.53269-1-jeebjp@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220722134808.16692-1-jeebjp@gmail.com> References: <20220722134808.16692-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/2] 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: ajNoD1Cgfx8q 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 | 50 ++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4746742c02..adcab43a30 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2301,27 +2301,16 @@ fail: return err < 0 ? err : ret; } -static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, - int *decode_failed) +static int encode_mux_subtitles(InputStream *ist, AVSubtitle *subtitle, int *got_output) { - AVSubtitle subtitle; + int ret = 0; int free_sub = 1; - int i, 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, @@ -2333,7 +2322,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; } @@ -2342,40 +2331,59 @@ 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) exit_program(1); - 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++; - for (i = 0; i < nb_output_streams; i++) { + for (int i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; if (!check_output_constraints(ist, ost) || !ost->encoding_needed || ost->enc->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 encode_mux_subtitles(ist, &subtitle, got_output); +} + static int send_filter_eof(InputStream *ist) { int i, ret;