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.

Endless MFX_WRN_DEVICE_BUSY in MFXVideoENCODE_EncodeFrameAsync

mao_r_
Beginner
879 Views

Hi,

I'm using intel media sdk for video encoding, normally it works well. But sometimes, the encoder API MFXVideoENCODE_EncodeFrameAsync returns busy, and after that, it return busy all the times, endless busy.

Since I write the encode code in a loop, just like the encode sample in the intel media SDK, my app stops response. Here is my encode loop:

    do
    {
        AnsycInfo = NULL;
        Status = MFXVideoENCODE_EncodeFrameAsync(m_Session, NULL, InSurf, &OutExtInfo->BitStream, &AnsycInfo);
        if (MFX_ERR_NONE < Status && !AnsycInfo)
        {
            if (MFX_WRN_DEVICE_BUSY == Status)
                Sleep(1);
        }
        else if (MFX_ERR_NONE < Status && AnsycInfo)
        {
            Status = MFX_ERR_NONE;
            break;
        }
        else if (MFX_ERR_NOT_ENOUGH_BUFFER == Status)
        {
            SimpleDbgOut(_T("No more out bit stream buffer!\n"));
            break;
        }
        else if (MFX_ERR_MORE_BITSTREAM == Status)
        {
            Status = MFX_ERR_NONE;
            break;
        }
        else
        {
            break;
        }
    } while (TRUE);

So, if encoder return busy all the time, my program will be trapped in infinity busy loop.

And my init parameters of encode is like this:

        EncParams.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
        EncParams.AsyncDepth = 4;
        EncParams.mfx.CodecId = MFX_CODEC_AVC;
        EncParams.mfx.CodecProfile = MFX_PROFILE_AVC_BASELINE;
        EncParams.mfx.TargetUsage = MFX_TARGETUSAGE_BEST_QUALITY;
        EncParams.mfx.TargetKbps = 8000;
        EncParams.mfx.MaxKbps = 12000;
        EncParams.mfx.RateControlMethod = MFX_RATECONTROL_VBR;

        EncParams.mfx.GopPicSize = 90;
        EncParams.mfx.GopRefDist = 1;
        ConvertFrameRate(FrameRate, &EncParams.mfx.FrameInfo.FrameRateExtN, &EncParams.mfx.FrameInfo.FrameRateExtD);
        EncParams.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
        EncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
        EncParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
        EncParams.mfx.FrameInfo.CropX = 0;
        EncParams.mfx.FrameInfo.CropY = 0;
        EncParams.mfx.FrameInfo.CropW = (mfxU16)FrameSize->cx;
        EncParams.mfx.FrameInfo.CropH = (mfxU16)FrameSize->cy;
        EncParams.mfx.FrameInfo.Width = (mfxU16)FrameSize->cx;
        EncParams.mfx.FrameInfo.Height = (mfxU16)FrameSize->cy;
        EncParams.mfx.BufferSizeInKB = 1500;

There is too video card in my computer, one is NVIDIA GTX 660, the other is INTEL i5 3470 CPU, OS is windows 8.1, 64bits. My program is 32bits. I don't known why encoder return endless busy status.

0 Kudos
12 Replies
mao_r_
Beginner
879 Views

According to media sdk tracer's log, the MFXVideoCORE_SyncOperation API returned MFX_ERR_DEVICE_FAILED with no output stream, and then it returned MFX_ERR_ABORTED, after restart my program, it works well for a period of time, but the problem is still existing.

It's puzzled,  there is no graphics card switching mechanism in my computer, and i just attach my monitor at GTX adapter, INTEL's output port is empty.

0 Kudos
Sravanthi_K_Intel
879 Views

Hi Mao,

Thanks for the details you provided. In the post you mention, there are three new changes - the code modifications you made, init params changes and different system configuration. To identify which one is the root cause, we need to triage this and I understand it could take a little longer. 

Before we get into your code, can you try this experiment on your system and report the behavior please:

