From patchwork Tue Jan 11 09:58:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33227 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3547707iog; Tue, 11 Jan 2022 02:03:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkgRoGoW5BezQsh/DltARIgOpP9UxT3zYt1k0utyj9zhbtdj0+kN8hqAco621vbnlT8Udu X-Received: by 2002:a05:6402:4387:: with SMTP id o7mr1675983edc.23.1641895402665; Tue, 11 Jan 2022 02:03:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641895402; cv=none; d=google.com; s=arc-20160816; b=dtegyat6SwRaWDL3JmCNmoHr/JhykSiBKRUMEV3aK/rQC4mZ0M+sjiv9+figi3ONsd WWOAF0s4eluo8RwOPNE0ENndClEEo+C5tDWT4gmOJrVLy8Ub13LV0So885sawPNC1W7x IZ6pzXx78XwjjvjSCT2gLShJoIeI8+1CDOQbZG8i5kpCB1RMHcu5sRCly7mdvKokRP95 uHm/jOtlZjyhAcoM2JsawWKlmb3FG55Zr+al7IG1MNqIlCnvJXfHd/jH0DYOUNtqruKc iny0G4RJh3aYLnp7InFABlZ0B9jEuWIz15BdcIhR9Sgv7XrSqUANakJm/17YPEnHpxhd +0gQ== 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=kwuf24x8suS6wvX8faApfRJ79oCxDW6izWqRNG5n0SA=; b=LS1AHbGHxsMOeW/9J1vergx4QkjXZ7W6GzU70sGGbpZYigtAMu1RlhJaIPpl1DHbLd VHhxYc0p6HWFsJ9AwI/BvHbwPVgJTE6S4/RUC+rgUrlovLLqFXMB6DbYIVrWhhiyavLW FuuxTCru6lNldsbUQ8vU5SDi5Qk/PcJaCrfXVWW32ODE6PAlkHLNssdnb/YY855rqdg6 8ysWZMGov+xe9cicjadEEBfc4RAfIa0iGlldsAkTP2NqRAAJiQNVVLSJuPZ95jHkAsJu skD0JWPAJ904eeMWNWAH92KHCMHfRBqx75EQHLUHMZ10YDGWeybBCWibKElAyf5mpiiw VIsA== 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 hp40si2761292ejc.415.2022.01.11.02.03.21; Tue, 11 Jan 2022 02:03:22 -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 5656268B012; Tue, 11 Jan 2022 11:59:33 +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 A088468AF7E for ; Tue, 11 Jan 2022 11:59:10 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6BB5A240512 for ; Tue, 11 Jan 2022 10:59:08 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XKEqVKltHBIB for ; Tue, 11 Jan 2022 10:59:07 +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 A9A2424056A for ; Tue, 11 Jan 2022 10:59:02 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 146323A0A7F; Tue, 11 Jan 2022 10:59:02 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:58:17 +0100 Message-Id: <20220111095830.31542-15-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220111095830.31542-1-anton@khirnov.net> References: <20220111095830.31542-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/28] 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: pP0vbNJ5fLyO 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 5165573674..2637b25526 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 66062f0072..e828f71dc0 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_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 13b5d2d220..f4d76e1533 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -396,3 +396,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; +}