How can I know the input video resolution using directshow?

Sebastiano Zannoli 1 Reputation point
2022-03-22T11:15:21.65+00:00

Using DirectShow with a video acquisition card, is it possible to ask/know the resolution of the acquired video? Normally we know le list of available resolutions of the acquisition card, then we try to use each of them...
The best could be to use the DirectShow sw library to get the specific resolution of the acquired video.

Community Center | Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-03-23T09:49:27.203+00:00

    Hello,
    Welcome to Microsoft Q&A!

    I recommend using IAMStreamConfig interface.

    Applications can use this interface to set format properties, such as the output dimensions and frame rate (for video) or the sample rate and number of channels (for audio).

    Use IAMStreamConfig::GetFormat method to retrieves the current or preferred output format.

    I don't have video capture equipment around me, so I can only provide feasible sample for your reference. I hope it will be helpful to you.

    HRESULT hr;  
    IAMStreamConfig* pConfig = 0;  
    
    hr = pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, 0, pDeviceFilter, IID_IAMStreamConfig, (void**)& pConfig);  
    
    int iCount = 0, iSize = 0;  
    hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);  
    
    // Check the size to make sure we pass in the correct structure.  
    if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS))  
    {  
    	// Use the video capabilities structure.  
    
    	for (int iFormat = 0; iFormat < iCount; iFormat++)  
    	{  
    		VIDEO_STREAM_CONFIG_CAPS scc;  
    		AM_MEDIA_TYPE* pmtConfig;  
    		hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)& scc);  
    		if (SUCCEEDED(hr))  
    		{  
    			/* Examine the format, and possibly use it. */  
    			if ((pmtConfig->majortype == MEDIATYPE_Video) &&  
    				(pmtConfig->subtype == MEDIASUBTYPE_RGB24) &&  
    				(pmtConfig->formattype == FORMAT_VideoInfo) &&  
    				(pmtConfig->cbFormat >= sizeof(VIDEOINFOHEADER)) &&  
    				(pmtConfig->pbFormat != NULL))  
    			{  
    				VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;  
    				// pVih contains the detailed format information.  
    				LONG lWidth = pVih->bmiHeader.biWidth;  
    				LONG lHeight = pVih->bmiHeader.biHeight;  
    				if (lWidth == 1280)  
    				{ //2 = '1280x720YUV' YUV, 22 = '1280x800YUV', 26 = '1280x720RGB'  
    					hr = pConfig->SetFormat(pmtConfig);  
    				}  
    			}  
    			// Delete the media type when you are done.  
    			DeleteMediaType(pmtConfig);  
    		}  
    	}  
    }  
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.