From patchwork Tue Sep 6 09:22:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Wenbin" X-Patchwork-Id: 37692 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp3135737pzh; Tue, 6 Sep 2022 02:25:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR7150mLXiSxMnOYcgwJwAsCWjWgRQ8rtKmU7/LKWMp1rGMBfULgo+hEDMhstacGJfitQPgb X-Received: by 2002:a17:906:ef90:b0:730:9d18:17b3 with SMTP id ze16-20020a170906ef9000b007309d1817b3mr39725334ejb.141.1662456343439; Tue, 06 Sep 2022 02:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662456343; cv=none; d=google.com; s=arc-20160816; b=ypET6d+F2MCQ+aPyVdKRTrmhN8zSJQopnCSKTx1TfzQnW8CJB/ZCuEsF2Po/bkK0Vh WRwlZobcUNl+Ueoa6eEwQxNH3/F+BENrbH5b5/imO+/zrq6HC9S48pVcNrggtnerI5GT dNQtdsh1fPPl/zPXK+62bqcBvnJvFNV44govuWTBxARLnsTXTRVb37f0nKavf4fsyqi4 13COXuy8fRobKd5fhzdUfMclwIB0fU54crw5oCkRmXapFnZFc/5d5cUZTkS/Z7UhPUSk n3Owx/RxH1ya216WPGOv4LJ1QTFZXne72rHz3JCMMOp2rzk4IZcNaZzg0/a5CC1VvHe7 P6AA== 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=k+Z0/0x6oiAyakYl3nyHj+z5KsXX2ACfUo3JoTiwy7E=; b=tWCGH6qtuqFflYp+0FqTFT+uHBGONRAgKiMDYTh0E05Ld+QqA/gZS5wJV0lE+MmnS9 T/Q3uq0tGOrmrrhLdIEwsafL7akTfIxW9lDJmR5taQn0flonwGoB3rFK3e8vSa6Qu3Kd jlDDoGWMSQEJjOmdq31V/BIgvg6slGeuKhz4IWYs4+n0tvMigZQlQR+RtIPA024H8yZs CIrq41qWiRW8K+60HICPUg0XJ3286PHKla7Vkp8kNY1+jnjDGIc4fKs5+lCn8jZzQqQS InIuvPRsQRUkonObRu6vTQkr6qjOWo3s46hLWOpKhK5OJmry6BgilZRKf4N9+xGgCyFU 5SUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=BWjG0Hue; 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 e8-20020a17090658c800b0073d5b609447si1823253ejs.324.2022.09.06.02.25.31; Tue, 06 Sep 2022 02:25:43 -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=BWjG0Hue; 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 0FAC368013B; Tue, 6 Sep 2022 12:25:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 886C168BAB0 for ; Tue, 6 Sep 2022 12:25:02 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662456307; x=1693992307; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=N2CykzJAk8OKnjDlRTOyOJqM/LYGDBdPhsMb/1lEIPY=; b=BWjG0HuerkPcV+T2eHDFnA0VkzeHzcHzlNbeT6++ihfAEO8eyN3dKju2 iC0fY2qTCxALfb/EmAjiJKsAaRSAr5oFVBkm96lyH/W0dNAACPBpjXnuD sD1jXuWfFtu+GqJr8V1BwEjBiekxHjwUEIzzPW9nhXi3BxcPWydPvJ0Do BFdHLJiu9YZsfbX7nI3Z1XCuWH9PKYRATEHfzg449Bej6OzepdTsqcFFo EaCI1bIhsxipiR45RFYHTp9DIl/c8hO+KLYyXM5lJgeZL3qzoy+KHlHhJ PkUIKrBEoUpPVcXLkCbDNrg9FvJqPTcuS6UgNa1i9SoPkWvEe7jV3RSD0 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10461"; a="322720549" X-IronPort-AV: E=Sophos;i="5.93,293,1654585200"; d="scan'208";a="322720549" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2022 02:24:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,293,1654585200"; d="scan'208";a="565028241" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.4]) by orsmga003.jf.intel.com with ESMTP; 06 Sep 2022 02:24:57 -0700 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Sep 2022 17:22:54 +0800 Message-Id: <20220906092258.994742-3-wenbin.chen@intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220906092258.994742-1-wenbin.chen@intel.com> References: <20220906092258.994742-1-wenbin.chen@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/7] 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: KQZ3GG33HdOy Signed-off-by: Wenbin Chen --- doc/encoders.texi | 3 +++ libavcodec/qsvenc.c | 16 ++++++++++++++++ libavcodec/qsvenc.h | 2 ++ 3 files changed, 21 insertions(+) diff --git a/doc/encoders.texi b/doc/encoders.texi index aadb6ab9fd..bc1a4dae38 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 915a1abd26..9a0431630a 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -636,6 +636,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; @@ -1694,6 +1695,20 @@ 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) { @@ -1704,6 +1719,7 @@ static int update_parameters(AVCodecContext *avctx, QSVEncContext *q, 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 3984ae7dd8..5f6955a3a7 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -251,6 +251,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);