我正在尝试使用 ffmpeg 获取 dshow 设备列表。我无法得到它,但 ffmpeg 自己得到它。这是代码。它为 avdevice_list_input_sources 返回 AVERROR(ENOSYS)。但是 avformat_open_input 打印所有设备。如何在 C++ 代码中获取 dshow 设备和选项。
avdevice_register_all();
AVInputFormat *iformat = av_find_input_format("dshow");
printf("========Device Info=============\n");
AVDeviceInfoList *device_list = NULL;
AVDictionary* options = NULL;
//av_dict_set(&options, "list_devices", "true", 0);
int result = avdevice_list_input_sources(iformat, NULL, options, &device_list);
if (result < 0)
printf("Error Code:%s\n", av_err2str(result));//Returns -40 AVERROR(ENOSYS)
else printf("Devices count:%d\n", result);
AVFormatContext *pFormatCtx = avformat_alloc_context();
AVDictionary* options2 = NULL;
av_dict_set(&options2, "list_devices", "true", 0);
avformat_open_input(&pFormatCtx, NULL, iformat, &options2);
printf("================================\n");
最佳答案
“我们”还没有探测 libav 以返回设备列表。所以它要么解析 ffmpeg.exe -f dshow -list_devices true -i dummy
的输出,要么自己使用 dshow api 枚举它们:
https://trac.ffmpeg.org/wiki/DirectShow#Howtoprogrammaticallyenumeratedevices
关于c++ - 如何在 C++ 中使用 ffmpeg 获取 DirectShow 设备列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51991436/