From patchwork Mon Dec 13 15:20:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 32439 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5576644iog; Mon, 13 Dec 2021 07:25:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMg/FdT6696d0tgT4a7NxNvgTlkEOnJVk4lQzWN4GaJnvOa5fmH+czUzZX612K4NSoJGZz X-Received: by 2002:a17:907:2723:: with SMTP id d3mr1218157ejl.654.1639409153190; Mon, 13 Dec 2021 07:25:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639409153; cv=none; d=google.com; s=arc-20160816; b=dqFY33jVFqC1QY+NMSyQ/YH4C4VUOr6mSOEDa5Zc0U1gy9YH+eXKckbYkyz2fGxjmD 35lEFb4j1Dlj/XusrrJsN9rF3ItI3uPg0hAw7Kykg5BxjaBc2M7dlhHMu0JmoahYUAtP rPJyR6Wn6+xt8xmnQyUywxczWCGHhxG6eypIJw8WqssSKhJi3GdN69Ei+2UHMrHiuPrQ DMbLygyZaYJIJbzgy7cd2waZQnCSvANXBtwMudoih+opApwpfyjslYPzuMv7mHTFSgGm ASeMkD/9B7Vsi4Iccvhbaty0sjQnC/QRx5y3c1X7F+EKFAKzkB64t5ajAQ17mhOpUAte Td7A== 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=8sk75POO2uUesRsfYp7G/UshT5QHRxlO5721rO7gxBE=; b=iz8igt1g/aHNlwO8WH65jhTYTtNWnk4aaTuBdx1qaGPIS7BmnvqyLMpsAlcl5gGmt0 8Zed6UTY4rrZrQmSwEFfi+Fq+nYKequ16mSRMx7zZaRed6j7kfJ7+Ga8EtSWO9E6TI73 yQbI5NagxCbCof0+n2hBcek4LfLIs1tvj4IrKTXOGeTQXFt0Ec1AhK0RkOen/c2Si5sy t9Dxv4xehsV/NKIiMh9DdH1z8e5K+QYlljENte6D/WomjJv09NnNwK65mHIHWqhOyUBH 8VqZnrfM2mH9G3Mb5Z2X0v6rCZUpb8d9Bo4OXs4+zucu79qSewhue1R+7RK+cd2/QqJY 8qZg== 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 bl4si15314569ejb.152.2021.12.13.07.25.52; Mon, 13 Dec 2021 07:25:53 -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; 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 3278E68AF75; Mon, 13 Dec 2021 17:22:34 +0200 (EET) 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 9DBC168AFBE for ; Mon, 13 Dec 2021 17:22:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6380A24052D for ; Mon, 13 Dec 2021 16:22:12 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id OMn4TenVAiZb for ; Mon, 13 Dec 2021 16:22:11 +0100 (CET) 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 D2643240590 for ; Mon, 13 Dec 2021 16:22:07 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 49FB33A0B4A; Mon, 13 Dec 2021 16:22:07 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 13 Dec 2021 16:20:34 +0100 Message-Id: <20211213152042.5900-16-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211213152042.5900-1-anton@khirnov.net> References: <20211213152042.5900-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/24] 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: aGdxkmM5hFc/ 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 902f190191..d69e4119ef 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2909,12 +2909,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"); @@ -2923,8 +2926,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 78c2295c8e..8119282aed 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -697,5 +697,7 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue); int of_finished(OutputFile *of); int64_t of_bytes_written(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 3ee0fc0667..6c9f10db9c 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -390,3 +390,10 @@ int64_t of_bytes_written(OutputFile *of) return of->mux->final_filesize ? of->mux->final_filesize : pb ? pb->bytes_written : -1; } + +AVChapter * const * +of_get_chapters(OutputFile *of, unsigned int *nb_chapters) +{ + *nb_chapters = of->ctx->nb_chapters; + return of->ctx->chapters; +}