Thursday, August 04, 2005

Extract wav from wmv using Windows Media Format SDK

Modify the AudioPlayer example in the Media Format SDK 9.
There are several things needed to be done:
1. Call IWMReaderAdvanced::SetUserProvidedClock(TRUE) so that the program can use IWMReaderAdvanced::DeliverTime to request the reader to process the stream as fast as possible (ignore actual time)
2. Call IWMReaderAdvanced::DeliverTime in OnTime call back to request the reader process more data
3. Select the audio stream. Get IWMProfile interface by QueryInterface on IWMReader interface. Get the number of streams by IWMProfile::GetStreamCount. Get config (IWMStreamConfig) of each stream by IWMProfile::GetStream. Get the stream type by IWMStreamConfig::GetStreamType. Look for stream with type WMMEDIATYPE_Audio. Get stream number using IWMStreamConfig::GetStreamNumber. Use IWMReaderAdvanced::SetManualStreamsSelection(TRUE) to enable manual stream selection. Use IWMReaderAdvanced::SetStreamsSelected to select the audio stream.
4. Modify OnSample function to write the wav samples to a file.
5. Remove unnecessary part of the program

Note: AudioPlayer sample use asynchronous reader (IWMReader). It might be easier to use the synchronous reader (IWMSyncReader) obtained by WMCreateSyncReader.

No comments: