I'm trying to use DirectShow devices with FFmpeg in a C program. I'm using DLLs built with vcpkg using the command .\vcpkg install ffmpeg[nvcodec]:x64-windows
. The vcpkg log shows Enabled indevs: dshow
av_find_input_format is returning nullptr for me (no "dshow" devices found).
If I query the downloaded FFmpeg executable, I get a list of 14 "dshow" devices.
How can I get FFmpeg to return the list of "dshow" devices? Do I need to manually build FFmpeg using mingw-w64
?
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;
}
CodePudding user response:
You have to call avdevice_register_all()
before av_find_input_format("dshow")
.
The following code returns a valid pointer:
avdevice_register_all();
AVInputFormat* inFormat = av_find_input_format("dshow");
I don't know much about the subject, but I guess avdevice_register_all()
expands the list of available formats.