From patchwork Tue Dec 21 07:56:47 2021 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: 32775 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5181972iog; Mon, 20 Dec 2021 23:57:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWekSqh8+/fLwalGaV7JaMBj5N/tC+8dG0enyFF2+fod4tIvr0Bna84uF2QEvLJUNNXmd0 X-Received: by 2002:a50:cbcb:: with SMTP id l11mr2037390edi.195.1640073428063; Mon, 20 Dec 2021 23:57:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640073428; cv=none; d=google.com; s=arc-20160816; b=AuFfoQvAxo1PVFlOerD2T5aoqU0NCaWEIlixfUdtcu6sEz1wZ2r2zlIgXG10MkMddM 2HPU8615FX4YWvTHcHw3uNMvcCqVQvK5JyHsOHbc+RVqOs8eSBj60ZdVr/V7XssBjgn+ eSHOq+XUllE38xfvdRiT2Q+RPmhnOmunODicQgXlwGlL0G2r3PhW6DDJKWQO++3eGiyW ZGjF4zevco3B+BKokEDJI1DjPdKOcUzSr2CIx7PGcJ2qfDDL/aM+ToMAMiTtX3MQ82/E LIzl1/+NeNsiCygrYhrVqXXvMsQxny2JQHwbafezEm1COk4LmC5hOeTL4Avc5rQCM6qP kJjQ== 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=Rz8fMQhuJyj+HZYejYJ36g6h2HTVV7A7Y96yFtFWuLA=; b=gLEyodpBhrESNJewGvBJx0cfECUDidB0n0ae0/RmWTgEhjutCKtdrXYZcfbBThjuLW vYThYWKLSpHwJquSRJo9LDdFWj+7HT9bAMuI9KzfvstmSz6RwwhZw/qRj1Yo+JzQrE6i zEsZHDJW33YAv3xldsuRQNZcZ5kWkq8vJfWcqP+G+aoGr/LKkPCrfgKGytGvL+TpgHeq ee4G42jOzZOMlwrv8/uEbX8uHZMjCd2hbW7CjUAKdE3O51cZSqOmEqlhswOjNnzqzonf B6uDuAYlmBPNpegKeArX8RdH+1h8YsZRHe+qVHJ+yU0+GLyc6rZWylEQQ4CBnF6b6y4x NOdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=WazP0Zl7; 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 ox26si1965234ejb.331.2021.12.20.23.57.07; Mon, 20 Dec 2021 23:57:08 -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=WazP0Zl7; 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 1168A68AEFA; Tue, 21 Dec 2021 09:57:04 +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 2F14568AB2E for ; Tue, 21 Dec 2021 09:56:57 +0200 (EET) Received: by mail-lf1-f43.google.com with SMTP id g26so11627370lfv.11 for ; Mon, 20 Dec 2021 23:56:57 -0800 (PST) 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=gm6dcGHiqhKZYWzHVtOqOcv/hreywT9mfLrh/C2+usI=; b=WazP0Zl7O8XFQnzkxALcOQ3VBllGuRD9T6j8/cpBE8gUMMb51eLZh6sn3Ib07PnHNJ 1dH6CQxMJ+K80bE84cIFZgt0LaUBNwfmyaEuUb67l5aRr7rjflI0IZXFepFSFH/e+SwG JG/Yqj1TYm5ewY48rGpHtBiJJchBF9TheAAfpdCVQwC73iHzYWbrviv/r8c2myAktDnv o7qmy6aP00GNSUDj74UpDpEaCI6HeV0rceQGyfyZpEcnJVob6PoccH5oTED6/JDnCV6O qN+0n3233nNc+pgS46WatouYnyetzcWmvQPrYfjm8BB/rfGAMHgluYraQhDBCmJuXrgV qrEw== 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=gm6dcGHiqhKZYWzHVtOqOcv/hreywT9mfLrh/C2+usI=; b=Uv1ZAsPtOBAjTK+kVYkqAoc3cCykPtKkbxjLzmNxDeXm7XUFbV3dxSSNtda8StAd75 UgMiu3H4HYXZ7Tnlg3lDnfLvZkxilDRexy3MRkFDBVMLlt9kKUvOk8R97QTo1tRA6ZOV Kv9u14suMTfhmQ+s4N8IMwRnSy4liGtD2Fad3WmZ7AyVojY9m6SqxzaKYahe7dxWSDGj +O1nGr5wIyWZJGw463GwnXGWOCFaRc4ucm2DBPjudqSrv+VLrhqs7ZKhGfkrPaqk2JSW melUzc+7z9cNDppShyzuSL0pUumeWY4R85eXenFaR1/a49Wbmt0asICxditjd4Mv3gF8 Nx7g== X-Gm-Message-State: AOAM533MFlI5lt4jDQj3qmTF4z9iGubjXGdd4bCBnyK5PRN7FjSQPEfT 2o3VhnA55Z9lvBy9ehntwIAZfAKT3eU= X-Received: by 2002:a19:4f13:: with SMTP id d19mr2023322lfb.104.1640073416477; Mon, 20 Dec 2021 23:56:56 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j18sm2631729lfg.60.2021.12.20.23.56.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 23:56:56 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Dec 2021 09:56:47 +0200 Message-Id: <20211221075648.13059-1-jeebjp@gmail.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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: M139+vWRgRQr From: Jan Ekström This enables us to later call this when generating additional subtitles for splitting purposes. 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 bdeff9a12e..1697891a99 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2482,27 +2482,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, @@ -2514,7 +2503,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; } @@ -2523,7 +2512,7 @@ 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_alloc(8 * sizeof(AVSubtitle)); @@ -2534,31 +2523,50 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, if (ret < 0) exit_program(1); } - av_fifo_generic_write(ist->sub2video.sub_queue, &subtitle, sizeof(subtitle), NULL); + av_fifo_generic_write(ist->sub2video.sub_queue, subtitle, sizeof(*subtitle), NULL); 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;