通过私有 CoCreateInstance 使用 DirectShow 过滤器而不注册它 [英] Using a DirectShow filter without registering it, via a private CoCreateInstance

查看:14
本文介绍了通过私有 CoCreateInstance 使用 DirectShow 过滤器而不注册它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我读了这个,http://www.gdcl.co.uk/2011/June/UnregisteredFilters.htm.

So basiclly I read this, http://www.gdcl.co.uk/2011/June/UnregisteredFilters.htm.

它告诉您如何在不注册的情况下使用过滤器.有两种方法,新方法和使用私有 CoCreateInstance.我正在尝试使用 CoCreateInstance 方法.

Which tells you how to use filters without registering them. There are two methods, new and using a private CoCreateInstance. Im trying to use the CoCreateInstance method.

在网站的示例中,代码被列为,

In the sample from the site the code is listed as,

IUnknownPtr pUnk;
HRESULT hr = CreateObjectFromPath(TEXT("c:\path\to\myfilter.dll"), IID_MyFilter, &pUnk);
if (SUCCEEDED(hr))
{
    IBaseFilterPtr pFilter = pUnk;
    pGraph->AddFilter(pFilter, L"Private Filter");
    pGraph->RenderFile(pMediaClip, NULL);
}

我的代码如下,

IUnknownPtr pUnk;
HRESULT hr = CreateObjectFromPath(TEXT("c:\filters\mp4demux.dll"), IID_BaseFilter, &pUnk);
if (SUCCEEDED(hr))
{
  //add functionality
}

我猜 IID_BaseFilter 是我应该使用的,它是我用于其他过滤器的.但我收到错误ClassFactory 无法提供请求的类".

I'm guessing IID_BaseFilter is what Im supposed to use, its what I use for other filters. But I'm given the error 'ClassFactory cannot supply requested class'.

我在这里遗漏了什么吗?任何帮助将不胜感激.提前致谢!

Am I missing something here? Any help would be greatly appreciated. Thanks in advance!

代码

IBaseFilter *pSrc = NULL, *pSrc2 = NULL, *pWaveDest = NULL, *pWriter = NULL;
IFileSinkFilter *pSink= NULL;
IGraphBuilder *pGraph;
ICaptureGraphBuilder2 *pBuild;
IMediaControl *pControl = NULL;
// This example omits error handling.

hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER,
    IID_ICaptureGraphBuilder2, (void**)&pBuild);

hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&pGraph);
//Initialize the Capture Graph Builder
hr = pBuild->SetFiltergraph(pGraph);

// Not shown: Use the System Device Enumerator to create the 
// audio capture filter.
hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pSrc);
hr = pGraph->AddFilter(pSrc, L"VideooCap");

hr = pMoniker2->BindToObject(0, 0, IID_IBaseFilter, (void**)&pSrc2);
hr = pGraph->AddFilter(pSrc2, L"AudioCap");

IBaseFilter *pMux;
//IFileSinkFilter *pSink;
hr = pBuild->SetOutputFileName(
    &MEDIASUBTYPE_Avi,  // Specifies AVI for the target file.
    L"C:\wav\Example2.mp4", // File name.
    &pMux,              // Receives a pointer to the mux.
    NULL);              // (Optional) Receives a pointer to the file sink.

IUnknownPtr pUnk;
//static CLSID const clsid = { 0x025BE2E4, 0x1787, 0x4DA4, { 0xA5,0x85,0xC5,0xB2,0xB9,0xEE,0xB5,0x7C } };

static CLSID const clsid = { 0x5FD85181, 0xE542, 0x4e52, { 0x8D,0x9D,0x5D,0x61,0x3C,0x30,0x13,0x1B } };
//5FD85181-E542-4e52-8D9D5D613C30131B
HRESULT hr = CreateObjectFromPath(TEXT("c:\filters\mp4mux.dll"), clsid, &pUnk);
if (SUCCEEDED(hr))
{
    IBaseFilterPtr pFilter = pUnk;
    HRESULT hr = pGraph->AddFilter(pFilter, L"Private Filter");
}

hr = pBuild->RenderStream(
    NULL,//NULL,//&PIN_CATEGORY_CAPTURE, // Pin category.
    NULL,//&MEDIATYPE_Interleaved,//NULL,//&MEDIATYPE_Audio,      // Media type.
    pSrc,                  // Capture filter.
    NULL,                  // Intermediate filter (optional).
    pMux);                 // Mux or file sink filter.

hr = pBuild->RenderStream(
    NULL,//NULL,//&PIN_CATEGORY_CAPTURE, // Pin category.
    NULL,//&MEDIATYPE_Interleaved,//NULL,//&MEDIATYPE_Audio,      // Media type.
    pSrc2,                  // Capture filter.
    NULL,                  // Intermediate filter (optional).
    pMux);                 // Mux or file sink filter.

    IMediaControl *pMC = NULL;
    hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pMC);
    printf("START");  
    hr = pMC->Run();
    Sleep(4000);
      hr = pMC->Stop();
    printf("END");  
CoUninitialize();
    }
}

推荐答案

你应该重新阅读 使用过滤器无需注册.第二个参数是CLSID,类标识符,不是接口标识符(IBaseFilter).

You should re-read Using Filters Without Registration. The second parameter is CLSID, the class identifier, not interface identifier (IBaseFilter).

对于 GDCL MPEG-4 Demultiplexer,它是这样的:

For the GDCL MPEG-4 Demultiplexer, it is like this:

class __declspec(uuid("025BE2E4-1787-4DA4-A585-C5B2B9EEB57C")) GdclMp4Demux; // GDCL Mpeg-4 Demultiplexor
... = CreateObjectFromPath(..., __uuidof(GdclMp4Demux), ...);

这篇关于通过私有 CoCreateInstance 使用 DirectShow 过滤器而不注册它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