Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
Announcements
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.

Encoder reset fails

Harris_G_
Novice
1,387 Views

Hi.

I am trying to apply new encoder parameter setting but I keep getting a NULL_POINTER error, but the pointer is definitely not null.

I have written a test module that sets up a SDK session with a VPP and ENCODER pipeline.

I am loading a test video sequence of 300 frames and what I'm trying to do is to change the TargetBitrate after 100 frames. The first 100 frames are encoded without problem but when I'm trying to change the encoder parameters with Reset, I always get the same return code(-2)

These are the initial parameters of the encoder

//Initialization of encoder parameters
	memset(&internal_encode_qsv.ENCParams,0,sizeof(internal_encode_qsv.ENCParams));
	internal_encode_qsv.ENCParams.mfx.CodecId					= MFX_CODEC_AVC;
	internal_encode_qsv.ENCParams.mfx.CodecProfile				= MFX_PROFILE_AVC_HIGH;
	internal_encode_qsv.ENCParams.mfx.TargetUsage 				= MFX_TARGETUSAGE_BALANCED;
	internal_encode_qsv.ENCParams.mfx.TargetKbps 				= 18000;
	internal_encode_qsv.ENCParams.mfx.MaxKbps					= 20000;
	internal_encode_qsv.ENCParams.mfx.RateControlMethod 		= MFX_RATECONTROL_VBR;
	internal_encode_qsv.ENCParams.mfx.FrameInfo.FrameRateExtN	= 30;
	internal_encode_qsv.ENCParams.mfx.FrameInfo.FrameRateExtD	= 1;
	internal_encode_qsv.ENCParams.mfx.IdrInterval				= 5 * internal_encode_qsv.ENCParams.mfx.FrameInfo.FrameRateExtN;//0xFFFFU;
	internal_encode_qsv.ENCParams.mfx.GopRefDist				= 1;//B-frames disabled
	internal_encode_qsv.ENCParams.mfx.NumRefFrame				= 1;
	internal_encode_qsv.ENCParams.mfx.NumSlice					= 1;
	internal_encode_qsv.ENCParams.mfx.FrameInfo.FourCC			= MFX_FOURCC_NV12;
	internal_encode_qsv.ENCParams.mfx.FrameInfo.ChromaFormat	= MFX_CHROMAFORMAT_YUV420;
	internal_encode_qsv.ENCParams.mfx.FrameInfo.PicStruct		= MFX_PICSTRUCT_PROGRESSIVE;
	internal_encode_qsv.ENCParams.mfx.FrameInfo.CropX			= 0;
	internal_encode_qsv.ENCParams.mfx.FrameInfo.CropY			= 0;
	internal_encode_qsv.ENCParams.mfx.FrameInfo.CropW			= target_width;
	internal_encode_qsv.ENCParams.mfx.FrameInfo.CropH			= target_height;
	
	//Width is aligned as a multiple of 16
	internal_encode_qsv.ENCParams.mfx.FrameInfo.Width = MSDK_ALIGN16(target_width);
	
	//Same applies for height unless it's a field picture so it is a multiple of 32
	internal_encode_qsv.ENCParams.mfx.FrameInfo.Height = (MFX_PICSTRUCT_PROGRESSIVE == internal_encode_qsv.ENCParams.mfx.FrameInfo.PicStruct)?
        MSDK_ALIGN16(target_height) : MSDK_ALIGN32(target_height);
	
	internal_encode_qsv.ENCParams.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
	
	//Additional ENCODER configuration for low latency
	internal_encode_qsv.ENCParams.AsyncDepth = 1;
	
	//Setting up the extended buffers
	mfxExtCodingOption conf;
	memset(&conf, 0, sizeof(conf));
	conf.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
	conf.Header.BufferSz = sizeof(conf);
	conf.RecoveryPointSEI = MFX_CODINGOPTION_ON;
	conf.MaxDecFrameBuffering = 1;

	
	mfxExtCodingOption2 conf2;
	memset(&conf2, 0, sizeof(conf2));
	conf2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
	conf2.Header.BufferSz = sizeof(conf2);
	conf2.Trellis = MFX_TRELLIS_I | MFX_TRELLIS_P;
	conf2.RepeatPPS = MFX_CODINGOPTION_OFF;
	
	//Adding the extended buffers
	mfxExtBuffer *extrasBuf[2];
	extrasBuf[0] = (mfxExtBuffer*)&conf;
	extrasBuf[1] = (mfxExtBuffer*)&conf2;
	internal_encode_qsv.ENCParams.ExtParam = extrasBuf;
	internal_encode_qsv.ENCParams.NumExtParam = 2;

I'm trying to apply a new bitrate like this:

mfxVideoParam tmp;
	memcpy(&tmp, &internal_encode_qsv.ENCParams, sizeof(mfxVideoParam));
	printf("[%s] Copied %d bytes.\n", video_encode_qsv_name, sizeof(tmp));
        tmp.mfx.TargetKbps = 8000;
	tmp.mfx.MaxKbps    = 10000;
        internal_encode_qsv.mfxENC.Query(&tmp, &tmp);
	MSDK_CHECK_RESULT(internal_encode_qsv.sts, MFX_ERR_NONE, internal_encode_qsv.sts);
	memcpy(&internal_encode_qsv.ENCParams, &tmp, sizeof(mfxVideoParam));
	internal_encode_qsv.sts = internal_encode_qsv.mfxENC.Reset(&internal_encode_qsv.ENCParams);
	MSDK_CHECK_RESULT(internal_encode_qsv.sts, MFX_ERR_NONE, internal_encode_qsv.sts);

In the last check I'm always getting -2. Is there anything that I'm missing?

Any help is greatly appreciated!

0 Kudos
1 Solution
Harris_G_
Novice
1,387 Views

Hi again.

I solved the problem on my own.

Problem was that I was not adding the mfxExtEncoderResetOption to the parameters.

By doing so, the Reset works like a charm!

View solution in original post

0 Kudos
1 Reply
Harris_G_
Novice
1,388 Views

Hi again.

I solved the problem on my own.

Problem was that I was not adding the mfxExtEncoderResetOption to the parameters.

By doing so, the Reset works like a charm!

0 Kudos
Reply