[FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle

Stefano Sabatini stefasab at gmail.com
Tue Dec 12 02:47:13 EET 2023


On date Monday 2023-12-11 02:52:01 +0100, ffmpeg-devel Mailing List wrote:
> 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 at nihil.gay>
> ---

>  libavdevice/gdigrab.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Missing doc/indevs.texi updates.

> diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
> index c069232472..05d3c0c929 100644
> --- a/libavdevice/gdigrab.c
> +++ b/libavdevice/gdigrab.c
> @@ -273,9 +273,13 @@ gdigrab_read_header(AVFormatContext *s1)
>          }
>      } else if (!strcmp(filename, "desktop")) {
>          hwnd = NULL;

> +    } else if (!strncmp(filename, "hwnd=", 5)) {
> +        name = filename + 5;
> +        
> +        hwnd = strtol(name, NULL, 0);

This should fail in case the parsing failed, for this you can check
the second argument (see examples in the code).


More information about the ffmpeg-devel mailing list