Reputation: 746
I have a stream of bytes encoded by H264.Now I want to playback using Media Foundation I have the frames as raw data without container and I receive it frame by frame.does any one have any idea how can I do that?
Upvotes: 1
Views: 318
Reputation: 30699
The code snippet below demonstrates how to create an IMFSample object from a byte buffer. Once you have an IMFSample it can be fed to the 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);
Upvotes: 1