From patchwork Thu Aug 18 06:59:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Wenbin" X-Patchwork-Id: 37339 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp148140pzh; Thu, 18 Aug 2022 00:01:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ZErs6bMgUv4gJc7DCClwvc3RjZxABvFYKsNnSMNbtZaYcBure4VAvTyLU1tzLLcRzHQ14 X-Received: by 2002:a50:ed06:0:b0:445:e986:599e with SMTP id j6-20020a50ed06000000b00445e986599emr1217522eds.10.1660806105242; Thu, 18 Aug 2022 00:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660806105; cv=none; d=google.com; s=arc-20160816; b=Zre1E4k8YPgPFAkzRyimB/x4KL6z/k5skRi7ZOQabzuwQ6/jLGOJSflrBjUeKR/CdK K8yLu74XKcaleICovzlbwsSZHcbguEEF3m1PVWAin1U3d9PHbKYmVnIfpLJtUk08IHfI ZdDOpcOk1XhRLiMCFgg4D1+MOoi0AVS8lp3kGOPDC95veT2YQupxKIx3sB4GpnJyPmNW sn2fFHOdf9xRA3Xbts/lzPBJYYo1+WFQUZmQuurwz18fYgLuB3vHtmXyEiNXBzelaaKR tG7O2Pq8uxZPgA059qMShu5dN1JmQCauILEhf+YM8cbQD5vndokOH9YZKgjaKKok7pmk 1dgQ== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=wQib1eAf4LSz9yMp2rsWRflu0bsEigCh9/ZrKeRCCOs=; b=C5RoxO5jBMLyG4GAgyopbYkz0QT6CQaAon+YanOq/nVmitAQd5bz75DbrIXyy41wqU PHHRzfaZcTtroPhIP1telidVrX81xrDBVmSTFTfY+l8tngQWQVgCnwFsnk7yuAJeiKEo XyXZfYPBbo3fhqodDvxH8JNe3S+BPvqh3h+Sf2ZBdKEY/84KCd+FqPqSsL3HR7pCX7Mv qLth2liIzM6GcdCZBwKN3PyTy6dKma7JPMhFhjCMBYcMOIikbgNAtlSW7pO/GBAWKjFn 70c3b28Y8e588pR8cFBY55C6vLoTPQzmCXgfi+8/KSKi+8g+xAU4w2EV/EMPxAiKUYC9 stfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=H4z7mYBT; 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 mc3-20020a170906eb4300b0073836824062si438137ejb.202.2022.08.18.00.01.44; Thu, 18 Aug 2022 00:01:45 -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=H4z7mYBT; 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 4D0E268B991; Thu, 18 Aug 2022 10:01:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C92D568B8ED for ; Thu, 18 Aug 2022 10:01:28 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660806094; x=1692342094; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=H9QUtxRjhcYCGCxzXFlGcNZzE1iJKnF47X4Tfj54/yc=; b=H4z7mYBTdDttc4u4s0VyiB4fTleqWRL1whkL7lUT/KzvQvSbhfX7yZ2D Dw3cIC2q45j2xHlc4Ho/yQc2Ym7N3OTr5hwbuqTEk1Vv9jcZnEmwPcn1X pJ/uLd7nHd0yrzgz3bE8fY7zV/JQCa4m1mx7oUbkOnb8WqRn4mJ5WxAJA pTGWOjxTAqXOArzacxitNCGuk23sKunYT8WQMktqWa+b58uyAGvBmBklo x3v9QMTMDe6L3eBnffUjfEtHtB/EmuhMl6wtURVSc1e2nj0oJpmj6xixa EaZfezimGTus9XFe+QtdJotUKcwGQVzBhoAtWO7yisaSXPNkVkIt6Ys/V A==; X-IronPort-AV: E=McAfee;i="6500,9779,10442"; a="378975923" X-IronPort-AV: E=Sophos;i="5.93,245,1654585200"; d="scan'208";a="378975923" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2022 00:01:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,245,1654585200"; d="scan'208";a="604155641" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.4]) by orsmga007.jf.intel.com with ESMTP; 18 Aug 2022 00:01:11 -0700 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Aug 2022 14:59:08 +0800 Message-Id: <20220818065912.158693-2-wenbin.chen@intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220818065912.158693-1-wenbin.chen@intel.com> References: <20220818065912.158693-1-wenbin.chen@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6] libavcodec/qsvenc: Add gop_size reset support to qsvenc 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: Cn72vZwXcOA+ Signed-off-by: Wenbin Chen --- doc/encoders.texi | 3 +++ libavcodec/qsvenc.c | 18 +++++++++++++++++- libavcodec/qsvenc.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index 69fa46f3ea..9fb63856b1 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3348,6 +3348,9 @@ Change these value to reset qsv codec's qp configuration. @item @var{max_frame_size} Supported in h264_qsv and hevc_qsv. Change this value to reset qsv codec's MaxFrameSize configuration. + +@item @var{gop_size} +Change this value to reset qsv codec's gop configuration. @end table @subsection H264 options diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index c911b81e7d..b3820e4fe0 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -635,6 +635,7 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) q->param.mfx.CodecProfile = q->profile; q->param.mfx.TargetUsage = avctx->compression_level; q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size); + q->old_gop_size = avctx->gop_size; q->param.mfx.GopRefDist = FFMAX(-1, avctx->max_b_frames) + 1; q->param.mfx.GopOptFlag = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? MFX_GOP_CLOSED : MFX_GOP_STRICT; @@ -1692,16 +1693,31 @@ static int update_max_frame_size(AVCodecContext *avctx, QSVEncContext *q) return updated; } +static int update_gop_size(AVCodecContext *avctx, QSVEncContext *q) +{ + int updated = 0; + UPDATE_PARAM(q->old_gop_size, avctx->gop_size); + if (!updated) + return 0; + + q->param.mfx.GopPicSize = FFMAX(0, avctx->gop_size); + av_log(avctx, AV_LOG_DEBUG, "reset GopPicSize to %d\n", + q->param.mfx.GopPicSize); + + return updated; +} + static int update_parameters(AVCodecContext *avctx, QSVEncContext *q, const AVFrame *frame) { int needReset = 0, ret = 0; - if (!frame) + if (!frame || avctx->codec_id == AV_CODEC_ID_MJPEG) return 0; needReset = update_qp(avctx, q); needReset |= update_max_frame_size(avctx, q); + needReset |= update_gop_size(avctx, q); if (!needReset) return 0; diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index c452c5b806..fdedae28dd 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -237,6 +237,8 @@ typedef struct QSVEncContext { float old_b_quant_offset; // This is used for max_frame_size reset int old_max_frame_size; + // This is used for gop reset + int old_gop_size; } QSVEncContext; int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q);