- (Case 1): Keeping the system configuration the same (too video card in my computer, one is NVIDIA GTX 660, the other is INTEL i5 3470 CPU, OS is windows 8.1, 64bits) , does sample_encode complete successfully?

- (Case 2): With the system config above & modifying the init parameters acc to your use-case, does sample_encode complete successfully?-

- (Case 3): If (Case 2) works successfully, can you add in your code changes and see if the new application works?

Can you kindly send the behavior of the scenarios above? Before we move ahead with debug or concluding it an issue, we need to identify what change was the cause. We recommend starting with our sample_encode because that is a validated sample and when reporting issues, we want to ensure we all have the same baseline.

Thank you once again.

0 Kudos
Sravanthi_K_Intel
879 Views

One more question, when you say this - "It's puzzled,  there is no graphics card switching mechanism in my computer, and i just attach my monitor at GTX adapter, INTEL's output port is empty." 

I need some clarification - Is your monitor connected to the Intel Gfx or not? Can you run sample_encode successfully with your configuration?

0 Kudos
mao_r_
Beginner
879 Views

Sorry, I means that my monitor is connected to the NVIDIA GTX 660 video card, while the INTEL integrated video card connects no monitor. And there is no auto video card switch mechanism in my computer.

The INTEL sample_encode is single thread, my program is multi-thread, MFXVideoENCODE_EncodeFrameAsync and MFXVideoCORE_SyncOperation were called in different thread. Dose intel SDK support multi-thread?

As you said, we'll try the sample_encode, thank you.

0 Kudos
mao_r_
Beginner
879 Views

I found that every time before MFXVideoCORE_SyncOperation returns MFX_ERR_DEVICE_FAILED, the d3d11 throw a exception, this exception was caught by itself and return error to igfx11cmrt32.dll. Here is the call stack, dumped by windbg.

02c9f478 749922b4 KERNELBASE!RaiseException+0x48
02c9f4b0 6807e806 msvcrt!_CxxThrowException+0x59
02c9f4d0 68051cfd d3d11!ThrowFailure+0x57cd9
02c9f580 68051be2 d3d11!CDecodeContext::DecodeExtension+0xe1
02c9f62c 5dd56903 d3d11!CContext::DecoderExtension+0x6a
WARNING: Stack unwind information not available. Following frames may be wrong.
02c9f660 5dd5861f igfx11cmrt32!CmDevice_RT::LoadProgram+0x133
02c9f6b0 5dd587fc igfx11cmrt32!CmQueue_RT::Enqueue+0x1ef
02c9f6d4 5b5a3acb igfx11cmrt32!CmQueue_RT::EnqueueCopyCPUToGPUFullStride+0x1c
02c9f700 5b5b5224 libmfxhw32+0x3acb
02c9f848 5b5b44fa libmfxhw32!MFXVideoCORE_GetHandle+0x79f4
02c9f9dc 5b67083b libmfxhw32!MFXVideoCORE_GetHandle+0x6cca
02c9fb4c 5b6032be libmfxhw32!MFXVideoVPP_GetVPPStat+0xb05eb
02c9fc80 5b5e387f libmfxhw32!MFXVideoVPP_GetVPPStat+0x4306e
02c9fddc 5b5e4cc5 libmfxhw32!MFXVideoVPP_GetVPPStat+0x2362f
02c9fe0c 5b5cc59c libmfxhw32!MFXVideoVPP_GetVPPStat+0x24a75
02c9ff44 5b8cdca4 libmfxhw32!MFXVideoVPP_GetVPPStat+0xc34c
02c9ff7c 5b8cddcc libmfxhw32!MFXVideoVPP_GetVPPStat+0x30da54
02c9ff88 76e6919f libmfxhw32!MFXVideoVPP_GetVPPStat+0x30db7c
02c9ff94 770bb54f KERNEL32!BaseThreadInitThunk+0xe
02c9ffdc 770bb51a ntdll!__RtlUserThreadStart+0x2f
02c9ffec 00000000 ntdll!_RtlUserThreadStart+0x1b

