简体   繁体   中英

multichannel support for Windows Media Foundation AAC encoder

I'm writing a program using Windows Media Foundation AAC encoder to encode audio. According to documentation here - AAC Encoder - 6 channels is supported. But in my program when I set it to 6, I'll get a MF_E_INVALIDMEIDATYPE error. Below is my code

CLSID* pCLSIDs = NULL;// Pointer to an array of CLISDs.
UINT32 nCount = 0;
MFT_REGISTER_TYPE_INFO encoderInfo;
encoderInfo.guidMajorType = MFMediaType_Audio; 
encoderInfo.guidSubtype = MFAudioFormat_AAC;// AAC Encoder class id is not exposed, so we have to enumerate      

HRESULT hr = fpMFTEnum(MFT_CATEGORY_AUDIO_ENCODER, 0, NULL, &encoderInfo, NULL, &pCLSIDs, &nCount);
ciEncoder.CreateObject(pCLSIDs[0], IID_IMFTransform);
LComObject<IMFMediaType> ciInputType;  // Input media type of the encoder
hr = fpMFCreateMediaType((IMFMediaType**)(ciInputType.GetAssignablePtrRef()));
hr = ciInputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
hr = ciInputType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_PCM);
hr = ciInputType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, 16); // must be 16
hr = ciInputType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, Samplerate);
hr = ciInputType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, Channels); //Must be 1 (mono)or 2 (stereo), or 6 (5.1).
hr = ciEncoder->SetInputType(0, ciInputType.get(), 0);      
if (FAILED(hr)) {
   LDEBUG("Failed to set encoder input meida type"); 
   break;      
}

I've removed all error handling code and please ignore my wrapper on the COM object.

ciEncoder->SetInputType() will fail when Channels == 6. But when Channels == 1 or 2, SetInputType succeeds. It happens on both 32 and 64 bit Win7 Professional.

Original Windows 7 AAC Encoder did not have support for 5.1 audio . It was added later with newer OS releases (Windows 8 or 8.1). MSDN article does not have a mention of this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM