From patchwork Fri Aug 5 13:19:43 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: 37145 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:92a9:b0:8d:7f3b:94fc with SMTP id q41csp186709pzg; Fri, 5 Aug 2022 06:20:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR6it0RiH0QnPX9cfjdx2v+6xmpFrSldP0coWehs6qvTUT4SVz5nIQCVr9lyEM3JcX36Xa4u X-Received: by 2002:a05:6402:274b:b0:43b:f23f:e011 with SMTP id z11-20020a056402274b00b0043bf23fe011mr6801332edd.259.1659705620244; Fri, 05 Aug 2022 06:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659705620; cv=none; d=google.com; s=arc-20160816; b=SS01zLaGC2DkATlWKc8rJ6VBC/PypukWjBZaqPYBEM4uijpohHG5klxF0r67I5K+RG dKDJ+LOKfsuUC1ZD8N/x5x+V+IeU+ek7MWMzHdMg4iFG3DoSL3xVo/6t6Hvfl2wL3pcu jhj5RTqqpVNwtPdzvgtMaboM+qz/m6JKV6RgGRuN5g2Dlr3K6+8DsoIdfs2UO5omTJgi UDtPgjoQJ7RPpv4MoFH78SVS86PRKWAul2v6VQsEnM7NqJ7DE+PVLClf6qffQBnaujad QxzqSqkcx8VAW0QXOv1auxV/kNjA9CdimBUAQNO/SVBKwRNlT+Ems/4o8M7gNkQYAlbd MGUQ== 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=O4V6NjLnLyPnGH5E5pN/HmaTo92IpYJoIhvLIfEktYM=; b=hbzn+ZV1PcAExhDAJEYapTCE/ZVe7Ue0USRO5oMB4Ll2Q0tiS4Bo9Himb8UotePQwF OANjeap/3COWE+lbmGqk0+qtVGCtgcac8iyZMgrW/bp6xuG+ORkTDaCH+lohB8iGYJwC LTI3KDQ0muEHTHXgvFfAWwFU+F5pHYs3XRs+8m//vKLKZdltO4h9CHAOWb/wp+JtmsiK kOfQBtHzc+XwPs70oOg+Y70EXqLbtcCeJWWZJUNo5dVGdMWeI9OmAsSzcpkRWIIgTKjn syzPFX1ovmxS8pSu2NaJbtvpP0RhK4TXkBko788GfTR5EqOpNR90PsKg3V7t3/Aa9kQa a5sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=f5ExlbjI; 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 w20-20020a05640234d400b0043d2b797e58si4579772edc.497.2022.08.05.06.20.04; Fri, 05 Aug 2022 06:20:20 -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=f5ExlbjI; 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 47BAD68B590; Fri, 5 Aug 2022 16:20:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D0AC068B4F6 for ; Fri, 5 Aug 2022 16:19:52 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id y11so3402458lfs.6 for ; Fri, 05 Aug 2022 06:19:52 -0700 (PDT) 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; bh=vxHdnQrKY2vBXc5P0icor/74xIzNTj1NxH97YMfTiuo=; b=f5ExlbjIM1dR1/tgMVrSQAS2/5yFIepXDFIdsMatAwhuNBkeYz4fu4x2yf9n4i9lmr vFKoIgHwKj2lJEL/mENP4gFwKe5LLS6KlzMzMT+Zn7I39hnEl2i5Nh9l6p7OWfnRYtdf Jxn1xGzioph2RbcBV7dIqToVoNEIz2orG1xCPPliRy6NecIE+7sxh6v0VZbSqG77RUjU Bn32xNPB/BMhdFYe66u5r6swhbMZJsMaELzqDGHpoXTgucVM6/3eI/dOQqnW8+TI2agL kIBLQY9z3/ETQqPWFEC3fezJM4Lp6GuKR9PMvSZNClTxSNBg8eCnbHFcQWMpFj31ydM0 XW8g== 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; bh=vxHdnQrKY2vBXc5P0icor/74xIzNTj1NxH97YMfTiuo=; b=AKLREksx3q/++5Fgy4EhGOHcyXeusWTxLv16ofsnEGvo2jjpuGwno4yoseAgEzHDd4 qkoxnmjvP6CITHGwjRgFWBzSsXCqVz6m9NEHDd/KDaZ6ueySOkEM3Hub8tyOtdslPbsR Q8up/jEBfdyvFGbtBirW4sWs+nWvfES3HbvngmKrPz8RKhkXJg09jodug/CIDCmXIfEg B2m5cAOeg4ug2jex7Zzc6M1C2IMcxPXUJzIByw+HeuwZfs4j00tXB1FUZO/a5ZAlR1aX 05VeGUyLYIesy/baJYjIXRSh4AsoQg8gLBKZ4FgHNO0N3nIuqvhsiY6BIL1WrRehYPhK hP2Q== X-Gm-Message-State: ACgBeo1Ts4h0FeLM/E0GKYp3l5IJx5wmj3JHoGbmOQaR8QIOJYL3/OXQ BH/tTfLSMqIolSsUX+3uiOrDAOuTVpA= X-Received: by 2002:ac2:4f02:0:b0:481:43a8:e368 with SMTP id k2-20020ac24f02000000b0048143a8e368mr2221192lfr.65.1659705591808; Fri, 05 Aug 2022 06:19:51 -0700 (PDT) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id o20-20020a2e9b54000000b0025e2c5a12b6sm467373ljj.129.2022.08.05.06.19.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 06:19:50 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Aug 2022 16:19:43 +0300 Message-Id: <20220805131945.21970-1-jeebjp@gmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220729133537.53269-1-jeebjp@gmail.com> References: <20220729133537.53269-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 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: ACzWz5bD1blF 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..9b514a2db5 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 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, @@ -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 process_subtitle(ist, &subtitle, got_output); +} + static int send_filter_eof(InputStream *ist) { int i, ret;