From patchwork Mon Feb 14 06:50:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Chen, Wenbin" X-Patchwork-Id: 34274 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:14aa:0:0:0:0 with SMTP id bz10csp5266611nkb; Sun, 13 Feb 2022 22:51:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbvmdK7XNAm7s517OJHEolDncFH902codZ9jJI0geBdYMjj5f9yqIFq+UhithkyEG8gVF7 X-Received: by 2002:a17:907:3ea9:: with SMTP id hs41mr10679945ejc.727.1644821479735; Sun, 13 Feb 2022 22:51:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644821479; cv=none; d=google.com; s=arc-20160816; b=0JzBm6HvfrJNqAGFhbVR6qYsx0iIfZoi37/LPP6zyrKkwk/lA5rI4y2ULs9pKcvzXm LecL0IutqHMZa7G4Bw/RRIegc/tST51NpBA1dJZ9XPnO/kXBhaZjNSjU2Dy6w/qOtgPh J9UocTM+/nQy0CIxjVwsYScKhVHfB6yLUv8A+OMe1AAkZn2EWZKWneth/OfJ8xPoBLUj yF5G9dRNDqFmVsB42u5yKM4yll79q54MmdAyRou5gsp1Fr+nOm4qdS6UQ8yo+zMa+/YT loQ8UGmTGCgY+OQ9KrIfjjYsDZBHj9Wocpo3l7C/vOVmzrqXXCmPfZAesXDx7aIXFi6e ingQ== 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=PVzInguSgUZcOJ/iATpRWxA0OE7lZOmM8A9tRJKexFs=; b=QKpukjvc8sG+6c1y11vYy/5du7MHic30CHkTiCsUQCj2d9ABVm/RH9ZbEX96rEA6E/ Ugy4L/JSUan77ZKaP/a8BTUIZMgUVNZa2KFUlX9RjLUp2wBNIuh/PXKgUwxJbDQ94vq2 BYelQ8G5wbj7WzDtMNyI6TXdWjUcxP0M/t2QdHLAO2WLgrUsrU9dT7Y0PsyYyHVF2RZR rRUi79bYWtdLyBm2woAPIEernOTdg9O1KcM0dntB9uTbzoC/0KwRPmX+TQ14mzzR0oYx nWxnBVOaREYpfD0erX1NIfMuxD195b1jgnr2IYqBOifcQZLU89snjh0S6q7giNrvtH3x qvIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=CzrWafyq; 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 s26si606137edx.522.2022.02.13.22.51.19; Sun, 13 Feb 2022 22:51:19 -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=CzrWafyq; 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 2A88668B05A; Mon, 14 Feb 2022 08:51:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 39CD468B025 for ; Mon, 14 Feb 2022 08:51:06 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644821472; x=1676357472; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=+UxTU56EfADuod7n+pSnUhnNtZGfIeowbPfvxJTJSrU=; b=CzrWafyqAPp/Cl4PkEInqFdzaW5pRy0D9M2kj8CTvLLGuB6DmbjpOCIA E8NKckDIDPb2wjjUli4E0LomFm9UnDmuwDOLCCmm0Zs00PiFFoSl7vVNd HczMSdzvezErE6wVckjfwT17qM21gXHTBZeKqjKcpwriZRvFUX0VI2kiJ X5kp6dez2+Z5Cwa5UxRxWAuPeyBpqcNb1O6bmQPMf1NqKHT6kWZzn6GFB oqgNS9H0iuebwSGz1/QS7FfCTxt1te1DYLkf5L3R4B5fQYCxaLXK9gjw4 6+Duh6BUnSjCml24vKkmfwHAq2dH9peWfUaDXPozIXvns4KsxwLQHCriN Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10257"; a="310764645" X-IronPort-AV: E=Sophos;i="5.88,367,1635231600"; d="scan'208";a="310764645" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2022 22:51:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,367,1635231600"; d="scan'208";a="631955938" Received: from wenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by fmsmga002.fm.intel.com with ESMTP; 13 Feb 2022 22:51:01 -0800 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Mon, 14 Feb 2022 14:50:59 +0800 Message-Id: <20220214065059.565884-1-wenbin.chen@intel.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavcodec/qsvenc_hevc: encode RGB format rawvideo 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: /n7BthhCnCyI Add support for hevc_qsv to input RGB format frame. It will transform frame to yuv inside MediaSDK instead of using auto scale. Now hevc_qsv supports directly encoding BGRA and X2RGB10 format. X2RGB10 is only supported in VDENC (-low_power 1). The X2RGB10 correspond to the A2RGB20 format in MediaSDK. Sigend-off-by: Wenbin Chen --- libavcodec/qsv.c | 16 ++++++++++++++++ libavcodec/qsvenc.c | 15 +++++++++++++++ libavcodec/qsvenc_hevc.c | 6 ++++++ 3 files changed, 37 insertions(+) diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index 1a432dbd82..b75877e698 100644 --- a/libavcodec/qsv.c +++ b/libavcodec/qsv.c @@ -189,6 +189,12 @@ enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc) case MFX_FOURCC_NV12: return AV_PIX_FMT_NV12; case MFX_FOURCC_P010: return AV_PIX_FMT_P010; case MFX_FOURCC_P8: return AV_PIX_FMT_PAL8; +#if QSV_VERSION_ATLEAST(1, 9) + case MFX_FOURCC_A2RGB10: return AV_PIX_FMT_X2RGB10; +#endif +#if QSV_VERSION_ATLEAST(1, 17) + case MFX_FOURCC_RGB4: return AV_PIX_FMT_BGRA; +#endif #if CONFIG_VAAPI case MFX_FOURCC_YUY2: return AV_PIX_FMT_YUYV422; #if QSV_VERSION_ATLEAST(1, 27) @@ -211,6 +217,16 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc) case AV_PIX_FMT_P010: *fourcc = MFX_FOURCC_P010; return AV_PIX_FMT_P010; +#if QSV_VERSION_ATLEAST(1, 9) + case AV_PIX_FMT_X2RGB10: + *fourcc = MFX_FOURCC_A2RGB10; + return AV_PIX_FMT_X2RGB10; +#endif +#if QSV_VERSION_ATLEAST(1, 17) + case AV_PIX_FMT_BGRA: + *fourcc = MFX_FOURCC_RGB4; + return AV_PIX_FMT_BGRA; +#endif #if CONFIG_VAAPI case AV_PIX_FMT_YUV422P: case AV_PIX_FMT_YUYV422: diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 07be4287b7..f834691d1a 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -776,6 +776,13 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) brc_param_multiplier = (FFMAX(FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes), initial_delay_in_kilobytes) + 0x10000) / 0x10000; +#if QSV_VERSION_ATLEAST(1, 9) + if (sw_format == AV_PIX_FMT_X2RGB10 && q->low_power != 1) { + av_log(avctx, AV_LOG_ERROR, "Only VDENC support encoding x2rgb10\n"); + return AVERROR(EINVAL); + } +#endif + switch (q->param.mfx.RateControlMethod) { case MFX_RATECONTROL_CBR: case MFX_RATECONTROL_VBR: @@ -1616,6 +1623,14 @@ static int submit_frame(QSVEncContext *q, const AVFrame *frame, qf->surface.Data.V = qf->surface.Data.UV + 2; break; + case AV_PIX_FMT_X2RGB10: + case AV_PIX_FMT_BGRA: + qf->surface.Data.B = qf->frame->data[0]; + qf->surface.Data.G = qf->frame->data[0] + 1; + qf->surface.Data.R = qf->frame->data[0] + 2; + qf->surface.Data.A = qf->frame->data[0] + 3; + break; + default: /* should not reach here */ av_assert0(0); diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c index 5cac141c4d..ade546d4ca 100644 --- a/libavcodec/qsvenc_hevc.c +++ b/libavcodec/qsvenc_hevc.c @@ -304,6 +304,12 @@ const AVCodec ff_hevc_qsv_encoder = { .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12, AV_PIX_FMT_P010, AV_PIX_FMT_QSV, +#if QSV_VERSION_ATLEAST(1, 17) + AV_PIX_FMT_BGRA, +#endif +#if QSV_VERSION_ATLEAST(1, 9) + AV_PIX_FMT_X2RGB10, +#endif AV_PIX_FMT_NONE }, .priv_class = &class, .defaults = qsv_enc_defaults,