My libmfxhw32.dll file version is 5.14.12.1, and the time stamp of the digital signature is 12/01 2014.

0 Kudos
Sravanthi_K_Intel
879 Views

Hi Mao,

I had typed a response to this earlier, but it is lost. Apologies for that.

From your last message, I do not understand if you ran sample_encode (without any modifications) - which is (Case 1) in the previous post. Can you please confirm if you did and what is the outcome? Without that, it is hard to understand where the issue it.

Some other notes:

DirectX11 versus DirectX9 - In DiredtX9, with multiple gfx adapters, it was required to connect monitor to the iGfx for the SDK to work. With DX11, the driver should recognize the iGfx. Since you are using DX11 and still seeing the error, can you please connect the monitor to the intel Gfx and see if the issue occurs? (Again, please run these experiments on unmodified sample_encode).

Thanks.

0 Kudos
mao_r_
Beginner
879 Views

Hi, sravanthi,

I tried the sample_encode, it hit the same error. But after MFXVideoCORE_SyncOperation returns MFX_ERR_DEVICE_FAILED, the sample code reset the encoder, then try to continue.

        if (MFX_ERR_DEVICE_LOST == sts || MFX_ERR_DEVICE_FAILED == sts)
        {
            msdk_printf(MSDK_STRING("\nERROR: Hardware device was lost or returned an unexpected error. Recovering...\n"));
            sts = pPipeline->ResetDevice();
            MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1);

            sts = pPipeline->ResetMFXComponents(&Params);
            MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1);
            continue;
        }

The parameters of running sample_encode.exe is: h264 -i d:\in.nv12 -o d:\out.h264 -w 1280 -h 720 -d3d9 -hw -async 4 -nv12 -b 8000 -f 30 -u quality

This error can be hit within an hour. Is this condition normal? I don't think that's a good idea to reset the encoder frequently. The encoder should be very stable.

0 Kudos
Sravanthi_K_Intel
879 Views

Hi Mao,

This is surely not the expected behavior - we expect the encoder to run for a long time without any issues.

I see you are using d3d9 -> With the config you mentioned previously "monitor is connected to the NVIDIA GTX 660 video card, while the INTEL integrated video card connects no monitor", the device error could occur if the iGfx is not visible since it does not have a monitor connected. In D3D9 implementation, it was required to have the monitor connected to iGfx to identify the iGfx in multi-Gfx system. This requirement was removed in D3D11. With D3D11, even if the monitor was not connected, the iGfx was recognized. 

Having said that, I am seeing a crash for sample_encoder on the latest release (API 1.15), but API 1.13 is working without issues.

Can you verify these commands and tell me what you see;

h264 -i d:\in.nv12 -o d:\out.h264 -w 1280 -h 720 -d3d9 -hw -async 4 -nv12 -b 8000 -f 30

h264 -i d:\in.nv12 -o d:\out.h264 -w 1280 -h 720 -d3d11 -hw -async 4 -nv12 -b 8000 -f 30

What is your API version and MSS version? Can you paste the error message as seen on the command window?

Thanks for bringing this to our notice.

0 Kudos
mao_r_
Beginner
879 Views

Hi sravanthi,

Thank you very for your suggestion. Last night, I ran two sample_encode.exe instances, before instance A start, I connect a monitor to the INTEL iGfx output. After instance A started, then unplug the monitor, lunch instance B. This morning, I found instance A has hit the error, and instance B still running ok with no error.

Here is the message on the command window of instance A:

Encoding Sample Version 5.0.491.98875

Input file format       NV12
Output video            AVC
Source picture:
        Resolution      1280x720
        Crop X,Y,W,H    0,0,1280,720
Destination picture:
        Resolution      1280x720
        Crop X,Y,W,H    0,0,1280,720
