Using IMFSourceReader to open a video file

2.1k views Asked by At

I want to open a video file using IMFSourceReader to access its Frames as IMFSample. In a WinRT C++ Class I send the RandomAccessStream of a video file and use the following code to create an IMFSourceReader object.

HRESULT hr = S_OK;

ComPtr<IMFSourceReader> pSourceReader;
ComPtr<IMFByteStream> spByteStream;

if (SUCCEEDED(hr))
{
    // Initialize the Media Foundation platform.
    hr = MFStartup(MF_VERSION);


    hr = MFCreateMFByteStreamOnStreamEx((IUnknown*)InputVideoStream, &spByteStream);

    ComPtr<IMFAttributes> Atrr;
    hr = MFCreateAttributes(&Atrr, 10);
    hr = Atrr->SetUINT32(MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, true);

    hr = MFCreateSourceReaderFromByteStream(spByteStream.Get(), Atrr.Get(), &pSourceReader);
 }

But the HRESULT of the function MFCreateSourceReaderFromByteStream() is returning The Byte Stream Type of the Given URL is unsupported.

I don't know what i'm doing wrong. Can anyone show me the correct way? I'm using Windows 8.1.

2

There are 2 answers

0
croc On BEST ANSWER

I have found a solution to the The Byte Stream Type of the Given URL is unsupported problem of IMFSourceReader. I could read Byte Stream of WMV files, some MP4 files but not all kind of video files. So before using MFCreateSourceReaderFromByteStream() I converted the video stream to VC-1/WMV format which the MFCreateSourceReaderFromByteStream() is able to read. I used the Transcoding media sample of MSDN to convert he video into WMV video. Now I am able to use MFCreateSourceReaderFromByteStream() without any error.

8
Anton Angelov On

The return code sounds pretty clear. What is the video/audio format of the file you want to play? If you are unable to play it back with TopoEdit either, then you have no available codec for this format.

Is there any other way to extract the video frames other than using IMFSourceReader?

To extract an uncompressed video sample no matter what way, first you have to decode it from it's encoded stream. In your case you are missing a decoder. Maybe your question should be is there another framework I can use instead of Media Foundation?

I don't think so. The DirectShow API is not available for Windows RT, as far as I know even ffmpeg can not be compiled for that OS. So I guess your only choice is to rely on Media Foundation and it's set of codecs.

My only idea coming to mind is to find third party decoder components (MFTs) or build your own decoders.

Edit:

In your case the IMFMSourceReader factory function (MFCreateMFByteStreamOnStreamEx) is unable to create source reader. This will mean that your system lacks a adequate container parser (i.e. splitter a.k.a. demultiplexor). So it is unable to extract the elementary media streams from the container. This is really the stage before decoding.

So again, you can search for a third-party media source parser, or write/port one. Of course you will first find out what is the particular format that MF is lacking source reader for.

Some links:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms700134%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ee318417%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/aa371872%28v=vs.85%29.aspx