From patchwork Tue Sep 24 07:09:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51786 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ad12:0:b0:48e:c0f8:d0de with SMTP id w18csp173951vqy; Tue, 24 Sep 2024 00:19:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXj054aE6YU8ixpo8DYFnbGOxbVD9U5sS9eIMTybcqAyvojq7lzppEzoOUGQ/ETlIpQrQTmnoATLRpc+o0w6Jg3@gmail.com X-Google-Smtp-Source: AGHT+IG9EWVSDOpN/dwiYjDR+OFyb50264lCEoZNfp0OMQG8s35GbB981VFuZ3yDkWZaiUwLoNa3 X-Received: by 2002:a17:907:c899:b0:a7a:a960:99ee with SMTP id a640c23a62f3a-a90d5033daamr1357646466b.32.1727162358323; Tue, 24 Sep 2024 00:19:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727162358; cv=none; d=google.com; s=arc-20240605; b=LIeKN4p+eLgKRG7yl7cs8I6ZmV4+zIx//KT/96KtJxuZsOttrKfwGn/I8R7SNp1M2E vLo8A1TaSqTVZhbGcAOc3n6s9FoO3CgYdYCe2jEScrz/COiTHJJVIaFssq/mibCvDmK+ Gj5WccGeZKPBmKldi21v3OJTJAhF6OY+bYkBMw7YQlmyq5nbG6YROVRxunHcCvnNX92i J+Sd/tfemmVW/pIsV+sDIA38TMfcn8ToAeq1kC3afvDh0t4zbvq7BlfpOb6QrgAkXl/A S+6hxTX7OEWOsRFWuly+RpYIR6Q65YOBfBYDuOVMzDVKa+mlQqSAGnNebvZbkshwPhZZ hHyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=V6LtAWUpxbhpY1/8Pp/exgHISZZeEMBjnpGcho3bM28=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=UPblj2yAHJPWs2ONCtqQNDGz3UgeV6KKu1jJb8VpmFoJlRN/Igjja94dOS6CR0vM2k 5okaGfNzCW6PFcB0vbQelKh90oKsMrsmmgzotXCow4lra0QI+ZJr5kRwqLfP1DmhZ7C1 Nkj/bwVaZQKlRhTRmHOgyyz/HmQwj9dSLlO+FX3nP21NIO4eK5ZqowZCC5skCAY9pYZO dtOuWKyqIKMrcLGnk728BoMo7cl2oMqpoO7AKNAJl1J/M3/ad1Lsmyc6YvWqiYPydOz+ meLTq+cSY6qHQk85Pd4robMcUI7d5So86AsZuqicd8SigY8eUZHZ4g8Jzd3pelpHpaqU IxJg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=ieQ8WQY+; 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 a640c23a62f3a-a93930ef373si56019066b.640.2024.09.24.00.19.18; Tue, 24 Sep 2024 00:19:18 -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=@khirnov.net header.s=mail header.b=ieQ8WQY+; 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 555E868DB8F; Tue, 24 Sep 2024 10:10:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 00E6568DA68 for ; Tue, 24 Sep 2024 10:10:22 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=ieQ8WQY+; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 7D91B4E12 for ; Tue, 24 Sep 2024 09:10:18 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id o65lOfUMdKzi for ; Tue, 24 Sep 2024 09:10:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727161816; bh=ApDmMqnk79N+qf3rlQ3CnUwCTapWl+2frdI3VG5X3k4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ieQ8WQY+QdgJCOUClnci+dY2PC+Uhzs+veQO87/GvU5xdRQOBEox6y0gYatdU2CJV zDCWRvxKF3lCbD1Tk8fIQybxSrAmPIMGLLX00t1UosmB0wmFqGUGpKSfXBOOh6+NrM gvtuZ46rbkEqgRUyD+/dgEh5TZBq3ZpF2YQhfKhaICqfL7vMkfp73O0l7+CMY8AS8Q FtVvo8UOJ6vqdmSvymxv49kmemnewzA5d0lkvQKv0vfl1tBhnNKT8ZxwFhPq30j6vx Vz5Mj+Y5JX21wX0XiStYtykk+t+AwkDlwS1UIZMcPzwgXXct7MPkChjjpDNqxF5is/ VMJNC/JQQha+A== 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 mail1.khirnov.net (Postfix) with ESMTPS id 9A7374E16 for ; Tue, 24 Sep 2024 09:10:16 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 066B53A0F02 for ; Tue, 24 Sep 2024 09:10:10 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 24 Sep 2024 09:09:45 +0200 Message-ID: <20240924071000.11428-4-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240924071000.11428-1-anton@khirnov.net> References: <20240924071000.11428-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/13] fftools/ffmpeg_enc: do not set AVStream timebase directly 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: W0JV8oDLtXvb Instead, pass the encoder context to of_stream_init() and have the muxer take the timebase from there. Note that the muxer can currently access the codec context directly, but that will change in future commits. This is a step towards decoupling encoders from muxers. --- fftools/ffmpeg.h | 3 ++- fftools/ffmpeg_enc.c | 6 +----- fftools/ffmpeg_mux.c | 9 ++++++++- fftools/ffmpeg_mux_init.c | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 122372440f..98080213fd 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -871,7 +871,8 @@ int enc_loopback(Encoder *enc); * * Open the muxer once all the streams have been initialized. */ -int of_stream_init(OutputFile *of, OutputStream *ost); +int of_stream_init(OutputFile *of, OutputStream *ost, + const AVCodecContext *enc_ctx); int of_write_trailer(OutputFile *of); int of_open(const OptionsContext *o, const char *filename, Scheduler *sch); void of_free(OutputFile **pof); diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index c11ec218d7..ba79f6a3fc 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -367,11 +367,7 @@ int enc_open(void *opaque, const AVFrame *frame) return ret; } - // copy timebase while removing common factors - if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) - ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1}); - - ret = of_stream_init(of, ost); + ret = of_stream_init(of, ost, enc_ctx); if (ret < 0) return ret; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 71ff9b45ab..71a771052f 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -608,12 +608,19 @@ static int bsf_init(MuxStream *ms) return 0; } -int of_stream_init(OutputFile *of, OutputStream *ost) +int of_stream_init(OutputFile *of, OutputStream *ost, + const AVCodecContext *enc_ctx) { Muxer *mux = mux_from_of(of); MuxStream *ms = ms_from_ost(ost); int ret; + if (enc_ctx) { + // use upstream time base unless it has been overridden previously + if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) + ost->st->time_base = av_add_q(enc_ctx->time_base, (AVRational){0, 1}); + } + /* initialize bitstream filters for the output stream * needs to be done here, because the codec id for streamcopy is not * known until now */ diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 1b75430e4e..b2351de177 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -3385,7 +3385,7 @@ int of_open(const OptionsContext *o, const char *filename, Scheduler *sch) OutputStream *ost = of->streams[i]; if (!ost->enc) { - err = of_stream_init(of, ost); + err = of_stream_init(of, ost, NULL); if (err < 0) return err; }