How to capture h264 raw stream from a camera device? RRS feed

  • Question

  • My Logitech C920 cam has 3 streams to output,and the stream3 output h264 raw stream,I wrote below code to capture h264 raw stream with HD1080p30 format,but the "ReadSample()" function failed,it return "MF_E_INVALIDMEDIATYPE",so what's wrong with my code?How to capture h264 raw stream?

        HRESULT hr;
        LPCWSTR pwsDevSymbLink = (LPCWSTR)m_cbCapDevices.GetItemData(m_cbCapDevices.GetCurSel());
        DWORD dwStreamIdx = (DWORD)m_cbDevStreams.GetCurSel();    // is 2 beacause camera output h264 on stream3
        DWORD dwMediaTypeIdx = (DWORD)m_cbStreamMediaTypes.GetCurSel();    // the mediatype index for HD1080p30 video format

        CVideoCapCallback vidCapCB;        // capture callback class

        CComPtr<IMFAttributes> pAttrs;
        hr = pAttrs->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK,&vidCapCB);
        assert(hr == S_OK);
        assert(hr == S_OK);

        CComPtr<IMFMediaSource> pSourceDev;

        CComPtr<IMFSourceReader> pReader;
        hr = MFCreateSourceReaderFromMediaSource(pSourceDev,pAttrs,&pReader);
        assert(hr == S_OK);
        vidCapCB.m_pReader = pReader;
        vidCapCB.m_dwRdStream = dwStreamIdx;
        CComPtr<IMFMediaType> pTargetMT;
        hr = pReader->GetNativeMediaType(dwStreamIdx,dwMediaTypeIdx,&pTargetMT);    // get the HD1080p30 mediatype
        hr = pReader->SetCurrentMediaType(dwStreamIdx,NULL,pTargetMT);
        hr = pReader->SetStreamSelection(vidCapCB.m_dwRdStream,TRUE);
        assert(hr == S_OK);
        hr = pReader->ReadSample(vidCapCB.m_dwRdStream,0,NULL,NULL,NULL,NULL);
        assert(SUCCEEDED(hr));    // return S_OK,because I use async callback,but the "hrStatus" of "OnReadSample()" is MF_E_INVALIDMEDIATYPE;


        pReader = NULL;    

    Friday, July 1, 2016 8:56 AM

All replies

  • I am also getting the same for H264 samples. The hrStatus in OnReadSample is MF_E_INVALIDMEDIATYPE. I also made sure the stream selection is set for index 2.

    I will be investigating this and will post updates here.

    Wednesday, July 20, 2016 6:44 AM
  • Are you using Windows 7 or Windows 8.1/10?
    Wednesday, July 20, 2016 6:46 AM
  • I have not been able to resolve this yet.

    Anybody else ever got this to work?

    Tuesday, July 26, 2016 4:53 AM