From patchwork Thu Dec 20 20:40:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 11495 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 1EE3144CCED for ; Thu, 20 Dec 2018 22:45:47 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5022868AE21; Thu, 20 Dec 2018 22:45:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CD6FF68AD4D for ; Thu, 20 Dec 2018 22:45:39 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id m22so3666417wml.3 for ; Thu, 20 Dec 2018 12:45:42 -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=Dj44z4huN5PeuWyJy0I6OJy4grVzu0c1a/bT7pKdZyU=; b=u3AdRpZP36TOVqqHxHji3Qxqzc3Oq7O0/I8epBx0iW9Hres1GAtSIBCGYyh7xxXToA eZP7HcmxOgPgAfRF3ZiyxU4TH244ZwFEr2LvPct/lHj5LxAXFdlg7hBaAylUee5AqJZ6 0v//0uPAioXDtj3uJuA4G+aES7+LKcgw5KGyJ+c9JoJlr4fMBiM3mJJbewDS/bAXhpJw +bR8P0cEK6lcVFB/3st/SaplotrxqD91KWXQ+6ZggkXcKZ9SNSvDFMhJJZZnaYAFRpT7 OatoL/N72laCU6Awe6NBCO62rnI44byKqiRuzs4CQyfarRYIVuVH0VYNzce/s5jS/uC6 lEaA== 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=Dj44z4huN5PeuWyJy0I6OJy4grVzu0c1a/bT7pKdZyU=; b=GGyc+hwJe5fvV4GUqke1iIVP6CkxLsUpY7YEACeK2mBVjm0K7/ugrs/+sVym6S37tg B2VzOJRlhMuZUYyQRJ9zD65+fzqP9nrJ7daZ6HfQpANpZvTtRdW3mZ5bgOnRmw04Q7qc dh2qWXBq0ZXQ2P27943KYOxbFiR1a+zVw1GQ8uLpYsD4vdjgDzuvSuRpyPm1hpMXEFJ/ 9Z3x7IHe3QHnCEzF/TFm8KtQGSoqwf9r13/bdULntXo9Ba+NLQ/lmi18nP5MsUMhSLDy mOttL3qOLGLyVQF2gljUeF56G0SEWH16MaOwTnwosBTFi01ewQlx2k7PinS7eQhqa504 TfaQ== X-Gm-Message-State: AA+aEWaq+k5erGsVZUUxwg2xS34S3yQLi2wpdRlKl0AzKwm0MFf2phSr 0cV1GaMGDd0qajRxj4BIlmdnk9IMPpI= X-Google-Smtp-Source: ALg8bN4RB3sOrb3YEkSxnYufNsEiHtGByCSmhOOu6kNG8sRo9L8NS8TfvyylbWhWaRK8jVvgAlNVXg== X-Received: by 2002:a1c:2c44:: with SMTP id s65mr167992wms.80.1545338422526; Thu, 20 Dec 2018 12:40:22 -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 x10sm11956884wrn.29.2018.12.20.12.40.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 12:40:21 -0800 (PST) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Dec 2018 20:40:03 +0000 Message-Id: <20181220204008.32766-9-sw@jkqxz.net> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181220204008.32766-1-sw@jkqxz.net> References: <20181220204008.32766-1-sw@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/14] 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 1d40e06667..220fc089fb 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -1067,15 +1067,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; @@ -1083,15 +1089,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 pic_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; @@ -1115,6 +1117,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), @@ -1166,6 +1170,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); } @@ -1182,9 +1189,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 },