Dear sir.
I would like to extract a image frame from a MPEG-4 part 2 file.
I have done on MPEG-4 file. but as MPEG-4 part 2 did not.
Here's the source code.
----------------------------------
TCHAR BASED_CODE szFilter[] = _T("MPEG-4 Files (*.mp4)|*.mp4|All Files (*.*)|*.*||");
CFileDialog dialogOpenFile(TRUE, _T("mp4"), NULL, OFN_FILEMUSTEXIST, szFilter, this);
if (IDCANCEL == dialogOpenFile.DoModal())
{
return;
}
CString strFileName = dialogOpenFile.GetPathName();
CComPtr<IMFSourceReader> SourceReader;
VERIFY(S_OK == MFCreateSourceReaderFromURL(strFileName, nullptr, &SourceReader));
CComPtr<IMFTransform > pMpeg4sDecoder;
VERIFY(S_OK == pMpeg4sDecoder.CoCreateInstance(CLSID_CMpeg4sDecMFT));
UINT32 Width, Height;
CComPtr <IMFMediaType>pInputType;
CComPtr <IMFMediaType>pOutputType;
for (DWORD MediaTypeIndex = 0;; MediaTypeIndex++)
{
CComPtr < IMFMediaType> pNativeType;
if (S_OK != SourceReader->GetNativeMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM,MediaTypeIndex, &pNativeType))
{
break;
}
MFGetAttributeSize(pNativeType, MF_MT_FRAME_SIZE, &Width,&Height);
GUID majorType, subtype;
pNativeType->GetGUID(MF_MT_MAJOR_TYPE, &majorType);
if (majorType == MFMediaType_Video)
{
GUID NativeSubtype;
pNativeType->GetGUID(MF_MT_SUBTYPE, &NativeSubtype);
MFCreateMediaType(&pInputType);
pInputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
pInputType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_MP4V);
VERIFY(S_OK == SourceReader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, nullptr, pInputType));
VERIFY(S_OK == MFSetAttributeSize(pInputType, MF_MT_FRAME_SIZE, Width, Height));
VERIFY(S_OK == pMpeg4sDecoder->SetInputType(0, pNativeType, 0));
MFCreateMediaType(&pOutputType);
pOutputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
pOutputType->SetGUID(MF_MT_SUBTYPE, MEDIASUBTYPE_YV12);
VERIFY(S_OK == MFSetAttributeSize(pOutputType, MF_MT_FRAME_SIZE, Width, Height));
VERIFY(S_OK == pMpeg4sDecoder->SetOutputType(0, pOutputType, 0));
}
}
SourceReader->SetStreamSelection(MF_SOURCE_READER_ANY_STREAM, FALSE);
SourceReader->SetStreamSelection(MF_SOURCE_READER_FIRST_VIDEO_STREAM, TRUE);
DWORD StreamIndex, Flags;
LONGLONG TimeStamp;
CComPtr<IMFSample> Sample;
SourceReader->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, &StreamIndex, &Flags, &TimeStamp, &Sample);
if (Flags & MF_SOURCE_READERF_ENDOFSTREAM)
{
return;
}
HRESULT hr;
VERIFY(S_OK==(hr= pMpeg4sDecoder->ProcessInput(0, Sample, 0) ));
-----------------
The last line fails with E_UNEXPECTED Catastrophic failure.
I think that the pMpeg4sDecoder is correctly configured.but I don't have a resolution.
I looked for the more infomation of CLSID_CMpeg4sDecMFT, but I found only a following page.
https://msdn.microsoft.com/ja-jp/library/windows/desktop/ff819454%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
Please tell me my wrong point.
Sincerely yours.