我有一个由H264编码的字节流。现在我想使用Media Foundation播放我将帧作为原始数据而没有容器,我逐帧接收它。任何人都知道我该怎么做?
答案 0 :(得分:1)
下面的代码片段演示了如何从字节缓冲区创建IMFSample对象。获得IMFSample后,可以将其输入MF Enhanced Video Renderer。
MFCreateSample(&reConstructedVideoSample);
CHECK_HR(MFCreateMemoryBuffer(srcBufLength, &reConstructedBuffer), "Failed to create memory buffer.\n");
CHECK_HR(reConstructedVideoSample->AddBuffer(reConstructedBuffer), "Failed to add buffer to re-constructed sample.\n");
CHECK_HR(reConstructedVideoSample->SetSampleTime(llVideoTimeStamp), "Error setting the re-constructed video sample time.\n");
CHECK_HR(reConstructedVideoSample->SetSampleDuration(llSampleDuration), "Error setting re-constructed video sample duration.\n");
byte *reconByteBuffer;
DWORD reconBuffCurrLen = 0;
DWORD reconBuffMaxLen = 0;
CHECK_HR(reConstructedBuffer->Lock(&reconByteBuffer, &reconBuffMaxLen, &reconBuffCurrLen), "Error locking re-constructed buffer.\n");
memcpy(reconByteBuffer, srcByteBuffer, srcBuffCurrLen); // srcByteBuffer is a byte * that contains the sample video data read from file.
CHECK_HR(reConstructedBuffer->Unlock(), "Error unlocking re-constructed buffer.\n");
reConstructedBuffer->SetCurrentLength(srcBuffCurrLen);