Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6664259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:35:27+00:00 2026-05-26T02:35:27+00:00

I’m writing program which captures audio in C# using DirectShow library and writes it

  • 0

I’m writing program which captures audio in C# using DirectShow library and writes it to ogg container. I created a graph in GraphEditPlus. It generates a GraphBuilder method code which I copied to my code. This code is:

class AudioCapture
{
  public static void checkHR(int hr, string msg)
  {
    if (hr < 0)
    {
      MessageBox.Show(msg);
      DsError.ThrowExceptionForHR(hr);
    }
  }

  public static void BuildGraph (IGraphBuilder pGraph, string dstFile)
  {
    int hr = 0;

    //graph builder
    ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
    hr = pBuilder.SetFiltergraph(pGraph);
    checkHR(hr, "Can't SetFiltergraph");

    Guid CLSID_XiphOrgVorbisEncoder = new Guid("{5C94FE86-B93B-467F-BFC3-BD6C91416F9B}");
    Guid CLSID_XiphOrgOggMuxer = new Guid("{1F3EFFE4-0E70-47C7-9C48-05EB99E20011}");

    //add microphone
    IBaseFilter pMicrophone = (IBaseFilter) new AudioRecord();
    hr = pGraph.AddFilter(pMicrophone, "Microphone");
    checkHR(hr, "Can't add microphone to graph");

    //add Vorbis Encoder
    IBaseFilter pVorbisEncoder = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_XiphOrgVorbisEncoder));
    checkHR(hr, "Can't add Vorbis Encoder to graph");

    //connect Microphone and Vorbis Encoder
    hr = pGraph.ConnectDirect(GetPin(pMicrophone, "Capture"), GetPin(pVorbisEncoder, "PCM In"), null);
    checkHR(hr, "Can't connect Microphone and Vorbis Encoder");

    //add Ogg Muxer
    IBaseFilter pOggMuxer = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_XiphOrgOggMuxer));
    checkHR(hr, "Can't add Ogg Muxer to graph");

    //set destination filename
    IFileSinkFilter pOggMuxer_sink = pOggMuxer as IFileSinkFilter;
    if (pOggMuxer_sink == null)
      checkHR(unchecked((int)0x80004002), "Can't get IFileSinkFilter");
    hr = pOggMuxer_sink.SetFileName(dstFile, null);
    checkHR(hr, "Can't set filename");

    //connect Vorbis Encoder and Ogg Muxer
    hr = pGraph.ConnectDirect(GetPin(pVorbisEncoder, "VorbisOut"), GetPin(pOggMuxer, "Ogg Packet In"), null);
    checkHR(hr, "Can't connect Vorbis Encoder and Ogg Muxer");
  }

  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;
  }
}

When I’m trying to execute this code program throws me a message “Pin can’t found” after trying to connect microphone and vorbis encoder filters. After debugging I found out that it can’t find the microphone pin. Does anybody knows where is my error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:35:27+00:00Added an answer on May 26, 2026 at 2:35 am

    You should not look for pins by their names, as this is not quite reliable. Perhaps it might be still more or less acceptable if you are absolutely sure what filter/class you are dealing with, but it is definitely not the way to do with generic audio source filter (more specifically: noone gives a promise that capture pin is named “Capture”, instead pins implement IKsPropertySet to indicate that).

    Your best approach would be using ICaptureGraphBuilder::RenderStream with PIN_CATEGORY_CAPTURE argument so that it could pick up capture pin for you. See MSDN for details http://msdn.microsoft.com/en-us/library/dd311932%28v=vs.85%29.aspx and I am pretty sure you will easily find sample code for doing this too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.