You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下FFmpeg7.1的avio_open_dir返回-40(未实现)求助

Windows 10下FFmpeg 7.1调用avio_open_dir返回-40(Function not implemented)问题排查

在Windows 10系统中使用FFmpeg 7.1(libavformat版本61),调用avio_open_dir传入目录绝对路径时执行失败,返回值为-40,通过av_err2str获取到的错误信息为“Function not implemented”。

已通过std::filesystem::exists("D:\\music") && std::filesystem::is_directory("D:\\music")验证该路径正确且为目录,排除路径本身的问题。

相关代码

extern "C"
{
#include <libavformat/avformat.h>
}

int main()
{
    av_log_set_level(AV_LOG_DEBUG);

    auto dir = "D:\\music";
    AVIODirContext* dirCtx;
    auto ret = avio_open_dir(&dirCtx, dir, nullptr);
    if (ret < 0)
    {
        av_log(nullptr, AV_LOG_ERROR, "Can't open %s: %s\n", dir, av_err2str(ret));
        exit(EXIT_FAILURE);
    }
}

程序输出

Can't open D:\music: Function not implemented

问题原因及解决方向

核心原因

FFmpeg的Windows版本默认可能未启用目录遍历功能,或者你使用的FFmpeg编译包未包含avio_dir相关实现代码:

  • avio_open_dir等目录操作函数依赖平台特定的文件系统遍历逻辑,Windows平台下这部分功能需要编译时开启对应配置选项。
  • 多数预编译FFmpeg发行包(尤其是精简版共享库)默认不会编译目录操作模块,导致调用时触发“未实现”错误。

解决建议

  1. 编译配置检查:若自行编译FFmpeg,需确保编译时添加支持目录操作的配置项(如--enable-avio-dir,具体以对应FFmpeg版本的编译文档为准),保证Windows平台的目录遍历代码被编译进库。
  2. 更换FFmpeg包:使用官方提供的完整功能预编译包,或确认所用包的编译配置包含avio_dir支持。
  3. 替代方案:暂时无法更换FFmpeg的话,可使用Windows原生API(FindFirstFile/FindNextFile)或C++标准库std::filesystem实现目录遍历,绕过avio_open_dir函数。

内容的提问来源于stack exchange,提问作者グルグル

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 19:17:36