From patchwork Fri Jan 27 14:29:29 2023 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: 40144 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp1391799pzj; Fri, 27 Jan 2023 06:29:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXuN4MIjVLszVTjMz5WJZKh6dh5GinW7XwoEvB7IPCcnBW432eJoQsQVzqYkPCIX2l8oODXT X-Received: by 2002:a05:6402:194c:b0:498:b9ea:1896 with SMTP id f12-20020a056402194c00b00498b9ea1896mr47919639edz.9.1674829799537; Fri, 27 Jan 2023 06:29:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674829799; cv=none; d=google.com; s=arc-20160816; b=brbsBg248gtM7x5oe5Sn6kkjxoaXxD89dANXPpWVQLpeM3Y9ELAOzM9kaZhjIOCulo d8TRV9tE+L2VYVI+WjQMmvS/CHR6UDeE1dZIBSBcYOAGWrLExikFTQ+44mzdOUywTo57 T4brQp7q24jTNadfuMfB17ltaVlTO1LvBc4fOjiGFkpvEtGJ66RPFroLJwGNzu/864FB LCaWrY7mzdZUqFdPK7IN9D0sdUycLhXvYLm6uvROpb6jKS6feNpv4dfVj4yJM8jTLO7S anVyGGKmh3xlkmQ4/Pra45VAPcwGOVwHhYrL2kXM6cj598Ca33a4g38wc2qKLRB+okin 4/lg== 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=yz6Q+iSiACCSF5BWRmlmIIoUelJU2wzvVy8ECgmWRd4=; b=G101Pz5xyricPF583v0NCpyolGnLcNqNjFKv63lRIozdLBOPln/KqMdoyXteV3gz1Q 1z1QqdSo7py3eb9hb8kC8oRp7ocRXDoTt0gP4NPoQ3WtyTdPYqCBWAyNnt2UmhmwFEu+ fKSrTTWohQhRGP4HebPMMipbpNEpb5iIMW0nRNOsWyYQqbTbR97EZnyLVWxF8kixECJi n9HyRqckcaiqZvbEdUKkxAmcvyNFl2h+qQpb9m5r3+djYhdYY2mh+guUoZh2HF0XMpoV 2mHKCpmkf/mhoaUrE+9g8MSkPEus1CNdEZKxK/fndF0O+9p3yDyh+VwI1VZDaM8J8xAy 71rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=kGhime2X; 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 j18-20020a170906535200b00877da25cb20si5448574ejo.966.2023.01.27.06.29.59; Fri, 27 Jan 2023 06:29:59 -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=kGhime2X; 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 A7EF568BE2B; Fri, 27 Jan 2023 16:29:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0351868BB4C for ; Fri, 27 Jan 2023 16:29:41 +0200 (EET) Received: by mail-ej1-f54.google.com with SMTP id k4so8706082eje.1 for ; Fri, 27 Jan 2023 06:29:40 -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=TXcbWEAMm9uaLrKDs6a9snzoL6eSCt4fZTPwVBPPURk=; b=kGhime2X1CWvj3gTq9AGhhSe8lUIky804lM9170CY2U/qxd3dF7OA8TbYoNq22BrVI GBDbBceVFsTfZeJAzUCAEk8L+HEEOVy9zQw/4KUpz4ad7ql/xaqGIUA0tJciDey+4Zqx z75WIxKG2cT0wALzhniM6lNNOevDPBxYdnQlHOQ8VLKeV8J72AEbNz0DMIrDZf0Y8bdq BQ4UL6cpeOzYA8wvK3Gz0ooqTA+saXdF0u3/B4RyiKB+fWwOZokxIE8sstBDgzi7/xLM RfXIG+LPlQ2H0cfqcdXoxe3W5ya5FmQtM9tzSiPqNwggo0KN8uI6lky71H7crkNnpj0x yj8Q== 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=TXcbWEAMm9uaLrKDs6a9snzoL6eSCt4fZTPwVBPPURk=; b=WL89BohLUnQguDCnRaM+mPr2xbDIw32KD98GkzfWAvQzIVP3FxVGvdyLuDyycUt++a D1ISMP5EhWxfAvcMJhMDODfSbYGvA0zLJdb5DbQ6IAoc+maEiYGQfFR6BUUlvYHkqBq1 jZ35rPFRlLNFt3O6EbDZWuOZdd0fismx6m9Z+OhX/PoXHeVDeY7Px+9WZhApT2niT4V6 xNGtvW6kCFucSfcBFePNi0OwFv74VNJWBA1Cm3MfjRxEo7qzh/ObkEegKxwBCWakkH5Z aw0US3aQQaQiRKJM/02qVRAlxVMRJ9y9bA9oU1kkJwDyoCAieWyg50PQTAanZYtl49ma l7rw== X-Gm-Message-State: AFqh2kp9N7N+hn0cd8o6hAqZavnyOCA8/+IdJ1TP3WFxALjOFep03FDq 2QzQbHWzlfDoVOz33smHU7YyUyd7EkI= X-Received: by 2002:a17:907:2c65:b0:873:971:4dd with SMTP id ib5-20020a1709072c6500b00873097104ddmr43466494ejc.44.1674829780460; Fri, 27 Jan 2023 06:29:40 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id cm20-20020a170907939400b00871cb1b8f63sm2326387ejc.26.2023.01.27.06.29.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 06:29:39 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Jan 2023 16:29:29 +0200 Message-Id: <20230127142931.35061-2-jeebjp@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230127142931.35061-1-jeebjp@gmail.com> References: <20230127142931.35061-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 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: qdQ1DZeN6OV7 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 f722ae7632..1a062f3863 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2199,27 +2199,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, @@ -2231,7 +2219,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; } @@ -2240,20 +2228,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++; @@ -2263,15 +2251,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;