From patchwork Sat Oct 26 14:18:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhong Li X-Patchwork-Id: 15976 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 464CA444B66 for ; Sat, 26 Oct 2019 17:49:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2B45368AEAD; Sat, 26 Oct 2019 17:49:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-m963.mail.126.com (mail-m963.mail.126.com [123.126.96.3]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9264B68AE28 for ; Sat, 26 Oct 2019 17:48:54 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=fhaOsOpe9uEZBy3eFb xUfyhFquloqXeJGynfAzs1Sls=; b=lXDbqSP9+iOMmkLUL7WjtcsVBbGg98Eg+I sh9mlI9c5sEjxj0iB2/063oKTqJjqjdujCMazvxKZvQ2rS01WQUD6Sul5IVRoEZm 8KpBXx9uhJGyl52bgoO8okkNDKdydSEUUqzIMtrne87+phWJriMvhP0Hv9Mp8Q8n 8U6exZnlQ= Received: from localhost.localdomain (unknown [112.64.2.210]) by smtp8 (Coremail) with SMTP id NORpCgB37CO6VbRdgATqAQ--.21S2; Sat, 26 Oct 2019 22:18:34 +0800 (CST) From: zhongli_dev@126.com To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Oct 2019 22:18:31 +0800 Message-Id: <20191026141832.6465-1-zhongli_dev@126.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: NORpCgB37CO6VbRdgATqAQ--.21S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxKr1Uur1fXw17Zr4DKF48Zwb_yoW3Jw18pa 12y39xtryUJwn3Cwn7Jws3Gw1jyryFgFyxWws2vr18trWftFyvqrZ7tF13GFWxWrZ3Za4F 9r4UGasruw4UG3DanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U8sqAUUUUU= X-Originating-IP: [112.64.2.210] X-CM-SenderInfo: x2kr0wxolbvvby6rjloofrz/1tbiGBpawFpD98A93QAAsW Subject: [FFmpeg-devel] [PATCH 1/2] lavc/qsvenc: enable vp9 encoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Zhong Li MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Zhong Li 1. must enable low_power mode since just VDENC can be supported by iHD driver right now 2. Coding option1 and extra_data are not supported by MSDK 3. IVF header will be inserted in MSDK by default, but it is not needed for FFmpeg, so disable it. Signed-off-by: Zhong Li --- Changelog | 1 + configure | 6 ++++ libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/qsvenc.c | 62 +++++++++++++++++++++++++++++++++++++++++- libavcodec/qsvenc.h | 6 ++++ 6 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index f49c4d351d..4ccd6373a4 100644 --- a/Changelog +++ b/Changelog @@ -18,6 +18,7 @@ version : - arnndn filter - bilateral filter - maskedmin and maskedmax filters +- Intel QSV-accelerated VP9 encoding version 4.2: diff --git a/configure b/configure index 8413826f9e..7af7569092 100755 --- a/configure +++ b/configure @@ -3088,6 +3088,8 @@ vp9_qsv_decoder_select="qsvdec" vp9_rkmpp_decoder_deps="rkmpp" vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9" vp9_vaapi_encoder_select="vaapi_encode" +vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9" +vp9_qsv_encoder_select="qsvenc" vp9_v4l2m2m_decoder_deps="v4l2_m2m vp9_v4l2_m2m" wmv3_crystalhd_decoder_select="crystalhd" @@ -6239,6 +6241,10 @@ enabled liblensfun && require_pkg_config liblensfun lensfun lensfun.h lf_ # can find the libraries and headers through other means. enabled libmfx && { check_pkg_config libmfx libmfx "mfx/mfxvideo.h" MFXInit || { require libmfx "mfx/mfxvideo.h" MFXInit "-llibmfx $advapi32_extralibs" && warn "using libmfx without pkg-config"; } } +if enabled libmfx; then + check_cc MFX_CODEC_VP9 "mfx/mfxvp9.h mfx/mfxstructures.h" "MFX_CODEC_VP9" +fi + enabled libmodplug && require_pkg_config libmodplug libmodplug libmodplug/modplug.h ModPlug_Load enabled libmp3lame && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame $libm_extralibs enabled libmysofa && { check_pkg_config libmysofa libmysofa mysofa.h mysofa_neighborhood_init_withstepdefine || diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 37a84a6bb4..25e16f9de4 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -685,6 +685,7 @@ OBJS-$(CONFIG_VP9_CUVID_DECODER) += cuviddec.o OBJS-$(CONFIG_VP9_MEDIACODEC_DECODER) += mediacodecdec.o OBJS-$(CONFIG_VP9_RKMPP_DECODER) += rkmppdec.o OBJS-$(CONFIG_VP9_VAAPI_ENCODER) += vaapi_encode_vp9.o +OBJS-$(CONFIG_VP9_QSV_ENCODER) += qsvenc_vp9.o OBJS-$(CONFIG_VPLAYER_DECODER) += textdec.o ass.o OBJS-$(CONFIG_VP9_V4L2M2M_DECODER) += v4l2_m2m_dec.o OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 41f680101f..23a778e041 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -784,6 +784,7 @@ extern AVCodec ff_vp9_cuvid_decoder; extern AVCodec ff_vp9_mediacodec_decoder; extern AVCodec ff_vp9_qsv_decoder; extern AVCodec ff_vp9_vaapi_encoder; +extern AVCodec ff_vp9_qsv_encoder; // The iterate API is not usable with ossfuzz due to the excessive size of binaries created #if CONFIG_OSSFUZZ diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index ba85d645ca..b8eabd78da 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -637,7 +637,8 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) // The HEVC encoder plugin currently fails with some old libmfx version if coding options // are provided. Can't find the extract libmfx version which fixed it, just enable it from // V1.28 in order to keep compatibility security. - if ((avctx->codec_id != AV_CODEC_ID_HEVC) || QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 28)) { + if (((avctx->codec_id != AV_CODEC_ID_HEVC) || QSV_RUNTIME_VERSION_ATLEAST(q->ver, 1, 28)) + && (avctx->codec_id != AV_CODEC_ID_VP9)) { q->extco.Header.BufferId = MFX_EXTBUFF_CODING_OPTION; q->extco.Header.BufferSz = sizeof(q->extco); @@ -761,6 +762,15 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif } +#if QSV_HAVE_EXT_VP9_PARAM + if (avctx->codec_id == AV_CODEC_ID_VP9) { + q->extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM; + q->extvp9param.Header.BufferSz = sizeof(q->extvp9param); + q->extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF; + q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extvp9param; + } +#endif + if (!check_enc_param(avctx,q)) { av_log(avctx, AV_LOG_ERROR, "some encoding parameters are not supported by the QSV " @@ -789,6 +799,53 @@ static int qsv_retrieve_enc_jpeg_params(AVCodecContext *avctx, QSVEncContext *q) return 0; } +static int qsv_retrieve_enc_vp9_params(AVCodecContext *avctx, QSVEncContext *q) +{ + int ret = 0; +#if QSV_HAVE_EXT_VP9_PARAM + mfxExtVP9Param vp9_extend_buf = { + .Header.BufferId = MFX_EXTBUFF_VP9_PARAM, + .Header.BufferSz = sizeof(vp9_extend_buf), + }; +#endif + +#if QSV_HAVE_CO2 + mfxExtCodingOption2 co2 = { + .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2, + .Header.BufferSz = sizeof(co2), + }; +#endif + +#if QSV_HAVE_CO3 + mfxExtCodingOption3 co3 = { + .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3, + .Header.BufferSz = sizeof(co3), + }; +#endif + + mfxExtBuffer *ext_buffers[] = { + (mfxExtBuffer*)&vp9_extend_buf, +#if QSV_HAVE_CO2 + (mfxExtBuffer*)&co2, +#endif +#if QSV_HAVE_CO3 + (mfxExtBuffer*)&co3, +#endif + }; + + q->param.ExtParam = ext_buffers; + q->param.NumExtParam = FF_ARRAY_ELEMS(ext_buffers); + + ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param); + if (ret < 0) + return ff_qsv_print_error(avctx, ret, + "Error calling GetVideoParam"); + + q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000; + + return 0; +} + static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) { AVCPBProperties *cpb_props; @@ -1112,6 +1169,9 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) case AV_CODEC_ID_MJPEG: ret = qsv_retrieve_enc_jpeg_params(avctx, q); break; + case AV_CODEC_ID_VP9: + ret = qsv_retrieve_enc_vp9_params(avctx, q); + break; default: ret = qsv_retrieve_enc_params(avctx, q); break; diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h index ec8b5419cb..a3e9357865 100644 --- a/libavcodec/qsvenc.h +++ b/libavcodec/qsvenc.h @@ -38,6 +38,8 @@ #define QSV_HAVE_CO3 QSV_VERSION_ATLEAST(1, 11) #define QSV_HAVE_CO_VPS QSV_VERSION_ATLEAST(1, 17) +#define QSV_HAVE_EXT_VP9_PARAM QSV_VERSION_ATLEAST(1, 26) + #define QSV_HAVE_TRELLIS QSV_VERSION_ATLEAST(1, 8) #define QSV_HAVE_MAX_SLICE_SIZE QSV_VERSION_ATLEAST(1, 9) #define QSV_HAVE_BREF_TYPE QSV_VERSION_ATLEAST(1, 8) @@ -122,6 +124,10 @@ typedef struct QSVEncContext { mfxExtMultiFrameParam extmfp; mfxExtMultiFrameControl extmfc; #endif +#if QSV_HAVE_EXT_VP9_PARAM + mfxExtVP9Param extvp9param; +#endif + mfxExtOpaqueSurfaceAlloc opaque_alloc; mfxFrameSurface1 **opaque_surfaces; AVBufferRef *opaque_alloc_buf;