diff mbox series

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

Message ID 719e708c-25a8-422d-8392-6a837b138fe3@nihil.gay
State New
Headers show
Series [FFmpeg-devel] gdigrab: Allow capturing a window by its handle | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

Lena Dec. 10, 2023, 10:10 p.m. UTC
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>
---
  libavdevice/gdigrab.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

      }

Comments

Andreas Rheinhardt Dec. 11, 2023, 12:34 a.m. UTC | #1
Lena via ffmpeg-devel:
> 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>
> ---
>  libavdevice/gdigrab.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> 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 won't even compile due to the extra '+'.

>      } 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;
>      }
Lena Dec. 11, 2023, 1:35 a.m. UTC | #2
I'm so sorry, will resend immediately.


Andreas Rheinhardt via ffmpeg-devel:

> Lena via ffmpeg-devel:
>> 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>
>> ---
>>   libavdevice/gdigrab.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> 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 won't even compile due to the extra '+'.
>
>>       } 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;
>>       }
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Lena Dec. 11, 2023, 1:52 a.m. UTC | #3
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>
---
 libavdevice/gdigrab.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

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);
     } 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;
     }
Stefano Sabatini Dec. 12, 2023, 12:47 a.m. UTC | #4
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@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).
diff mbox series

Patch

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);
      } 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;