From patchwork Fri Feb 18 01:42:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Fei W" X-Patchwork-Id: 34371 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp514907nkx; Thu, 17 Feb 2022 17:48:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3d7pSTraoHZnai/e6NOTBWc7O1bL6R7rqMXhZnJMV9bJWqSPuQOwdxx4UGcKD3C+04M3K X-Received: by 2002:a50:9f08:0:b0:410:b961:eea4 with SMTP id b8-20020a509f08000000b00410b961eea4mr5765764edf.394.1645148903736; Thu, 17 Feb 2022 17:48:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645148903; cv=none; d=google.com; s=arc-20160816; b=hKW8l5Uizqc/mrTAzLk0C9tr6zxqsJOMHUwflEOYtpqlGRmllSF15h4r7V8USRfqmo NB+gGABIGI+p7tj+EzjKo9ToMN2+kMa0PgP4hmyBKcUdNyarUDUCubOIH6uurb1YxF3C yAnLBEjJBBrHiCeJ3HS80t32e//0+DMucWaYDLuWYiTdqDTvTsUlkWe2xzde+qwzO9xZ 28MTl0sYsgVEn3kb1OL/S0EAFOUZ9sj5avGQqjks9INrPHzlPYEi3v9kEdkGPpzKGZvf MsEUvzZSbS00i3+izjc2upSQxh1yvFI7WlTRatWpjZSATXCMAcZlu0CpBFc/5TBRz+Zj S5QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=h9gSgJVUBfBgw1iPbJfQ9Z3MZkO2eqnnJkxE38hffUc=; b=q/4T5KgAIsRPpGYNvrabySXNljUD3hC6ePxZNcos9pXJUbS7DY6moCPQYk25uEhXOM P/RhmvbSIitm8Kab7HStYticXddVBSIRKnmQYdc3/fy4wloPhn9hmruGKnvLX+EkNh5Z V4rLxPDIkAQKHKvCenVDWaPjLPJI92BYej3zGrc58CixRRRN+YporpX+BJfCiXZa28x1 ihaukSFbk9Ql2E9Db13IxWRAaSzlUvdhPtiMIqgE7t7mN4DRwLSfFeJwkdBzASrpwK7Y KCwuCMcLyklpGlCvEYngmxR6pmvOL6g1hLuv1GmcK1xihr4PJVd2tOj6kzXVUmUyQalO OVFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=DhLQw6pE; 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 hp3si3397335ejc.847.2022.02.17.17.48.23; Thu, 17 Feb 2022 17:48:23 -0800 (PST) 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=@intel.com header.s=Intel header.b=DhLQw6pE; 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 99FDE68B2F6; Fri, 18 Feb 2022 03:48:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BF81068B2F6 for ; Fri, 18 Feb 2022 03:48:13 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645148899; x=1676684899; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=r5zEsWxpHPI0q8COMLYw0h3yEglZJku2zbbBz2Gp0HI=; b=DhLQw6pE547/FaUYuOI28q/csPtPki3WvaLRK+MgX+gbEVAHY5uLeWMj WeAidXJkG8VofvIjVTH0WM3kWM78LMHIB2D/d0d759k/OBmJO3XfjCKVD CwC7Fo1Ykwuy/O5wMDuIRa29Tt7UGZRaYAirmJc2n6JCS2helcRoOvVUT tv+lJXVxqkHaBQ+GwWryB0njeisbaJxPw+rxh86meDWL4Z4MCDlm63Y4h 5vEO64lo9GTR8o0ieiu4YzMrdTm5OUR49Ywfk8b914icRrcmUNZXKuD0G tBT+LQCEh37vC3fyHznOXY/wjCh9Gl8PVOW8sKUcDf5YWs8JxrtHWTQaz g==; X-IronPort-AV: E=McAfee;i="6200,9189,10261"; a="231010239" X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="231010239" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 17:48:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="777781284" Received: from t.sh.intel.com ([10.239.159.147]) by fmsmga005.fm.intel.com with ESMTP; 17 Feb 2022 17:48:10 -0800 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Fri, 18 Feb 2022 09:42:58 +0800 Message-Id: <20220218014301.1830754-1-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 1/4] lavc/vaapi_encode_h265: Add P frame to GPB frame support for hevc_vaapi 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 Cc: Fei Wang , Linjie Fu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BPXUBXkHI/sk From: Linjie Fu Use GPB frames to replace regular P frames if backend driver does not support it. - GPB: Generalized P and B picture. P frames replaced by B frames with forward-predict only, L0 == L1. Normal B frames still have 2 different ref_lists and allow bi-prediction Signed-off-by: Linjie Fu Signed-off-by: Fei Wang --- libavcodec/vaapi_encode.c | 33 +++++++++++++++++++++++++++++++-- libavcodec/vaapi_encode.h | 1 + libavcodec/vaapi_encode_h265.c | 15 +++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 3bf379b1a0..95eca7c288 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -1845,6 +1845,30 @@ static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx) ref_l1 = attr.value >> 16 & 0xffff; } + ctx->p_to_gpb = 0; + +#if VA_CHECK_VERSION(1, 9, 0) + attr = (VAConfigAttrib) { VAConfigAttribPredictionDirection }; + 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 prediction direction " + "attribute: %d (%s).\n", vas, vaErrorStr(vas)); + } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) { + av_log(avctx, AV_LOG_VERBOSE, "Driver does not report whether " + "support GPB, use regular P frames.\n"); + } else { + if (attr.value & VA_PREDICTION_DIRECTION_BI_NOT_EMPTY) { + ctx->p_to_gpb = 1; + av_log(avctx, AV_LOG_VERBOSE, "Use GPB B frames to replace " + "regular P frames.\n"); + } else + av_log(avctx, AV_LOG_VERBOSE, "Use regular P frames.\n"); + } +#endif + if (ctx->codec->flags & FLAG_INTRA_ONLY || avctx->gop_size <= 1) { av_log(avctx, AV_LOG_VERBOSE, "Using intra frames only.\n"); @@ -1861,8 +1885,13 @@ static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx) ctx->p_per_i = INT_MAX; ctx->b_per_p = 0; } else { - av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames " - "(supported references: %d / %d).\n", ref_l0, ref_l1); + if (ctx->p_to_gpb) + av_log(avctx, AV_LOG_VERBOSE, "Using intra, GPB-B-frames and " + "B-frames (supported references: %d / %d).\n", + ref_l0, ref_l1); + else + av_log(avctx, AV_LOG_VERBOSE, "Using intra, P- and B-frames " + "(supported references: %d / %d).\n", ref_l0, ref_l1); ctx->gop_size = avctx->gop_size; ctx->p_per_i = INT_MAX; ctx->b_per_p = avctx->max_b_frames; diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index b41604a883..61c5615eb8 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -328,6 +328,7 @@ typedef struct VAAPIEncodeContext { int idr_counter; int gop_counter; int end_of_stream; + int p_to_gpb; // Whether the driver supports ROI at all. int roi_allowed; diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index e1dc53dfa9..ea45893508 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -886,6 +886,7 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice) { + VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodeH265Context *priv = avctx->priv_data; VAAPIEncodeH265Picture *hpic = pic->priv_data; const H265RawSPS *sps = &priv->raw_sps; @@ -908,6 +909,9 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, sh->slice_type = hpic->slice_type; + if (sh->slice_type == HEVC_SLICE_P && ctx->p_to_gpb) + sh->slice_type = HEVC_SLICE_B; + sh->slice_pic_order_cnt_lsb = hpic->pic_order_cnt & (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1; @@ -1066,6 +1070,9 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, av_assert0(pic->type == PICTURE_TYPE_P || pic->type == PICTURE_TYPE_B); vslice->ref_pic_list0[0] = vpic->reference_frames[0]; + if (ctx->p_to_gpb && pic->type == PICTURE_TYPE_P) + // Reference for GPB B-frame, L0 == L1 + vslice->ref_pic_list1[0] = vpic->reference_frames[0]; } if (pic->nb_refs >= 2) { // Forward reference for B-frame. @@ -1073,6 +1080,14 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, vslice->ref_pic_list1[0] = vpic->reference_frames[1]; } + if (pic->type == PICTURE_TYPE_P && ctx->p_to_gpb) { + vslice->slice_type = HEVC_SLICE_B; + for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) { + vslice->ref_pic_list1[i].picture_id = vslice->ref_pic_list0[i].picture_id; + vslice->ref_pic_list1[i].flags = vslice->ref_pic_list0[i].flags; + } + } + return 0; } From patchwork Fri Feb 18 01:42:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Fei W" X-Patchwork-Id: 34372 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp514991nkx; Thu, 17 Feb 2022 17:48:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHk27/wT0w2blnTCVjXCAw5WfO8DWJVTpw+BPCVdqTuqjm0pKVivuYgraODyU1CfMHSleG X-Received: by 2002:a17:906:1244:b0:6cf:118c:932f with SMTP id u4-20020a170906124400b006cf118c932fmr4612615eja.563.1645148912703; Thu, 17 Feb 2022 17:48:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645148912; cv=none; d=google.com; s=arc-20160816; b=Z4utw+3cegVAxpJQtfK4bZuuNqnlT9rliURDfrCwTr6xHT8/VB8500bzEi9R4o7qHT A4tvNslO2k9Qt34zIhGhfEQq/DJH9ZjpYAQYntHzr3yEE7ewwLbMDIpGVLAIrXHd9dyq wbyjzqE5sUC8oAxAPecnZlZBOUi/QA3cmjT3j6MbNrsx6MhX9ELr59ypBBLY+vxqsrV3 OG2NKdCuk3toGzVck/9+ncSIJuUvq04QzLCyv6EYuA7oecHIOTd+JPyVf4TrzRB5Bm4v +TCzViIhSBA/A/Ej9zGKqkqohzaPjQa6LwrywtRv0lhGRGZGWs90DVpKLHS969Hb5OVU leeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=wAohjtOnI1lifdfQRLAtSJVQlqcGFWJytOc4V0RB/8c=; b=LN04knKWBUnaLpWgWiUNzT0dA6Va2xV1wnOrisvyreWpkBsLQlyLcwjiCZlj6Kdh+M lT/kn/ctS41WdYSR2P5E0DIZBX0lzSbC2rmqqLVNTQ8Q3B0pt9BRTzkQiJoRT73VAvCy 0KeiSh3LILiXONnLC95CCBYuErDiPTb5BnckNfLPEyacmOKErznEVbjGxXR9FFS2+Ei+ 3abreQOM+eCODzNz1pr6pq/Pk+Bd8vPfdSWMEV46t3IWX2xvgpj1H0hFZtdnULc4g+SN A47CE95s4+QUsA3Ls0Tb0QGaH5yXtY+k1DzGyPttnKZUbWZTxTBKw4WHh8byi481iZST WB1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=nBcX+nJR; 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 gm1si3606490ejc.503.2022.02.17.17.48.32; Thu, 17 Feb 2022 17:48:32 -0800 (PST) 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=@intel.com header.s=Intel header.b=nBcX+nJR; 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 B3CED68B367; Fri, 18 Feb 2022 03:48:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 785C968B332 for ; Fri, 18 Feb 2022 03:48:17 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645148902; x=1676684902; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uKBuhV11S5+2JDvyHDlu0X6rA/8Lc/XANCczAZMmzdE=; b=nBcX+nJRpK1gq/70NH6NqGJXKqrsOm07V+8e0DcKsldNWmhPsfORUpV1 dFQUjZK9nGt1GZsq8YviZ8sR2pz8Vj0mxPIJ52WTpomZbnPDCGpKHyNYb Gas4aglL1zKj4qRC5tUtLwl2BY/yIuIOEVeCqP10LvtcUf4FVEjqdToeH 3bpp2jSm8CTd5iRAz+G6Z0cyZMnmcEnbrBL6rVQjvoA4LiGZsP31yacR0 uCxXKE+Hd+1BALXSRirkS9br9EJzAalG8XKBjEojbMExITUwtOOzt5JFp JFFIhAmF3FhVIdvV+enNEKjxSGEcZwANQV6AJfy8EMQi8XEx5A1IEPpRx w==; X-IronPort-AV: E=McAfee;i="6200,9189,10261"; a="231010258" X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="231010258" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 17:48:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="777781334" Received: from t.sh.intel.com ([10.239.159.147]) by fmsmga005.fm.intel.com with ESMTP; 17 Feb 2022 17:48:14 -0800 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Fri, 18 Feb 2022 09:42:59 +0800 Message-Id: <20220218014301.1830754-2-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220218014301.1830754-1-fei.w.wang@intel.com> References: <20220218014301.1830754-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 2/4] vaapi_encode: Move block size calculation after entrypoint selection 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 Cc: Mark Thompson , Fei Wang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: zfnMmybmaVm0 From: Mark Thompson The block size can be dependent on the profile and entrypoint selected. It defaults to 16x16, with codecs able to override this choice with their own function. Signed-off-by: Fei Wang --- libavcodec/vaapi_encode.c | 14 ++++++++++++++ libavcodec/vaapi_encode.h | 7 +++++++ libavcodec/vaapi_encode_h265.c | 32 ++++++++++++++++++++++++++------ libavcodec/vaapi_encode_mjpeg.c | 16 +++++++++++++--- libavcodec/vaapi_encode_mpeg2.c | 3 --- libavcodec/vaapi_encode_vp8.c | 3 --- libavcodec/vaapi_encode_vp9.c | 14 ++++++++++---- 7 files changed, 70 insertions(+), 19 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 95eca7c288..763fe50009 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -2041,6 +2041,8 @@ static av_cold int vaapi_encode_init_slice_structure(AVCodecContext *avctx) return 0; } + av_assert0(ctx->slice_block_height > 0 && ctx->slice_block_width > 0); + ctx->slice_block_rows = (avctx->height + ctx->slice_block_height - 1) / ctx->slice_block_height; ctx->slice_block_cols = (avctx->width + ctx->slice_block_width - 1) / @@ -2430,6 +2432,18 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) if (err < 0) goto fail; + if (ctx->codec->get_encoder_caps) { + ctx->codec->get_encoder_caps(avctx); + } else { + // Assume 16x16 blocks. + ctx->surface_width = FFALIGN(avctx->width, 16); + ctx->surface_height = FFALIGN(avctx->height, 16); + if (ctx->codec->flags & FLAG_SLICE_CONTROL) { + ctx->slice_block_width = 16; + ctx->slice_block_height = 16; + } + } + err = vaapi_encode_init_rate_control(avctx); if (err < 0) goto fail; diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index 61c5615eb8..2e5cfd7a72 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -376,6 +376,13 @@ typedef struct VAAPIEncodeType { // factor depending on RC mode. int default_quality; + // Determine encode parameters like block sizes for surface alignment + // and slices. This may need to query the profile and entrypoint, + // which will be available when this function is called. If not set, + // assume that all blocks are 16x16 and that surfaces should be + // aligned to match this. + void (*get_encoder_caps)(AVCodecContext *avctx); + // Perform any extra codec-specific configuration after the // codec context is initialised (set up the private data and // add any necessary global parameters). diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index ea45893508..5b8dbe841d 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -55,6 +55,10 @@ typedef struct VAAPIEncodeH265Picture { typedef struct VAAPIEncodeH265Context { VAAPIEncodeContext common; + // Encoder features. + uint32_t ctu_size; + uint32_t min_cb_size; + // User options. int qp; int aud; @@ -1091,6 +1095,27 @@ static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, return 0; } +static av_cold void vaapi_encode_h265_get_encoder_caps(AVCodecContext *avctx) +{ + VAAPIEncodeContext *ctx = avctx->priv_data; + VAAPIEncodeH265Context *priv = avctx->priv_data; + + if (!priv->ctu_size) { + priv->ctu_size = 32; + priv->min_cb_size = 16; + } + av_log(avctx, AV_LOG_VERBOSE, "Using CTU size %dx%d, " + "min CB size %dx%d.\n", priv->ctu_size, priv->ctu_size, + priv->min_cb_size, priv->min_cb_size); + + ctx->surface_width = FFALIGN(avctx->width, priv->min_cb_size); + ctx->surface_height = FFALIGN(avctx->height, priv->min_cb_size); + + ctx->slice_block_width = ctx->slice_block_height = priv->ctu_size; + + return; +} + static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; @@ -1160,6 +1185,7 @@ static const VAAPIEncodeType vaapi_encode_type_h265 = { .default_quality = 25, + .get_encoder_caps = &vaapi_encode_h265_get_encoder_caps, .configure = &vaapi_encode_h265_configure, .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture), @@ -1205,12 +1231,6 @@ static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx) VA_ENC_PACKED_HEADER_SLICE | // Slice headers. VA_ENC_PACKED_HEADER_MISC; // SEI - ctx->surface_width = FFALIGN(avctx->width, 16); - ctx->surface_height = FFALIGN(avctx->height, 16); - - // 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; diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c index 6206b23e5f..c4fe879073 100644 --- a/libavcodec/vaapi_encode_mjpeg.c +++ b/libavcodec/vaapi_encode_mjpeg.c @@ -434,6 +434,18 @@ static int vaapi_encode_mjpeg_init_slice_params(AVCodecContext *avctx, return 0; } +static av_cold void vaapi_encode_mjpeg_get_encoder_caps(AVCodecContext *avctx) +{ + VAAPIEncodeContext *ctx = avctx->priv_data; + const AVPixFmtDescriptor *desc; + + desc = av_pix_fmt_desc_get(ctx->input_frames->sw_format); + av_assert0(desc); + + ctx->surface_width = FFALIGN(avctx->width, 8 << desc->log2_chroma_w); + ctx->surface_height = FFALIGN(avctx->height, 8 << desc->log2_chroma_h); +} + static av_cold int vaapi_encode_mjpeg_configure(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; @@ -483,6 +495,7 @@ static const VAAPIEncodeType vaapi_encode_type_mjpeg = { .flags = FLAG_CONSTANT_QUALITY_ONLY | FLAG_INTRA_ONLY, + .get_encoder_caps = &vaapi_encode_mjpeg_get_encoder_caps, .configure = &vaapi_encode_mjpeg_configure, .default_quality = 80, @@ -509,9 +522,6 @@ static av_cold int vaapi_encode_mjpeg_init(AVCodecContext *avctx) ctx->desired_packed_headers = VA_ENC_PACKED_HEADER_RAW_DATA; - ctx->surface_width = FFALIGN(avctx->width, 8); - ctx->surface_height = FFALIGN(avctx->height, 8); - return ff_vaapi_encode_init(avctx); } diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c index d084d8c4b9..f8809b08ab 100644 --- a/libavcodec/vaapi_encode_mpeg2.c +++ b/libavcodec/vaapi_encode_mpeg2.c @@ -623,9 +623,6 @@ static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx) ctx->desired_packed_headers = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE; - ctx->surface_width = FFALIGN(avctx->width, 16); - ctx->surface_height = FFALIGN(avctx->height, 16); - return ff_vaapi_encode_init(avctx); } diff --git a/libavcodec/vaapi_encode_vp8.c b/libavcodec/vaapi_encode_vp8.c index 7d4578f674..ab3c84a618 100644 --- a/libavcodec/vaapi_encode_vp8.c +++ b/libavcodec/vaapi_encode_vp8.c @@ -210,9 +210,6 @@ static av_cold int vaapi_encode_vp8_init(AVCodecContext *avctx) // adding them anyway. ctx->desired_packed_headers = 0; - ctx->surface_width = FFALIGN(avctx->width, 16); - ctx->surface_height = FFALIGN(avctx->height, 16); - return ff_vaapi_encode_init(avctx); } diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c index be706e3bd6..b7560c4b81 100644 --- a/libavcodec/vaapi_encode_vp9.c +++ b/libavcodec/vaapi_encode_vp9.c @@ -184,6 +184,15 @@ static int vaapi_encode_vp9_init_picture_params(AVCodecContext *avctx, return 0; } +static av_cold void vaapi_encode_vp9_get_encoder_caps(AVCodecContext *avctx) +{ + VAAPIEncodeContext *ctx = avctx->priv_data; + + // Surfaces must be aligned to 64x64 superblock boundaries. + ctx->surface_width = FFALIGN(avctx->width, 64); + ctx->surface_height = FFALIGN(avctx->height, 64); +} + static av_cold int vaapi_encode_vp9_configure(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; @@ -231,6 +240,7 @@ static const VAAPIEncodeType vaapi_encode_type_vp9 = { .picture_priv_data_size = sizeof(VAAPIEncodeVP9Picture), + .get_encoder_caps = &vaapi_encode_vp9_get_encoder_caps, .configure = &vaapi_encode_vp9_configure, .sequence_params_size = sizeof(VAEncSequenceParameterBufferVP9), @@ -251,10 +261,6 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx) // can write its own headers and there is no metadata to include. ctx->desired_packed_headers = 0; - // Surfaces must be aligned to superblock boundaries. - ctx->surface_width = FFALIGN(avctx->width, 64); - ctx->surface_height = FFALIGN(avctx->height, 64); - return ff_vaapi_encode_init(avctx); } From patchwork Fri Feb 18 01:43:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Fei W" X-Patchwork-Id: 34373 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp515059nkx; Thu, 17 Feb 2022 17:48:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1YhdMLDqd5KsLssHczgvMNTG73ZbOIWhEZI1O4bfnLMkkt7qanajTpg15mmlOX6MsmYqp X-Received: by 2002:a17:906:3a4f:b0:6cf:86e0:586c with SMTP id a15-20020a1709063a4f00b006cf86e0586cmr4575210ejf.626.1645148922063; Thu, 17 Feb 2022 17:48:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645148922; cv=none; d=google.com; s=arc-20160816; b=LM9rb3b9ix8DHZC0TOcBr1Qdquie6+M6ZiS3St84Z1UCsGEcFjSKIV3MGtv1XuEB6e BtA7OAgn4xLNZs9Gs616Xx/brObJkujwspOuQWwei94G8SBHg6jpwIoJmi+jgSKgwjI/ KOdL8550Cg78OyrstIZg95GXO6qsZ3VdkbKarq1xt/mfZwOUr7lwBSD8SUyl6v4zR8KI VPTCBSfQZtuIWxDvVzWpp0RXYdm4VmllB63x7y5iZeWt/7l4LQFXmFJBOxmF53ExG63z ln1L/1wb9uSvTyhpzAK/KrUzfPdQTkKFgi4CBTJFUAlqQgSuLQXVYdpcz5g9ymAhDyIJ iCYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Hp7xAWEEQfszMlmQPeafb7GZPOHI8e5na0/YCq2LRKc=; b=YJGpagPckYAYvLNeWxzNd8rsXb72bqnfg2m1LWgJpSbuRkeKCyE6iR/T5bBHH7LvXS /7b89YOh3radFTQ6eLzoePKEkDGe8OnXF4GDSCkD4NxqAZQ8VoRLf4YZ091bUvTB3gs9 8ES75DVsSfZUZQFsixh+jTwFgW9QeoGNf80ln/blkJgfpEX5kqlkSi7b6HHQWJSmpm5k PWYwZ8qOZ6J9len4ujidyBFG/vx89r4cRDBJ/B2fS6cj55wzq66pP7S51GYWULWwq1C2 QpoRsYAye6DrLG872Y9U1ycZu/D0L1xEaMSJkjAJvkfkGglTayEEZTHj2mGsdDmR/PZm u0HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=Te555Zqw; 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 ox29si2824950ejb.433.2022.02.17.17.48.41; Thu, 17 Feb 2022 17:48:42 -0800 (PST) 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=@intel.com header.s=Intel header.b=Te555Zqw; 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 C965F68B370; Fri, 18 Feb 2022 03:48:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA65A68B332 for ; Fri, 18 Feb 2022 03:48:18 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645148904; x=1676684904; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yf2UOafZYgaGBlQApk7GLFnJk2zJh+xgqBSoqNkEBLY=; b=Te555ZqwEd+7jaaRewluxXdPdWK2rq7KhM5nrQFH1sFR5uwBUZAmp4IB ACVsH+aWmRrYxrNXjE9sfNDGBroX6KshB7c3rj0+ko0cqnjOn/YYFdwo0 alib3pmKQhXbPS4sWuPwq8u+CUUEoriwZ0tONIFAqbzagV24gbPy5MkYF BT35KCuxjSRDPwh2DKX6XdEN3ezcWQ5sExC2kXC8T+5gAkzcQmcm8d2ZL ABGkv0fLw94wZbLgNsKkgaB6EFgHXVT92GLuiTTNOUDpXUMtCt4Ye4zQ/ QlxiZIYNvj33XjUQ+uBULE1rivl6/bqUNGsKD4waSdObFMpXjjBYsWM1w Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10261"; a="231010265" X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="231010265" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 17:48:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="777781353" Received: from t.sh.intel.com ([10.239.159.147]) by fmsmga005.fm.intel.com with ESMTP; 17 Feb 2022 17:48:16 -0800 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Fri, 18 Feb 2022 09:43:00 +0800 Message-Id: <20220218014301.1830754-3-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220218014301.1830754-1-fei.w.wang@intel.com> References: <20220218014301.1830754-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 3/4] vaapi_encode_h265: Explicitly set and correct some flags 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 Cc: Mark Thompson , Fei Wang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vEfcGp5LpaGe From: Mark Thompson max_14bit_constraint_flag should be set if the bit depth is not greater than 14 (currently always true). one_picture_only_flag should not be set because we don't support the still picture profiles. general_profile_compatibility_flag should be set according to general_profile_idc instead of bit depth. Signed-off-by: Fei Wang --- libavcodec/vaapi_encode_h265.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 5b8dbe841d..8319848e4a 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -303,17 +303,21 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) ptl->general_profile_idc = avctx->profile; ptl->general_tier_flag = priv->tier; - if (chroma_format == 1) { - ptl->general_profile_compatibility_flag[1] = bit_depth == 8; - ptl->general_profile_compatibility_flag[2] = bit_depth <= 10; + ptl->general_profile_compatibility_flag[ptl->general_profile_idc] = 1; + + if (ptl->general_profile_compatibility_flag[1]) + ptl->general_profile_compatibility_flag[2] = 1; + if (ptl->general_profile_compatibility_flag[3]) { + ptl->general_profile_compatibility_flag[1] = 1; + ptl->general_profile_compatibility_flag[2] = 1; } - ptl->general_profile_compatibility_flag[4] = 1; ptl->general_progressive_source_flag = 1; ptl->general_interlaced_source_flag = 0; ptl->general_non_packed_constraint_flag = 1; ptl->general_frame_only_constraint_flag = 1; + ptl->general_max_14bit_constraint_flag = bit_depth <= 14; ptl->general_max_12bit_constraint_flag = bit_depth <= 12; ptl->general_max_10bit_constraint_flag = bit_depth <= 10; ptl->general_max_8bit_constraint_flag = bit_depth == 8; @@ -323,6 +327,7 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) ptl->general_max_monochrome_constraint_flag = chroma_format == 0; ptl->general_intra_constraint_flag = ctx->gop_size == 1; + ptl->general_one_picture_only_constraint_flag = 0; ptl->general_lower_bit_rate_constraint_flag = 1; From patchwork Fri Feb 18 01:43:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Fei W" X-Patchwork-Id: 34374 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp515159nkx; Thu, 17 Feb 2022 17:48:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgipmX6YdD5tknIXwbdh7fS8dIkQRxRQpEjcjv0/JzQ4a7j7nMjUJq7l713iykg7XdA3pT X-Received: by 2002:aa7:cd48:0:b0:410:6081:9cb with SMTP id v8-20020aa7cd48000000b00410608109cbmr5594727edw.361.1645148931726; Thu, 17 Feb 2022 17:48:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645148931; cv=none; d=google.com; s=arc-20160816; b=OLT0IgKmlJKiABuOV3pnWV1UcoBIXpkz91Vgfx5MORf+f1PY9kvPzLO/WwG95d3GGP Ul+YLfeApMZBwBH4J/VBP+7NIAKY7VstMB6b/tX2LYk0ZR+g/J+xMNSCALh/FZdroHuH hPSBoq+kak5Dikd4skfChxvSMHftyvYxBu5PVgYN11NHIlQz0LlgGjxBs5QlG168YYTg 9HvshIiORrnhUzA9tI38TEuocUl8BA4MitJ5RttYRTJqnlG6jB1Gp7EYznmS3UQulVow JIxoBN5SELCYBRXF57VC4u9Om9ooMP4HJxPJD/USL8AmGxylnxk/lzHNiPRbZG8jRgD8 hPvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=4DmXxhvimnRnNwvkKOtmc+tAmuZItnQ3rbjm9MJ3hPw=; b=dzQIx6Tz4nCaXNUGuRMKq6nQUyfY5WlmohbIwuTWhvggjJ76DVYOGay4lfGdffR0SU cDoZ+anW6SP1rxo4VfWSah9aT3EbszEwvt6t2sIdNCH7atgcSsQIlqfnsD2p5JGqbZJz rBq1fDh/BlGcZNe0pHf/wXRqbLtOtnVBgI2IGnVd+0hfDgM2AEiDtvBaBpCAjoQXijnK 5BL5GCX6ozdUV6YTyfxGZKu4FGjd8glq6izIVbnE0Bix+V39tBiJWQ8UyR0r4iwYCQHJ /1WYSmgmX1WYJr59tss7PcioJ1LggsZ4tDG1mnG7kZIgFh8ZXBPKXf9/6p9ZDks5cvKr ah4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=ZVyPW8rO; 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 z67si5300595ede.475.2022.02.17.17.48.51; Thu, 17 Feb 2022 17:48:51 -0800 (PST) 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=@intel.com header.s=Intel header.b=ZVyPW8rO; 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 D6EB968B379; Fri, 18 Feb 2022 03:48:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AEACD68B366 for ; Fri, 18 Feb 2022 03:48:19 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645148906; x=1676684906; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=38NEKgWnzwv87NzJQUNwLBx6exwtvi5rXDgNbrZJu7E=; b=ZVyPW8rOc4+xncKsjKj4l3SNh4T+2i6gjZP2O7PUp5KPUBgkDwiS1M68 YdhNoE8UD1dhr6fhzmLKwvnUq/6TgBV5j8cOQ0arh9Ozk9HEe+uFgx//o 6OjleisKCQewHj6h49RkJHbfgbDaNMcmXq0EYfrOJMEIyNRt4xvgYh2oQ b/LFgaaKHLTCOWZE1q74UQKq25dB+Rl8nB7NYGQcDBQHbSErn26yuhBJ6 Lv47c5D0dp6+USpn/0RE9KTy4qpOhgMX2mkTIArQP3ANnZJWYR/7ZA2z8 3WmutAy88sX0G5mph7qrnGGi2H9mXwM7ocIBsDaYnmXB8QvSVW/TVmBBB w==; X-IronPort-AV: E=McAfee;i="6200,9189,10261"; a="231010270" X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="231010270" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 17:48:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,377,1635231600"; d="scan'208";a="777781371" Received: from t.sh.intel.com ([10.239.159.147]) by fmsmga005.fm.intel.com with ESMTP; 17 Feb 2022 17:48:17 -0800 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Fri, 18 Feb 2022 09:43:01 +0800 Message-Id: <20220218014301.1830754-4-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220218014301.1830754-1-fei.w.wang@intel.com> References: <20220218014301.1830754-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 4/4] vaapi_encode_h265: Query encoding block sizes and features 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 Cc: Mark Thompson , Fei Wang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FhNaIcNzF2R8 From: Mark Thompson Signed-off-by: Fei Wang --- libavcodec/vaapi_encode_h265.c | 107 +++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 5 deletions(-) diff --git a/libavcodec/vaapi_encode_h265.c b/libavcodec/vaapi_encode_h265.c index 8319848e4a..e98502503d 100644 --- a/libavcodec/vaapi_encode_h265.c +++ b/libavcodec/vaapi_encode_h265.c @@ -56,6 +56,9 @@ typedef struct VAAPIEncodeH265Context { VAAPIEncodeContext common; // Encoder features. + uint32_t va_features; + // Block size info. + uint32_t va_bs; uint32_t ctu_size; uint32_t min_cb_size; @@ -427,9 +430,9 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) vps->vps_max_latency_increase_plus1[i]; } - // These have to come from the capabilities of the encoder. We have no - // way to query them, so just hardcode parameters which work on the Intel - // driver. + // These values come from the capabilities of the first encoder + // implementation in the i965 driver on Intel Skylake. They may + // fail badly with other platforms or drivers. // CTB size from 8x8 to 32x32. sps->log2_min_luma_coding_block_size_minus3 = 0; sps->log2_diff_max_min_luma_coding_block_size = 2; @@ -447,6 +450,42 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) sps->pcm_enabled_flag = 0; +// update sps setting according to queried result +#if VA_CHECK_VERSION(1, 13, 0) + if (priv->va_features) { + VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features }; + + // Enable feature if get queried result is VA_FEATURE_SUPPORTED | VA_FEATURE_REQUIRED + sps->amp_enabled_flag = + !!features.bits.amp; + sps->sample_adaptive_offset_enabled_flag = + !!features.bits.sao; + sps->sps_temporal_mvp_enabled_flag = + !!features.bits.temporal_mvp; + sps->pcm_enabled_flag = + !!features.bits.pcm; + } + + if (priv->va_bs) { + VAConfigAttribValEncHEVCBlockSizes bs = { .value = priv->va_bs }; + sps->log2_min_luma_coding_block_size_minus3 = + ff_ctz(priv->min_cb_size) - 3; + sps->log2_diff_max_min_luma_coding_block_size = + ff_ctz(priv->ctu_size) - ff_ctz(priv->min_cb_size); + + sps->log2_min_luma_transform_block_size_minus2 = + bs.bits.log2_min_luma_transform_block_size_minus2; + sps->log2_diff_max_min_luma_transform_block_size = + bs.bits.log2_max_luma_transform_block_size_minus2 - + bs.bits.log2_min_luma_transform_block_size_minus2; + + sps->max_transform_hierarchy_depth_inter = + bs.bits.max_max_transform_hierarchy_depth_inter; + sps->max_transform_hierarchy_depth_intra = + bs.bits.max_max_transform_hierarchy_depth_intra; + } +#endif + // STRPSs should ideally be here rather than defined individually in // each slice, but the structure isn't completely fixed so for now // don't bother. @@ -539,6 +578,23 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) pps->cu_qp_delta_enabled_flag = (ctx->va_rc_mode != VA_RC_CQP); pps->diff_cu_qp_delta_depth = 0; +// update pps setting according to queried result +#if VA_CHECK_VERSION(1, 13, 0) + if (priv->va_features) { + VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features }; + if (ctx->va_rc_mode != VA_RC_CQP) + pps->cu_qp_delta_enabled_flag = + !!features.bits.cu_qp_delta; + + pps->transform_skip_enabled_flag = + !!features.bits.transform_skip; + // set diff_cu_qp_delta_depth as its max value if cu_qp_delta enabled. Otherwise + // 0 will make cu_qp_delta invalid. + if (pps->cu_qp_delta_enabled_flag) + pps->diff_cu_qp_delta_depth = sps->log2_diff_max_min_luma_coding_block_size; + } +#endif + if (ctx->tile_rows && ctx->tile_cols) { int uniform_spacing; @@ -640,8 +696,8 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) .coded_buf = VA_INVALID_ID, - .collocated_ref_pic_index = 0xff, - + .collocated_ref_pic_index = sps->sps_temporal_mvp_enabled_flag ? + 0 : 0xff, .last_picture = 0, .pic_init_qp = pps->init_qp_minus26 + 26, @@ -674,6 +730,8 @@ static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx) .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag, .loop_filter_across_tiles_enabled_flag = pps->loop_filter_across_tiles_enabled_flag, + .pps_loop_filter_across_slices_enabled_flag = + pps->pps_loop_filter_across_slices_enabled_flag, .scaling_list_data_present_flag = (sps->sps_scaling_list_data_present_flag | pps->pps_scaling_list_data_present_flag), .screen_content_flag = 0, @@ -1105,6 +1163,45 @@ static av_cold void vaapi_encode_h265_get_encoder_caps(AVCodecContext *avctx) VAAPIEncodeContext *ctx = avctx->priv_data; VAAPIEncodeH265Context *priv = avctx->priv_data; +#if VA_CHECK_VERSION(1, 13, 0) + { + VAConfigAttribValEncHEVCBlockSizes block_size; + VAConfigAttrib attr; + VAStatus vas; + + attr.type = VAConfigAttribEncHEVCFeatures; + 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 encoder " + "features, using guessed defaults.\n"); + } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) { + av_log(avctx, AV_LOG_WARNING, "Driver does not advertise " + "encoder features, using guessed defaults.\n"); + } else { + priv->va_features = attr.value; + } + + attr.type = VAConfigAttribEncHEVCBlockSizes; + 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 encoder " + "block size, using guessed defaults.\n"); + } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) { + av_log(avctx, AV_LOG_WARNING, "Driver does not advertise " + "encoder block size, using guessed defaults.\n"); + } else { + priv->va_bs = block_size.value = attr.value; + + priv->ctu_size = + 1 << block_size.bits.log2_max_coding_tree_block_size_minus3 + 3; + priv->min_cb_size = + 1 << block_size.bits.log2_min_luma_coding_block_size_minus3 + 3; + } + } +#endif + if (!priv->ctu_size) { priv->ctu_size = 32; priv->min_cb_size = 16;