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 DE826405BE for ; Sun, 27 Mar 2022 23:10:27 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF6EC68B26D; Mon, 28 Mar 2022 02:10:24 +0300 (EEST) Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 87A9068B1C7 for ; Mon, 28 Mar 2022 02:10:18 +0300 (EEST) Received: by mail-ot1-f50.google.com with SMTP id o20-20020a9d7194000000b005cb20cf4f1bso9600315otj.7 for ; Sun, 27 Mar 2022 16:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=CEsTmUDJoobDdrswEpQg9UyYInD0V9zsQ2I7UCC4cTI=; b=p3xmP9I8JMRFkVkIeDa7v1Tz3Pz6mC6m5L/Fz+Zd1nyHnyQQcVYzPWEP/2xWN2RY6W ZwGWEY0OTuxoVOhEFhe9RjJolD4Au6RGOAy7npTw4I0MeGudlwaRK+1sjXHFyJi5yC5A xaBOA+SfEvBRJxYgMgKZLLhT6OfXl9YqrWz4QFGS2ZvXUBYiP0oe2jg9whcWT4ROGaQS q6c8Wh9/1/J3eXQtHV8N9mUBDhPdbiLMop23E51L2rwZ526ALLp8GIq5ZuwnNSWB9LAI 5iQ8D7KkooGQwDZpOUgxgCWQyLrqkF2pAfQWuJVDQU4ifgYbJL8YigvP3zvTaZwIE8JQ rESA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=CEsTmUDJoobDdrswEpQg9UyYInD0V9zsQ2I7UCC4cTI=; b=H78GkonvCfdkPkG8JbqdpT0O/PVsZusEjsYDuCUQ0e3BuZ4ytvFnos7fei/0ep80sC 8hihaAMYWjoQbP1j30Fk3gWkO1iO+5iXAogd/xPOFCc76ZbEljlOiSGDuB7O+E2nx2YY fRvKG2iDKtGtv/K1U5cGX8Hv1Hl5XBkd0rN9YJX1BubzpMENe++SzGnbLlj7piZUbn1u SV1R8hec591n6lPgb1mu8uDrn8nkip42m87qdqozJSDKqrEnE3WApK5RDLosSZoEhGt5 A3eIDCuOQFw0I68Yko6hH44Ph1fi1jMQ1Rp2famrIs9C6Iv93q6N7OHZUtWau3np87yi FZGg== X-Gm-Message-State: AOAM531s8SWZ86BxEzS4s1Qu4Ht2FQPpZUQfCrbiZPa4hp5cmplDpB+H Up8yeZ78FItenG7qU/1bobURhRRLXc0HKA== X-Google-Smtp-Source: ABdhPJzYSZqICK+/nFrikPwcB9AyfwJjX1PdAr6LtC4jHSjpgGUG9hRncm1ADI83PJ2l6lKUdJyXMA== X-Received: by 2002:a05:6830:3150:b0:5cd:a820:3966 with SMTP id c16-20020a056830315000b005cda8203966mr9360758ots.223.1648422616287; Sun, 27 Mar 2022 16:10:16 -0700 (PDT) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id k10-20020a4abd8a000000b00324907b406fsm1994552oop.21.2022.03.27.16.10.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 16:10:15 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 27 Mar 2022 20:10:02 -0300 Message-Id: <20220327231002.1506-1-jamrial@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/libsvtav1: give svtav1-params priority over avctx values 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: If the svt equivalent option to an avctx AVOption is passed by the user then it should have priority. The exception are fields like dimensions, bitdepth and pixel format, which must match what lavc will feed the encoder after init. This addresses libsvt-av1 issue #1858. Signed-off-by: James Almer --- libavcodec/libsvtav1.c | 69 +++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c index 6cf280377e..41428a3b61 100644 --- a/libavcodec/libsvtav1.c +++ b/libavcodec/libsvtav1.c @@ -178,6 +178,9 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, param->rate_control_mode = 1; else param->rate_control_mode = 2; + + param->max_qp_allowed = avctx->qmax; + param->min_qp_allowed = avctx->qmin; } param->max_bit_rate = avctx->rc_max_rate; param->vbv_bufsize = avctx->rc_buffer_size; @@ -191,6 +194,37 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, param->enable_adaptive_quantization = 0; } + desc = av_pix_fmt_desc_get(avctx->pix_fmt); + param->color_primaries = avctx->color_primaries; + param->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? + AVCOL_SPC_RGB : avctx->colorspace; + param->transfer_characteristics = avctx->color_trc; + + if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED) + param->color_range = avctx->color_range == AVCOL_RANGE_JPEG; + else + param->color_range = !!(desc->flags & AV_PIX_FMT_FLAG_RGB); + + if (avctx->profile != FF_PROFILE_UNKNOWN) + param->profile = avctx->profile; + + if (avctx->level != FF_LEVEL_UNKNOWN) + param->level = avctx->level; + + if (avctx->gop_size > 0) + param->intra_period_length = avctx->gop_size - 1; + + if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { + param->frame_rate_numerator = avctx->framerate.num; + param->frame_rate_denominator = avctx->framerate.den; + } else { + param->frame_rate_numerator = avctx->time_base.den; + param->frame_rate_denominator = avctx->time_base.num * avctx->ticks_per_frame; + } + + /* 2 = IDR, closed GOP, 1 = CRA, open GOP */ + param->intra_refresh_type = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? 2 : 1; + #if SVT_AV1_CHECK_VERSION(0, 9, 1) while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) { EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value); @@ -214,7 +248,6 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, param->source_width = avctx->width; param->source_height = avctx->height; - desc = av_pix_fmt_desc_get(avctx->pix_fmt); param->encoder_bit_depth = desc->comp[0].depth; if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1) @@ -228,22 +261,6 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, return AVERROR(EINVAL); } - param->color_primaries = avctx->color_primaries; - param->matrix_coefficients = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? - AVCOL_SPC_RGB : avctx->colorspace; - param->transfer_characteristics = avctx->color_trc; - - if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED) - param->color_range = avctx->color_range == AVCOL_RANGE_JPEG; - else - param->color_range = !!(desc->flags & AV_PIX_FMT_FLAG_RGB); - - if (avctx->profile != FF_PROFILE_UNKNOWN) - param->profile = avctx->profile; - - if (avctx->level != FF_LEVEL_UNKNOWN) - param->level = avctx->level; - if ((param->encoder_color_format == EB_YUV422 || param->encoder_bit_depth > 10) && param->profile != FF_PROFILE_AV1_PROFESSIONAL ) { av_log(avctx, AV_LOG_WARNING, "Forcing Professional profile\n"); @@ -253,25 +270,7 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, param->profile = FF_PROFILE_AV1_HIGH; } - if (avctx->gop_size > 0) - param->intra_period_length = avctx->gop_size - 1; - - if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { - param->frame_rate_numerator = avctx->framerate.num; - param->frame_rate_denominator = avctx->framerate.den; - } else { - param->frame_rate_numerator = avctx->time_base.den; - param->frame_rate_denominator = avctx->time_base.num * avctx->ticks_per_frame; - } - avctx->bit_rate = param->target_bit_rate; - if (avctx->bit_rate) { - param->max_qp_allowed = avctx->qmax; - param->min_qp_allowed = avctx->qmin; - } - - /* 2 = IDR, closed GOP, 1 = CRA, open GOP */ - param->intra_refresh_type = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? 2 : 1; return 0; } -- 2.35.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".