* [FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle @ 2023-12-10 22:10 Lena via ffmpeg-devel 2023-12-11 0:34 ` Andreas Rheinhardt 0 siblings, 1 reply; 14+ messages in thread From: Lena via ffmpeg-devel @ 2023-12-10 22:10 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Lena 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; } -- 2.43.0 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle 2023-12-10 22:10 [FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle Lena via ffmpeg-devel @ 2023-12-11 0:34 ` Andreas Rheinhardt 2023-12-11 1:35 ` Lena via ffmpeg-devel 2023-12-11 1:52 ` Lena via ffmpeg-devel 0 siblings, 2 replies; 14+ messages in thread From: Andreas Rheinhardt @ 2023-12-11 0:34 UTC (permalink / raw) To: 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle 2023-12-11 0:34 ` Andreas Rheinhardt @ 2023-12-11 1:35 ` Lena via ffmpeg-devel 2023-12-11 1:52 ` Lena via ffmpeg-devel 1 sibling, 0 replies; 14+ messages in thread From: Lena via ffmpeg-devel @ 2023-12-11 1:35 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Lena 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". _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle 2023-12-11 0:34 ` Andreas Rheinhardt 2023-12-11 1:35 ` Lena via ffmpeg-devel @ 2023-12-11 1:52 ` Lena via ffmpeg-devel 2023-12-12 0:47 ` Stefano Sabatini 1 sibling, 1 reply; 14+ messages in thread From: Lena via ffmpeg-devel @ 2023-12-11 1:52 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Lena, Andreas Rheinhardt 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; } -- 2.43.0 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle 2023-12-11 1:52 ` Lena via ffmpeg-devel @ 2023-12-12 0:47 ` Stefano Sabatini 2023-12-12 13:59 ` [FFmpeg-devel] [PATCH v2] " Lena via ffmpeg-devel 0 siblings, 1 reply; 14+ messages in thread From: Stefano Sabatini @ 2023-12-12 0:47 UTC (permalink / raw) To: FFmpeg development discussions and patches; +Cc: Lena, Andreas Rheinhardt 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). _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* [FFmpeg-devel] [PATCH v2] gdigrab: Allow capturing a window by its handle 2023-12-12 0:47 ` Stefano Sabatini @ 2023-12-12 13:59 ` Lena via ffmpeg-devel 2023-12-12 14:07 ` Nicolas George 0 siblings, 1 reply; 14+ messages in thread From: Lena via ffmpeg-devel @ 2023-12-12 13:59 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Lena, Stefano Sabatini, Andreas Rheinhardt Added the change to the documentation and added error checking on `strtol`, according to the stdlib documentation. The documentation for `strtol` says that on error, 0 is returned. This makes it impossible to specify a window handle of 0 (the whole desktop), but that case is already covered by the "desktop" input filename, so it should be fine. 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 | 13 ++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/indevs.texi b/doc/indevs.texi index 863536a34d..6da0ccac62 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: +There are three options for the input filename: @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..f310d8f3d7 100644 --- a/libavdevice/gdigrab.c +++ b/libavdevice/gdigrab.c @@ -273,9 +273,20 @@ 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); + + if (hwnd == NULL) { + av_log(s1, AV_LOG_ERROR, + "Invalid window handle.\n"); + 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; } -- 2.43.0 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] gdigrab: Allow capturing a window by its handle 2023-12-12 13:59 ` [FFmpeg-devel] [PATCH v2] " Lena via ffmpeg-devel @ 2023-12-12 14:07 ` Nicolas George 2023-12-12 15:31 ` Rémi Denis-Courmont 0 siblings, 1 reply; 14+ messages in thread From: Nicolas George @ 2023-12-12 14:07 UTC (permalink / raw) To: FFmpeg development discussions and patches Lena via ffmpeg-devel (12023-12-12): > The documentation for `strtol` says that on error, 0 is returned. This > makes it impossible to specify a window handle of 0 (the whole > desktop), but that case is already covered by the "desktop" input > filename, so it should be fine. The correct way to test for error in strtol is to check the endptr. But just use a single sscanf() and %n to see if it reached the end of the string. > -There are two options for the input filename: > +There are three options for the input filename: “Amongst options for the imput filenames are such elements as:” ;-) Regards, -- Nicolas George _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] gdigrab: Allow capturing a window by its handle 2023-12-12 14:07 ` Nicolas George @ 2023-12-12 15:31 ` Rémi Denis-Courmont 2023-12-13 10:03 ` Nicolas George 0 siblings, 1 reply; 14+ messages in thread From: Rémi Denis-Courmont @ 2023-12-12 15:31 UTC (permalink / raw) To: FFmpeg development discussions and patches Le 12 décembre 2023 16:07:28 GMT+02:00, Nicolas George <george@nsup.org> a écrit : >Lena via ffmpeg-devel (12023-12-12): >> The documentation for `strtol` says that on error, 0 is returned. This >> makes it impossible to specify a window handle of 0 (the whole >> desktop), but that case is already covered by the "desktop" input >> filename, so it should be fine. > >The correct way to test for error in strtol is to check the endptr. ...and test for overflow errors in errno.m (which shall have been zeroed beforehand). AFAIK, you need to do both if you want strict error detection. > >But just use a single sscanf() and %n to see if it reached the end of >the string. Don't some distros forbid the use of the n specifier for (debatable) "security reasons"? Or is that only for formatting, and not in scanning? >> -There are two options for the input filename: >> +There are three options for the input filename: > >“Amongst options for the imput filenames are such elements as:” > >;-) > >Regards, > >-- > Nicolas George >_______________________________________________ >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". _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] gdigrab: Allow capturing a window by its handle 2023-12-12 15:31 ` Rémi Denis-Courmont @ 2023-12-13 10:03 ` Nicolas George 2023-12-14 10:32 ` [FFmpeg-devel] [PATCH v3] " Lena via ffmpeg-devel 2023-12-14 10:52 ` [FFmpeg-devel] [PATCH v2] " Rémi Denis-Courmont 0 siblings, 2 replies; 14+ messages in thread From: Nicolas George @ 2023-12-13 10:03 UTC (permalink / raw) To: FFmpeg development discussions and patches Rémi Denis-Courmont (12023-12-12): > ...and test for overflow errors in errno.m (which shall have been > zeroed beforehand). AFAIK, you need to do both if you want strict > error detection. Or we can consider that 30064771114 is just another valid way if writing 42 = 042 = 0x2a. It would be better to check, but it is less critical than checking for garbage at the and, which itself is less critical than checking that the number is entirely absent. > Don't some distros forbid the use of the n specifier for (debatable) > "security reasons"? Or is that only for formatting, and not in > scanning? First time I ear of that. We use %n in quite a few places — not only code by me — and we did not have a problem. If there is a real security consideration about %n, I would like a pointer to the explanations; but I strongly doubt there are, it is just another conversion specifier with all the usual caveats. If not, and there are distros who forbid it for no valid reason, then I say to hell with them. Regards, -- Nicolas George _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* [FFmpeg-devel] [PATCH v3] gdigrab: Allow capturing a window by its handle 2023-12-13 10:03 ` Nicolas George @ 2023-12-14 10:32 ` Lena via ffmpeg-devel 2023-12-16 15:31 ` Stefano Sabatini 2023-12-14 10:52 ` [FFmpeg-devel] [PATCH v2] " Rémi Denis-Courmont 1 sibling, 1 reply; 14+ messages in thread From: Lena via ffmpeg-devel @ 2023-12-14 10:32 UTC (permalink / raw) To: ffmpeg-devel Cc: Lena, Stefano Sabatini, Nicolas George, Remi Denis-Courmont, Andreas Rheinhardt Updated the wording of the documentation, and added error checking for strtol. I looked at how other parts of the codebase check for errors on strtol and implemented it that way (iec61883, filter_units_bsf, etc). As for checking if the string value is larger/smaller than a long, i don't think there's a need, as the documentation says it'd just get set to LONG_MIN/LONG_MAX and fail anyway. 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(-) 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..3153b6f711 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.\n"); + 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; } -- 2.43.0 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH v3] gdigrab: Allow capturing a window by its handle 2023-12-14 10:32 ` [FFmpeg-devel] [PATCH v3] " Lena via ffmpeg-devel @ 2023-12-16 15:31 ` Stefano Sabatini 2023-12-17 17:29 ` [FFmpeg-devel] [PATCH v4] " Lena via ffmpeg-devel 0 siblings, 1 reply; 14+ messages in thread From: Stefano Sabatini @ 2023-12-16 15:31 UTC (permalink / raw) To: Lena Cc: Nicolas George, Remi Denis-Courmont, ffmpeg-devel, Andreas Rheinhardt On date Thursday 2023-12-14 11:32:44 +0100, Lena wrote: > Updated the wording of the documentation, and added error checking for strtol. > > I looked at how other parts of the codebase check for errors on strtol and implemented it that way (iec61883, filter_units_bsf, etc). > > As for checking if the string value is larger/smaller than a long, i don't think there's a need, as the documentation says it'd just get set to LONG_MIN/LONG_MAX and fail anyway. > > > 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(-) > > 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..3153b6f711 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.\n"); Here you can provide some context: "Invalid window handle '%s', must be an valid integer.", name Looks good otherwise, thanks. _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* [FFmpeg-devel] [PATCH v4] gdigrab: Allow capturing a window by its handle 2023-12-16 15:31 ` Stefano Sabatini @ 2023-12-17 17:29 ` Lena via ffmpeg-devel 2023-12-17 18:17 ` Stefano Sabatini 0 siblings, 1 reply; 14+ messages in thread From: Lena via ffmpeg-devel @ 2023-12-17 17:29 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Lena, Stefano Sabatini, Remi Denis-Courmont 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(-) 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; } -- 2.43.0 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH v4] gdigrab: Allow capturing a window by its handle 2023-12-17 17:29 ` [FFmpeg-devel] [PATCH v4] " Lena via ffmpeg-devel @ 2023-12-17 18:17 ` Stefano Sabatini 0 siblings, 0 replies; 14+ messages in thread From: Stefano Sabatini @ 2023-12-17 18:17 UTC (permalink / raw) To: ffmpeg-devel, Lena 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. _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] gdigrab: Allow capturing a window by its handle 2023-12-13 10:03 ` Nicolas George 2023-12-14 10:32 ` [FFmpeg-devel] [PATCH v3] " Lena via ffmpeg-devel @ 2023-12-14 10:52 ` Rémi Denis-Courmont 1 sibling, 0 replies; 14+ messages in thread From: Rémi Denis-Courmont @ 2023-12-14 10:52 UTC (permalink / raw) To: FFmpeg development discussions and patches Le 13 décembre 2023 12:03:55 GMT+02:00, Nicolas George <george@nsup.org> a écrit : >Rémi Denis-Courmont (12023-12-12): >> ...and test for overflow errors in errno.m (which shall have been >> zeroed beforehand). AFAIK, you need to do both if you want strict >> error detection. > >Or we can consider that 30064771114 is just another valid way if writing >42 = 042 = 0x2a. It would be better to check, but it is less critical >than checking for garbage at the and, which itself is less critical than >checking that the number is entirely absent. That's completely arbitrary, TBH. Both cases are syntax errors, and there are no particular reasons to tolerate one but not the other. And even if it constitued a sensible distinction, that's simply not how strtoul() handles overflow: it returns ULONG_MAX, not a wrapped-around value. In this case, both error cases are strong signs of a typing error or corruption. _______________________________________________ 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". ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2023-12-17 18:17 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-12-10 22:10 [FFmpeg-devel] [PATCH] gdigrab: Allow capturing a window by its handle Lena via ffmpeg-devel 2023-12-11 0:34 ` Andreas Rheinhardt 2023-12-11 1:35 ` Lena via ffmpeg-devel 2023-12-11 1:52 ` Lena via ffmpeg-devel 2023-12-12 0:47 ` Stefano Sabatini 2023-12-12 13:59 ` [FFmpeg-devel] [PATCH v2] " Lena via ffmpeg-devel 2023-12-12 14:07 ` Nicolas George 2023-12-12 15:31 ` Rémi Denis-Courmont 2023-12-13 10:03 ` Nicolas George 2023-12-14 10:32 ` [FFmpeg-devel] [PATCH v3] " Lena via ffmpeg-devel 2023-12-16 15:31 ` Stefano Sabatini 2023-12-17 17:29 ` [FFmpeg-devel] [PATCH v4] " Lena via ffmpeg-devel 2023-12-17 18:17 ` Stefano Sabatini 2023-12-14 10:52 ` [FFmpeg-devel] [PATCH v2] " Rémi Denis-Courmont
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git