- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We use Media SDK to do software h.264 video encoding.
We switched from Media SDK 2012 R2 to Media SDK 2014 R2. Long run tests revealed a problem: after a period (several hours, not constant), encoding stops working, no more video frames are encoded.
After investigations, we found that the function MFXVideoENCODE::EncodeFrameAsync(...) returns -5, i.e. MFX_ERR_NOT_ENOUGH_BUFFER
The documentation stipulates that this error happens when: The bitstream buffer size is insufficient.
We have output the state of the bitstream buffer when the error occurred and here are some:
- Encoding Error: -5 - encode buffer state: max: 9375000, current: 1041, offset: 0
- Encoding Error: -5 - encode buffer state: max: 9375000, current: 585, offset: 0
- Encoding Error: -5 - encode buffer state: max: 9375000, current: 1284, offset: 0
- Encoding Error: -5 - encode buffer state: max: 9375000, current: 1024, offset: 0
- Encoding Error: -5 - encode buffer state: max: 9375000, current: 81, offset: 0
- Encoding Error: -5 - encode buffer state: max: 9375000, current: 859, offset: 0
As you can see, the bitstream buffer seems large enough to handle a new frame. Our code doesn't change and it worked perfectly with Media SDK 2012.
We have currently a workaround which consist to destroy and re-create the bitstream buffer and reinitialize the buffer data length with: (mfxVideoParam)m_MFXEncParams.mfx.BufferSizeInKB * 1000
However it doesn't seem to be an expected behavior, so I would like to know if it is something that has already been remarked?
Here is our initialization code and the code added to skirt the problem:
Init parameters:
m_MFXEncParams.mfx.CodecId = MFX_CODEC_AVC;
m_MFXEncParams.mfx.TargetUsage = MFX_TARGETUSAGE_BEST_SPEED ;
m_MFXEncParams.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
m_MFXEncParams.mfx.GopRefDist = 1;
m_MFXEncParams.AsyncDepth = 1;
m_MFXEncParams.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
m_MFXEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
// specify memory type
m_MFXEncParams.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
/*Initializing Extcoding options with msxdecframebuffering = 1 to reduce decode latency*/
mfxExtBuffer *extBuffersInit[1];
mfxExtCodingOption extCO;
memset( &extCO, 0, sizeof( extCO)) ;
extCO.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
extCO.Header.BufferSz = sizeof(mfxExtCodingOption);
extCO.MaxDecFrameBuffering = 1;
extBuffersInit[0] = reinterpret_cast<mfxExtBuffer*>(&extCO);
m_MFXEncParams.NumExtParam = 1;
m_MFXEncParams.ExtParam = extBuffersInit;
m_MFXEncParams.mfx.NumRefFrame = 1;
//Initialization of the specific encoding params
m_MFXEncParams.mfx.FrameInfo.Width = ALIGN_16(m_StreamFormat.GetWidth()) ;
m_MFXEncParams.mfx.FrameInfo.Height = ALIGN_16(m_StreamFormat.GetHeight()) ;
m_MFXEncParams.mfx.FrameInfo.CropX = 0;
m_MFXEncParams.mfx.FrameInfo.CropY = 0;
m_MFXEncParams.mfx.FrameInfo.CropW = m_StreamFormat.GetWidth() ;
m_MFXEncParams.mfx.FrameInfo.CropH = m_StreamFormat.GetHeight() ;
m_MFXEncParams.mfx.TargetKbps = (mfxU16)m_StreamFormat.GetBitrate() ; // in Kbps
m_MFXEncParams.mfx.FrameInfo.FrameRateExtN = (mfxU32)m_StreamFormat.GetFps() ;
m_MFXEncParams.mfx.FrameInfo.FrameRateExtD = 1 ;
m_MFXEncParams.mfx.GopPicSize = m_MFXEncParams.mfx.FrameInfo.FrameRateExtN*2 ;
m_MFXEncParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
Encode:
do
{
mfxError = m_MFXEncoder->EncodeFrameAsync( FKFC, surface, &m_MFXEncodedBs, &sp);
if (mfxError == MFX_ERR_NONE)
break ;
if (mfxError == MFX_WRN_DEVICE_BUSY)
Sleep(1) ;
else
{
CStdString dbgStr ;
dbgStr.Format( L"- Encoding Err: %d - encode buffer state: max: %d, current: %d, offset: %d\n", mfxError, m_MFXEncodedBs.MaxLength, m_MFXEncodedBs.DataLength, m_MFXEncodedBs.DataOffset) ;
OutputDebugString( dbgStr.GetString()) ;
if (mfxError == MFX_ERR_NOT_ENOUGH_BUFFER)
{
//resize the buffer to the needed size
delete [] m_MFXEncodedBs.Data ;
memset( &m_MFXEncodedBs, 0, sizeof( m_MFXEncodedBs)) ;
m_MFXEncodedBs.Data = new unsigned char[m_MFXEncParams.mfx.BufferSizeInKB * 1000] ;
m_MFXEncodedBs.MaxLength = m_MFXEncParams.mfx.BufferSizeInKB * 1000;
}
return errEncode ;
}
}
while (true) ;
Computer:
CPU: Intel Core i7-2600
OS: Windows 7 Pro 64 bits
Graphic Drivers: latest
SDK Library version used: 32 bits
Thank you,
Benjamin
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Can you update to MSDK 2015 new version API 1.13 which is available as part of INDE now from https://software.intel.com/en-us/intel-inde. Also if you can send us the logs from System analyzer and tracer which will help us further look into the issue of buffer reset. Also are you running a 4k video? As I see HW is a 2nd generation SKU. Logs from the tools will provide us more information.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Harsh,
Thanks for your fast answer! I will download the new SDK and try to reproduce with it. If I succeeded, I will use the system analyzer and tracer to create logs.
The video resolution is only 640x480.
Have a good day,
Benjamin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Harsh,
I have updated to the new version of the MSDK (1.13) from Inde and performed several days of testing without modifying the code.
And it works! I have never seen again the 'not enough' buffer error. It seems that there was probably a problem with the 2014R2 version of MSDK.
Thanks for your time,
Benjamin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Yes, with every new release of MSDK API, we have fixes and new implementaion. Glad to know you don't see the issue.
Thanks,
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page