IMFCaptureEngine Access Violation for MJPG Video format on Windows 8 32bit RRS feed

  • Question

  • I'm developing the desktop application to record .mp4 video format from USB camera using Capture Engine sample code. My application is crashing while recording the MJPG video format on Windows 8 32bit OS.

    I have modified the capture engine sample code as per my requirement and completed the development. My application is working fine in the following OSes: Window 10 64bit, Window 8.1 32/64bit and Windows 8 64bit.

    The USB camera supports two video formats: UYVY and MJPG. The Access violation occurs only when the camera has MJPG and  UYVY format. To verify the crash issue, I tried different cameras which have above formats and able to recreate the issue. 

    Then, I tried the camera which supports YUY2 and MJPG format and my application are able to record a video in the two formats without any crash.

    Also, I updated the PC and tried it but unfortunately, the issue still persists.

    The issue is occurring after initializing the preview and retrieving the current media type using GetCurrentDeviceMediaType(). Below code snippet is used to configure for video recording.

    HRESULT RecordVideo(TCHAR *tzDestinationFile)
    	HRESULT hr = E_FAIL;
    	IMFCaptureSink *pCaptureSink = NULL;
    	IMFCaptureRecordSink *pRecordSink = NULL;
    	IMFCaptureSource *pCaptureSource = NULL;
    	IMFMediaSource *pMediaSource = NULL;
    	IMFPresentationDescriptor *pPD = NULL;
    	IMFMediaType* pSrcMediaType = NULL;
    	if((m_pCaptureEngine == NULL) || (m_pCaptureEngineCB == NULL))	{	return MF_E_NOT_INITIALIZED;	}
    	hr = m_pCaptureEngine->GetSink(MF_CAPTURE_ENGINE_SINK_TYPE_RECORD, &pCaptureSink);	if (FAILED(hr)){	goto done;	}
    	hr = pCaptureSink->QueryInterface(IID_PPV_ARGS(&pRecordSink));	if (FAILED(hr)){	goto done;	}
    	hr = m_pCaptureEngine->GetSource(&pCaptureSource);	if (FAILED(hr)){	goto done;	}
    	// Clear any existing streams from previous recordings.
    	hr = pRecordSink->RemoveAllStreams();	if (FAILED(hr)){	goto done;	}
    	hr = pRecordSink->SetOutputFileName(tzDestinationFile);		if (FAILED(hr)){	goto done;	}
    	hr = ConfigureVideoEncoding(pCaptureSource, pRecordSink, MFVideoFormat_H264);	if (FAILED(hr)){	goto done;	}
    	hr = m_pCaptureEngine->StartRecord();	if (FAILED(hr)){	goto done;	}
    	m_bRecording = true;		
        return hr;	
    HRESULT ConfigureVideoEncoding(IMFCaptureSource *pCaptureSource, IMFCaptureRecordSink *pRecordSink, REFGUID guidEncodingType)
    	IMFMediaType *pMediaType = NULL;
    	IMFMediaType *pH264MediaType = NULL;
    	GUID guidSubType = GUID_NULL;
    	if((pCaptureSource == NULL) || (pRecordSink == NULL) || (guidEncodingType == GUID_NULL))
    		return E_FAIL;
    	// Configure the video format for the recording sink.
    	HRESULT hr = pCaptureSource->GetCurrentDeviceMediaType((DWORD)MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_RECORD , &pMediaType);	if (FAILED(hr)){	goto done;	}
    	if(pMediaType == NULL)
    		return E_FAIL;
    	hr = ConfigureH264EncoderMediaType(pMediaType, guidEncodingType, &pH264MediaType);	if (FAILED(hr)){	goto done;	}
    	// Connect the video stream to the recording sink.		
    	DWORD dwSinkStreamIndex = 0;
    	hr = pRecordSink->AddStream((DWORD)MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_RECORD, pH264MediaType, NULL, &dwSinkStreamIndex);	if (FAILED(hr)){	goto done;	}
        return hr;

    In addition to that, I'm posting the access violation exception and my PC configuration here. I hope this will be helpful to find the root cause.


    First-chance exception at 0x75151A65 in .exe: Microsoft C++ exception: _com_error at memory location 0x0312F538.
    First-chance exception at 0x75151A65 in .exe: Microsoft C++ exception: _com_error at memory location 0x0312F538.
    First-chance exception at 0x53D9FF4C (mfreadwrite.dll) in .exe: 0xC0000005: Access violation reading location 0x00000000.
    Unhandled exception at 0x53D9FF4C (mfreadwrite.dll) in .exe: 0xC0000005: Access violation reading location 0x00000000.


    System Information
    Time of this report: 5/9/2018, 18:17:57
           Machine name: WindowsTeam
       Operating System: Windows 8 Pro 32-bit (6.2, Build 9200) (9200.win8_gdr.151112-0600)
               Language: English (Regional Setting: English)
    System Manufacturer: Dell Inc.
           System Model: Vostro 3900  
                   BIOS: BIOS Date: 03/03/15 15:17:01 Ver: 04.06.05
              Processor: Intel(R) Core(TM) i5-4460  CPU @ 3.20GHz (4 CPUs), ~3.2GHz
                 Memory: 4096MB RAM
    Available OS Memory: 3502MB RAM
              Page File: 1139MB used, 3003MB available
            Windows Dir: C:\Windows
        DirectX Version: DirectX 11
    DX Setup Parameters: Not found
       User DPI Setting: Using System DPI
     System DPI Setting: 96 DPI (100 percent)
        DWM DPI Scaling: Disabled
         DxDiag Version: 6.02.9200.16384 32bit Unicode

    I investigated in many ways but I could not get any clue to solve this issue. I was stick with the issue for past one week. 

    May I know why this issue is occurring only on Windows 8 32bit?

    Let me know if you require any other information from my end.

    Thanks in advance.

    • Edited by KSM Abi Wednesday, May 9, 2018 2:00 PM
    Wednesday, May 9, 2018 1:58 PM

All replies

  • I solved this issue by myself
    • Marked as answer by KSM Abi Wednesday, June 27, 2018 6:20 AM
    • Unmarked as answer by KSM Abi Wednesday, June 27, 2018 6:20 AM
    Wednesday, June 27, 2018 6:20 AM
  • what is a solution ?
    Monday, April 29, 2019 4:46 PM