我有一个MOV文件,我想解码它,并将所有帧作为单独的图像。媒体基金会设置视频隔行扫描和解码
所以我尝试按以下方式配置未压缩的媒体类型:
// configure the source reader
IMFSourceReader* m_pReader;
MFCreateSourceReaderFromURL(filePath, NULL, &m_pReader);
// get the compressed media type
IMFMediaType* pFileVideoMediaType;
m_pReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, &pFileVideoMediaType);
// create new media type for uncompressed type
IMFMediaType* pTypeUncomp;
MFCreateMediaType(&pTypeUncomp);
// copy all settings from compressed to uncompressed type
pFileVideoMediaType->CopyAllItems(pTypeUncomp);
// set the uncompressed video attributes
pTypeUncomp->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB8);
pTypeUncomp->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
pTypeUncomp->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
// set the new uncompressed type to source reader
m_pReader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, pTypeUncomp);
// get the full uncompressed media type
m_pReader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, &pTypeUncomp);
我注意到,即使我明确设置MF_MT_INTERLACE_MODE
到MFVideoInterlace_Progressive
最终配置仍与旧模式MFVideoInterlace_MixedInterlaceOrProgressive
配置。
之后,我遍历所有的样本,看看它们的大小:
IMFSample* videoSample = nullptr;
IMFMediaBuffer* mbuffer = nullptr;
LONGLONG llTimeStamp;
DWORD streamIndex, flags;
m_pReader->ReadSample(
MF_SOURCE_READER_FIRST_VIDEO_STREAM,
0, // Flags.
&streamIndex, // Receives the actual stream index.
&flags, // Receives status flags.
&llTimeStamp, // Receives the time stamp.
&videoSample) // Receives the sample or NULL.
videoSample->ConvertToContiguousBuffer(&mbuffer);
BYTE* videoData = nullptr;
DWORD sampleBufferLength = 0;
mbuffer->Lock(&videoData, nullptr, &sampleBufferLength);
cout << sampleBufferLength << endl;
我也得到了相当的样本大小不同:从31bytes到18000bytes。 即使将格式更改为MFVideoFormat_RGB32
也不会影响样本大小。
This问题似乎有同样的问题,但解决方案没有解决它。
为什么我不能改变隔行扫描以及如何正确解码视频帧并从样本中获取图像数据?
非常感谢提前。
也许你应该尝试先调用GetNativeMediaType而不是m_pReader-> GetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM,&pFileVideoMediaType);.你还检查每个样本是否交错:pSample-> GetUINT32(MFSampleExtension_Interlaced,&isSampleInterlaced); – VuVirt
您可以在此检查ConfigureDecoder函数:https://msdn.microsoft.com/en-us/library/windows/desktop/dd389281(v=vs.85).aspx#setting_output_formats。调用ReadSample时,您还可以在收到状态标志中检查MF_SOURCE_READERF_CURRENTMEDIATYPECHANGED,以查看类型是否已更改。 – VuVirt
@VuVirt,感谢您的评论。获取本地媒体类型不会改变任何内容。检查隔行扫描样本最终出现错误。并没有媒体类型的变化。你脑子里还有别的东西吗?如果你能找到几分钟看我的代码:https://github.com/mbaros100/Media-Foundation-video-decoder。非常感谢您的帮助。 – mbaros