locked
How to decode mpeg2 video data using source reader? RRS feed

  • Question

  • I have a media source which read DVD. And I create a source reader from this media source. I set the output format of source reader as MFVideoFormat_RGB32 for video. But I can not get MFVideoFormat_RGB32 when I call IMFSourceReader::GetCurrentMediaType . It seems that no correct decoder is loaded.

    I have custom WinRT mpeg2 decoder which can be used in Metro. Can I make source reader to load my custom WinRT mpeg2 decoder? How to do this? Thanks.

         IMediaSource *mediaSouce;

        ................................

    //Create Source Reader

        IMFSourceReader *pReader;

        HRESULT hr = MFCreateSourceReaderFromMediaSource(mediaSource, NULL, &pReader);

    //Set output formats

        HRESULT hr = sourceReader->GetNativeMediaType(dwStreamIndex, 0, &pNativeType);
        if (FAILED(hr))
        {
            return hr;
        }

        GUID majorType, subtype;

        // Find the major type.
        hr = pNativeType->GetGUID(MF_MT_MAJOR_TYPE, &majorType);
        if (FAILED(hr))
        {
            goto done;
        }

        // Define the output type.
        hr = MFCreateMediaType(&pType);
        if (FAILED(hr))
        {
            goto done;
        }

        hr = pType->SetGUID(MF_MT_MAJOR_TYPE, majorType);
        if (FAILED(hr))
        {
            goto done;
        }

        // Select a subtype.
        if (majorType == MFMediaType_Video)
        {
            subtype= MFVideoFormat_RGB32;
        }

        hr = pType->SetGUID(MF_MT_SUBTYPE, subtype);
        if (FAILED(hr))
        {
            goto done;
        }

        // Set the uncompressed format.
        hr = pReader->SetCurrentMediaType(dwStreamIndex, NULL, pType);
        if (FAILED(hr))
        {
            goto done;
        }

    //Then I call GetCurrentMediaType, I can not get RGB32 as subtype output.

        pReader->GetCurrentMediaType(dwStreamIndex, pOutputType);

     

    Wednesday, July 18, 2012 9:33 AM

Answers

All replies