LibAV FFmpeg C++ av_find_input_format("dshow") 返回 nullptr

LibAV FFmpeg C++ av_find_input_format("dshow") returning nullptr

我正在尝试在 C++ 程序中使用 DirectShow 设备和 FFmpeg。我正在使用通过命令 .\vcpkg install ffmpeg[nvcodec]:x64-windows 使用 vcpkg 构建的 DLL。 vcpkg 日志显示 Enabled indevs: dshow

av_find_input_format 对我来说是 returning nullptr(没有找到“dshow”设备)。

如果我查询下载的 FFmpeg 可执行文件,我会得到一个包含 14 个“dshow”设备的列表。

如何让 FFmpeg 进入 return“dshow”设备列表?我需要使用 mingw-w64 手动构建 FFmpeg 吗?

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

int main(int argc, char *argv[])
{
    AVFormatContext* inFormatContext = avformat_alloc_context();
    AVInputFormat* inFormat = av_find_input_format("dshow");

    if (!inFormat || !inFormat->priv_class  || !AV_IS_INPUT_DEVICE(inFormat->priv_class->category))
    {
        return false;
    }

    AVDeviceInfoList* deviceList;
    int deviceCount = avdevice_list_input_sources(inFormat, nullptr, nullptr, &deviceList);

    avdevice_free_list_devices(&deviceList);
    avformat_free_context(inFormatContext);

    return 0;
}

您必须在 av_find_input_format("dshow") 之前调用 avdevice_register_all()

下面的代码returns一个有效的指针:

avdevice_register_all();

AVInputFormat* inFormat = av_find_input_format("dshow");

我不太了解这个主题,但我想 avdevice_register_all() 扩展了可用格式列表。