VC/MFC 音频/视频Q:如何判断视频媒体文件的格式?
A:
directshow: IGraphBuilder::AddSourceFilter ( LPCWSTR lpcwstrFileName, LPCWSTR lpcwstrFilterName, IBaseFilter **ppFilter)加入文件名得到文件pFilter指针,然后得到pFilter的输出pin,然后大概如下面函数判断类型:
typedef enum
{
TYPE_UNKNOWN,
TYPE_MPEG1,
TYPE_MPEG2,
TYPE_AVI,
......
}MEDIA_TYPE;
HRESULT GetMediaTypeByPin(IPin *pPin, MEDIA_TYPE* pemType)
{
HRESULT hr;
ULONG n;
AM_MEDIA_TYPE mt;
AM_MEDIA_TYPE *pmt = NULL;
CComPtr pEnumMt;
if(FAILED(hr=pPin->EnumMediaTypes(&pEnumMt)))
return hr;
BOOL bGot = FALSE;
pEnumMt->Reset();
while(! bGot && pEnumMt->Next(1, &pmt, &n)==S_OK)
{
if(pmt->majortype != GUID_NULL)
{
memcpy(&mt, pmt, sizeof(mt));
bGot = TRUE;
}
DeleteMediaType(pmt);
}
if(! bGot)
return E_FAIL;
// MPEG1
if(mt.majortype == MEDIATYPE_Stream &&
(mt.subtype == MEDIASUBTYPE_MPEG1System||mt.subtype==MEDIASUBTYPE_MPEG1Video || mt.subtype == MEDIASUBTYPE_MPEG1VideoCD )
)
{
*pemType = TYPE_MPEG1;
}
// MPEG2
else if(mt.majortype == MEDIATYPE_Stream &&
(mt.subtype == MEDIASUBTYPE_MPEG2_PROGRAM || mt.subtype==MEDIASUBTYPE_MPEG2_TRANSPORT)
)
{
*pemType = TYPE_MPEG2;
}
// AVI
else if(mt.majortype == MEDIATYPE_Stream &&
mt.subtype == MEDIASUBTYPE_Avi)
{
*pemType = TYPE_AVI;
}
...... // 加上其他判断类型
else
{
*pemType = TYPE_UNKNOWN;
}
return S_OK;
}
阅读(844) | 评论(0) | 转发(0) |