Using AM_MEDIA_TYPE structure in a frame & audio grabber application for source videos with audio nChannels > 2.


  •  hr = pGrabberFa->QueryInterface(IID_ISampleGrabber, (LPVOID*) &pGrabberA);
     // We need to specify the media type for the connection on the
     // input pin of the Sample Grabber. For that, we will use the 
     // AM_MEDIA_TYPE structure.
     ZeroMemory(&amt, sizeof(AM_MEDIA_TYPE));
     amt.majortype = MEDIATYPE_Audio;
     amt.subtype = MEDIASUBTYPE_PCM;
     amt.formattype = FORMAT_WaveFormatEx;
    #if 1
     amt.cbFormat = sizeof(WAVEFORMATEXTENSIBLE);
     ZeroMemory(pbFormatvalue, sizeof(WAVEFORMATEXTENSIBLE));
     pbFormatvalue->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
     pbFormatvalue->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
     amt.pbFormat = (BYTE*) pbFormatvalue;
     hr = pGrabberA->SetMediaType(&amt);

    Two things can happen when this code snippet is used / not used:

    (a) when the #if 1 code block is used, the entire program's thread is terminated by the codec as soon as this part of the graph is combined with the opened .m2ts video source file's input filter,

    (b) when the #if 1 code block is turned off via using instead #if 0: on a machine with only 2-channel stereo sound, 6 channel (5.1 AC3 input file) is reported as WAVEFORMATEX field nChannels == 2, but on a machine with 4 speakers configured from the creative labs Audig 2zs sound card driver's speakers settings utility program, nChannels == 4. The number of audio channels in the same .m2ts has not changed--only the computer on which the same program is running.

    I am using the video Null Renderer, but could not attach a Null Renderer to the audio output without getting a runtime error (happened 2009 or 2010, so details are only as noted in my source code's comments).

    See my posting at for additional code details.

    Is there a way of insuring that the nChannels of audio are processed in a way that is independent of the speaker settings of the current computer running the software?

    Ideally, if the source .m2ts video file is 5.1 channel, I want to see that information being sample-grabbed / processed as though using WAVEFORMATEXTENSIBLE and seeing the real number of audio channels reported & data from those channels sample-grabbed via the call-back routines I've set up for this purpose.

    This is a hobby project for myself, not a large corporation with bags of cash to spare.  I'm using Win2k, MS VS 6, MS VC++98, Windows SDK vintage 2004 or so, Directx9 SDK and so do not have access to newer MF-based multimedia system calls.

    The program can capture audio / video from .m2ts h.264 AVC video & AAC or Dolby AC3 audio in all sorts of screen resolutions.

    Web searching the keywords ("AM_MEDIA_TYPE" waveformatextensible), I get some web pages describing the use of

    #include <dshow.h> // old version of dshow.h was streams.h (dx6)
    #include <MMREG.H>
    #include <ks.h> // required by <ksmedia.h>
    #include <KSMEDIA.H>

    but, the documentation provides no concrete sample code as to when and where to use the structures & GUIDs, etc, that would integrate well within my existing source code & tools at my disposal:

    I have also tried to change the requested media type after the sample grabbing has already successfully grabbed video and audio, but this seems to have had zero effect on the nChannels value reported by the grabbed sample data buffer / pointer, nor to the amount of data received.


    Solution Found--third party tools configuration issue. 

    The differences between machine configurations was examined by changing the creative labs audigy 2zs speakers configuration which had no effect on the nChannels number of audio channels accessible by the program.  This indicated that the difference was due to the install options chosen during the k-lite codec pack installation because that configuration matched exactly the machine's configuration.

    The automatically loaded decoding codecs were FFmpeg Audio, and by selecting Start, Programs, K-Lite Codec Pack, Configuration, FFmpeg Audio, the configuration applet was displayed.

    In that applet the major categories are listed down the left hand side.  The setting that was askew was "Mixer" that selected the down-mix of the audio channels to suit user's hardward configuration.  By changing the Mixer setting to "match the source material" the nChannel field's value returned in the working configuration of the development program matched exactly the format of the .m2ts video file--6 channel sound.

    • Edited by ckskinner Friday, February 24, 2012 1:17 AM Updated SDK vintage & put in solution found information.
    Thursday, February 23, 2012 10:59 AM