我有一个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;
我得到了不同的样本大小:从31字节到18 000字节。即使将格式更改为MFVideoFormat_RGB32
,也不会影响样本大小。
This问题似乎有同样的问题,但解决办法不是解决它。
关于为什么我不能改变交错和如何正确解码视频帧和从样本中获取图像数据的帮助吗?
在此之前,非常感谢您。
发布于 2017-04-20 16:13:51
为了使SourceReader将示例转换为RGB,您需要如下所示创建它:
IMFAttributes* pAttr = NULL;
MFCreateAttributes(&pAttr, 1);
pAttr->SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, TRUE);
pAttr->SetUINT32(MF_SOURCE_READER_ENABLE_VIDEO_PROCESSING, TRUE);
IMFSourceReader* m_pReader;
throwIfFailed(MFCreateSourceReaderFromURL(filePath, pAttr, &m_pReader), Can't create source reader from url");
pAttr->Release();
稍后,当MF_SOURCE_READERF_CURRENTMEDIATYPECHANGED发生时,您不应该中断循环。现在你将得到所有大小相同的样品。否则,您可以使用MFVideoFormat_NV12子类型,然后在创建读取器时不需要指定MF_SOURCE_READER_ENABLE_VIDEO_PROCESSING属性。
https://stackoverflow.com/questions/43507393
复制相似问题