From patchwork Thu Jun 16 19:55:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36276 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1128847pzb; Thu, 16 Jun 2022 13:06:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vd8Ts6CVyaV+iBd+Ns1/Evqa3eWUhaj+AcqrDFGpWK5bRzAxYLUVN8x95CpSbu6QqjL9Dw X-Received: by 2002:a05:6402:190d:b0:431:4e5d:d780 with SMTP id e13-20020a056402190d00b004314e5dd780mr8649397edz.279.1655410005920; Thu, 16 Jun 2022 13:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655410005; cv=none; d=google.com; s=arc-20160816; b=qdEXes5ZDFB0Wwz1pIwEAV7tFgpxc/umOj2oMeaBXiRGC1OIlZCzO0H0g6ICEAtpCt ULxZZbW7DPzxRca8QZv8d9m22lvxHlHQD9RWYCPXYy3STevoQJzrlOWzKOEz9seLhXv3 bZvqe1oHGxsFL4cmmdm1Vk4NQMKI/BCqY2kyDF+UyDiQWXUcsTwsKZTIQm3EX57iYIYT sADcHk1WBX/1qVKMnhq0aisqAuoETH4L0ZGoMXPQsaVEih5iZYUAZszGnmla5IFFAXyX H7G/wV6b1ulwgrF8RnI1EcuR7CdYio5H0KCKUk2XoqiA7h1GTkC8AOiTo+nC+EggX8zo jQ3A== 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=53Ynzo2FOo8MWlKHQuhGFmeVRQB8V3kD3Ih10qOMYEs=; b=xQpGAGC/tiqBc0csvrrW/+Pha2EfDO0oboBIckRhlVYUu35rJu4mMi4c340zkO2lrp isToMyx76IKIxfGKZJtZunJ/ICTFX9gMFDL/nIW7H7xgP7ywckiTBDNdxQJkTRtR01kD SVTeicfryu1019czfTO+BjQsGFpWFINFUc8GqpX0q0F2na//e0bcW0dtsVk+fDwOcFz6 /UWA6Vh6McBtg3PYKTM7XEsrCfMAtIFdhyedkWEYWRVTQy5cZkCZ+U11TwvZxghQLjt7 NjA+I0EQrFm+xAoG9EGsK0Nx5qnH6xS+kRiWLVFZQtm1yn/QEHMFmzHeu0OAkgA8K79M RNlw== 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 eg42-20020a05640228aa00b004351e9a54d5si3084205edb.351.2022.06.16.13.06.41; Thu, 16 Jun 2022 13:06:45 -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 5B0BB68B887; Thu, 16 Jun 2022 23:03:59 +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 D822768B80F for ; Thu, 16 Jun 2022 23:03:40 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 10069240511 for ; Thu, 16 Jun 2022 22:03:39 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id IE3v6Z79i9I8 for ; Thu, 16 Jun 2022 22:03:38 +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 EDB48240555 for ; Thu, 16 Jun 2022 22:03:33 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 9D3533A141E; Thu, 16 Jun 2022 22:03:30 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Jun 2022 21:55:08 +0200 Message-Id: <20220616195534.5278-9-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220616195534.5278-1-anton@khirnov.net> References: <20220616195534.5278-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/35] 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: 9VNeEeQL7Zcr 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 75c2322091..d8ab0ffb9c 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2860,12 +2860,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"); @@ -2874,8 +2877,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 ea226eb901..7bc5d2ce2e 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -705,5 +705,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 78395bebb4..19519052fe 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -382,3 +382,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; +}