c++ffmpeg

FFmpeg avio_open_dir returns -40 on Windows, even when directory exists


I'm use ffmpeg7.1 on windows 10. And libavformat's version is 61. I use a absolute path of a directory on avio_open_dir but it's failed, and return -40. I use av_err2str got Function not implemented. What problem it is?

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);
    }
}

output

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

It's not the path incorrect problem. I used std::filesystem::exists("D:\\music") && std::filesystem::is_directory("D:\\music") to verify that the path is correct.


Solution

  • avio_open_dir looks up the handler for the file protocol, and its url_open_dir virtual function is file_open_dir.

    That function returns your "not implemented" error if the HAVE_LSTAT macro is not defined, which would be the case when compiling under Windows.