gdigrab: allow capturing a window by its handle

x11grab can capture windows by their ID, but gdigrab can only capture
windows by their names, internally calling FindWindowW to lookup its
handle.

This patch simply allows the user to specify a window handle directly.
Signed-off-by: Lena <lena@nihil.gay>
This commit is contained in:
Lena 2023-12-17 18:29:33 +01:00 committed by Stefano Sabatini
parent 419145c11b
commit d7ac7101ee
3 changed files with 21 additions and 3 deletions

View File

@ -9,6 +9,7 @@ version <next>:
- aap filter - aap filter
- demuxing, decoding, filtering, encoding, and muxing in the - demuxing, decoding, filtering, encoding, and muxing in the
ffmpeg CLI now all run in parallel ffmpeg CLI now all run in parallel
- enable gdigrab device to grab a window using the hwnd=HANDLER syntax
version 6.1: version 6.1:
- libaribcaption decoder - libaribcaption decoder

View File

@ -722,7 +722,7 @@ Win32 GDI-based screen capture device.
This device allows you to capture a region of the display on Windows. This device allows you to capture a region of the display on Windows.
There are two options for the input filename: Amongst options for the imput filenames are such elements as:
@example @example
desktop desktop
@end example @end example
@ -730,9 +730,13 @@ or
@example @example
title=@var{window_title} title=@var{window_title}
@end example @end example
or
@example
hwnd=@var{window_hwnd}
@end example
The first option will capture the entire desktop, or a fixed region of the The first option will capture the entire desktop, or a fixed region of the
desktop. The second option will instead capture the contents of a single desktop. The second and third options will instead capture the contents of a single
window, regardless of its position on the screen. window, regardless of its position on the screen.
For example, to grab the entire desktop using @command{ffmpeg}: For example, to grab the entire desktop using @command{ffmpeg}:

View File

@ -273,9 +273,22 @@ gdigrab_read_header(AVFormatContext *s1)
} }
} else if (!strcmp(filename, "desktop")) { } else if (!strcmp(filename, "desktop")) {
hwnd = NULL; hwnd = NULL;
} else if (!strncmp(filename, "hwnd=", 5)) {
name = filename + 5;
char *p;
hwnd = strtol(name, &p, 0);
if (p == NULL || p == name || p[0] == '\0')
{
av_log(s1, AV_LOG_ERROR,
"Invalid window handle '%s', must be a valid integer.\n", name);
ret = AVERROR(EINVAL);
goto error;
}
} else { } else {
av_log(s1, AV_LOG_ERROR, av_log(s1, AV_LOG_ERROR,
"Please use \"desktop\" or \"title=<windowname>\" to specify your target.\n"); "Please use \"desktop\", \"title=<windowname>\" or \"hwnd=<hwnd>\" to specify your target.\n");
ret = AVERROR(EIO); ret = AVERROR(EIO);
goto error; goto error;
} }