Frame rate      30.00
Bit rate(Kbps)  8000
Target usage    quality
Memory type     system
Media SDK impl          hw
Media SDK version       1.11

Processing started
Frame number: 2458945
Return on error: error code -17,        d:\projects\intel sample\sample_encode\s
rc\pipeline_encode.cpp 1198


Return on error: error code -17,        d:\projects\intel sample\sample_encode\s
rc\pipeline_encode.cpp  1360


ERROR: Hardware device was lost or returned an unexpected error. Recovering...

Message of instance B:

Encoding Sample Version 5.0.491.98875

Input file format       NV12
Output video            AVC
Source picture:
        Resolution      1280x720
        Crop X,Y,W,H    0,0,1280,720
Destination picture:
        Resolution      1280x720
        Crop X,Y,W,H    0,0,1280,720
Frame rate      30.00
Bit rate(Kbps)  8000
Target usage    quality
Memory type     system
Media SDK impl          hw_d3d11
Media SDK version       1.11

Processing started
Frame number: 8479700

BTW:

1).I think there is a small bug in Line 1511 of pipeline_encode.cpp. For example, the value of impl is 0x205 (MFX_IMPL_VIA_D3D9|MFX_IMPL_HARDWARE2), the result of sImpl will be "sw".

2).For testing convenience, I modified some code, so the line number in output message should not match the original sample code, I add a function in pipeline_encode.cpp:

mfxStatus CEncodingPipeline::ReInit(sInputParams *pParams)
{
 mfxStatus sts = MFX_ERR_NONE;


 sts = m_FileReader.Init(pParams->strSrcFile,
  pParams->ColorFormat,
  pParams->numViews,
  pParams->srcFileBuff);
 MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

 m_MVCflags = pParams->MVC_flags;

 sts = InitFileWriters(pParams);
 MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

 return sts;
}

and after the encoding of input file finished, I call this function then continue to the encoding loop.Because there is no big enough input file to hit the error(The data processing finished before error occurred). I think these changes shall not effect the testing.

Both of these instance has the same command line: h264 -i d:\in.nv12 -o d:\out.h264 -w 1280 -h 720 -d3d9 -hw -async 4 -nv12 -b 8000 -f 30 -u quality. Also I specified -d3d9, the message on instance B's command line shows d3d11.

Thank you again, I'll try it again with the command that you suggested: 

a).h264 -i d:\in.nv12 -o d:\out.h264 -w 1280 -h 720 -d3d9 -hw -async 4 -nv12 -b 8000 -f 30

b).h264 -i d:\in.nv12 -o d:\out.h264 -w 1280 -h 720 -d3d11 -hw -async 4 -nv12 -b 8000 -f 30

 

0 Kudos
Sravanthi_K_Intel
879 Views

Hi Mao,

Thanks for getting back to us. I think we may have a full picture here to debug the issue you are seeing:

- Instance A is using D3D9 implementation - With D3D9, this is a known limitation. D3D9 impl from Microsoft can only view one adapter in a switchable graphics scenario (as yours). DX11 was an improvement over D3D9 abd does not have that limitation - so your instance B is working fine.

(This could be confusing - if you want more details, we can discuss in PMs. Feel free to send me a PM).

Going forward, in switchable graphics scenario, it is recommended to use D3D11 implementation.

Hopefully that should fix the issue you are seeing. I noticed you are on API version 1.11. The latest one out there is 1.15 and has many fixes and new features as well. Will be good if you'd update to the latest.

0 Kudos
mao_r_
Beginner
879 Views

Maybe, but after more than 20 hours, instance B also met the same error.

0 Kudos
Sravanthi_K_Intel
879 Views

Hi Mao - The encoder is D3D11 implementation should work without crashing. If it is, then we need to understand why. Let us discuss this issue on messages - there are multiple things to check here to identify the issue. (My recent run of sample_encode for multiple hours worked without any crash).

Before that, can you please update to the latest MSS release and driver> You are 1.11 and our latest is 1.15.

0 Kudos
Reply