lavc/qsvenc: enable vp9 encoder

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 <zhongli_dev@126.com>
This commit is contained in:
Zhong Li 2019-10-26 22:18:31 +08:00
parent e786e37326
commit 33583803e1
6 changed files with 76 additions and 1 deletions

View File

@ -20,6 +20,7 @@ version <next>:
- maskedmin and maskedmax filters
- VDPAU VP9 hwaccel
- median filter
- QSV-accelerated VP9 encoding
version 4.2:

6
configure vendored
View File

@ -3090,6 +3090,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"
@ -6243,6 +6245,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 ||

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;