none
Problem change resolution DirectShow Setformat() Error HRESULT = 0x80040200,

    Question

  •  I was trying to change resolution using DirectShow Setformat(). but Setformat return to Error HRESULT = 0x80040200, 
    My development environment : VS2008 C++,Windows SDK 7, DeskTop PC = intel i5core, WebCam : Microsoft Life cam cinema or Life cam
    Please help me T_T
    
    
    //---------------------------------------------------------------------------------------------------------------------//
    //---------------------------------------------------------------------------------------------------------------------//
    // 	HWND			hOwner;				
    // 	IGraphBuilder	* pGraphBldr;		
    // 	ICaptureGraphBuilder	* pCaptureBuilder;
    // 	ICaptureGraphBuilder2	* pCapGraphBldr;
    // 	ISpecifyPropertyPages * pCaptureFilterProp;
    // 	IBaseFilter		* pVideoCapFilter;	
    // 	IMediaControl	* pMediaCtl;		
    // 	IVideoWindow	* pVidWin;			
    // 	IAMStreamConfig	* pConfig ;	
    
    //-----------------init member variable
    /* 
    	this->hOwner = NULL;
    	this->pGraphBldr = NULL;
    	this->pCapGraphBldr = NULL;
    	this->pVideoCapFilter = NULL;
    	this->pMediaCtl = NULL;
    	this->pVidWin = NULL;
    	this->pCaptureFilterProp = NULL;
    	this->pCaptureBuilder=NULL;
    */
    HRESULT CreateFilterGraph(WCHAR szCameraDeviceFriendlyName[])
    {
    	// szCameraDeviceFriendlyName is webcam device name
    
    
    	HRESULT hr;
    
    	if (this->pGraphBldr)
    
    		this->ReleaseFilterGraph();
    
    	//---------------------------------------------------
    
    	// Create FilterGraph and CaptureGraphBuilder
    	hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&(this->pGraphBldr));
    	if (FAILED(hr))
    	{
    		TRACE1(L"[DomoneRecorder::CreateFilterGraph] Failed HRESULT: 0x%x\n", hr);
    		return hr;
    	}
    
    	hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&(this->pCapGraphBldr));
    	if (FAILED(hr))
    	{
    		TRACE1(L"[DomoneRecorder::CreateFilterGraph] Failed CoCreateInstance CaptureGraphBuilder2 HRESULT: 0x%x\n", hr);
    		return hr;
    	}
    	hr = pCapGraphBldr->SetFiltergraph(pGraphBldr);
    	if (FAILED(hr))
    	{
    		TRACE1(L"[DomoneRecorder::CreateFilterGraph] Failed SetFiltergraph HRESULT: 0x%x\n", hr);
    		return hr;
    	}
    
    	//---------------------------------------------------
    	// CreateFilterOfCategory using Devicename
    
    	hr = DShowSupporter::CreateFilterOfCategory(CLSID_VideoInputDeviceCategory, szCameraDeviceFriendlyName, &this->pVideoCapFilter, pGraphBldr);
    	if (FAILED(hr))
    	{
    		TRACE1(L"[DomoneRecorder::CreateFilterGraph] Failed CreateFilterOfCategory HRESULT: 0x%x\n", hr);
    		return hr;
    	}
    
    	//---------------------------------------------------
    	// Complite FilterGraph
    
    	hr = pCapGraphBldr->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, this->pVideoCapFilter, NULL, NULL);
    	if (FAILED(hr))
    	{
    		TRACE1(L"[DomoneRecorder::CreateFilterGraph] Failed RenderStream HRESULT: 0x%x\n", hr);
    		return hr;
    	}
    
    	//---------------------------------------------------
    	// QueryInterface to IMediaControl
    
    	hr = this->pGraphBldr->QueryInterface(IID_IMediaControl, (void**)&this->pMediaCtl);
    	if (FAILED(hr))
    	{
    		TRACE1(L"[DomonePlayer::CreateFilterGraph] IMediaControl Failed QueryInterface. HRESULT: 0x%x\n", hr);
    		return hr;
    	}
    
    	//--------------------------------------------------------------------------------
    
    	// QueryInterface to IVideoWindow
    
    	hr = this->pGraphBldr->QueryInterface(IID_IVideoWindow, (void**)&this->pVidWin);
    
    	if (FAILED(hr))
    	{
    		TRACE1(L"[DomonePlayer::CreateFilterGraph] IVideoWindow Failed QyeryInterface HRESULT: 0x%x\n", hr);
    		return hr;
    	}
    
    	////--------------------------------------------------------------------------------Here, change resolution
    
    	hr =pCapGraphBldr->FindInterface(&PIN_CATEGORY_CAPTURE,0,pVideoCapFilter,IID_IAMStreamConfig,(void **)&pConfig);
    	VIDEO_STREAM_CONFIG_CAPS scc;
    	AM_MEDIA_TYPE *pCureMediaType = NULL;
    	AM_MEDIA_TYPE *pNewMediaType = NULL;
    	hr = pConfig->GetFormat(&pCureMediaType);
    	hr = pConfig->GetStreamCaps(1,&pNewMediaType,(BYTE *)&scc); // here 0~7 available, 
    	if(MEDIATYPE_Video == pCureMediaType->majortype)
    	{
    		if(FORMAT_VideoInfo == pCureMediaType->formattype)
    		{
    
    			VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pCureMediaType->pbFormat;
    			VIDEOINFOHEADER *pVih2 = (VIDEOINFOHEADER *)pNewMediaType->pbFormat;
    			pVih->dwBitRate = pVih2->dwBitRate;
    			pVih->dwBitErrorRate = pVih2->dwBitErrorRate;
    			pVih->AvgTimePerFrame = pVih2->AvgTimePerFrame;
    			pVih->bmiHeader.biWidth = pVih2->bmiHeader.biWidth;
    			pVih->bmiHeader.biHeight = pVih2->bmiHeader.biHeight;
    			pVih->bmiHeader.biPlanes = pVih2->bmiHeader.biPlanes;
    			pVih->bmiHeader.biBitCount = pVih2->bmiHeader.biBitCount;
    			pVih->bmiHeader.biCompression = pVih2->bmiHeader.biCompression;
    			pVih->bmiHeader.biSizeImage = pVih2->bmiHeader.biSizeImage;
    			pVih->bmiHeader.biXPelsPerMeter = pVih2->bmiHeader.biXPelsPerMeter;
    			pVih->bmiHeader.biYPelsPerMeter = pVih2->bmiHeader.biYPelsPerMeter;
    			pVih->bmiHeader.biClrUsed = pVih2->bmiHeader.biClrUsed;
    			pVih->bmiHeader.biClrImportant = pVih2->bmiHeader.biClrImportant;
    
    			// hr = pConfig->SetFormat(pNewMediaType); // another method is same error	
    			hr = pConfig->SetFormat(pCureMediaType); //
    
    			if (FAILED(hr))
    				TRACE1(L"SetFormat Failed : HRESULT = 0x%x",hr); 
    
    			return S_FALSE;
    
    		}
    	}
    }	
    
    
    
    
    • Edited by JongSeonKim Thursday, September 02, 2010 7:19 AM easily read
    Thursday, September 02, 2010 6:56 AM

