From patchwork Fri Jul 22 13:48: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: 36891 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp442472pzb; Fri, 22 Jul 2022 06:48:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ua+R7KkaAVqqJ36ZxpnL6CfqCZ7jNhb0knNPX6/QK8vU/i9iyyz7+CyZwj7bRQgR5KoeN7 X-Received: by 2002:a05:6402:524a:b0:43a:c2a7:f52b with SMTP id t10-20020a056402524a00b0043ac2a7f52bmr816177edd.258.1658497707612; Fri, 22 Jul 2022 06:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658497707; cv=none; d=google.com; s=arc-20160816; b=MSK73MoXau3cFVgmnnRBOMnz2r+LJ7B9Tazqx4svV4LeMZpZHj9lEQUH0z1G2KhwP/ QrUtMmT0D/7OPVwBThF+EdNRXbwbEuPAtVNQfMTQ4fe4zBtV7km1EIMEcyi5I8Te/Wka zn9ffLv+7b9bCON2ayzQ/aFQZoReG4u4J7Q7zYHI4XtyHh1Qgkf8nO4gZoxf0X5OXbDP ggRpDRYdh8uuNdj27HWiYECrshdsr6au9TTKrtztiIQ/obx9NZwxewgk9axpkO4SAEn7 nl1npCTKbuufSu3HcHN++sTsBApLP+VbZkfOTtBYT2mjW9Jq7bEFaNuesYGcbDC1hSc7 J8pg== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=mhzXavTjIxMCZgEBcigHsvpObnVkw8UQDkcxEF6LeG8=; b=qZgbUJojhK0mqFVvkqT6SPO9uYIc+Jwk349NP364yk5TJvo/ikBirN5SyY0kba/llZ igCZSrlaSJbV173mt0FU9i/o2KdPXWE6nYR+cz+80cmOotZmnXKLvsBaa18qrauZQfnK 53UK+LXFP2vurNRGqVcrEnBiME4flhshyVj+i651qMPzNoA6GwY3nFC6UoFK9a/2gY+f qkyQCXU3oceI3wM93ORVZq1msnFZt0+TaDM/PVtsNTDWGrYTTC4IKcqw5QjXFXMMjZQg dckoPAPomf4NUC9I1lodQM02eCqzWLNYho9JGwM5laaEKQudCeMyEw855PvRQnXFuCcA VzNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ZwkD+0k4; 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 hd37-20020a17090796a500b00712018edf25si5752143ejc.687.2022.07.22.06.48.26; Fri, 22 Jul 2022 06:48:27 -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=ZwkD+0k4; 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 9ACE168B6EA; Fri, 22 Jul 2022 16:48:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1876368B451 for ; Fri, 22 Jul 2022 16:48:16 +0300 (EEST) Received: by mail-lj1-f177.google.com with SMTP id r14so5510808ljp.2 for ; Fri, 22 Jul 2022 06:48:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ni0hn6MljEx8SR45epxs3+gyPV0D4ZSF7MHypIYc0BM=; b=ZwkD+0k4+aN9hMBEcYZ/rFmqPc0hcjRT6WtDi07ZCvdDfMdLIf/Z2UehI+J0W2kjpo WSXUhGexoX0XWJ0f8QKiWD4kQ9SciTYSQdrs+KBq/vaZ+NOS6Gdir6fhwDdTCi4yQQc8 Mx6SjYz8yboTTrisr/MzFSAdVR2hLaoXNbvos4iGRAEBdVViNh9DMpmISU27ZUfBEYoV egrJha4ypfDbYB8fz7WT1dVlf+JKzHqZFSRdIVyIhsQWuRXetupMU6lXC/JWUh9k6KI2 jZXJnPu4f/2iT5cqgCPKtAIwb849lIfDsYFN9WgA57h1qLvL+JO3bpZGHlahu/RIPwUs B2Ng== 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:mime-version :content-transfer-encoding; bh=Ni0hn6MljEx8SR45epxs3+gyPV0D4ZSF7MHypIYc0BM=; b=Uq1qfaZ2Y8BJmQUASfKzdi4xjtphJP3V/qhvQn+wsz7QEMKEH5ib1Mmw2LBhNHNQYn qkX0gJlS83FBnwp7yopzAoVL5BR7+gRv6NjTsTH/GkgbsVxvoU/jJtWjL3gWNu4OGyc4 XOlTGKAGhpBsx5zrd4jdHSHpPdUD603UiA/ibttSUxvrH1NG18D/sOYRmbHtKY6cIeK6 9eJIvQwdyhZwdhvt/GIfrdhjGvDj+MK0UT9a+hpsOQTfVWhvOY0PHsCf5uBPaK2Zw9mc hdstODRV8uZn3HJj3+ploQMZBoBID41k40LqnBK+rMbFdbQ1fDf9TY3fQBtwozYE2V1S Bidw== X-Gm-Message-State: AJIora8tijISdbRXTEfocWJolBlvLRasMjj4AsFd81Y2LA02LHYotpgu GONc9yClh8+FXQc1eXrkgsOkhxtiIYU= X-Received: by 2002:a2e:9941:0:b0:25b:c885:3143 with SMTP id r1-20020a2e9941000000b0025bc8853143mr31972ljj.477.1658497694709; Fri, 22 Jul 2022 06:48:14 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id s2-20020a056512314200b0047f8cb94004sm1071647lfi.35.2022.07.22.06.48.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 06:48:13 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 Jul 2022 16:48:07 +0300 Message-Id: <20220722134808.16692-1-jeebjp@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: N7XPRIuQEvMF 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 ed3075f6e6..fb148a0404 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2278,27 +2278,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(ist->dec_ctx, AV_LOG_DEBUG, @@ -2310,7 +2299,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; } @@ -2319,40 +2308,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;