Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Ovidiu_R_
Beginner
113 Views

Video encoder MF plugin hangs on ->Finalize()

Hello

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:

#include "stdafx.h"

#include <iostream>

#include <mfapi.h>
#include <mfidl.h>
#include <Mfreadwrite.h>
#include <mferror.h>
#include <dshow.h>

#include <ks.h>
#include <codecapi.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    CoInitialize(NULL);
    MFStartup(MF_VERSION);

    HRESULT hr;
    IMFSinkWriter *pSinkWriter = NULL;
    DWORD StreamIndexVid;

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

    pMediaTypeOutV->Release();
    pMediaTypeInV->Release();

    hr = pSinkWriter->BeginWriting();

    LONGLONG sampleTime = 0;
    UINT64 duration = 0;
    MFFrameRateToAverageTimePerFrame(24, 1, &duration);

    for(int i=0;i<100;i++)
    {
        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;

        cout<<i<<" ";

        pSample->Release();
        pBuffer->Release();
    }
    
    hr = pSinkWriter->Finalize();

    MFShutdown();
    CoUninitialize();
}

0 Kudos
5 Replies
Anthony_P_Intel
Employee
113 Views

Hi,

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.

Thanks

Ovidiu_R_
Beginner
113 Views

Hi,

I am running Windows 7 SP1 and Intel Media SDK 2013 R2. I wrote the program under Visual Studio 2010 SP1.

I have attached the output of the sys_analyzer tool to this post.

Thanks

john_w_1
Beginner
113 Views

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?

Lasse_K_
Beginner
113 Views

Hi

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.

Ovidiu_R_
Beginner
113 Views

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.

Reply