Answers

All replies

  • The error code is "An invalid media type was specified." Break before SetFormat call and check what exactly you are providing as argument, you probably have something wrong there with your pCureMediaType.


    http://alax.info/blog/tag/directshow
    Thursday, September 02, 2010 8:21 AM
  • Thanks for your reply.

    I Trying to your point.

    Thursday, September 02, 2010 8:41 AM
  • I tried your point that MediaType was woring.

    but, I don't know How can i modity my code.

    so, I print my MediaType.

    //////////////////////////////////////////////////////////////////////

    pMT->bFixedSizeSamples? Yes
    pMT->bTemporalCompression? No
    pMT->lSampleSize: 921600 Byte
    szFormatType: {47504A4D-0000-0010-8000-00AA00389B71}
    pMT->cbFormat: 88 bytes

    Video info header(Video info header)
      pVih->dwBitRate: 184320000
      pVih->dwBitErrorRate: 0
      pVih->AvgTimePerFrame 400000
     Bitmap Info Header (Bitmap Info Header)
        pVih->bmiHeader.biWidth:  640
        pVih->bmiHeader.biHeight: 480
        pVih->bmiHeader.biPlanes: 1
        pVih->bmiHeader.biBitCount: 24
        pVih->bmiHeader.biCompression 1196444237
        pVih->bmiHeader.biSizeImage: 921600 Byte
        pVih->bmiHeader.biXPelsPerMeter: 0
        pVih->bmiHeader.biYPelsPerMeter: 0
        pVih->bmiHeader.biClrUsed: 0
        pVih->bmiHeader.biClrImportant: 0
    ///////////////////////////////////////////////////////////////////////////

    My wab cam support MediaType.subtype : MJPG (47504A4D-0000-0010-8000-00AA00389B71).

    actually I lost my way how can i coding for resolution chang..

    Please.. I need your Tip. 

     

    Thursday, September 02, 2010 9:45 AM
  • Another point : some capture filters do not accept to change the mediatype when connected. Try to set the mediatype before doing RenderStream.
    Michel Roujansky, http://www.roujansky.com
    Thursday, September 02, 2010 4:27 PM
    Moderator
  • Thank you.

    I will try your another point.

     

     

    Friday, September 03, 2010 12:24 AM
  • Suggestion worked for me ...!!

    Thanks

    Thursday, February 09, 2017 1:08 PM