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 ESMTPS id E442A4D1F1 for ; Tue, 18 Feb 2025 13:09:07 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D751D68C161; Tue, 18 Feb 2025 15:08:43 +0200 (EET) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BFD6A68C0D9 for ; Tue, 18 Feb 2025 15:08:35 +0200 (EET) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-220d601886fso71160805ad.1 for ; Tue, 18 Feb 2025 05:08:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739884113; x=1740488913; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=61SxzPDqza+upp0JG+6rRX7xCVhdIZKrx4wz15iwOGw=; b=ZDg9amFMbDj1ffqkKcmASsjxUgOacU+iYUtp35uZXP7NHLzktckWjEfPLyLxxMEBF7 c2gGu49qegOC+cdJBPfgbC9TX/5sOuwb6aKkHOPiNutQ4OfowviM2S/noX42beTrLlo+ pYEItxs4UcEOnjyAXphzU/LqobZOfwmLasE2ubcRUejdV/ixynRecTuk3GHFmu1+gKCL QhosuePyFF7uekQHGsrJuAOGcABJ6bcje2Mfl65j65OEriMyjWnnrl0YEigq4ywKPPJ5 dAByy5P9PCzTW8VrjfY+a7x1HZb8qbgDTUK7e2oAOgM0hQFtf7F5+DxfNr6PXBt2Q9s8 ZwMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739884113; x=1740488913; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=61SxzPDqza+upp0JG+6rRX7xCVhdIZKrx4wz15iwOGw=; b=TmeYoe2fzHTxRsSujgI+sKbYQzrJBw80s3UhnVxzVSKlR6ZpCC8ZufrvWjeDoiyd9l TZDq/wAO1Q3+ldk+Sk395CASkZNpTcWlrNH3JVeL1mYfbo47K40WEwsxG7/UuQ0tMApK 3MIVrJ6spYe36go18Mh4QD6kouwlt3WKHTiISvEvQ2KJrHJdtLoiYC+4dBUdmc1JRXTS ZaiTIbE/lXn6VvSFzRu0o1cow9WskO2wlmDafwDNJaqpTe870Ug0ab2rKhRg7j3G9EI9 +9cqll2ER2I2SS/s+DdDVrBWLTHiZx66I67D77vshIsypcKQUF6L1RkCilIhvCPb/BTS 86jw== X-Gm-Message-State: AOJu0Yx1+w+vekSxW3Ca7oougULb/eod8UPVhu4B4ZfEcyHDOflwFwIn DwS1EjlJBftIuxRY7kC+5uKDliwu4wS4NfpyOZceFrNFjkLof0U+WXBMD/Dk X-Gm-Gg: ASbGncu5aJ2W0GsJinuhUyaq1EDZ2iy5Ig/iLHCEIetw9ToGM/1YMx1bWChEEbUHI6S E19BWscIe6DxJyj6hv6eRa7lK/aRPTJ2zSmTgvQtZrM1oypJJCEGMlYagWJYjaU/uvwnrh6D+G/ cC119w/aB/t89QlywFqVDSUbJtLC624AmnwScBUOyevoC2XSFXB2rGD33vQtnw73GzvIcuwAiR5 NJ9jebN5mMFVfHCP0hhSp04FOlTJaOLE7ZxAqEMSvttDGjXFbuBGYF7ZNtpg0xu+8iIM7bkCDzz uINH49zM9V+D6uFvVH+W5vj3fl0LWg== X-Google-Smtp-Source: AGHT+IHTt/c4ogECXuqBjQu07SnKTC0qx92a2j5I1EM/Dv8fgGU+qIbIsXUnPGP6J7HsWZ7QnXX/BQ== X-Received: by 2002:a17:903:2cb:b0:21f:6ce6:7243 with SMTP id d9443c01a7336-221040d84c0mr216405485ad.51.1739884113100; Tue, 18 Feb 2025 05:08:33 -0800 (PST) Received: from localhost.localdomain ([2800:2121:b040:c:a0a7:974:71c7:ca89]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d556d66fsm89178635ad.180.2025.02.18.05.08.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2025 05:08:32 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Feb 2025 10:08:05 -0300 Message-ID: <20250218130813.74-3-jamrial@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250218130813.74-1-jamrial@gmail.com> References: <20250218130813.74-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/11] avcodec/libx264: refactor encoder configuration functions 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: Will be useful in the next commit. Signed-off-by: James Almer --- libavcodec/libx264.c | 88 ++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 409f45fc7d..f5517ad080 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -194,54 +194,64 @@ static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, return 1; } -static void reconfig_encoder(AVCodecContext *ctx, const AVFrame *frame) +static void reconfig_encoder(AVCodecContext *ctx) { X264Context *x4 = ctx->priv_data; - AVFrameSideData *side_data; + if (x4->avcintra_class >= 0) + return; - if (x4->avcintra_class < 0) { - if (x4->params.b_interlaced && x4->params.b_tff != !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST)) { + if (x4->params.vui.i_sar_height*ctx->sample_aspect_ratio.num != ctx->sample_aspect_ratio.den * x4->params.vui.i_sar_width) { + x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den; + x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num; + x264_encoder_reconfig(x4->enc, &x4->params); + } - x4->params.b_tff = !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST); - x264_encoder_reconfig(x4->enc, &x4->params); - } - if (x4->params.vui.i_sar_height*ctx->sample_aspect_ratio.num != ctx->sample_aspect_ratio.den * x4->params.vui.i_sar_width) { - x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den; - x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num; - x264_encoder_reconfig(x4->enc, &x4->params); - } + if (x4->params.rc.i_vbv_buffer_size != ctx->rc_buffer_size / 1000 || + x4->params.rc.i_vbv_max_bitrate != ctx->rc_max_rate / 1000) { + x4->params.rc.i_vbv_buffer_size = ctx->rc_buffer_size / 1000; + x4->params.rc.i_vbv_max_bitrate = ctx->rc_max_rate / 1000; + x264_encoder_reconfig(x4->enc, &x4->params); + } - if (x4->params.rc.i_vbv_buffer_size != ctx->rc_buffer_size / 1000 || - x4->params.rc.i_vbv_max_bitrate != ctx->rc_max_rate / 1000) { - x4->params.rc.i_vbv_buffer_size = ctx->rc_buffer_size / 1000; - x4->params.rc.i_vbv_max_bitrate = ctx->rc_max_rate / 1000; - x264_encoder_reconfig(x4->enc, &x4->params); - } + if (x4->params.rc.i_rc_method == X264_RC_ABR && + x4->params.rc.i_bitrate != ctx->bit_rate / 1000) { + x4->params.rc.i_bitrate = ctx->bit_rate / 1000; + x264_encoder_reconfig(x4->enc, &x4->params); + } - if (x4->params.rc.i_rc_method == X264_RC_ABR && - x4->params.rc.i_bitrate != ctx->bit_rate / 1000) { - x4->params.rc.i_bitrate = ctx->bit_rate / 1000; - x264_encoder_reconfig(x4->enc, &x4->params); - } + if (x4->crf >= 0 && + x4->params.rc.i_rc_method == X264_RC_CRF && + x4->params.rc.f_rf_constant != x4->crf) { + x4->params.rc.f_rf_constant = x4->crf; + x264_encoder_reconfig(x4->enc, &x4->params); + } - if (x4->crf >= 0 && - x4->params.rc.i_rc_method == X264_RC_CRF && - x4->params.rc.f_rf_constant != x4->crf) { - x4->params.rc.f_rf_constant = x4->crf; - x264_encoder_reconfig(x4->enc, &x4->params); - } + if (x4->params.rc.i_rc_method == X264_RC_CQP && + x4->cqp >= 0 && + x4->params.rc.i_qp_constant != x4->cqp) { + x4->params.rc.i_qp_constant = x4->cqp; + x264_encoder_reconfig(x4->enc, &x4->params); + } - if (x4->params.rc.i_rc_method == X264_RC_CQP && - x4->cqp >= 0 && - x4->params.rc.i_qp_constant != x4->cqp) { - x4->params.rc.i_qp_constant = x4->cqp; - x264_encoder_reconfig(x4->enc, &x4->params); - } + if (x4->crf_max >= 0 && + x4->params.rc.f_rf_constant_max != x4->crf_max) { + x4->params.rc.f_rf_constant_max = x4->crf_max; + x264_encoder_reconfig(x4->enc, &x4->params); + } +} - if (x4->crf_max >= 0 && - x4->params.rc.f_rf_constant_max != x4->crf_max) { - x4->params.rc.f_rf_constant_max = x4->crf_max; +static void reconfig_encoder_from_frame(AVCodecContext *ctx, const AVFrame *frame) +{ + X264Context *x4 = ctx->priv_data; + AVFrameSideData *side_data; + + reconfig_encoder(ctx); + + if (x4->avcintra_class < 0) { + if (x4->params.b_interlaced && x4->params.b_tff != !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST)) { + + x4->params.b_tff = !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST); x264_encoder_reconfig(x4->enc, &x4->params); } } @@ -528,7 +538,7 @@ static int setup_frame(AVCodecContext *ctx, const AVFrame *frame, pic->i_type = X264_TYPE_AUTO; break; } - reconfig_encoder(ctx, frame); + reconfig_encoder_from_frame(ctx, frame); if (x4->a53_cc) { void *sei_data; -- 2.48.1 _______________________________________________ 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".