question

46922172 avatar image
0 Votes"
46922172 asked 46922172 commented

Capture camera stream media foundation wrong format

Hello. Please help me solve the problem. I am trying to get a stream of data from a webcam using Media Foundation.

 IMFSourceReader* pReader;
 HRESULT hr = MFCreateSourceReaderFromMediaSource(captureDevice, NULL, &pReader);
 if (FAILED(hr))
 return hr;
    
 // Tried setting the video format like this:
 //hr = SetDeviceFormat(captureDevice, FormatIndex);   //I need to configure the camera to format
 //if (FAILED(hr))
 // return hr; // But this did not give the desired result.
    
    
 Next, I just check what is set by default:
 IMFMediaType* pType = NULL;
 hr = pReader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, &pType);
 LogMediaType(pType, 0, NULL);
 pReader->SetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, NULL, pType);


//And the following format is set there:

 **MF_MT_MAJOR_TYPE MFMediaType_Video
 MF_MT_SUBTYPE MFVideoFormat_MJPG
 MF_MT_FRAME_SIZE 3040 x 1080
 MF_MT_ALL_SAMPLES_INDEPENDENT 1
 MF_MT_SAMPLE_SIZE 9849600**


In the onReadSample callback, I should receive a sample with a buffer of size 6566400.
As if this format is set:

 MF_MT_MAJOR_TYPE MFMediaType_Video
 MF_MT_SUBTYPE MFVideoFormat_YUY2
 MF_MT_FRAME_SIZE 3040 x 1080
 MF_MT_DEFAULT_STRIDE 6080
 MF_MT_ALL_SAMPLES_INDEPENDENT 1
 MF_MT_FIXED_SIZE_SAMPLES 1
 MF_MT_SAMPLE_SIZE 6566400

Format setting function

  HRESULT SetDeviceFormat(IMFMediaSource* pSource, DWORD dwFormatIndex)
     {
     IMFPresentationDescriptor* pPD = NULL;
     IMFStreamDescriptor* pSD = NULL;
     IMFMediaTypeHandler* pHandler = NULL;
     IMFMediaType* pType = NULL;
     IMFMediaType** pTypex = NULL;
        
     HRESULT hr = pSource->CreatePresentationDescriptor(&pPD);
     if (FAILED(hr))
     {
     goto done;
     }
        
     BOOL fSelected;
     hr = pPD->GetStreamDescriptorByIndex(0, &fSelected, &pSD);
     if (FAILED(hr))
     {
     goto done;
     }
        
     hr = pSD->GetMediaTypeHandler(&pHandler);
     if (FAILED(hr))
     {
     goto done;
     }
        
     hr = pHandler->GetMediaTypeByIndex(dwFormatIndex, &pType);
     if (FAILED(hr))
     {
     goto done;
     }
        
     LogMediaType(pType, dwFormatIndex, NULL);
        
     hr = pHandler->SetCurrentMediaType(pType);
     done:
     SafeRelease(&pPD);
     SafeRelease(&pSD);
     SafeRelease(&pHandler);
     SafeRelease(&pType);
     return hr;
     }


So my question is, why the callback function does not return samples from the type I have selected? Any advice?

Thanks in advance

Best regards








windows-apic++
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What's the size you received in the callback? Do you check this code sample about how to capture the video from device using Media Foundation and CaptureEngine?


0 Votes 0 ·
     MF_MT_MAJOR_TYPE    MFMediaType_Video
     MF_MT_SUBTYPE    MFVideoFormat_MJPG
     MF_MT_FRAME_SIZE    3040 x 1080
     MF_MT_SAMPLE_SIZE    9849600

With this format, I expect a size of 9849600 but I get a size of 6566400
I tried examples from sdk. But there are few examples with getting an array of raw data.
And in the YUY2 format, the FPS is too small and still needs to be converted to RGB.
Tried to configure IMFTransform to transform but it doesn't work. For some reason, it throws E_Fail on ProcessOutput


0 Votes 0 ·

0 Answers