DirectShow音频设备没有引脚

时间:2014-04-23 09:34:44

标签: c# directshow directshow.net

我想在avi mux中使用音频捕获来捕获网络摄像头捕获并将该文件写入磁盘。

这适用于graphedit。enter image description here

我尝试使用directshowlib在c#中重新创建它。这个工作到目前为止,但唯一没有麦克风捕获。我的麦克风过滤器已创建但没有引脚。我试过两台不同的笔记本电脑。我的麦克风过滤器代码:

Guid microphonFilter = new Guid("{E30629D2-27E5-11CE-875D-00608CB78066}"); 
IBaseFilter pMikrofonRealtekHighDefinitionAudio = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(microphonFilter));
hr = pGraph.AddFilter(pMikrofonRealtekHighDefinitionAudio, "Mikrofon (Realtek High Definition Audio) ");

我也尝试过:

IBaseFilter microphonFilter = (IBaseFilter) new AudioRecord();

我找到针脚的代码:

static IPin GetPin(IBaseFilter filter, string pinname)
{
    IEnumPins epins;
    int hr = filter.EnumPins(out epins);
    checkHR(hr, "Can't enumerate pins");
    IntPtr fetched = Marshal.AllocCoTaskMem(4);
    IPin[] pins = new IPin[1];
    while (epins.Next(1, pins, fetched) == 0)
    {
        PinInfo pinfo;
        pins[0].QueryPinInfo(out pinfo);
        bool found = (pinfo.name == pinname);
        DsUtils.FreePinInfo(pinfo);
        if (found)
            return pins[0];
    }
    checkHR(-1, "Pin not found");
    return null;
}

1 个答案:

答案 0 :(得分:1)

此类音频(和视频)捕获设备无法使用CoCreateInstance实例化(在C#中使用CLSID - Activator.CreateInstance。你必须使用monikers创建它们,通常是通过枚举,如MSDN(包含源代码片段)所述:Selecting a Capture Device

以下是用于视频捕获的DirectShow.NET示例的代码片段,您需要类似于音频设备类别。

// This version of FindCaptureDevice is provide for education only.
// A second version using the DsDevice helper class is define later.
public IBaseFilter FindCaptureDevice()
{
  // ...

  // Create the system device enumerator
  ICreateDevEnum devEnum = (ICreateDevEnum) new CreateDevEnum();

  // Create an enumerator for the video capture devices
  hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum, 0);
  DsError.ThrowExceptionForHR(hr);

  // The device enumerator is no more needed
  Marshal.ReleaseComObject(devEnum);

  // If there are no enumerators for the requested type, then 
  // CreateClassEnumerator will succeed, but classEnum will be NULL.
  if (classEnum == null)
  {
    throw new ApplicationException("No video capture device was detected.\r\n\r\n" +
                                   "This sample requires a video capture device, such as a USB WebCam,\r\n" +
                                   "to be installed and working properly.  The sample will now close.");
  }