永发信息网

求问:directshow设置视频流格式

答案:2  悬赏:80  手机版
解决时间 2021-02-25 11:28
  • 提问者网友:像風在裏
  • 2021-02-25 06:37
环境:directx9 (feb 2005)sdk + vs2005 + xp pro sp2
目的:修改视频格式,使输出176x144的rgb24视频流
做法:
bool CCaptureVideo::SetCaptureSize(int width, int height)
{int iCount, iSize;
HRESULT hr;
VIDEO_STREAM_CONFIG_CAPS scc;
AM_MEDIA_TYPE *pmt;

IAMStreamConfig *pConfig = NULL;
hr = m_pCapture->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, // Any media type.
m_pBF, // Pointer to the capture filter.
IID_IAMStreamConfig, (void**)&pConfig);
if(FAILED(hr))
{
return hr;
}
hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);
if (sizeof(scc) != iSize)
{
// This is not the structure we were expecting.
return E_FAIL;
}
// Get the first format.
for(int mm=0; mm< iCount; mm++)
{
hr = pConfig->GetStreamCaps(mm, &pmt, reinterpret_cast(&scc));
if (hr == S_OK)
{
if ((pmt->majortype==MEDIATYPE_Video && pmt->formattype == FORMAT_VideoInfo &&
pmt->subtype == MEDIASUBTYPE_RGB24))
{
// Find the smallest output size.
//LONG width = scc.MinOutputSize.cx;
//LONG height = scc.MinOutputSize.cy;
LONG cbPixel = 3; // Bytes per pixel in UYVY
// Modify the format block.
VIDEOINFOHEADER *pVih =
reinterpret_cast(pmt->pbFormat);
pVih->bmiHeader.biWidth = width;
pVih->bmiHeader.biHeight = height;
// Set the sample size and image size.
// (Round the image width up to a DWORD boundary.)
pmt->lSampleSize = pVih->bmiHeader.biSizeImage = //176*144*3;
((width + 3) & ~3) * height * cbPixel;
// Now set the format.
hr = pConfig->SetFormat(pmt);
if (FAILED(hr))
{
//MessageBox(NULL, TEXT("SetFormat Failed\n"), NULL, MB_OK);
}
}
else{
}
DeleteMediaType(pmt);
}else
{
}
}
return true;
}
网上很多参考都是这样写的,代码应该是没问题的。但是调试后发现GetStreamCaps输出的AM_MEDIA_TYPE的subtype字段总是为 MEDIASUBTYPE_YUY2。而我又用另外一种方法去枚举采集filter的pin,发现每个pin的AM_MEDIA_TYPE的 subtype字段也是MEDIASUBTYPE_YUY2。

其方法如下:
IPin * CCaptureVideo::GetVideoPin(IBaseFilter * pFilter)
{
IEnumPins * m_EnumPins;
HRESULT hr = E_FAIL;

hr = pFilter->EnumPins(&m_EnumPins);
if(FAILED(hr))
{
return NULL;
}
IPin * pin = NULL;
bool b_getPin = false;
ULONG n_get = 0;
while(S_OK == m_EnumPins->Next(1, &pin, &n_get) && b_getPin==false)
{
PIN_DIRECTION pin_dir;
pin->QueryDirection(&pin_dir);
if(pin_dir == PINDIR_OUTPUT)
{

IEnumMediaTypes * p_Enum_MediaType;

hr = pin->EnumMediaTypes(&p_Enum_MediaType);
if(FAILED(hr))
{
continue;
}
AM_MEDIA_TYPE * p_am_type;
ULONG n_types = 0;
while(S_OK == p_Enum_MediaType->Next(1, &p_am_type, &n_types) && b_getPin==false)
{
if(p_am_type->majortype == MEDIATYPE_Video && p_am_type->subtype==MEDIASUBTYPE_RGB24)
{
b_getPin = true;
}

DeleteMediaType(p_am_type);
p_am_type = NULL;
}
p_Enum_MediaType->Release();
}
}
m_EnumPins->Release();
if(b_getPin == true)
re
最佳答案
  • 五星知识达人网友:妄饮晩冬酒
  • 2021-02-25 06:54
说明视频捕获设备的输出是YUY2,如果需要输出RGB24,需要另外做一个转换
全部回答
  • 1楼网友:duile
  • 2021-02-25 07:06
最有可能是会声会影9坏了,重装。还可能是directx安装不成功,重装directx。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