Problem extracting audio from a movie using DirectShow

Just starting out? Need help? Post your questions and find answers here.
D Ogre
User
User
Posts: 17
Joined: Tue Jan 01, 2008 3:15 am
Location: Michigan, USA

Problem extracting audio from a movie using DirectShow

Post by D Ogre »

I am currently learning how to use DirectShow natively with PB. I have a project that requires the ability to extract audio from any movie played.

I have been using a trial version of GraphEdit Plus to test the graph, so I have no code to show the problem currently. I figured that I would test the graph first before I try to write the code in PB to make sure that my efforts were not wasted if it doesn't work in GraphEdit Plus.

I tried the supposed method shown on MSDN to build my test graph with very dissapointing results...

Procedure:

1 - I rendered an Mpeg file for test purposes in GraphEdit Plus

The rendered graph contained the following:

VIDEO filters with pin connections:
Testfile.mpeg--->MainConcept Mpeg Demultiplexer-->Mpeg Video Decoder-->Video Renderer

AUDIO filters with pin connections:
Testfile.mpeg--->MainConcept Mpeg Demultiplexer-->Mpeg Audio Decoder-->DirectSound(output)

2 - I edited the graph on the sound part in GraphEdit Plus

The edited portion of the graph now looks like this:

AUDIO filters with pin connections
Testfile.mpeg-->MainConcept Mpeg Demultiplexer-->Mpeg Audio Decoder-->WAV Dest2-->File Writer (test.wav)

GraphEdit Plus seemed to accept all the connections without fail.

According to MSDN, the file writer should write any data pass to it. In this case that data should be wave data. Am I wrong?? The graph appears to run showing the video with no audio which should be sent directly to my file called, "test.wav". This seems to be correct.

The problem arises when trying to open the newly created file in Windows Media Player. The time does not match the original length of the audio from the video file, and the test wave file appears to have no sound upon playback. I must be missing something obviously, but I'm not sure what it is.

I even tried connecting the Mpeg Demux directly to WAV Dest2 and then to the File Writer with no success. Can anyone point me in the right direction?

BTW, I just used an mpeg file for testing purposes, but wish to be able to do this with any supported file type supported by DirectShow such as avi, mpeg, mwv, divx, ect. I understand that the graph will be somewhat different for each, but the the sound file output will be the same (.wav).
D Ogre
User
User
Posts: 17
Joined: Tue Jan 01, 2008 3:15 am
Location: Michigan, USA

Have some work to do...

Post by D Ogre »

Okay.... I know that what I presented above is not specifically a PB coding question presently, but I figured I would post it here anways in the hopes that someone here could give me a little help with the logics.

I will try to build a PB project that does the same thing to see if I can get it to work outside of GraphEdit plus within the next week or so. Maybe I will stumble on the problem myself. I'm not sure though; because I'm still learning how to use Directshow.

I'm pretty sure the Mpeg demuxer is not a Microsoft DirectShow filter. I think it came with one of the third party codec packs that I currently installed on my computer. However, I seems to work properly and should make no difference with my said problem. I believe the problem lies in the output of the wav data. Everything else in the test graph looks to be part of the DirectShow filters.

I did found a reference for the File Writer under DirectShow on MSDN. It mentioned something about the Istream in the interface (COM) is supposed to write the file header. I'm wondering if I'm supposed to do something with this during the file writing operation of the graph. (ie. Setting the bitrate of the samples, how may channels, and compression.)
Does this make since to anyone?

Since I'm a total newbie at using DirectShow, I guess I have some more research to do... Maybe I should just download the entire SDK for DirectShow....

If anyone has any info about this in the mean time, can you please post some insights, tricks, or tips on this please.

Thanks,
D Ogre
D Ogre
User
User
Posts: 17
Joined: Tue Jan 01, 2008 3:15 am
Location: Michigan, USA

Problem fixed! WAV Dest2 was a bad PCM Wave Encoder...

Post by D Ogre »

I obtained a copy of the original Microsoft Graphedit which contained several codecs including the Wav Dest.ax file. Apparently, the filter I was using was not working properly. After changing the rendered graph using the original Microsoft DirectShow filter, the output file was written properly.

I searched the forums here and found an example of how to build a specific custom graph using filters I specify. It seems to work, but now I have more questions. Hopefully someone can give me some info...

If I use my custom graph to extract the audio, is there a way to speed up the file writing process? In other words, can I write the outputted .wav file from the graph faster than just playing the movie back and capturing the audio stream at the video FPS rate? I'm sure this would employ a different method, but I'm not sure where to start. (Probably using a third party SDK.)

I'm a bit shakey on using the Istream COM interface as this would probably allow me to set the bitrate and audio channels. I can query the Interface from Graphedit by clicking on the audio decoder which in this case is the Mpeg Audio decoder, but how would I do this in PB code? Can some one give an example?

I hope what I've said makes since. Any info that anyone has on this would be greatly appreciated. I'm not asking anyone to do it for me. I just need a little help here and there that's all. As I said before, I'm still learning.

BTW, I'll try to post my example custom filter code example soon. I'm not done playing around with it yet.

Thanks again,
D Ogre
Post Reply