- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to encode video using the "Intel® Quick Sync Video H.264 Encoder MFT".Encoder initializes normal. The following code provides reference!
CHECK_HR(CoInitialize(NULL), "Failed to init Com! \n");
CHECK_HR(MFStartup(MF_VERSION), "Failed to start Microsoft Media Foundation \n");
hr = MFTEnumEx(MFT_CATEGORY_VIDEO_ENCODER,MFT_ENUM_FLAG_ASYNCMFT | MFT_ENUM_FLAG_SYNCMFT | MFT_ENUM_FLAG_LOCALMFT | MFT_ENUM_FLAG_SORTANDFILTER | MFT_ENUM_FLAG_HARDWARE, NULL, &outType, &ppActivate, &count);
;
if (SUCCEEDED(hr) && count != 0)
{
hr = ppActivate[0]->ActivateObject(IID_PPV_ARGS(&_pTransform));
ppActivate[0]->GetAllocatedString(MFT_ENUM_HARDWARE_URL_Attribute, &hardwareUrl, NULL);
}
for (UINT32 i = 0; i < count; i++)
{
ppActivate->Release();
}
CoTaskMemFree(ppActivate);
MFCreateAttributes(&pAttributes, 10);
hr2 = _pTransform->GetAttributes(&pAttributes);
CHECK_HR(pAttributes->GetUINT32(MF_SA_D3D11_AWARE, punValue), "Failed to FindEncoder \n");
if (punValue == 0) goto done;
CHECK_HR(MFCreateDXGIDeviceManager(&pResetToken, &ppDXVAManager), "Failed to create MFCreateDXGIDeviceManager \n");
CHECK_HR(ppDXVAManager->ResetDevice(m_Device, (UINT)pResetToken), "Failed to ResetDevice \n");
CHECK_HR(ppDXVAManager->OpenDeviceHandle(phDevice), "Failed to OpenDeviceHandle");
hr2 = pAttributes->SetUINT32(MF_TRANSFORM_ASYNC, 1);
hr2 = pAttributes->SetString(MFT_ENUM_HARDWARE_URL_Attribute, hardwareUrl);
hr2 = pAttributes->SetUINT32(MFT_SUPPORT_DYNAMIC_FORMAT_CHANGE, 1);
hr2 = pAttributes->SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 1);
hr2 = pAttributes->SetUnknown(MF_SINK_WRITER_D3D_MANAGER, ppDXVAManager);
hr2= pAttributes->SetUINT32(MF_TRANSFORM_ASYNC_UNLOCK, 1);
MFCreateMediaType(&pMFTOutputMediaType);
CHECK_HR(pMFTOutputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video), "Failed to set media type MF_MT_MAJOR_TYPE \n");
CHECK_HR(pMFTOutputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264), "Failed to set media type MF_MT_SUBTYPE \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(MF_MT_AVG_BITRATE, TARGET_AVERAGE_BIT_RATE), "Failed to set media type MF_MT_AVG_BITRATE \n");
CHECK_HR(MFSetAttributeRatio(pMFTOutputMediaType, MF_MT_FRAME_RATE, TARGET_FRAME_RATE, 1), "Failed to set media type MF_MT_FRAME_RATE \n");
CHECK_HR(MFSetAttributeSize(pMFTOutputMediaType, MF_MT_FRAME_SIZE, CAMERA_RESOLUTION_WIDTH, CAMERA_RESOLUTION_HEIGHT), "Failed to set media type MF_MT_FRAME_SIZE \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, 2), "Failed to set media type MF_MT_INTERLACE_MODE \n"); // 2 = Progressive scan, i.e. non-interlaced.
CHECK_HR(pMFTOutputMediaType->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH264VProfile_Base), "Failed to set media type MF_MT_MPEG2_PROFILE \n");
CHECK_HR(MFSetAttributeRatio(pMFTOutputMediaType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1), "Failed to set media type MF_MT_PIXEL_ASPECT_RATIO \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE), "Failed to set media type MF_MT_ALL_SAMPLES_INDEPENDENT \n");CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncCommonRateControlMode, eAVEncCommonRateControlMode_GlobalLowDelayVBR), "Failed to set media type CODECAPI_AVEncCommonRateControlMode");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncCommonQuality, 70), "Failed to set media type CODECAPI_AVEncCommonQuality \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncAdaptiveMode, eAVEncAdaptiveMode_None), "Failed to set CODECAPI_AVEncAdaptiveMode \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncCommonBufferSize, AVEncCommonBufferSize), "Failed to set CODECAPI_AVEncCommonBufferSize \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncCommonMeanBitRate, TARGET_AVERAGE_BIT_RATE), "Failed to set CODECAPI_AVEncCommonMeanBitRate \n");CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncCommonQualityVsSpeed, 50), "Failed to CODECAPI_AVEncCommonQualityVsSpeed \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncH264SPSID, 31), "Failed to set CODECAPI_AVEncCommonMaxBitRate \n");CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncMPVDefaultBPictureCount, 0), "Failed to set CODECAPI_AVEncCommonMaxBitRate \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncCommonMaxBitRate, TARGET_AVERAGE_BIT_RATE), "Failed to set CODECAPI_AVEncCommonMaxBitRate \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncMPVGOPSize, 1), "Failed to set CODECAPI_AVEncMPVGOPSize \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncVideoEncodeQP, 24), "Failed to set CODECAPI_AVEncVideoEncodeQP \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncVideoForceKeyFrame, 1), "Failed to set CODECAPI_AVEncVideoForceKeyFrame \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVLowLatencyMode, 1), "Failed to set CODECAPI_AVEncVideoForceKeyFrame \n");
CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncVideoMinQP, 1), "Failed to set CODECAPI_AVEncVideoMinQP \n");CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncVideoLTRBufferControl, 0), "Failed to set CODECAPI_AVEncVideoLTRBufferControl \n");CHECK_HR(pMFTOutputMediaType->SetUINT32(CODECAPI_AVEncVideoLTRBufferControl, 0), "Failed to set CODECAPI_AVEncVideoLTRBufferControl \n");
CHECK_HR(_pTransform->SetOutputType(0, pMFTOutputMediaType, 0), "Failed to set media type SetOutputType \n");
hr2 = _pTransform->GetInputCurrentType(0, &pMFTInputMediaType);
MFCreateMediaType(&pMFTInputMediaType);
CHECK_HR(pMFTInputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video), "Failed to set inputmediatype MF_MT_MAJOR_TYPE \n");
CHECK_HR(pMFTInputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12), "Failed to set inputmediatype MF_MT_SUBTYPE \n");
//CHECK_HR(MFSetAttributeSize(pMFTInputMediaType, MF_MT_FRAME_SIZE, CAMERA_RESOLUTION_WIDTH, CAMERA_RESOLUTION_HEIGHT), "Failed to set inputmediatype MF_MT_FRAME_SIZE");
CHECK_HR(MFSetAttributeRatio(pMFTInputMediaType, MF_MT_FRAME_RATE, TARGET_FRAME_RATE, 1), "Failed to set inputmediatype MF_MT_FRAME_RATE");
CHECK_HR(MFSetAttributeRatio(pMFTInputMediaType, MF_MT_PIXEL_ASPECT_RATIO, 1, 1), "Failed to set inputmediatype MF_MT_PIXEL_ASPECT_RATIO");
CHECK_HR(pMFTInputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, 2), "Failed to set inputmediatype MF_MT_INTERLACE_MODE");
//CHECK_HR(_pTransform->SetInputType(0, pMFTInputMediaType, 0), "Failed to set inputmediatype");
hr2 = _pTransform->SetInputType(0, pMFTInputMediaType, 0);
//CHECK_HR(_pTransform->GetInputStatus(0, &mftStatus), "Failed to GetInputStatus \n");
hr2 = _pTransform->GetInputStatus(0, &mftStatus);
/*if (MFT_INPUT_STATUS_ACCEPT_DATA != mftStatus) {
goto done;
}*/
hr2 = _pTransform->QueryInterface(IID_IMFMediaEventGenerator, (void**)&mpH264EncoderEventGenerator);
mpH264EncoderEventGenerator->AddRef();
//CHECK_HR(_pTransform->ProcessMessage(MFT_MESSAGE_COMMAND_FLUSH, NULL), "Failed to process FLUSH command on H.264 MFT.\n");
//CHECK_HR(_pTransform->ProcessMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, NULL), "Failed to process BEGIN_STREAMING command on H.264 MFT.\n");
//hr2 = _pTransform->ProcessMessage(MFT_MESSAGE_NOTIFY_BEGIN_STREAMING, NULL);
hr2 = mpH264EncoderEventGenerator->BeginGetEvent(this, NULL);
I entered ID3D11Texture2D in the capture of the MFT event!!
hr = mpH264EncoderEventGenerator->EndGetEvent(pAsyncResult, &pEvent);
if (FAILED(hr))
return hr;
hr = pEvent->GetType(&meType);
hr = pEvent->GetStatus(&hStatus);
pEvent->Release();
if (FAILED(hr))
return hr;
if (hStatus == S_OK)
{
if (meType == METransformNeedInput)
{
IMFSample *videoSample = VideoSampleList.front();
hr = _pTransform->ProcessInput(0, videoSample, 0);
}
else if (meType == METransformHaveOutput)
{
//-------------
}
}
The ProcessInput method is wrong:0x6B21DEED (mfx_mft_h264ve_32.dll) There is an unprocessed exception: an access conflict occurs when the 0xC0000005: reads the location 0x1234567C. what do I lack? Or is there a mistake in the code?
- Tags:
- Development Tools
- Graphics
- Intel® Media SDK
- Intel® Media Server Studio
- Media Processing
- Optimization
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Luo,
Were you able to solve the problem? I'm too stuck with the same issue. Please direct me if you found the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Donghui and Ramesh,
This should be MFT issues.
You can check it by running our sample code with Media SDK, you can install by download the latest version from following page:
https://software.intel.com/en-us/media-sdk after downloading, you can try to run the sample in the release package and see if you still get error.
https://software.intel.com/en-us/media-sdk
Here are some old posts, and let me know if it helps.
https://software.intel.com/en-us/forums/intel-media-sdk/topic/607189
Mark Liu
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page