From patchwork Mon Apr 4 11:30:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 35173 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp1913021pzb; Mon, 4 Apr 2022 04:35:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhDA0WSqxKffXBxU+vLw6XOU1XhiyFmr/X9HPPrkLfyN6kap3biNPIvKyuvfzI/QTvUtLz X-Received: by 2002:a50:d64f:0:b0:418:f142:5d1c with SMTP id c15-20020a50d64f000000b00418f1425d1cmr32534314edj.192.1649072132309; Mon, 04 Apr 2022 04:35:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649072132; cv=none; d=google.com; s=arc-20160816; b=coe06yDz9z5ICcoeocp0HooO7jAlZRYUTsfOF+vpBbExoZ56v3veYugsbQxoizuKqG kfISusOQmgUmLTyh1aydMSA1bCxnrFi0oyDXy1IMES8UPSby5BMrJKNXbvM5tGqVLbKK C2mINpEotO+uTj/VSu/po+WHHCvAkMBVe1MZ7JHHfeNCm2jOkPX18RcYiQxblUruUbIG 8d737kDTsbBus39xSPnm9RbCFD+re8GyIETrrLDAc/P9B3mfDb4JZ+77lCLE2+QCYPMi LpPbrJ+hAn2PnF4dlQPkLI3c0Iwddm1EVwM/vPryJOsjqmRTBNNtWBaFziUxmkYl+XfG crfg== 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:delivered-to; bh=MI9K3gFweuq9mS1DIzI/mowm1cc0ToVNfqrKg/BeXFc=; b=0Q/BQkAO8t3KJzRjFmTA1RDGH58pMozp5lY6ECZM8hJmrsv+geC+3VLhhU0z/Q1OH2 H4DkiomCblU04Ie1lXJ7gzpGAKnESh8UalQtaA12ORcKiWr0TX34VwiSENEZ0g+S3QPM EPYnbm9I2gLHApe3GLCvg4w8ybozM+cOdylQ150gBraMUiDljwwjjl6FzMQRW96mDuJP k03B0cAg33/KrU5Pnr8zDDEiugEAhXx+yBOI3IV0W+1T5IxfzHRrfsQK2G6RKKI/d4sX RCbgqJ8gAMEgxwVws/nYfnvb7euoZzeXiYaS2hruFwd8HYqd2/vyVbzq23sZRdf+D2pO DOtA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qx23-20020a170906fcd700b006df76385d9esi6346749ejb.574.2022.04.04.04.35.32; Mon, 04 Apr 2022 04:35:32 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3F95168B2F9; Mon, 4 Apr 2022 14:32:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D082668B24D for ; Mon, 4 Apr 2022 14:32:26 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 69D73240179 for ; Mon, 4 Apr 2022 13:32:26 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id imeLCcV3FY7h for ; Mon, 4 Apr 2022 13:32:25 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 7902924068D for ; Mon, 4 Apr 2022 13:32:15 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id DA7AB3A0B49; Mon, 4 Apr 2022 13:32:11 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Apr 2022 13:30:06 +0200 Message-Id: <20220404113037.13070-19-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220404113037.13070-1-anton@khirnov.net> References: <20220404113037.13070-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/49] fftools/ffmpeg: access output file chapters through a wrapper 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: TlKsp9Lz4WOH Avoid accessing the muxer context directly, as this will become forbidden in future commits. --- fftools/ffmpeg.c | 15 +++++++++------ fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_mux.c | 7 +++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index dfd57d2d03..b9ecbf4739 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2915,12 +2915,15 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, *next++ = 0; if (!memcmp(p, "chapters", 8)) { - - AVFormatContext *avf = output_files[ost->file_index]->ctx; + OutputFile *of = output_files[ost->file_index]; + AVChapter * const *ch; + unsigned int nb_ch; int j; - if (avf->nb_chapters > INT_MAX - size || - !(pts = av_realloc_f(pts, size += avf->nb_chapters - 1, + ch = of_get_chapters(of, &nb_ch); + + if (nb_ch > INT_MAX - size || + !(pts = av_realloc_f(pts, size += nb_ch - 1, sizeof(*pts)))) { av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n"); @@ -2929,8 +2932,8 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0; t = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); - for (j = 0; j < avf->nb_chapters; j++) { - AVChapter *c = avf->chapters[j]; + for (j = 0; j < nb_ch; j++) { + const AVChapter *c = ch[j]; av_assert1(index < size); pts[index++] = av_rescale_q(c->start, c->time_base, avctx->time_base) + t; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index ec0d454fcc..8e34ae0702 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -700,5 +700,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue); int of_finished(OutputFile *of); int64_t of_filesize(OutputFile *of); +AVChapter * const * +of_get_chapters(OutputFile *of, unsigned int *nb_chapters); #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 927d9228b7..9dd5e8b076 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -395,3 +395,10 @@ int64_t of_filesize(OutputFile *of) return ret; } + +AVChapter * const * +of_get_chapters(OutputFile *of, unsigned int *nb_chapters) +{ + *nb_chapters = of->ctx->nb_chapters; + return of->ctx->chapters; +}