Record directshow audio device to file
Asked Answered
A

2

0

I've stumbled through some code to enumerate my microphone devices (with some help), and am able to grab the "friendly name" and "clsid" information from each device.

I've done some tinkering with GraphEd.exe to try and figure out how I can take audio from directshow and write it to a file (I'm not currently concerned about the format, wav should be fine), and can't seem to find the right combination.

One of the articles I've read linked to this Windows SDK sample, but when I examined the code, I ended up getting pretty confused at how to use that code, ie. setting the output file, or specifying which audio capture device to use.

I also came across a codeguru article that has a nicely featured audio recorder, but it does not have an interface for selecting the audio device, and I can't seem to find where it statically picks which recording device to use.

I think I'd be most interested in figuring out how to use the Windows SDK sample, but any explanation on either of the two approaches would be fantastic.

Edit: I should mention my knowledge and ability as a win32 COM programmer is very low on the scale, so if this is easy, just explain it to me like I'm five, please.

Arithmetician answered 12/10, 2012 at 19:14 Comment(0)
A
3

Recording audio into file with DirectShow needs you to build the right filter graph, as you should have figured out already. The parts include:

  1. The device itself, which you instantiate via moniker (not CLSID!), it is typically PCM format
  2. Multiplexer component that converts streams into container format
  3. File Writer Filter that takes file-compatible stream and writes into a file

The tricky moment is #2 since there is not standard component available. Windows SDK samples however contains the missing part - WavDest Filter Sample. Building it and making it ready for use, you can build a graph that records from device into .WAV file.

Your graph will look like this, and it's built easily programmatically as well:

enter image description here

I noticed that I have a variation of WavDest installed with Google Earth - for the case you have troubles building it yourself and you will be looking for prebuilt binary.

Artina answered 12/10, 2012 at 20:6 Comment(6)
How do I "use it" after I build it?Arithmetician
1 you can build it interactively in GraphEdt, as any other filter (it will appear on the list) 2 you can add it to the topology programmatically as any other filter 3 you can use GraphEditPlus app (similar to GraphEdit) which allows building graph interactively and then it can generate a skeleton of C++ code for you.Artina
By use it, I guess I actually meant install it. Is it possible to not register it? What I mean is either I add the directshow filter directly in my code, or in my code specify the DLL? I'll be distributing the application and filter in a known location, and I can't guarantee that the end user will have the admin rights to install a direct show filter (which needs some sort of heightened priviledge, from my understanding).Arithmetician
Yes you can do it, see Using a DirectShow filter without registering it, via a private CoCreateInstanceArtina
so what's the easy programmatic way here? Just build the graph manually?Calico
@rogerdpack: programmatically one would repeat the graph building: create graph, add filters connect them, then run/stop. That's it, about perhaps a few tens of lines of code in total.Artina
C
0

You can instruct ffmpeg to record from a directshow device, and output to a file.

Calico answered 26/11, 2012 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.