You can use Directshow filters to construct a graph that will save the audio as .wav.
The interfaces that you need to use are: (Note: This solution will extract audio from avi files)
IGraphBuilder: This will be used to build graph.
IBaseFilter: This will be the filters that you initialize to make part of the graph
To initialize graph you do:
IGraphBuilder *pGraph = NULL;
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph)
CLSID_FilterGraph is defined in uuids.h which is part of PaltformSDK.
Once the graph is initialized, you will need to initialize 3 filters that will be added in the graph.
- AVI Multiplexer: CLSID_AviDest
- File Writer: CLSID_FileWriter.
- Null renderer: CLSID_NullRenderer
You can initialize filters by:
IBaseFilter *pF = NULL;
CoCreateInstance(clsid, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&pF);
clsid = clsid of the filter
And add the filter in graph using:
pGraph->AddFilter(pF, name)
name = name of the filter. Can be 'AVI Mux' etc
Once you initialize 'File writer' filter you will need to set the path where you wish to write the file. You can do that:
IFileSinkFilter* pFileSink=NULL;
fileWriterFilter->QueryInterface(IID_IFileSinkFilter, (void**)&pFileSink);
pFileSink->SetFileName(filepath, NULL);
Here: fileWriter = file writer filter instance.
Make sure that the extension of file name is .wav
Once you added the filters in graph, you will need to render the video file like:
pGraph->RenderFile(sourcePath, NULL);
Once rendered, you will now need to Run this graph. You can do this by querying couple of interfaces from the graph:
IMediaControl Used to run the filter
and IMediaEvent Used to get events from graph.
Query the interface:
pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
and pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
Run the graph:
pControl->Run();
And wait for the rendering for completion:
pEvent->WaitForCompletion(INFINITE, &evCode);
Once done, you will find a file having audio in .wav format.
I have tested this through graphedit and it works. I hope this will help.