设置AAC解码器输入类型始终失败(UWP)
我正在尝试在clsid_msaacdecmft
对象的实例上设置输入类型,但是它总是失败 针对媒体类型指定的数据无效,不一致或不受此对象的支持。
基于Microsoft文档,我在尝试将其设置为输入之前设置了强制性值:
ComPtr<IUnknown> pUnknown = nullptr;
HRESULT hResult = CoCreateInstance(CLSID_MSAACDecMFT, nullptr, CLSCTX_INPROC_SERVER, IID_IUnknown, &pUnknown);
if (S_OK != hResult) {
LogError("Failed to create AAC decoder");
return false;
}
hResult = pUnknown->QueryInterface(IID_PPV_ARGS(&mAudioDecoder));
if (hResult != S_OK) {
LogError("Failed to create AAC decoder");
return false;
}
ComPtr<IMFMediaType> pInputMediaType = nullptr;
hResult = MFCreateMediaType(&pInputMediaType);
if (S_OK != hResult) {
return false;
}
pInputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
pInputMediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_AAC);
pInputMediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, 16);
pInputMediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, 48000);
pInputMediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, 2);
任何人都可以告诉我为什么失败?
非常感谢 彼得
I'm trying to set the input type on a instance of the CLSID_MSAACDecMFT
object, but it always fails withThe data specified for the media type is invalid, inconsistent, or not supported by this object.
Based on the Microsoft documentation I've set the mandatory values before attempting to set it as input:
ComPtr<IUnknown> pUnknown = nullptr;
HRESULT hResult = CoCreateInstance(CLSID_MSAACDecMFT, nullptr, CLSCTX_INPROC_SERVER, IID_IUnknown, &pUnknown);
if (S_OK != hResult) {
LogError("Failed to create AAC decoder");
return false;
}
hResult = pUnknown->QueryInterface(IID_PPV_ARGS(&mAudioDecoder));
if (hResult != S_OK) {
LogError("Failed to create AAC decoder");
return false;
}
ComPtr<IMFMediaType> pInputMediaType = nullptr;
hResult = MFCreateMediaType(&pInputMediaType);
if (S_OK != hResult) {
return false;
}
pInputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
pInputMediaType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_AAC);
pInputMediaType->SetUINT32(MF_MT_AUDIO_BITS_PER_SAMPLE, 16);
pInputMediaType->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, 48000);
pInputMediaType->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, 2);
Can anyone tell me why this fails?
Many thanks,
Peter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这很痛苦!误读文档,还有一个其他字段要设置,
mf_mt_user_data
字段。经过大量的反复错误,我明白了:如何设置
MF_MF_USER_DATA
不太清楚,您无需创建waveformatex
object objoctwaveformatex
这就是您只需要在介质类型上设置斑点,代表波格格式结构以后的相关字段。人们还可能使用的是如何生成输出类型...文件仅表示有三个强制性字段:数字通道,位和样本率。这对我不起作用,但是我通过可能的输出类型的列表进行了迭代,并且只要有浮点输出类型,将其采用并使用了:
Well this was a pain! Misread the documents and there is an additional field to set, the
MF_MT_USER_DATA
field. After a lot of trial and error, I got it:How to set the
MF_MF_USER_DATA
wasn't very clear, you don't need to create theWAVEFORMATEX
object or anything like that, you only need to set a blob on the media type, representing the relevant fields after wave format struct.What will also potentially be of use to people is how to generate the output type... The documents only say that there are three mandatory fields: num channels, bits and sample rate. This didn't work for me, but I iterated through the list of possible output types and, provided there is a float output type, took it and used it: