locked
MFAudioFormat_WMAudioV8 causes SetInputMediaType() to return MF_E_INVALIDMEDIATYPE RRS feed

  • Question

  • I'm using Media Foundation to mix an uncompressed video stream with audio data captured via the WASAPI loopback adapter. I want the encoding to work on Vista and newer.

    I initially used MFAudioFormat_AAC as the output audio format (manually converting the input audio from MFAudioFormat_Float to 16-bit MFAudioFormat_PCM), but I'm having some problems playing the resulting video in anything apart from Windows Media Player. VLC, for instance, says the audio codec is undefined. Furthermore, MSDN says the AAC encoder is only available on Windows 7 and up, so I can't use it anyway.

    I therefore decided to use MFAudioFormat_WMAudioV8 as the target format since it's available all the way back to Windows XP. However, it's proving very difficult to choose the right parameters for the input and output audio formats since I keep getting an MF_E_INVALIDMEDIATYPE when calling SetInputMediaType(). It seems mostly related to the output format's MF_MT_AUDIO_BLOCK_ALIGNMENT attribute (if I don't specify it, SetInputMediaType() at least succeeds although something else fails later on).

    There have been some other questions here on the forum regarding something like mine (such as http://social.msdn.microsoft.com/Forums/en/mediafoundationdevelopment/thread/55e14d46-053e-4cd5-b069-adfa4cd60207). Another thread (http://social.msdn.microsoft.com/Forums/en-US/mediafoundationdevelopment/thread/26e5bb34-d26f-476f-91d9-e9896c793dbf) suggests using MFTranscodeGetAudioOutputAvailableTypes(), but that again is only available on Windows 7 and up.

    The audio parameters I'm currently testing with look like this:

     

    hr = pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);   
    hr = pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_WMAudioV8);
    hr = pMediaTypeOut->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, SamplesPerSecond);   
    hr = pMediaTypeOut->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, BitsPerSample);   
    hr = pMediaTypeOut->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, ChannelCount); 
    hr = pMediaTypeOut->SetUINT32(MF_MT_AUDIO_AVG_BYTES_PER_SECOND, BitsPerSample / 8 * ChannelCount * SamplesPerSecond);   
    hr = pMediaTypeOut->SetUINT32(MF_MT_AUDIO_BLOCK_ALIGNMENT, BlockAlign); 
    hr = pMediaTypeOut->SetUINT32(MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1)
    hr = pMediaTypeOut->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, 1)
    hr = pMediaTypeOut->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, 1)
    
    hr = pMediaTypeIn->SetGUID( MF_MT_MAJOR_TYPE, MFMediaType_Audio );
    hr = pMediaTypeIn->SetGUID( MF_MT_SUBTYPE, MFAudioFormat_PCM );
    hr = pMediaTypeIn->SetUINT32( MF_MT_AUDIO_BITS_PER_SAMPLE, BitsPerSample );
    hr = pMediaTypeIn->SetUINT32( MF_MT_AUDIO_SAMPLES_PER_SECOND, SamplesPerSecond );
    hr = pMediaTypeIn->SetUINT32( MF_MT_AUDIO_NUM_CHANNELS, ChannelCount );
    hr = pMediaTypeIn->SetUINT32( MF_MT_AUDIO_AVG_BYTES_PER_SECOND, BlockAlign * SamplesPerSecond ) );
    hr = pMediaTypeIn->SetUINT32( MF_MT_AUDIO_BLOCK_ALIGNMENT, BlockAlign ) );
    hr = pMediaTypeIn->SetUINT32( MF_MT_AUDIO_PREFER_WAVEFORMATEX, 1 ) );
    

     


    Questions:

    • Am I correct in choosing MFAudioFormat_WMAudioV8 at all? I.e. would I be better off using a different codec?
    • How do I pick the best attributes / figure out what's causing SetInputMediaType() to fail.
    Thursday, October 27, 2011 2:09 PM

Answers

  • For audio enconding, the best thing to do is choose a media type from the output types available from the encoder.  This is essentially what MFTranscodeGetAudioOutputAvailableTypes does; you can do it manually by looping through GetOutputAvailableType on the encoder MFT.  This type will be guaranteed to have the right block alignment value and any necessary codec private data.
    Friday, December 2, 2011 7:38 PM

All replies