【发布时间】:2021-04-04 07:59:33
【问题描述】:
我用 C# 开发了一个 UWP 应用,其中包含一个 Windows 运行时组件 C++ 项目。该应用程序允许用户选择一个 mp4 文件并将此文件传递给 c++ 代码,然后利用 ffmpeg 库检索视频文件的演示时间戳并将其输出到文件中。
我面临的问题是使用avformat_open_input函数时c++代码无法打开mp4文件:
int PTSExtraction::parse_file(Platform::String^ filename)
{
int ret = 0;
AVPacket pkt = { 0 };
std::wstring fileNameW(filename->Begin());
std::string fileNameA(fileNameW.begin(), fileNameW.end());
const wchar_t* w_chars = fileNameW.c_str();
src_filename = fileNameA.c_str();
if (avformat_open_input(&fmt_ctx, src_filename, NULL, NULL) < 0) {
fprintf(stderr, "Could not open source file %s\n", src_filename);
return 1;
}
// rest of code
}
avformat_open_input 收到的错误是Permission Denied。我什至无法通过以下方式在此函数中打开随机文本文件:
ofstream output;
output.open("output.txt");
我意识到有文件系统权限阻止我的 uwp 应用程序的 C++ 组件打开文件。以下是我迄今为止尝试过的事情:
- 我已在 Package.appxmanifest (https://blogs.windows.com/windowsdeveloper/2018/05/18/console-uwp-applications-and-file-system-access/) 中启用了 broadFileSystemAccess - 在 Package.appxmanifest 文件的 Capabilities 部分中,我已允许访问位置、图片库和视频库。
- 我已检查计算机上的文件系统隐私设置并启用我的应用程序访问文件系统。
- 我尝试将 mp4 文件移动到不同位置(文档、图片库、视频库),以查看 C++ 组件是否可以访问这些位置。
- 我已经尝试过这篇帖子中的解决方案:Qt WinRT App cannot access file permission denied。
这些都不允许 C++ 组件打开任何文件。如果有人能解决这个问题,我将不胜感激。
【问题讨论】:
标签: c# c++ ffmpeg uwp windows-runtime