locked
MFInitMediaTypeFromWaveFormatEx failed RRS feed

  • 質問

  • Hi guys,

    I'm now trying to use MP3 encoder mft on Win10 pro Insider preview, but failed to set output media type. 

    Below is my code:

    // Fill in MPEGLAYER3WAVEFORMAT data    MPEGLAYER3WAVEFORMAT mp3wfx; ZeroMemory(&mp3wfx, sizeof(mp3wfx)); mp3wfx.wID = MPEGLAYER3_ID_MPEG; mp3wfx.fdwFlags = 2; // no padding mp3wfx.nBlockSize = int16_t(144 * (128000 / 44100)); // bitrate = 128000kbps mp3wfx.nFramesPerBlock = 1; mp3wfx.nCodecDelay = 0; mp3wfx.wfx.wFormatTag = WAVE_FORMAT_MPEGLAYER3;  // MP3  mp3wfx.wfx.nChannels = 2; mp3wfx.wfx.nSamplesPerSec = 44100; mp3wfx.wfx.wBitsPerSample = 16; mp3wfx.wfx.nBlockAlign = (mp3wfx.wfx.nChannels * mp3wfx.wfx.wBitsPerSample) / 8; mp3wfx.wfx.nAvgBytesPerSec = mp3wfx.wfx.nSamplesPerSec * mp3wfx.wfx.nBlockAlign; mp3wfx.wfx.cbSize = sizeof(MPEGLAYER3WAVEFORMAT) - sizeof(WAVEFORMATEX); // 12

    LComObject<IMFMediaType> ciOutputType;  // Output media type of the encoder hr = fpMFCreateMediaType((IMFMediaType**)(ciOutputType.GetAssignablePtrRef())); hr = fpMFInitMediaTypeFromWaveFormatEx(ciOutputType.get(), &(mp3wfx.wfx), sizeof(WAVEFORMATEX));

    please ignore the wrappers I have on those COM objects/interfaces.

    fpMFInitMediaTypeFromWaveFormatEx returns an error (hr = E_INVALIDARG One or more arguments are invalid).

    Mftrace output these

    2888,21C 04:28:58.37011 CMFPlatExportDetours::MFTEnumEx @ Category: MFT_CATEGORY_AUDIO_ENCODER, Flags: 0x00000001, input MT: <NULL>, output MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_SUBTYPE=MFAudioFormat_MP3
    2888,21C 04:28:58.37058 CMFAttributesDetours::GetUINT32 @0361DD08 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37071 CMFAttributesDetours::GetUINT32 @0361DE88 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37086 CMFAttributesDetours::GetUINT32 @0361DB08 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37096 CMFAttributesDetours::GetUINT32 @0361DB88 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37106 CMFAttributesDetours::GetUINT32 @0361DB88 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37117 CMFAttributesDetours::GetUINT32 @0361DD08 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37127 CMFAttributesDetours::GetUINT32 @0361DD48 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37138 CMFAttributesDetours::GetUINT32 @0361DC88 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37148 CMFAttributesDetours::GetUINT32 @0361DD48 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37158 CMFAttributesDetours::GetUINT32 @0361DB48 attribute not found guidKey = MFT_CODEC_MERIT_Attribute
    2888,21C 04:28:58.37167 CMFPlatExportDetours::MFTEnumEx @ Activate 00 @035FBF70, MFT_FRIENDLY_NAME_Attribute=MP3 Encoder ACM Wrapper MFT;MFT_INPUT_TYPES_Attributes=61 75 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 01 00 00 00 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MFT_TRANSFORM_CLSID_Attribute={11103421-354C-4CCA-A7A3-1AFF9A5B6701};MFT_OUTPUT_TYPES_Attributes=61 75 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 55 00 00 00 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MF_TRANSFORM_FLAGS_Attribute=1;MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_AUDIO_ENCODER
    2888,21C 04:28:58.37361 COle32ExportDetours::CoCreateInstance @ New MFT @0145D430, <NULL>
    2888,21C 04:28:58.37363 COle32ExportDetours::CoCreateInstance @ Created {11103421-354C-4CCA-A7A3-1AFF9A5B6701} MP3 ACM Wrapper MFT (C:\Windows\System32\mfcore.dll) @0145D430 - traced interfaces: IMFTransform @0145D430, 
    2888,21C 04:28:58.37432 CMFTransformDetours::SetOutputType @0145D430 Failed MT: 

    Thanks for help



    2015年7月16日 4:33

すべての返信

  • I've found why MFInitMediaTypeFromWaveFormatEx fails.

    Instead of

    MFInitMediaTypeFromWaveFormatEx(ciOutputType.get(), &(mp3wfx.wfx), sizeof(WAVEFORMATEX));

    I should do this:

    WAVEFORMATEX* pWave = (WAVEFORMATEX*)&mp3wfx;
    MFInitMediaTypeFromWaveFormatEx(ciOutputType.get(), pWave, sizeof(MPEGLAYER3WAVEFORMAT));

    Now I can create the output media type, but 

    ciEncoder->SetOutputType(0, ciOutputType.get(), 0);

    still fails

    Mftrace ouput:

    5552,500 05:05:15.03439 CMFPlatExportDetours::MFTEnumEx @ Activate 00 @034CE628, MFT_FRIENDLY_NAME_Attribute=MP3 Encoder ACM Wrapper MFT;MFT_INPUT_TYPES_Attributes=61 75 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 01 00 00 00 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MFT_TRANSFORM_CLSID_Attribute={11103421-354C-4CCA-A7A3-1AFF9A5B6701};MFT_OUTPUT_TYPES_Attributes=61 75 64 73 00 00 10 00 80 00 00 aa 00 38 9b 71 55 00 00 00 00 00 10 00 80 00 00 aa 00 38 9b 71 ;MF_TRANSFORM_FLAGS_Attribute=1;MF_TRANSFORM_CATEGORY_Attribute=MFT_CATEGORY_AUDIO_ENCODER
    5552,500 05:05:15.03616 COle32ExportDetours::CoCreateInstance @ New MFT @03510D20, <NULL>
    5552,500 05:05:15.03618 COle32ExportDetours::CoCreateInstance @ Created {11103421-354C-4CCA-A7A3-1AFF9A5B6701} MP3 ACM Wrapper MFT (C:\Windows\System32\mfcore.dll) @03510D20 - traced interfaces: IMFTransform @03510D20,
    5552,500 05:05:15.03681 CMFTransformDetours::SetOutputType @03510D20 Failed MT: MF_MT_AUDIO_AVG_BYTES_PER_SECOND=176400;MF_MT_AUDIO_BLOCK_ALIGNMENT=4;MF_MT_AUDIO_NUM_CHANNELS=2;MF_MT_MAJOR_TYPE=MEDIATYPE_Audio;MF_MT_AUDIO_SAMPLES_PER_SECOND=44100;MF_MT_AUDIO_PREFER_WAVEFORMATEX=1;MF_MT_USER_DATA=01 00 02 00 00 00 20 01 01 00 00 00 ;MF_MT_AUDIO_BITS_PER_SAMPLE=16;MF_MT_SUBTYPE=MFAudioFormat_MP3

    2015年7月16日 5:08
  • Update:

    I used ciEncoder->GetOutputAvailableType to enumerate all supported format, among them I can see

    fmt[1]: nChannels = 2, nSamplesPerSec = 44100, nAvgBytesPerSec = 40000, nBlockAlign = 1, wBitsPerSample = 0, cbSize = 12
    fmt[4]: nChannels = 2, nSamplesPerSec = 44100, nAvgBytesPerSec = 32000, nBlockAlign = 1, wBitsPerSample = 0, cbSize = 12
    fmt[7]: nChannels = 2, nSamplesPerSec = 44100, nAvgBytesPerSec = 28000, nBlockAlign = 1, wBitsPerSample = 0, cbSize = 12
    fmt[10]: nChannels = 2, nSamplesPerSec = 44100, nAvgBytesPerSec = 24000, nBlockAlign = 1, wBitsPerSample = 0, cbSize = 12
    fmt[13]: nChannels = 2, nSamplesPerSec = 44100, nAvgBytesPerSec = 20000, nBlockAlign = 1, wBitsPerSample = 0, cbSize = 12
    fmt[16]: nChannels = 2, nSamplesPerSec = 44100, nAvgBytesPerSec = 16000, nBlockAlign = 1, wBitsPerSample = 0, cbSize = 12
    fmt[19]: nChannels = 2, nSamplesPerSec = 44100, nAvgBytesPerSec = 14000, nBlockAlign = 1, wBitsPerSample = 0, cbSize = 12
    fmt[22]: nChannels = 2, nSamplesPerSec = 44100, nAvgBytesPerSec = 12000, nBlockAlign = 1, wBitsPerSample = 0, cbSize = 12

    That means, my blockalign, bitspersample and avgbytespersec are incorrect.

    The strange thing is, after setting all corresponding values to mp3wfx, SetOutputType still failed.

    Instead, if I supply the mediatype returned by GetOutputAvailableType to SetOutputType, it succeeded.

    So maybe there's still some difference between the mediatype I constructed and the one returned by GetOutputAvailableType 

    2015年7月16日 7:02
  • Update:

    Compared mftrace logs of failed and succeeded cases:

    the only difference lies in user data

    MF_MT_USER_DATA=01 00 02 00 00 00 a1 01 01 00 00 00  (succeeded) vs 

    MF_MT_USER_DATA=01 00 02 00 00 00 20 01 01 00 00 00 (failed)

    a1 01 = 417 vs 20 01 = 288.

    just because 

    144  * (128000 / 44100)

    actually should be

    144 * 128000 / 44100




    2015年7月16日 7:34
  • EDIT :

     just seen you got the answer on Stackoverflow.

    The size you pass to InitFromWaveFormatEx seems to work, but normaly you pass the size of WAVEFORMATEX + the extra size and not the size of another structure as it could be a dynamic structure and might vary in size. In the case of MPEGLAYER3WAVEFORMAT it works of course.

    Normaly you pass it this way :

    mp3wfx.wfx.cbSize = MPEGLAYER3_WFX_EXTRA_BYTES; // constant defined in Mmreg.h
    
    hr = MFInitMediaTypeFromWaveFormatEx(ciOutputType.get(), &mp3wfx.wfx, sizeof(WAVEFORMATEX) + mp3wfx.wfx.cbSize);

    -

    Regards,

    Francis








    2015年7月21日 21:36
  • Thanks co0Kie, I'll change the code using your style :D
    2015年7月23日 4:13