From patchwork Tue Sep 24 07:09:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51788 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ad12:0:b0:48e:c0f8:d0de with SMTP id w18csp173997vqy; Tue, 24 Sep 2024 00:19:25 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVYpW1xKyMB70csYS4a7xhXHoyzIU7HCXSQ5LbAm1lkMudRHg77I5hNkPssvHb4PA/yMUXe5uNvvIsrhDA3aKKP@gmail.com X-Google-Smtp-Source: AGHT+IHUA45YEjX8fxq3s7ilQzbte3lumpUu3SvrY2JLeRTC1t1SjGXvBrfP0je+cFBJvAWQMUZ+ X-Received: by 2002:a05:6512:39cc:b0:533:4108:a49e with SMTP id 2adb3069b0e04-537a6912794mr731645e87.29.1727162364919; Tue, 24 Sep 2024 00:19:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727162364; cv=none; d=google.com; s=arc-20240605; b=ebX62yLdAQyGbyA7wgRRrZc284T8F8publOW/jqnVUecxuIXCQtyyFJauJbD0sz+o6 /YhdlOZlcsudjtfInyPrch8sFlTG6onM6y6XKS5+kFTnnJcEnA6IRii9//spa2kmuCh9 3aQD8I4p+rKHKwVCFHxFtdPAi0YQabeTFhkGFY1TlionVbKQRs92qUka/W9E8yKkk5Jc VF84AKjSUbqzhqC++ITEWmoHfMqAuSXT2k+mBDfvPhZUGYv1t8Zo7cdL1s1Ts9iU/zll b5RtC/6rOMxDStRNKKkMJGFAjrpcpAAeUEkms1Zfct8eJJMRTxbsogXHohi3Lxve6Fli mC4A== 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=GDiLbxZVEEJyQrFrdnf5W49odE7lnL/hneZaWZLhHgQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=M2waWgZE7eyCIDvs/oTtqSfVkJxjaGe3uRRJln5b6emnxH6v3zxCmFw9Wux56xixd8 B+G6paSr5BSXrhNOw4ZQRXazCbyFcNdLnheBy7HfK2LVlj3iJF7n6EVDXTX0N1NT8hjq jIfgCyo9sT2uSy5WjHiGNas0nWWVw6m1JY5wjbLhYopEKePTS81Y7rZzRmRuMnKe+FQ9 HeBlzBDRZBp5dtbKJEsfUpzZYCYUdKUYVlSGlANPLO2rGUAuvlhRTxxcZce+QvGYW75f WfnxweQskJgWFzDP9iXHEZMDa9maesfmYkL9LNi4hLZzj4tYkT4nZpl/sC22MkF/DTQc c54g==; 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=WzKZz2EP; 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 2adb3069b0e04-537a8646249si255582e87.338.2024.09.24.00.19.23; Tue, 24 Sep 2024 00:19:24 -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=WzKZz2EP; 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 A679E68DBF1; Tue, 24 Sep 2024 10:10:38 +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 A219A68DB4B 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=WzKZz2EP; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 25AFC4E07 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 rUbINhpepnOE for ; Tue, 24 Sep 2024 09:10:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727161815; bh=RxVa/alDI4GlT/+QlaQ1VzsYWFokfNkoqttDJ/JwXSI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WzKZz2EP+j6TNdz6SUPX2hE3WN30LX4+GVCic7vAo1/HMY3Tp1V3oKwFpv8kpDSqG cnerLf2Iq+fDR/3Rj7eFXlgTfJxWcVetP13e2ghdM9+rBYe37qPEymzjM8OmbatueL 282LwgGSP22s7GJqVJGr8qg8ER8YAyz2zweEuL2Gt3dFDbONxsN+Ja11LuG/c0vXns 4POlgnPnZGK5pG2R5d1+bif9rVQbEVF+e3ZIBBgvNvs/DnUXis4qVUpv4pcSfogAe2 UG0LrQDUmtzlAgCV3pz0ux3KrzNLxN2S4NCwoAvJ89elNN02/PNWTXkpvpTILQpmfz K/WSJ77vpOUjQ== 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 89A0A4E11 for ; Tue, 24 Sep 2024 09:10:15 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5886D3A1A1B 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:52 +0200 Message-ID: <20240924071000.11428-11-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 11/13] fftools/ffmpeg_filter: stop accessing OutputStream.[max_]frame_rate 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: f0uTM48G7mll Pass them to ofilter_bind_ost() via OutputFilterOptions, as is done for most other data it needs. OutputStream.[max_]frame_rate/force_fps are no longer used outside of ffmpeg_mux*, and so can be made private. This is a step toward decoupling encoders from muxers. --- fftools/ffmpeg.h | 5 ++--- fftools/ffmpeg_filter.c | 4 ++-- fftools/ffmpeg_mux.h | 4 ++++ fftools/ffmpeg_mux_init.c | 16 +++++++++------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 13be7c4872..29679432c6 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -328,6 +328,8 @@ typedef struct OutputFilterOptions { enum AVColorRange color_range; enum VideoSyncMethod vsync_method; + AVRational frame_rate; + AVRational max_frame_rate; int sample_rate; AVChannelLayout ch_layout; @@ -605,9 +607,6 @@ typedef struct OutputStream { AVCodecContext *enc_ctx; /* video only */ - AVRational frame_rate; - AVRational max_frame_rate; - int force_fps; #if FFMPEG_OPT_TOP int top_field_first; #endif diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 7a37cb1d2d..94b4f4bb31 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -854,8 +854,8 @@ int ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost, return AVERROR(ENOMEM); ofp->fps.vsync_method = opts->vsync_method; - ofp->fps.framerate = ost->frame_rate; - ofp->fps.framerate_max = ost->max_frame_rate; + ofp->fps.framerate = opts->frame_rate; + ofp->fps.framerate_max = opts->max_frame_rate; ofp->fps.framerate_supported = opts->frame_rates; // reduce frame rate for mpeg4 to be within the spec limits diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index 5df718faf0..f41f2c18fa 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -85,6 +85,10 @@ typedef struct MuxStream { int ts_drop; #endif + AVRational frame_rate; + AVRational max_frame_rate; + int force_fps; + const char *apad; } MuxStream; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index bf2c0b8f67..1435d8339d 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -605,13 +605,13 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, st = ost->st; opt_match_per_stream_str(ost, &o->frame_rates, oc, st, &frame_rate); - if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) { + if (frame_rate && av_parse_video_rate(&ms->frame_rate, frame_rate) < 0) { av_log(ost, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate); return AVERROR(EINVAL); } opt_match_per_stream_str(ost, &o->max_frame_rates, oc, st, &max_frame_rate); - if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) { + if (max_frame_rate && av_parse_video_rate(&ms->max_frame_rate, max_frame_rate) < 0) { av_log(ost, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate); return AVERROR(EINVAL); } @@ -775,7 +775,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, } } - opt_match_per_stream_int(ost, &o->force_fps, oc, st, &ost->force_fps); + opt_match_per_stream_int(ost, &o->force_fps, oc, st, &ms->force_fps); #if FFMPEG_OPT_TOP ost->top_field_first = -1; @@ -796,7 +796,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, return ret; } - if ((ost->frame_rate.num || ost->max_frame_rate.num) && + if ((ms->frame_rate.num || ms->max_frame_rate.num) && !(*vsync_method == VSYNC_AUTO || *vsync_method == VSYNC_CFR || *vsync_method == VSYNC_VSCFR)) { av_log(ost, AV_LOG_FATAL, "One of -r/-fpsmax was specified " @@ -805,7 +805,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, } if (*vsync_method == VSYNC_AUTO) { - if (ost->frame_rate.num || ost->max_frame_rate.num) { + if (ms->frame_rate.num || ms->max_frame_rate.num) { *vsync_method = VSYNC_CFR; } else if (!strcmp(oc->oformat->name, "avi")) { *vsync_method = VSYNC_VFR; @@ -937,6 +937,8 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, .color_space = enc_ctx->colorspace, .color_range = enc_ctx->color_range, .vsync_method = vsync_method, + .frame_rate = ms->frame_rate, + .max_frame_rate = ms->max_frame_rate, .sample_rate = enc_ctx->sample_rate, .ch_layout = enc_ctx->ch_layout, .sws_opts = o->g->sws_dict, @@ -963,7 +965,7 @@ ost_bind_filter(const Muxer *mux, MuxStream *ms, OutputFilter *ofilter, if (ret < 0) return ret; } - if (!ost->force_fps) { + if (!ms->force_fps) { ret = avcodec_get_supported_config(enc_ctx, NULL, AV_CODEC_CONFIG_FRAME_RATE, 0, (const void **) &opts.frame_rates, NULL); @@ -1035,7 +1037,7 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary **e AVCodecContext *codec_ctx = NULL; - AVRational fr = ost->frame_rate; + AVRational fr = ms->frame_rate; int ret = 0;