From patchwork Mon Oct 10 12:44:55 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: 38669 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp348500pzb; Mon, 10 Oct 2022 05:45:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7HulAdNfuwwBM7Pl75q9LmrmMT4ogJruytWvmBcm1rj1kFoEERpYBTyGOCCrEvQuGSpIkG X-Received: by 2002:a05:6402:11ce:b0:45b:f851:2941 with SMTP id j14-20020a05640211ce00b0045bf8512941mr7451647edw.177.1665405915689; Mon, 10 Oct 2022 05:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665405915; cv=none; d=google.com; s=arc-20160816; b=fExNhbUvvT3XaBmFE4gFGZkZkzcoJttUmSHgBup/30zrk7A+MIH+Qr+96Momfbdj/j NKRgDDXM7/zeDZa6H3JPZxpUEk32RbcNqh8xBLBvWvw5NMZYW6o8N34PtS22Hyd17ywc oIPWE0KT03W/D7xvzj52wHcI+rIbORbWcH2+YMkpk2B/+SST1z4eisN2wK7g/uLQglb4 6JRCAz27t1JasK6auBZDt4d7AdXwB/FJtD1jDW7tM57nsWAOMdM140LbsIAUZkKZ1n2t sPIWu6x5t+Ooih8/VzR7SyGTjBvhuLPw5RD082E1nYYkUNo3SvdFM4xRbr4TbyaS9zRm AdIA== 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=WVYRsE/13JE4xv0xMAC4CLD24kA7VV7/p+PQQ2yBNaI=; b=B1XhDXWJLR0V8Y/mXWbFS47U1RsjpBmoXmpa4++h+EFtuMRJfA2EGZCQypVo2RwTYx /kcmKRQEpBfS4vVsw8NOyd9bL1KGZik/SqcvmmX2BdSUjJutku9WzxGWeQYJlcu8uT1l DNRiyRZh1IpgGaMekb33uGIeamMai03P/XwocWelaVTxuiR4fDEQFLFx9RXsWl4/Oqwe kYeUkgLRkOO5EBTv8xFlQlHpC8ukZERAh9wIJ9WBnvxZV62MFGMgLDyGVaTquBlFSwSu 3aOlXgYOvhk1eVjPEJolcvex90L8dYz39c1/jh81sj49N9J6Mj5I3KQ3cPi0CagMX/8v jg/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=oYa2irhl; 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 d9-20020aa7d689000000b004594e0c0fd8si8844614edr.473.2022.10.10.05.45.14; Mon, 10 Oct 2022 05:45:15 -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=oYa2irhl; 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 BA52E68BCF0; Mon, 10 Oct 2022 15:45:10 +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 5711968BC82 for ; Mon, 10 Oct 2022 15:45:04 +0300 (EEST) Received: by mail-lj1-f177.google.com with SMTP id h8so1106822lja.11 for ; Mon, 10 Oct 2022 05:45:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=J73wwsUeNn41xwgMtd00inIX6ks7V+ANDHGVMLmxQXI=; b=oYa2irhl3+a0miwgPLanMuDqCmS5gt17jNBokzkn5vaIViB9ZOuPBtZ5N3jMsW53Fz 48L6lJCXeOfNntTs7J1EAWrAB5Jr+YY2F2gQW6woXq4xOq4a47lDoZ1Qux7vu0L7pfxL 3VLEsC6LXT3eWKTKvdYFaT5o9JJeKP1+YlcVOM1DtM0vJXmRs4wAZVsm1rLfbEGr7UoM R1TTCLFSoxd40kZeW8DNk7CQP/9QxH/TxIpJWeD1YHiP4jqfTsUuAZmvsTA0ae5MtAUo /o2bff5ehoFOL01X3GYGeJbWMlSj7yFrvD/aFkNAQuVRxwNrdmpi7VSPFMGT/BWTUy/p QHbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=J73wwsUeNn41xwgMtd00inIX6ks7V+ANDHGVMLmxQXI=; b=OHkMe51G5A+kbMNItLKjAuVh+icz5LIK6J/r1dazPjmQHS0UFusLzBae6/39X2zfh2 Fawrsbcy626AzWunndz9ki0qR8TsWtLOtiUXg1APx14KmkfYbmud2YZWk64SyAl7mp9L 5mhOLixqX0Ae8cgM8ki0fN8ycpuH5bXOpDNydHrB+gmQ2jgWqz7PXW31jgghv4KbQYD5 m+3qaxmvmUk+S+LpyRni16/tJIyKtHv7L/3+veTBFefx+akpqs2q9xa4QUrvIIU1rI7k lg537ophUB4qyB700qPLZJXTFsJIxF4lWm4fGQ2RH6xIlG9GCdfOagnAEnm4aorRqzcQ Y65Q== X-Gm-Message-State: ACrzQf28hyZnkzbIrRSLNoFGIHwsSp4iXlbZCxOHRspUBS19XMoDZTi+ rD82I+3M7cTZ0Ry3tQspnxioyNSHpqQ= X-Received: by 2002:a05:651c:107a:b0:26e:8998:3f63 with SMTP id y26-20020a05651c107a00b0026e89983f63mr4836036ljm.23.1665405903370; Mon, 10 Oct 2022 05:45:03 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id 14-20020a2e154e000000b0026dd1968533sm1657722ljv.86.2022.10.10.05.45.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 05:45:02 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Oct 2022 15:44:55 +0300 Message-Id: <20221010124457.9213-1-jeebjp@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 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: Et2e5czWsPIk 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 | 51 +++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 754172e568..fe350fe2bb 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2304,27 +2304,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 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, @@ -2336,7 +2324,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; } @@ -2345,40 +2333,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) 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++; - 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->enc_ctx || 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;