【发布时间】:2017-11-27 15:08:28
【问题描述】:
我有一个 mp4 文件,其中包含 1 个视频和 2 个音频流。我想使用 Media Foundation 解码音频流(在选择其中之一之后)。这是我的代码(我取自 MediaFoundation SDK 示例的 MFAudio 示例)。
为简单起见,省略了错误检查。
// Set up the source reader for the file.
MFCreateSourceResolver(&pSourceResolver);
pSourceResolver->CreateObjectFromURL(
L"C:\\Users\\vahagng\\Desktop\\a.mp4", // URL of the source.
MF_RESOLUTION_MEDIASOURCE, // Create a source object.
NULL, // Optional property store.
&ObjectType, // Receives the created object type.
&uSource // Receives a pointer to the media source.
);
uSource->QueryInterface(IID_PPV_ARGS(&mediaFileSource));
MFCreateSourceReaderFromMediaSource(mediaFileSource, NULL, &pSourceReader);
// Deselect all streams, we only want the first
pSourceReader->SetStreamSelection(MF_SOURCE_READER_ALL_STREAMS, false);
pSourceReader->SetStreamSelection(MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);
MFCreateMediaType(&pAudioOutType);
pAudioOutType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
CHECK_HR(pAudioOutType->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_Float);
pSourceReader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, NULL, pAudioOutType);
上面的代码在最后一行 (pSourceReader->SetCurrentMediaType()) 失败,对于具有 2 个音频流但适用于 1 个音频流文件的媒体文件,错误代码为 0xc00d36b4 : The data specified for the media type is invalid, inconsistent, or not supported by this object.。
我正在测试的文件有 2 个 AAC 音频流,MediaFoundation 绝对支持。
MediaFoundation 是否支持解码多个音频流的文件?
【问题讨论】:
-
返回什么错误?
-
0xc00d36b4 : 为媒体类型指定的数据无效、不一致或不受此对象支持。
-
您可能会选择 MF 无法解码的音轨,因此出现错误代码(如预期的那样)。总而言之,该行为似乎没有错,或者您需要发布更多详细信息(示例音频文件,您选择的曲目)为什么您认为它不正确。
-
谢谢,罗曼。我已经用示例文件链接和音频流信息更新了帖子。正如您从帖子中看到的那样,我正在尝试通过选择 MF_SOURCE_READER_FIRST_AUDIO_STREAM 来检索第一个流
标签: c++ audio ms-media-foundation