c++ - 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 应该是什么,或者它可能是什么其他原因。
谢谢。
解决方案
"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 . . .
推荐阅读
- python - 如何从 treeWidgetItem 中获取 comboBox.currentText() 和 SpinBox.text()
- c# - c# asp.net:使用表单将元素添加到模型中的列表
- postgresql - Postgres insert-into-select 将一列保留为空,同时填充其他列
- sql - 如何匹配第 n 个位置的字符(Cloudera Impala SQL)
- html - 如何使用图像实现 Angular 7 下拉菜单?
- javascript - POST 表单答案到外部 API 离子角度
- python - PySpark:检查某些列中的值是否在范围内
- php - 在侧边栏显示数据库中具有一定价值的数据
- reactjs - 覆盖 CRA 3.x 上的 webpack 配置而不弹出
- excel - Excel GET请求缓存?