From patchwork Wed Aug 17 06:49:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Wenbin" X-Patchwork-Id: 37320 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp2297700pzi; Tue, 16 Aug 2022 23:52:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR5vQn3jPHRUuVv8n/hT5t+nAEEDbZjOQc6E13xNaN4MCEG7IAit/draLH2L7pBUbczMkxG+ X-Received: by 2002:a17:907:724d:b0:731:8022:94e9 with SMTP id ds13-20020a170907724d00b00731802294e9mr15965329ejc.172.1660719121453; Tue, 16 Aug 2022 23:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660719121; cv=none; d=google.com; s=arc-20160816; b=LQqwfFxVl0AO3J0DRCC0mFZ2/pRKT9tz7clGHc4rMlhhaPRs5XTbkVZ719NLFEcnJ7 KDmMR33bhU1X1E+ARUw8GCFyyHXPOwxbDt2SW/dR+wYxqiZ9sYXGtWnMux0JZzu1wlKW 3hfp/cJxQXlxQNel5KSpvDgrpf8IS3XwW9nM/EanXw4GPtQZiink7NITnWj+4+Ca5g4N MZm8TvPcZ17d72aTioFif30ZTJ1B4xWOxZwQve9Yik0sJsUmnjCI4485I80aU8QzmF5j kxh+A+IilMlKbikcGqRu1ewsM/7QOQwmPl1mubCdSjD/JhDq12XjwsuN8MGfbhohK2MG h0TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=wALqO+1K4iushDHIfbY9uetkLdwi0XKka8NRuzdWZ+8=; b=klTY9m1BaBKjFzYi2JaTcd6wftCOt2kG3+0i8nd2o/G0RwOLZ5x3zWHDBKKCTY1IFQ 6nnveOdZkZ4NYuW7CvvkKE0Qa5V/xUkA9Bgd1Wc4BSCUtNCoizo2ajaQgbX4+A+OmAIg Dietn9541pJ/UPdXCn/CxQ/o+hH765cjJhjAn9wxhRpb6MqzblZ3+aPVN56cr+Y7oPpv S9NArnIUK7PK2EtpAy43yNoV5mbPlR6Coqm9K/sbsvqarn7MmEoouWuChxF8k6yPak40 f0OwnQGMoyG7AFsAtw9P7oT2qRQKjfJXmztU8X+jh/jBb1AV1tugsG/3NVH7JfLgUa9X ajVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=QksWpTQ+; 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 q20-20020a170906b29400b0070bf25f1732si4454000ejz.155.2022.08.16.23.52.00; Tue, 16 Aug 2022 23:52:01 -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=@intel.com header.s=Intel header.b=QksWpTQ+; 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 5185068B7B1; Wed, 17 Aug 2022 09:51:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C5A3F68B4D0 for ; Wed, 17 Aug 2022 09:51:50 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660719116; x=1692255116; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=j4fScC/8nsPW0JDTrMUnvKNs5TsoDsVoqtSSBKkxN10=; b=QksWpTQ+KeDM8dP3uezeZ8Jlszjea++vH6sqlv/HRbXwoV4T7O4ksTTx Fq88ZI6DVdxHMlCBuO5EoBwA4OmE0c/5epRKh8JWns4IaHE3A/nURbC1g 84YH7CLkJjSawNNIvs6qdBfCrck2rswD5vvZVfQsjIGn1p7ijvyGIe2WL ubAegGZXuQizlaeRB94ywbUjy+bw4i/llt1mdh0taH+RMlwaWJBiaU6CT 5Cv7WrWsYhRhEmHkNmr02sfUGxQLQLJBA8fMT25zPhSyU4TNgkupfJd48 65CWP8Ux8P3RGSOQCr+UpZWgtJCpuvbsjsfJlxxXKvzRcoBjHfvnaOCX7 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10441"; a="279382693" X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="279382693" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 23:51:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="583641902" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.4]) by orsmga006.jf.intel.com with ESMTP; 16 Aug 2022 23:51:47 -0700 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 Aug 2022 14:49:50 +0800 Message-Id: <20220817064950.95841-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavcodec/qsvenc_hevc: add main10sp support to hevc_qsv 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Lsh+T4OD8MQg Main10sp is a combination of Main10 and one_pic_only flag. This profile encode 10bit single still picture. A option "main10sp" is added to ffmpeg-qsv. This option set MFX_PROFILE_HEVC_MAIN10 profile and MFX_HEVC_CONSTR_REXT_ONE_PICTURE_ONLY flag to enable main10sp in ffmpeg-qsv. Signed-off-by: Wenbin Chen --- doc/encoders.texi | 4 ++++ libavcodec/qsvenc.c | 33 +++++++++++++++++++++++++++++++-- libavcodec/qsvenc.h | 6 +++++- libavcodec/qsvenc_hevc.c | 3 +++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index 6d73f74196..da6f1213c8 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3627,6 +3627,10 @@ range is [-63, 63] for 10 bit-depth or [-75, 75] for 12 bit-depth respectively. @item @var{int_ref_cycle_dist} Distance between the beginnings of the intra-refresh cycles in frames. +@item @var{main10sp} +This option allows to encode 10 bit single still picture. This feature is only +supported in vpl runtime. + @item @var{max_qp_i} Maximum video quantizer scale for I frame. diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 4831640868..ab3500403e 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -185,6 +185,7 @@ static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q, mfxExtCodingOption3 *co3 = NULL; mfxExtHEVCTiles *exthevctiles = NULL; const char *tmp_str = NULL; + mfxExtHEVCParam *exthevcparam = NULL; if (q->co2_idx > 0) co2 = (mfxExtCodingOption2*)coding_opts[q->co2_idx]; @@ -195,6 +196,8 @@ static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q, if (q->exthevctiles_idx > 0) exthevctiles = (mfxExtHEVCTiles *)coding_opts[q->exthevctiles_idx]; + if (q->exthevcparam_idx > 0) + exthevcparam = (mfxExtHEVCParam *)coding_opts[q->exthevcparam_idx]; av_log(avctx, AV_LOG_VERBOSE, "profile: %s; level: %"PRIu16"\n", print_profile(avctx->codec_id, info->CodecProfile), info->CodecLevel); @@ -343,6 +346,12 @@ static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q, av_log(avctx, AV_LOG_VERBOSE, "NumTileColumns: %"PRIu16"; NumTileRows: %"PRIu16"\n", exthevctiles->NumTileColumns, exthevctiles->NumTileRows); } + + if (exthevcparam && + exthevcparam->GeneralConstraintFlags == MFX_HEVC_CONSTR_REXT_ONE_PICTURE_ONLY && + avctx->codec_id == AV_CODEC_ID_HEVC && + info->CodecProfile == MFX_PROFILE_HEVC_MAIN10) + av_log(avctx, AV_LOG_VERBOSE, "Main10sp (Main10 profile and one_pic_only flag): enable\n"); } static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q, @@ -956,6 +965,18 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->exthevctiles; } + if (avctx->codec_id == AV_CODEC_ID_HEVC && q->main10sp) { + if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 0)) { + q->param.mfx.CodecProfile = MFX_PROFILE_HEVC_MAIN10; + q->exthevcparam.Header.BufferId = MFX_EXTBUFF_HEVC_PARAM; + q->exthevcparam.Header.BufferSz = sizeof(q->exthevcparam); + q->exthevcparam.GeneralConstraintFlags = MFX_HEVC_CONSTR_REXT_ONE_PICTURE_ONLY; + q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->exthevcparam; + } else + av_log(avctx, AV_LOG_WARNING, + "This version of runtime doesn't support 10bit single still picture\n"); + } + q->extvsi.VideoFullRange = (avctx->color_range == AVCOL_RANGE_JPEG); q->extvsi.ColourDescriptionPresent = 0; @@ -1098,12 +1119,16 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) .Header.BufferSz = sizeof(hevc_tile_buf), }; - mfxExtBuffer *ext_buffers[6]; + mfxExtHEVCParam hevc_param_buf = { + .Header.BufferId = MFX_EXTBUFF_HEVC_PARAM, + .Header.BufferSz = sizeof(hevc_param_buf), + }; + mfxExtBuffer *ext_buffers[7]; int need_pps = avctx->codec_id != AV_CODEC_ID_MPEG2VIDEO; int ret, ext_buf_num = 0, extradata_offset = 0; - q->co2_idx = q->co3_idx = q->exthevctiles_idx = -1; + q->co2_idx = q->co3_idx = q->exthevctiles_idx = q->exthevcparam_idx = -1; ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata; ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co; @@ -1125,6 +1150,10 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) q->exthevctiles_idx = ext_buf_num; ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&hevc_tile_buf; } + if (avctx->codec_id == AV_CODEC_ID_HEVC && QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 0)) { + q->exthevcparam_idx = ext_buf_num; + ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&hevc_param_buf; + } q->param.ExtParam = ext_buffers; q->param.NumExtParam = ext_buf_num; diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index d35a1318f2..1df4e26583 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -138,6 +138,7 @@ typedef struct QSVEncContext { mfxExtMultiFrameControl extmfc; #endif mfxExtHEVCTiles exthevctiles; + mfxExtHEVCParam exthevcparam; mfxExtVP9Param extvp9param; #if QSV_HAVE_OPAQUE @@ -148,7 +149,7 @@ typedef struct QSVEncContext { mfxExtVideoSignalInfo extvsi; - mfxExtBuffer *extparam_internal[5 + (QSV_HAVE_MF * 2)]; + mfxExtBuffer *extparam_internal[6 + (QSV_HAVE_MF * 2)]; int nb_extparam_internal; mfxExtBuffer **extparam; @@ -235,6 +236,9 @@ typedef struct QSVEncContext { float old_i_quant_offset; float old_b_quant_factor; float old_b_quant_offset; + + int exthevcparam_idx; + int main10sp; } QSVEncContext; int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q); diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index e11f5dec4a..3f1a8cdf93 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -271,6 +271,9 @@ static const AVOption options[] = { { "int_ref_qp_delta", "QP difference for the refresh MBs", OFFSET(qsv.int_ref_qp_delta), AV_OPT_TYPE_INT, { .i64 = INT16_MIN }, INT16_MIN, INT16_MAX, VE }, { "int_ref_cycle_dist", "Distance between the beginnings of the intra-refresh cycles in frames", OFFSET(qsv.int_ref_cycle_dist), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT16_MAX, VE }, +#if QSV_ONEVPL + { "main10sp", "This option allows to encode 10 bit single still picture", OFFSET(qsv.main10sp), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE}, +#endif { NULL }, };