将x264vfw连接到自定义源过滤器

时间:2015-02-03 14:20:17

标签: c++ visual-c++ directshow

我尝试将自定义源过滤器连接到x264。我可以将它连接到leadtools编码器,主要概念编码器。我可以直接在graphedit中连接它们。我得到HR结果0x80040207 VFW_E_NO_ACCEPTABLE_TYPES。

HRESULT CStreaming::Init(){
    CoInitialize(NULL);
    HRESULT hr;
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&m_pGraph));
#ifdef _DEBUG
    DWORD dwRegister;
    hr = AddToRot(m_pGraph, &dwRegister);
#endif
    A_CheckResult(hr);
    IBaseFilter* pSource;
    IBaseFilter* pEncoder;
    IBaseFilter* pColorSpaceConverter;
    IBaseFilter* pTransport;
    FILTER_INFO pfi;

    /* Source Filter*/
    hr = InitFilter(StreamingFilterGUID, &pSource);
    A_CheckResult(hr);
    hr = pSource->QueryFilterInfo(&pfi);
    A_CheckResult(hr);
    hr = m_pGraph->AddFilter(pSource, pfi.achName);
    A_CheckResult(hr);

    hr = InitFilter(x264EncodeGUID, &pEncoder);  
    A_CheckResult(hr);
    hr = pEncoder->QueryFilterInfo(&pfi);
    A_CheckResult(hr);
    hr = m_pGraph->AddFilter(pEncoder, pfi.achName);
    A_CheckResult(hr);
    ...
    /* Queryt Control and Events */
    hr = m_pGraph->QueryInterface(IID_PPV_ARGS(&m_pControl));
    A_CheckResult(hr);
    hr = m_pGraph->QueryInterface(IID_PPV_ARGS(&m_pEvent));
    A_CheckResult(hr);

    /* Connect */
    hr = ConnectFilters(pSource, pEncoder);
    A_CheckResult(hr);
    hr = ConnectFilters(pEncoder, pColorSpaceConverter);
    A_CheckResult(hr);
    hr = ConnectFilters(pColorSpaceConverter, pTransport);
    A_CheckResult(hr);

    /* Release */
    SafeRelease(&pSource);
    SafeRelease(&pEncoder);
    SafeRelease(&pColorSpaceConverter);
    SafeRelease(&pTransport);

    return S_OK;
}

从MSDN直接连接Filler

HRESULT CStreamingAgent::ConnectFilters(IBaseFilter *pSrc, IBaseFilter *pDest)
{
    IPin *pOut = NULL;

    // Find an output pin on the first filter.
    HRESULT hr = FindUnconnectedPin(pSrc, PINDIR_OUTPUT, &pOut);
    if (SUCCEEDED(hr))
    {
        hr = ConnectOutputPinToFilter(pDest, pOut);
        pOut->Release();
    }
    return hr;
}

ConnectOutputPinToFilter已修改,但主要来自MSDN

HRESULT CStreamingAgent::ConnectOutputPinToFilter(IBaseFilter *pDest,IPin *pOut)
{
    IPin *pIn = NULL;

    // Find an input pin on the downstream filter.
    HRESULT hr = FindUnconnectedPin(pDest, PINDIR_INPUT, &pIn);
    if (SUCCEEDED(hr))
    {
        // Try to connect them.
        hr = m_pGraph->ConnectDirect(pOut, pIn, NULL);
        pIn->Release();
    }
    return hr;
}

在ConnectOutputPinToFilter中,我检查了每个引脚的MajorType和Subtype,它们匹配。
我的自定义输出滤镜硬编码为输出RGB32 1920x1080 24fp Init过滤器是一个包含cocreate的包装器,带有一些错误检查和一个addref

#define A_CheckResult(p) {if ((FAILED(p))) return(p);}

1 个答案:

答案 0 :(得分:1)

x264vfw不是标准过滤器。旧的VFW(Video for Windows)编解码器被包装并且所有共享CLSID。您需要使用友好名称或名字对象名称进行查找。此代码行不适用:

hr = InitFilter(x264EncodeGUID, &pEncoder);

这里的说明: Choosing a Compression Filter

另请参阅:Encoding with DirectShow filters