From patchwork Sun Feb 10 19:46:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 12023 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7D8D244665E for ; Sun, 10 Feb 2019 21:47:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7164968A6A0; Sun, 10 Feb 2019 21:47:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E98568A2B8 for ; Sun, 10 Feb 2019 21:47:14 +0200 (EET) Received: by mail-wm1-f68.google.com with SMTP id v26so12909660wmh.3 for ; Sun, 10 Feb 2019 11:47:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ytSuNo9CV6ug8zIQrpst7xXLHqvawYAFJRMsZXJra08=; b=yIFGWdMpK6fO4y5Dz2A1FAOSlUApf1h5Ex+vSZgYrcqYJ0lLV5EopZZ+07rcxFkxC+ 40gvbB7EwrF9RPhw+xojsOaU2PEZZEeRo4NcmF/bcZaT0rGbQefpn1lhTFjvFfzRvbyW uhjdQ9kjUU1JvrIg/njscTJCuG+AS1HYgMuq7IaHh1U2OKsbcj4PLFTT8W0l9NUijYVL FgZHgFo6Bk+GSZgFXZTENuK57x1lCyTJNIKNVnua+G53BhJ/XHk41aadSq4VyPC3wm14 B/AjwdLG0/Dij9YKLWIRwJKIphl+yLqgjYsdnRBZdnpgUkir09Ttpo1RjYs/U/GQfJOE v7VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ytSuNo9CV6ug8zIQrpst7xXLHqvawYAFJRMsZXJra08=; b=jWixBm/CHvpYAG7M4EYCkTd8dPrVG3SSm1tbqdUfz38TOzk/YRlASaRZBFYQtQN/du 6XenxLXJ/Ze9uLQh9xnCobIjoJL2wFp+nlZ48bAmMFhP3AexDmxx9LcSYNiL1iJxH6Bb fOqTXKDVKgkbzSY2QeguD/HN7esR82lXORMI3DAGm1qy6KxL7r8EwQjJOwLVcDPzUsRx Cvm8JsryJb6wSsOUgcEdg7WVzGaIr3Gu3iKS7Wzusx92w/85DnUyJZrzi7NPduvLIObI I9j1fK6XvXjS7oVh4++B2W6R9OqpdvjYfhmvI+a76kpRwUcpKFs7cfAgd6bruVm5Rw2P w2SA== X-Gm-Message-State: AHQUAuba3Km/yjx1RK/7EuOFbkNBEy7Y5hVZ0e07XqaB2pVbVBF2qY3N 4D25bzYgyKi09XcaD3EzLI1+ylqWlgd+Kg== X-Google-Smtp-Source: AHgI3IaSpQkdwSRCxXzt8OFQJew3vqeCqlKkVbyZT8Jr+m4yP2LDVVm3MCQXtNzPLw6Y3bxHNvIDPg== X-Received: by 2002:a5d:6b09:: with SMTP id v9mr25802874wrw.304.1549828033448; Sun, 10 Feb 2019 11:47:13 -0800 (PST) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id u15sm24059889wrm.63.2019.02.10.11.47.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 11:47:12 -0800 (PST) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Sun, 10 Feb 2019 19:46:56 +0000 Message-Id: <20190210194705.3598-3-sw@jkqxz.net> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190210194705.3598-1-sw@jkqxz.net> References: <20190210194705.3598-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 03/12] vaapi_encode_h265: Enable support for more RC modes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Also fixes QP going out of range when modified by the quant factor/offset values, and clarifies the QP behaviour for >8-bit modes. --- libavcodec/vaapi_encode_h265.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 19e7104e9e..4d2a64308e 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -1076,15 +1076,21 @@ static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx) return err; if (ctx->va_rc_mode == VA_RC_CQP) { - priv->fixed_qp_p = priv->qp; + // Note that VAAPI only supports positive QP values - the range is + // therefore always bounded below by 1, even in 10-bit mode where + // it should go down to -12. + + priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51); if (avctx->i_quant_factor > 0.0) - priv->fixed_qp_idr = (int)((priv->fixed_qp_p * avctx->i_quant_factor + - avctx->i_quant_offset) + 0.5); + priv->fixed_qp_idr = + av_clip((avctx->i_quant_factor * priv->fixed_qp_p + + avctx->i_quant_offset) + 0.5, 1, 51); else priv->fixed_qp_idr = priv->fixed_qp_p; if (avctx->b_quant_factor > 0.0) - priv->fixed_qp_b = (int)((priv->fixed_qp_p * avctx->b_quant_factor + - avctx->b_quant_offset) + 0.5); + priv->fixed_qp_b = + av_clip((avctx->b_quant_factor * priv->fixed_qp_p + + avctx->b_quant_offset) + 0.5, 1, 51); else priv->fixed_qp_b = priv->fixed_qp_p; @@ -1092,15 +1098,11 @@ static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx) "%d / %d / %d for IDR- / P- / B-frames.\n", priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b); - } else if (ctx->va_rc_mode == VA_RC_CBR || - ctx->va_rc_mode == VA_RC_VBR) { - // These still need to be set for pic_init_qp/slice_qp_delta. + } else { + // These still need to be set for init_qp/slice_qp_delta. priv->fixed_qp_idr = 30; priv->fixed_qp_p = 30; priv->fixed_qp_b = 30; - - } else { - av_assert0(0 && "Invalid RC mode."); } return 0; @@ -1124,6 +1126,8 @@ static const VAAPIEncodeType vaapi_encode_type_h265 = { FLAG_B_PICTURE_REFERENCES | FLAG_NON_IDR_KEY_PICTURES, + .default_quality = 25, + .configure = &vaapi_encode_h265_configure, .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture), @@ -1175,6 +1179,9 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx) // CTU size is currently hard-coded to 32. ctx->slice_block_width = ctx->slice_block_height = 32; + if (priv->qp > 0) + ctx->explicit_qp = priv->qp; + return ff_vaapi_encode_init(avctx); } @@ -1191,9 +1198,10 @@ static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx) #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) static const AVOption vaapi_encode_h265_options[] = { VAAPI_ENCODE_COMMON_OPTIONS, + VAAPI_ENCODE_RC_OPTIONS, { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)", - OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS }, + OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS }, { "aud", "Include AUD", OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },