Hardware H.264 encoder encoding failed

Hardware H.264 encoder encoding failed

Hi

I'm trying to use Intel hardware H.264 encoder MFT (Window Media Foundation) on my machine which has an Intel Core i5-2400 CPU and latest Intel driver installed. 

The code I tested is based on the example here https://msdn.microsoft.com/en-us/library/windows/desktop/ff819477%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

The change I've made is:

1. changed the way to create the SinkWriter

IMFAttributes *pMFAttributes = NULL;
hr = MFCreateAttributes(&pMFAttributes, 100);
hr = pMFAttributes->SetGUID(MF_TRANSCODE_CONTAINERTYPE, MFTranscodeContainerType_MPEG4); // format
hr = pMFAttributes->SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, true); // enable hardware Encoder
hr = MFCreateSinkWriterFromURL(L"output.mp4", NULL, pMFAttributes, &pSinkWriter);

 

2. changed the encoder type and input media format

const GUID   VIDEO_ENCODING_FORMAT = MFVideoFormat_H264;
const GUID   VIDEO_INPUT_FORMAT = MFVideoFormat_NV12;

 

3. manually create a NV12 buffer (Y=150, U=45, V=23)

 

// NV12 is 1.5 Byte/Pixel
const LONG cbWidth = 1.5 * VIDEO_WIDTH;
const DWORD cbBuffer = cbWidth * VIDEO_HEIGHT;
BYTE *pData = NULL;
// Create a new memory buffer.
HRESULT hr = MFCreateMemoryBuffer(cbBuffer, &pBuffer);
// Lock the buffer and copy the video frame to the buffer.
if (SUCCEEDED(hr)) {
   hr = pBuffer->Lock(&pData, NULL, NULL);
}
if (SUCCEEDED(hr)) {
   for (int i = 0; i < VIDEO_WIDTH * VIDEO_HEIGHT; i++) {
      *(pData++) = 150;
   }
   for (int i = 0; i < VIDEO_WIDTH * VIDEO_HEIGHT/2; i++) { 
      if (i % 2 == 0) *(pData++) = 45;
      else *(pData++) = 23;
   }
}

 

Result:

  • When I ran the program, pWriter->WriteSample failed after about 120 frames were successfully written (return value is S_OK). The resulting mp4 file was only 32 bytes. From the mftrace I saw
  • COle32ExportDetours::CoCreateInstance @ New MFT @01B509F0, MF_TRANSFORM_ASYNC=1;MFT_SUPPORT_DYNAMIC_FORMAT_CHANGE=1;MFT_ENUM_HARDWARE_URL_Attribute=AA243E5D-2F73-48c7-97F7-F6FA17651651
    COle32ExportDetours::CoCreateInstance @ Created {4BE8D3C0-0515-4A37-AD55-E4BAE19AF471} Intel® Quick Sync Video H.264 Encoder MFT (C:\Program Files\Intel\Media SDK\mfx_mft_h264ve_w7_32.dll) @01B509F0 - traced interfaces: IMFTransform @01B509F0, 
  • Once I used MFCreateSinkWriterFromURL(L"output.mp4", NULL, NULL, &pSinkWriter) so that a SinkWriter with MS software encoder is created, a correct MP4 file could be generated.

 

Hope someone can help, thanks!

 

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello There,

I can help with this issue, but I'm afraid the information about the bug/error is not enough to understand the problem and its cause. Can you please give us information such as Driver version, OS version and  sample application you used etc? For example, to debug issues, we recommend customers use our sample applications or share their code with us with details. We have a deprecated sample_mfoundation_transcode which call MFT's here: https://software.intel.com/sites/default/files/MSDK_Samples_Deprecated_W....

Let me know if you are able to repro the issue with the sample? If you can share you application code and repro steps, we will able to investigate further.

Thanks.

-Harsh

 

Leave a Comment

Please sign in to add a comment. Not a member? Join today