[Libav-user] gdigrab grab not working with c++ code.
Neural Net
neuralnetcode at gmail.com
Tue Dec 10 15:59:41 EET 2024
I am using build from https://github.com/BtbN/FFmpeg-Builds/releases for
Windows 64 with MSVC compiler, I need to capture screen using c++ code
using gdigrab, but gdigrab not working
So I check the ffmpeg exe with formats arg
.\ffmpeg.exe -formats
Give the result
D d gdigrab GDI API Windows frame grabber
Which says gdigrab is there with ffmpeg exe. And I can screen capture with
this exe too. I am linking the same lib coming with this exe, so the below
code should expected to work with gdigrab
avformat_network_init();
AVFormatContext *formatCtx = nullptr;
AVDictionary *options = nullptr;
const char *inputSource = "desktop";
const char *inputFormat = "gdigrab";
// Initialize options
av_dict_set(&options, "video_size", "800x600", 0);
av_dict_set(&options, "offset_x", "100", 0);
av_dict_set(&options, "offset_y", "100", 0);
av_dict_set(&options, "framerate", "30", 0);
// Debug options
char *dump = nullptr;
av_dict_get_string(options, &dump, '=', ',');
qDebug() << "Options: " << dump;
av_free(dump);
const AVInputFormat *fmt = nullptr;
void *opaque = nullptr;
while ((fmt = av_demuxer_iterate(&opaque))) {
qDebug() << fmt->name;
}
// Find input format
const AVInputFormat *inputFmt = av_find_input_format(inputFormat);
if (!inputFmt) {
qDebug() << "Error: Input format not found:" << inputFormat;
}
// Open input
int ret = avformat_open_input(&formatCtx, inputSource, inputFmt,
&options);
if (ret < 0) {
char errbuf[AV_ERROR_MAX_STRING_SIZE];
av_strerror(ret, errbuf, sizeof(errbuf));
qDebug() << "Error: Unable to open input source:" << inputSource <<
", " << errbuf;
return;
}
It always print
Error: Input format not found: gdigrab
Error: Unable to open input source: desktop , No such file or directory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20241210/a419f88b/attachment.htm>
More information about the Libav-user
mailing list