本质上,我正在构建HDV捕获图。我在图形生成器中具有图形功能,并且效果很好。可以在here中看到图形构建器图形。到目前为止,代码中的图形应该转到HDV Camera-> Demultiplexer-> FFDshow。但是我得到了VFW_E_NO_ACCEPTABLE_TYPES“这些引脚之间没有通用的媒体类型。”错误。我尝试在mt结构中使用不同的子媒体类型,但是没有运气。
编辑以澄清:
错误是连接多路复用器和ffdshow解码器。
相关代码(getPin枚举对象上的引脚并返回名为IPin的LPCOLESTR)
HRESULT hr = S_OK;
//graph builder
CComPtr<ICaptureGraphBuilder2> pBuilder;
hr = pBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2);
CHECK_HR(hr, "Can't Create Capture Graph Builder");
hr = pBuilder->SetFiltergraph(pGraph);
//add Canon XH A1S
CComPtr<IBaseFilter> pCanonXHA1S = GetCaptureDevice(CLSID_VideoInputDeviceCategory, L"Canon XH A1S");
hr = pGraph->AddFilter(pCanonXHA1S, L"Canon XH A1S");
CHECK_HR(hr, "Can't add Canon XH A1 to Graph");
//add MPEG-2 Demultiplexer
CComPtr<IBaseFilter> pMPEG2Demultiplexer;
hr = pMPEG2Demultiplexer.CoCreateInstance(CLSID_MPEG2Demultiplexer);
CHECK_HR(hr, "Can't create MPEG-2 Demultiplexer");
hr = pGraph->AddFilter(pMPEG2Demultiplexer, L"MPEG-2 Demultiplexer");
CHECK_HR(hr, "Can't add MPEG-2 Demultiplexer to graph");
//connect Canon XH A1S and MPEG-2 Demultiplexer
hr = pGraph->ConnectDirect(GetPin(pCanonXHA1S, L"MPEG2TS Out"), GetPin(pMPEG2Demultiplexer, L"MPEG-2 Stream"), NULL);
CHECK_HR(hr, "Can't connect Canon XH A1S and MPEG-2 Demultiplexer");
//This block configures the demultiplexer
IMpeg2Demultiplexer *pDemux;
IPin *pDemuxPin;
IMPEG2PIDMap *pPidMap;
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
mt.majortype = MEDIATYPE_Video;
pMPEG2Demultiplexer->QueryInterface(IID_IMpeg2Demultiplexer, (void**)&pDemux);
if(hrcheck(hr, "Can't find MPEG2 Demux interface"))
return E_FAIL;
hr = pDemux->CreateOutputPin(&mt, L"MPEG2 Out", &pDemuxPin);
if(hrcheck(hr, "Can't create Output Pin on MPEG2 Demux"))
return E_FAIL;
hr = pDemuxPin->QueryInterface(IID_IMPEG2PIDMap, (void**)&pPidMap);
if(hrcheck(hr, "Can't create PIDMap"))
return E_FAIL;
// Assign PID 0x31 to pin 0. Set the type to "PES payload."
ULONG Pid = 0x30;
hr = pPidMap->MapPID(1, &Pid, MEDIA_ELEMENTARY_STREAM);
if(hrcheck(hr, "Problem mapping PID pins"))
return E_FAIL;
CComPtr<IBaseFilter> pFFDshowVideoDecoder;
hr = pFFDshowVideoDecoder.CoCreateInstance(CLSID_FFDshowVideoDecoder);
CHECK_HR(hr, "Can't create ffdshow Video Decoder");
hr = pGraph->AddFilter(pFFDshowVideoDecoder, L"ffdshow Video Decoder");
CHECK_HR(hr, "ffdshow Video Decoder");
hr = pGraph->ConnectDirect(pDemuxPin, GetPin(pFFDshowVideoDecoder, L"In"), &mt);
if(hrcheck(hr, "Problem with renderstream"))
return E_FAIL;
最佳答案
发现问题出在创建时传递给输出引脚的AM_MEDIA_TYPE结构的声明中。我使用的结构:
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_MPEG2_VIDEO;
mt.formattype = FORMAT_MPEG2Video;
mt.cbFormat = sizeof(MPEG2VIDEOINFO);
mt.pbFormat = (BYTE*)CoTaskMemAlloc(mt.cbFormat);
if (mt.pbFormat == NULL)
{
}
ZeroMemory(mt.pbFormat, mt.cbFormat);
MPEG2VIDEOINFO *pMVIH = (MPEG2VIDEOINFO*)mt.pbFormat;
RECT rcSrc = {0, 1080, 0, 1440}; // Source rectangle.
pMVIH->hdr.rcSource = rcSrc;
pMVIH->hdr.dwBitRate = 4000000; // Bit rate.
pMVIH->hdr.AvgTimePerFrame = 333667; // 29.97 fps.
pMVIH->hdr.dwPictAspectRatioX = 16; // 4:3 aspect ratio.
pMVIH->hdr.dwPictAspectRatioY = 9;
pMVIH->dwLevel = AM_MPEG2Profile_Main; // MPEG-2 profile.
pMVIH->dwProfile = AM_MPEG2Level_Main; // MPEG-2 level.
关于c++ - 连接IMPEG2DEMULTIPLEXER和ffdshow Directshow过滤器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5543407/