Getting height and width of video
This page shows you how to obtain width and height from a video file. Please note that error handling codes are omitted to keep the sample code simple.
Sample code
The following sample code shows how to get height and width from a video media file. Please note that this sample does not play the MPEG file. It ends right away.
#include <stdio.h>
#include <dshow.h>
// change here
#define FILENAME L"c:\\DXSDK\\Samples\\Media\\butterfly.mpg"
int
main()
{
IGraphBuilder *pGraphBuilder;
IMediaControl *pMediaControl;
IBasicVideo *pBasicVideo;
CoInitialize(NULL);
CoCreateInstance(CLSID_FilterGraph,
NULL,
CLSCTX_INPROC,
IID_IGraphBuilder,
(LPVOID *)&pGraphBuilder);
pGraphBuilder->QueryInterface(IID_IMediaControl,
(LPVOID *)&pMediaControl);
pMediaControl->RenderFile(FILENAME);
pGraphBuilder->QueryInterface(IID_IBasicVideo,
(LPVOID *)&pBasicVideo);
// obtain width and height
long height, width;
pBasicVideo->get_VideoHeight(&height);
pBasicVideo->get_VideoWidth(&width);
printf("width=%d, height=%d\n", width, height);
// release
pBasicVideo->Release();
pMediaControl->Release();
pGraphBuilder->Release();
CoUninitialize();
return 0;
}