连接 IMPEG2DEMULTIPLEXER 和 ffdshow Directshow Filter

发布于 2024-10-30 19:21:27 字数 2839 浏览 2 评论 0原文

本质上我正在构建一个 HDV 捕获图。我的图表在图表生成器中运行并且运行良好。可以在此处查看图形生成器图形。在代码中,到目前为止的图表应该是 HDV Camera ->解复用器-> FFD秀。但我得到一个 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;

Essentially I am building a HDV capture graph. I have the graph functioning in graph builder and it works well. The graph builder graph can be seen here. In code the graph so far should go HDV Camera -> Demultiplexer -> FFDshow. But I get a VFW_E_NO_ACCEPTABLE_TYPES "There is no common media type between these pins." error. I have tried using different submedia types in the mt structure but no luck.

Edit to clarify:
the error is connecting the multiplexer and the ffdshow decoder.

Relevant code (getPin enumerates the pins on an object and returns the LPCOLESTR named IPin)

    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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

焚却相思 2024-11-06 19:21:27

发现问题出在创建时传递到输出引脚的 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.

The problem was found to be in the declaration of the AM_MEDIA_TYPE structure passed to the output pin on creation. The structure I used:

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文