From patchwork Wed Aug 17 07:07:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Wenbin" X-Patchwork-Id: 37321 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp2304134pzi; Wed, 17 Aug 2022 00:09:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4guSUmf1CJKSDKvukU3+YuWcJEIe/d7zmkibJ2C6VdyX57EQ9BFTcDTaHFVmbRAVgeJP4k X-Received: by 2002:a05:6402:40c2:b0:440:4ecd:f75f with SMTP id z2-20020a05640240c200b004404ecdf75fmr21439116edb.405.1660720177994; Wed, 17 Aug 2022 00:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660720177; cv=none; d=google.com; s=arc-20160816; b=J4d+sMPS366Y5Ge4QR1KYSIBVBiuhYC+l0V6CEd76RN8uq1/xLmiKEk1GzoA3Sn0ka Ad3UV9AvUHZUF5OQqtlIULaRQnI6OpK8Z4COqQepk/Y0EpbYksmr6/N/uaJ554iyQRtM mNTUwHFqaGGS9ri8pI2S08n+xuyva5Z1aRqtTE96/w+XCRAMFeqraPRM9aqjenxUjYRd PxKv+h7nmWHDAEYWMmju5eO0Cpx/CNGHGyPbdmrJlqt2JLtB4g9i2KHU+GDNpqeLA2iT rjg4N6Xi4Xil+4oPVR98oZ3bNmLjgxeRRLTdhdN9P4fYtD/B5N6CmGdo6DbnHptdNAtx DgnQ== 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=rfKa6glls4EDxVNW2BaHtPHZyDbm/WO1Rg1JN+p5WqI=; b=UrGHzRCm4fCBVckvm9IuhulJuIKEyt1G72/YO/xzKK7G/c52o3yTLCCA67SzOhdOaQ QiQnAC4Lm3WCf47xArXIvXC9zD11XCXinV06RL3eNx1SlIGxZno7IL1mFvCjfD+JwuJZ aEoSWyDHoAKVmrfYWjbllAaA6VwpOMj0ZsNc5VEJ6WLHiBccsbmMW4urzCTrjvSXpXGw nmHHEYz3VYYfMk1H8mC0A1YCTamOExFFd8X8P6u7NGAIdsyPltqWNs+mT7AbMBlg45na epJB6aAzMj0lQR+O2/7SbtldkG1moIq+632syqEz+FbciXTwFRcTnkpecwTQoRYcglyr ZzLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=gEUxa1ys; 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 gt40-20020a1709072da800b007330c59455fsi14205349ejc.938.2022.08.17.00.09.37; Wed, 17 Aug 2022 00:09:37 -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=gEUxa1ys; 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 B593E68B8D2; Wed, 17 Aug 2022 10:09:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9CBBC68B6E8 for ; Wed, 17 Aug 2022 10:09:29 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660720174; x=1692256174; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=wHZpkT8fVZNvJw1eEjseq809YHNlR9XstV1hcm482cM=; b=gEUxa1ysYSbKDEPk6GwGBFWnY6EdXWmb/hQX3JazpoUuJKkxO06M6U5l KwAkvuZ1McqCiJEST79pZM44zUFwbs/rmGtJp9ubAtOi68xMnwH25TF+f Zy59AyNLv3YLNZvQCkAk4TXiN1JI4nEIDLaxeGrOZ4v190Gx/Nuwp++c3 reIOdH2E8+4x6FTHltRKq6P9S/z05BgzUo7b/OrAiOB8qLuuGjubf1TcV P2SW/EiPgjDIGH7z+38I6gTSrz5bLmjgRWi/RhvZyg0Qf+wLgso9EyqxJ YN+GVWvCYqTP8EuPZYfWB/GYHnIZmnbOAi7DGn1KOwEYEzRDK/8ffdDVn A==; X-IronPort-AV: E=McAfee;i="6400,9594,10441"; a="356419630" X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="356419630" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2022 00:09:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="783305034" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.4]) by orsmga005.jf.intel.com with ESMTP; 17 Aug 2022 00:09:17 -0700 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 Aug 2022 15:07:19 +0800 Message-Id: <20220817070719.96899-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavcodec/qsvenc: Add adaptive_i/b 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: 3jS7eAF/frzI Add adaptive_i/b feature to hevc_qsv. Adaptive_i allows changing of frame type from P and B to I. Adaptive_b allows changing of frame type frome B to P. Signed-off-by: Wenbin Chen --- doc/encoders.texi | 7 +++++++ libavcodec/qsvenc.c | 9 ++++----- libavcodec/qsvenc_hevc.c | 2 ++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index 6d73f74196..fed798ff42 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -3543,6 +3543,13 @@ Setting this flag turns on or off LowDelayBRC feautre in qsv plugin, which provi more accurate bitrate control to minimize the variance of bitstream size frame by frame. Value: -1-default 0-off 1-on +@item @var{adaptive_i} +This flag controls insertion of I frames by the QSV encoder. Turn ON this flag +to allow changing of frame type from P and B to I. + +@item @var{adaptive_b} +This flag controls changing of frame type from B to P. + @item @var{p_strategy} Enable P-pyramid: 0-default 1-simple 2-pyramid(bf need to be set to 0). diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 4831640868..ca5e6f0b6e 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -816,11 +816,6 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) q->extco2.LookAheadDS = q->look_ahead_downsampling; q->extco2.RepeatPPS = q->repeat_pps ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; - - if (q->adaptive_i >= 0) - q->extco2.AdaptiveI = q->adaptive_i ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; - if (q->adaptive_b >= 0) - q->extco2.AdaptiveB = q->adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; } if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_HEVC) { @@ -840,6 +835,10 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) if (q->b_strategy >= 0) q->extco2.BRefType = q->b_strategy ? MFX_B_REF_PYRAMID : MFX_B_REF_OFF; + if (q->adaptive_i >= 0) + q->extco2.AdaptiveI = q->adaptive_i ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; + if (q->adaptive_b >= 0) + q->extco2.AdaptiveB = q->adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; if ((avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) || (q->max_qp_i >= 0 && q->min_qp_i >= 0 && q->min_qp_i > q->max_qp_i) || (q->max_qp_p >= 0 && q->min_qp_p >= 0 && q->min_qp_p > q->max_qp_p) || diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index e11f5dec4a..19f028c078 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -233,6 +233,8 @@ static const AVOption options[] = { QSV_OPTION_DBLK_IDC QSV_OPTION_LOW_DELAY_BRC QSV_OPTION_MAX_MIN_QP + QSV_OPTION_ADAPTIVE_I + QSV_OPTION_ADAPTIVE_B { "idr_interval", "Distance (in I-frames) between IDR frames", OFFSET(qsv.idr_interval), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT_MAX, VE, "idr_interval" }, { "begin_only", "Output an IDR-frame only at the beginning of the stream", 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0, VE, "idr_interval" },