首页 > 解决方案 > IMFSinkWriter :请求无效,因为已调用 Shutdown()

问题描述

只是测试一些简单的音频到 mp3 的东西。

我正在尝试使用 IMFSinkWriter 来实际编码音频并将其保存到磁盘。

我什至无法正确创建 IMFSinkWriter。这一定是一些菜鸟问题或一个非常奇怪的错误......

#include <iostream>
#include <mfidl.h>
#include <Mfreadwrite.h>
#pragma comment(lib, "Mfreadwrite.lib")
int main()
{
    IMFSinkWriter* pSinkWriter;
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    std::cout << std::system_category().message(hr) << "\n";
    hr = MFCreateSinkWriterFromURL(L"Recording.mp3", NULL, NULL, &pSinkWriter);
    std::cout << std::system_category().message(hr) << "\n";
    system("pause");
}

输出:

操作成功完成。

该请求无效,因为已调用 Shutdown()。

按任意键继续 。. .

我可能需要调用“CoCreateInstance(__uuidof(SOMETHING), NULL, CLSCTX_ALL, __uuidof(IMFSinkWriter), (void**)&pSinkWriter);”,但我不确定 SOMETHING 应该是什么,或者它可能是什么其他原因。

谢谢。

标签: c++encodingms-media-foundation

解决方案


"MFStartup(MF_VERSION)" needed to be called:

IMFSinkWriter* pSinkWriter;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
std::cout << std::system_category().message(hr) << "\n";
hr = MFStartup(MF_VERSION);
std::cout << std::system_category().message(hr) << "\n";
hr = MFCreateSinkWriterFromURL(L"Recording.mp3", NULL, NULL, &pSinkWriter);
std::cout << std::system_category().message(hr) << "\n";
system("pause");

Output:

The operation completed successfully.

The operation completed successfully.

The operation completed successfully.

Press any key to continue . . .


推荐阅读