From patchwork Sun Apr 22 15:29:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 8566 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp2854385jad; Sun, 22 Apr 2018 08:31:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+/rhjNXSNvUCDJycPnDO1pDTS1Jy6zKCHuixXZUmoaNd+LLgLosVMpJ/C8R+3zJjHc9Oky X-Received: by 2002:adf:df02:: with SMTP id y2-v6mr12032799wrl.92.1524411091216; Sun, 22 Apr 2018 08:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524411091; cv=none; d=google.com; s=arc-20160816; b=NLFHseP3S1BXsaotVtxUGeKBFCNLxaN0hWEtjVFTNJ1okfG0uolLaIt8wKZFrrqMNA xie0XOajsaV3B/2oy8HZvp8CSuPQrDQ+T8MlKpIJ23QzUeb1Y3fWNdntbHQ1fUOFisMd 0eSIlC3r73zXXJOflxEgxHe0Nh0M0GBkeSU9vRlYZhpj5ESSAYcM6IJdZW3KDokm+ajC ZtkRgIOaBYfvdekgREZwhj/x/7KF6P75mgwRLpsmlXMD6vH92D19bCHo8t7F6YOmTcQq oyiyoeaIPrVqSBGgeuApmP7LTLqfaSzdQdf21Mhn1DcPb0C84g/wzjx4PRfZGKnyej4p ni5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=A5Y1cM+Rui0kGSRIGTbebqJp7vUfWT5hyWPPWtM0ygk=; b=VGsQXPFRBIibltkfZjweIVKXweWR3GP7aUnHLRlOO+/m4JuSr+A1Hjrr19zGDf48RN eChzLWeNr2JoZGbQEytyO9vqvmA9K2C2Cf4BHyZt7ttcRRaBNTQb7sKeLOuQ8FEx0Dn5 BzIceuzuKx3Z/6+oeTXKUAx0Qrpdlv+QQ13rU2sL6gsn7FV/ortGM1qhmp3Zjn8Jfxjl XnuYxNOrAxkwVhoSlnzL/f7IEHvKUrCSPtlWtjzXx9YBc4nYGnjrTxfGYKf0nt6OQiD4 hOiYLwV73wzN9XiO5/AqJQtOGINVrR1dPCWqN5nx+jitY4FLClldjrOPg/EiuMYrAjHM rduA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=TkSwbNEd; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v7-v6si4269862wrv.129.2018.04.22.08.31.30; Sun, 22 Apr 2018 08:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=TkSwbNEd; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 783D368A35F; Sun, 22 Apr 2018 18:29:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D93CB68A2D6 for ; Sun, 22 Apr 2018 18:29:13 +0300 (EEST) Received: by mail-wr0-f195.google.com with SMTP id f14-v6so34589610wre.4 for ; Sun, 22 Apr 2018 08:29:42 -0700 (PDT) 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; bh=CN+LxGZLdUTl6BEqukCpiiWVi+HM2uzmdYj8jZczWLA=; b=TkSwbNEdf9v41e2KI6oPSal5TqNQxjFvvhUQCT5WxB836k3utXbvgX3CwIKm8071go gLIilC5fIa7ymOgWvy8DadQav2s4LSj1SKky5LLhFWKp3fNCJYBJW/DilNsQ8eGtwWnP gH6k/+Yc7F3B9EFXeruLyHtuSF7wAwfehEJyS19q5gMxyIshEumPVcv5Cr58KGz3LdJx 4VJyb5dgSiOevgCLta8yeHSjhAirYBJUJvMB3iAzrSZdMvGlTiCuUgb1V39YZZC5haUO OaQStomLVKUbXD5b5Jv7dn/jL8VUCJjeimSn7EreEEg+1c9CX0jcXO09XVYXogcm4ieC ef3w== 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; bh=CN+LxGZLdUTl6BEqukCpiiWVi+HM2uzmdYj8jZczWLA=; b=gpUAZyRJabmUKHgEmz/DsbsyTix/4HXJTYCZYXeP9pZXrcqF5G4pLM6+CepjvbOOeo W6DRhwPi9BW6v9Zde5Cp0E03WdVRylZUhOaLXuYB0gOtLsNEEV+Slj2WR2wO0+n0gMSN V6Dx2SpXzlP0zJ3/GpTBe4GSMdV9hnQKyNWmBmur7PMGYj716WukHQL/kzVh+T/OdFuF CVxipxqSubeh7QNaBtgbevglsiJVJ3PG+DxnYsV5YEQcuh25QXyDK2T+2ZiAG4uV4pVh IJptS1HX6wIhN7zj0Duv0snXJF7cgxi8ckouTSlj6DAMWL108P4+G91LRvhPnYUOu8J0 QibA== X-Gm-Message-State: ALQs6tCUqJjoeax+sv7ju7Oc7xa53I205T6OrVwYGFblFRiSIpQLOzIg DBlDt5NFajKxwkoX8Px0o4yFc4SG X-Received: by 10.28.106.5 with SMTP id f5mr7797370wmc.84.1524410982120; Sun, 22 Apr 2018 08:29:42 -0700 (PDT) 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 32-v6sm7021498wrf.79.2018.04.22.08.29.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Apr 2018 08:29:41 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Apr 2018 16:29:08 +0100 Message-Id: <20180422152921.32510-14-sw@jkqxz.net> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180422152921.32510-1-sw@jkqxz.net> References: <20180422152921.32510-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 13/26] vaapi_encode: Add quality level to common options 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This was previously accessible only via AVCodecContext.compression_level for all encoders except H.264 where it was also a private option. This makes it an explicit option everywhere. --- libavcodec/vaapi_encode.c | 87 ++++++++++++++++++++++++++---------------- libavcodec/vaapi_encode.h | 8 ++++ libavcodec/vaapi_encode_h264.c | 6 --- 3 files changed, 62 insertions(+), 39 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 9c39bcdeff..a5eb072843 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -1381,6 +1381,52 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx) return 0; } +static av_cold int vaapi_encode_init_quality(AVCodecContext *avctx) +{ +#if VA_CHECK_VERSION(0, 36, 0) + VAAPIEncodeContext *ctx = avctx->priv_data; + VAStatus vas; + VAConfigAttrib attr = { VAConfigAttribEncQualityRange }; + + vas = vaGetConfigAttributes(ctx->hwctx->display, + ctx->va_profile, + ctx->va_entrypoint, + &attr, 1); + if (vas != VA_STATUS_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "Failed to query quality " + "config attribute: %d (%s).\n", vas, vaErrorStr(vas)); + return AVERROR_EXTERNAL; + } + + if (attr.value == VA_ATTRIB_NOT_SUPPORTED) { + if (ctx->quality != 0) { + av_log(avctx, AV_LOG_WARNING, "Quality attribute is not " + "supported: will use default quality level.\n"); + } + } else { + if (ctx->quality > attr.value) { + av_log(avctx, AV_LOG_WARNING, "Invalid quality level: " + "valid range is 0-%d, using %d.\n", + attr.value, attr.value); + ctx->quality = attr.value; + } + + ctx->quality_params.misc.type = + VAEncMiscParameterTypeQualityLevel; + ctx->quality_params.quality.quality_level = + ctx->quality; + + vaapi_encode_add_global_param(avctx, &ctx->quality_params.misc, + sizeof(ctx->quality_params)); + } +#else + av_log(avctx, AV_LOG_WARNING, "The encode quality option is " + "not supported with this VAAPI version.\n"); +#endif + + return 0; +} + static void vaapi_encode_free_output_buffer(void *opaque, uint8_t *data) { @@ -1562,6 +1608,14 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) if (err < 0) goto fail; + if (!ctx->quality) + ctx->quality = avctx->compression_level; + if (ctx->quality >= 0) { + err = vaapi_encode_init_quality(avctx); + if (err < 0) + goto fail; + } + vas = vaCreateConfig(ctx->hwctx->display, ctx->va_profile, ctx->va_entrypoint, ctx->config_attributes, ctx->nb_config_attributes, @@ -1611,39 +1665,6 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) goto fail; } - if (avctx->compression_level >= 0) { -#if VA_CHECK_VERSION(0, 36, 0) - VAConfigAttrib attr = { VAConfigAttribEncQualityRange }; - - vas = vaGetConfigAttributes(ctx->hwctx->display, - ctx->va_profile, - ctx->va_entrypoint, - &attr, 1); - if (vas != VA_STATUS_SUCCESS) { - av_log(avctx, AV_LOG_WARNING, "Failed to query quality " - "attribute: will use default compression level.\n"); - } else { - if (avctx->compression_level > attr.value) { - av_log(avctx, AV_LOG_WARNING, "Invalid compression " - "level: valid range is 0-%d, using %d.\n", - attr.value, attr.value); - avctx->compression_level = attr.value; - } - - ctx->quality_params.misc.type = - VAEncMiscParameterTypeQualityLevel; - ctx->quality_params.quality.quality_level = - avctx->compression_level; - - vaapi_encode_add_global_param(avctx, &ctx->quality_params.misc, - sizeof(ctx->quality_params)); - } -#else - av_log(avctx, AV_LOG_WARNING, "The encode compression level " - "option is not supported with this VAAPI version.\n"); -#endif - } - ctx->input_order = 0; ctx->output_delay = avctx->max_b_frames; ctx->decode_delay = 1; diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index 9e0826b30e..35d48eff2f 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -111,6 +111,10 @@ typedef struct VAAPIEncodeContext { // Global options. + // Encoding quality level. + // (Also exposed via AVCodecContext.compression_level.) + int quality; + // Use low power encoding mode. int low_power; @@ -302,6 +306,10 @@ int ff_vaapi_encode_close(AVCodecContext *avctx); #define VAAPI_ENCODE_COMMON_OPTIONS \ + { "quality", \ + "Set encode quality (trades off against speed, higher is faster)", \ + OFFSET(common.quality), AV_OPT_TYPE_INT, \ + { .i64 = 0 }, 0, INT_MAX, FLAGS }, \ { "low_power", \ "Use low-power encoding mode (only available on some platforms; " \ "may not support all encoding features)", \ diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index 49dc5229b5..a20cf15c1e 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -51,7 +51,6 @@ typedef struct VAAPIEncodeH264Context { // User options. int qp; - int quality; int coder; int aud; int sei; @@ -828,9 +827,6 @@ static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx) av_assert0(0 && "Invalid RC mode."); } - if (avctx->compression_level == FF_COMPRESSION_DEFAULT) - avctx->compression_level = priv->quality; - if (priv->sei & SEI_IDENTIFIER) { const char *lavc = LIBAVCODEC_IDENT; const char *vaapi = VA_VERSION_S; @@ -970,8 +966,6 @@ static const AVOption vaapi_encode_h264_options[] = { { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)", OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 20 }, 0, 52, FLAGS }, - { "quality", "Set encode quality (trades off against speed, higher is faster)", - OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8, FLAGS }, { "coder", "Entropy coder type", OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, "coder" }, { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, "coder" },