I am trying to use the Intel H264 Video Encoder Media Foundation plugin with the MF SinkWriter in order to encode video.
I have built the sample MF plugins, and I have registered the mfx_mft_h264ve_32.dll file using regsvr32.
I am using a C++ application that initializes a SinkWriter and writes some empty frames to it. If I don't register the Intel video encoder, my app uses the Microsoft H264 video encoder, and it successfully encodes the empty frames.
But if I register the Intel video encoder, the app uses the Intel encoder, and all the calls to WriteSample succeed, but the app hangs on the call to pSinkWriter->Finalize().
I have used MFTrace and I see that the app is really using the Intel video encoder, but it hangs in ->Finalize().
Does anyone know why the encoder hangs? And how can I get it to stop hanging?
This is the test code I am using:
using namespace std;
int _tmain(int argc, _TCHAR* argv)
IMFSinkWriter *pSinkWriter = NULL;
hr = MFCreateSinkWriterFromURL(L"d:\\out.mp4", NULL, NULL, &pSinkWriter);
IMFMediaType *pMediaTypeOutV = NULL;
IMFMediaType *pMediaTypeInV = NULL;
// Setup output media type
hr = MFCreateMediaType(&pMediaTypeOutV);
hr = pMediaTypeOutV->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
hr = pMediaTypeOutV->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);
hr = pMediaTypeOutV->SetUINT32(MF_MT_AVG_BITRATE, 1600000);
hr = pMediaTypeOutV->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
hr = MFSetAttributeSize(pMediaTypeOutV, MF_MT_FRAME_SIZE, 1280, 720);
hr = MFSetAttributeRatio(pMediaTypeOutV, MF_MT_FRAME_RATE, 24, 1);
hr = MFSetAttributeRatio(pMediaTypeOutV, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
hr = pSinkWriter->AddStream(pMediaTypeOutV, &StreamIndexVid);
// Setup input media type
hr = MFCreateMediaType(&pMediaTypeInV);
hr = pMediaTypeInV->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
hr = pMediaTypeInV->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12);
hr = pMediaTypeInV->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
hr = MFSetAttributeSize(pMediaTypeInV, MF_MT_FRAME_SIZE, 1280, 720);
hr = MFSetAttributeRatio(pMediaTypeInV, MF_MT_FRAME_RATE, 24, 1);
hr = MFSetAttributeRatio(pMediaTypeInV, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
hr = pSinkWriter->SetInputMediaType(StreamIndexVid, pMediaTypeInV, NULL);
hr = pSinkWriter->BeginWriting();
LONGLONG sampleTime = 0;
UINT64 duration = 0;
MFFrameRateToAverageTimePerFrame(24, 1, &duration);
IMFSample *pSample = NULL;
IMFMediaBuffer *pBuffer = NULL;
DWORD bufsize = 2*1280*720;
hr = MFCreateMemoryBuffer(bufsize, &pBuffer);
hr = pBuffer->SetCurrentLength(bufsize);
hr = MFCreateSample(&pSample);
hr = pSample->AddBuffer(pBuffer);
hr = pSample->SetSampleTime(sampleTime);
hr = pSample->SetSampleDuration(duration);
hr = pSinkWriter->WriteSample(StreamIndexVid, pSample);
sampleTime += duration;
hr = pSinkWriter->Finalize();
I'm not sure why you are seeing an issue with that code. Can you provide details of which OS and MediaSDK version you are using?
Also, can you provide the output of <install dir>\tools\mediasdk_sys_analyzer\win32\sys_analyzer.exe tool.
I'm also running into this issue when I use the Intel Quick Sync hardware H.264 encoder mft via a direct sink writer instance. The Microsoft encoder works fine, and also using the Quick Sync encoder via an entire topology works fine.
Did you ever find a solution to the hang?
Did any of you resolve this issue? I am running into the exact same problem :-( Microsoft Encoder works fine, but I cannot get the Intel QuickSync past the Finalize call.
Thanks in advance.
No, I never found a solution to this problem.
The guys from Intel never replied back, as you can see in this thread.
Nowadays they don't even include the Media Foundation plugin sample inside their samples package. It looks like they removed it and they washed their hands of this bug.