From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id F02B54ACA6 for ; Tue, 18 Jun 2024 13:48:46 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A2B3768D7CD; Tue, 18 Jun 2024 16:48:37 +0300 (EEST) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B5CC268D28D for ; Tue, 18 Jun 2024 16:48:28 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1D05E1C000A for ; Tue, 18 Jun 2024 13:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1718718508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xTuFf14dgCjPlI6/ymzXb7WnSoKEp4JSfXdufJkY24Q=; b=nx//uD68Qc9tNmyb3AwJ1d3nWf0X/OyUus9lrQENwrqFdToGzYLClB2bD5r+YGt3Gebls2 dJ6Rc0GmHcXzukYGjJ/JmDAFZFrHdnmOjby4s1EI0LIa0JXahJEdprRtRV9aokkd+4lFhm fmX0HcVQBp6EcXrt8eQ++9AK2z1STpqM3Soull5y2EZZvyfWpgBhtqxDLe4k1hUEebGofo AiNR2HDmVT3fPzpSIy2L1b/i9Y3sbST7oU4XmsrYwcKm+xYXvLSZBxleDmn9i7AzN+fZUT FujRbYA5Grw0gV2HBDdp31AMcPnI5eEzqS1+fFhROJjxNynKQdI1d7frrGw2JA== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 18 Jun 2024 15:48:21 +0200 Message-ID: <20240618134826.2189719-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618134826.2189719-1-michael@niedermayer.cc> References: <20240618134826.2189719-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/7] avcodec/ratecontrol: Try to keep fps as a rational 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: Michael Niedermayer --- libavcodec/ratecontrol.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 609d47faeb4..df27639ca73 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -56,20 +56,25 @@ void ff_write_pass1_stats(MpegEncContext *s) s->header_bits); } -static double get_fps(AVCodecContext *avctx) +static AVRational get_fpsQ(AVCodecContext *avctx) { if (avctx->framerate.num > 0 && avctx->framerate.den > 0) - return av_q2d(avctx->framerate); + return avctx->framerate; FF_DISABLE_DEPRECATION_WARNINGS - return 1.0 / av_q2d(avctx->time_base) #if FF_API_TICKS_PER_FRAME - / FFMAX(avctx->ticks_per_frame, 1) + return av_div_q((AVRational){1, FFMAX(avctx->ticks_per_frame, 1)}, avctx->time_base); +#else + return av_inv_q(avctx->time_base); #endif - ; FF_ENABLE_DEPRECATION_WARNINGS } +static double get_fps(AVCodecContext *avctx) +{ + return av_q2d(get_fpsQ(avctx)); +} + static inline double qp2bits(const RateControlEntry *rce, double qp) { if (qp <= 0.0) { @@ -332,12 +337,13 @@ static int init_pass2(MpegEncContext *s) RateControlContext *rcc = &s->rc_context; AVCodecContext *a = s->avctx; int i, toobig; - double fps = get_fps(s->avctx); + AVRational fps = get_fpsQ(s->avctx); double complexity[5] = { 0 }; // approximate bits at quant=1 uint64_t const_bits[5] = { 0 }; // quantizer independent bits uint64_t all_const_bits; - uint64_t all_available_bits = (uint64_t)(s->bit_rate * - (double)rcc->num_entries / fps); + uint64_t all_available_bits = av_rescale_q(s->bit_rate, + (AVRational){rcc->num_entries,1}, + fps); double rate_factor = 0; double step; const int filter_size = (int)(a->qblur * 4) | 1; -- 2.45.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".