diff mbox series

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

Message ID 20231217172932.60614-2-lena@nihil.gay
State New
Headers show
Series [FFmpeg-devel,v4] gdigrab: Allow capturing a window by its handle | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Lena Dec. 17, 2023, 5:29 p.m. UTC
Added more context in the error message and did a final test that it all works.

Thanks for the smooth patch submission process!


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>
---
 doc/indevs.texi       |  8 ++++++--
 libavdevice/gdigrab.c | 15 ++++++++++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)

Comments

Stefano Sabatini Dec. 17, 2023, 6:17 p.m. UTC | #1
On date Sunday 2023-12-17 18:29:33 +0100, Lena wrote:
> Added more context in the error message and did a final test that it all works.
> 
> Thanks for the smooth patch submission process!
> 
> 
> 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>
> ---
>  doc/indevs.texi       |  8 ++++++--
>  libavdevice/gdigrab.c | 15 ++++++++++++++-
>  2 files changed, 20 insertions(+), 3 deletions(-)

Thanks! Applied with a typo fix and a Changelog addition.
diff mbox series

Patch

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 863536a34d..a0c684f545 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -722,7 +722,7 @@  Win32 GDI-based screen capture device.
 
 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
 desktop
 @end example
@@ -730,9 +730,13 @@  or
 @example
 title=@var{window_title}
 @end example
+or
+@example
+hwnd=@var{window_hwnd}
+@end example
 
 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.
 
 For example, to grab the entire desktop using @command{ffmpeg}:
diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index c069232472..aa909a9392 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -273,9 +273,22 @@  gdigrab_read_header(AVFormatContext *s1)
         }
     } else if (!strcmp(filename, "desktop")) {
         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 an valid integer.\n", name);
+            ret = AVERROR(EINVAL);
+            goto error;
+        }
     } else {
         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);
         goto error;
     }