diff mbox series

[FFmpeg-devel,v4,1/1] avdevice/gdigrab add use_captureblt option

Message ID HK2PR03MB4596AB273414D034C0F0D34EC63B0@HK2PR03MB4596.apcprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,v4,1/1] avdevice/gdigrab add use_captureblt option | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

fgodtdev@hotmail.com Jan. 11, 2020, 9:18 a.m. UTC
From: FgoDt <fgodtdev@hotmail.com>

Add use_captureblt option for disable or use CAPTUREBLT flag, when useing the bitblt function with CAPTUREBLT may caused the Windows mouse cursor flicker. most time we don't need this flag to capture window
I tested on Windows 10 works fine

Signed-off-by: fgodt <fgodtdev@hotmail.com>
---
 doc/indevs.texi       |  7 +++++++
 libavdevice/gdigrab.c | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

Comments

Derek Buitenhuis Jan. 13, 2020, 4:10 p.m. UTC | #1
On 11/01/2020 09:18, fgodtdev@hotmail.com wrote:
> From: FgoDt <fgodtdev@hotmail.com>
> 
> Add use_captureblt option for disable or use CAPTUREBLT flag, when useing the bitblt function with CAPTUREBLT may caused the Windows mouse cursor flicker. most time we don't need this flag to capture window
> I tested on Windows 10 works fine
> 
> Signed-off-by: fgodt <fgodtdev@hotmail.com>
> ---
>  doc/indevs.texi       |  7 +++++++
>  libavdevice/gdigrab.c | 10 +++++++++-
>  2 files changed, 16 insertions(+), 1 deletion(-)

Does it make sense to name this something like 'capature_layered_windows'?

Using the name of the flag is a bit unintuitive from a user perspective.

Same for the description.

- Derek
Carl Eugen Hoyos Jan. 13, 2020, 11:24 p.m. UTC | #2
Am Mo., 13. Jan. 2020 um 17:10 Uhr schrieb Derek Buitenhuis
<derek.buitenhuis@gmail.com>:
>
> On 11/01/2020 09:18, fgodtdev@hotmail.com wrote:
> > From: FgoDt <fgodtdev@hotmail.com>
> >
> > Add use_captureblt option for disable or use CAPTUREBLT flag, when useing the bitblt function with CAPTUREBLT may caused the Windows mouse cursor flicker. most time we don't need this flag to capture window
> > I tested on Windows 10 works fine
> >
> > Signed-off-by: fgodt <fgodtdev@hotmail.com>
> > ---
> >  doc/indevs.texi       |  7 +++++++
> >  libavdevice/gdigrab.c | 10 +++++++++-
> >  2 files changed, 16 insertions(+), 1 deletion(-)
>
> Does it make sense to name this something like 'capature_layered_windows'?
>
> Using the name of the flag is a bit unintuitive from a user perspective.

Not sure if "capture_layered_windows" is more intuitive than using the name
of an os flag but ...

> Same for the description.

Shouldn't the description explain that this option helps against mouse
cursor flicker?

Carl Eugen
Calvin Walton Jan. 14, 2020, 7:01 p.m. UTC | #3
On Sat, 2020-01-11 at 17:18 +0800, fgodtdev@hotmail.com wrote:
> From: FgoDt <fgodtdev@hotmail.com>
> 
> Add use_captureblt option for disable or use CAPTUREBLT flag, when
> useing the bitblt function with CAPTUREBLT may caused the Windows
> mouse cursor flicker. most time we don't need this flag to capture
> window
> I tested on Windows 10 works fine

I have a suggestion for improving the documentation, see below.

Can you please test for me: If you use use_captureblt=0 and
draw_mouse=0 is the mouse cursor visible or not in the recorded video?

> +@item use_captureblt
> +gdigrab use CAPTUREBLT flag to capture window or desktop by default,
> which may make Windows mouse cursor flickering.
> +If not capture layered window you can set value @code{0} disable
> CAPTUREBLT flag, to fix Windows cursor flickering.
> +Default value is @code{1}
> +
> +Note the value @code{1} is essential to capture layered  window

@item use_captureblt

By default, this is set to @code{1}, which means that gdigrab will use
the CAPTUREBLT flag when grabbing images of a window. With this flag
set, gdigrab will capture the entire contents of a window even if it is
covered by other windows on the screen.

If this option is set to @code{0}, the image captured will match what
you see on the screen: the contents of any windows covering the
selected window will be visible in the capture.

Depending on your Windows version and graphics settings, you may see
the mouse cursor flicker on your screen while capturing with this
option set to @code{1}. If that happens, you can disable CAPTUREBLT by
setting this option to @code{0}.
fgodtdev@hotmail.com Jan. 16, 2020, 1:08 a.m. UTC | #4
On 2020/1/15 上午3:01, Calvin Walton wrote:
> On Sat, 2020-01-11 at 17:18 +0800, fgodtdev@hotmail.com wrote:
>> From: FgoDt <fgodtdev@hotmail.com>
>>
>> Add use_captureblt option for disable or use CAPTUREBLT flag, when
>> useing the bitblt function with CAPTUREBLT may caused the Windows
>> mouse cursor flicker. most time we don't need this flag to capture
>> window
>> I tested on Windows 10 works fine
> I have a suggestion for improving the documentation, see below.
>
> Can you please test for me: If you use use_captureblt=0 and
> draw_mouse=0 is the mouse cursor visible or not in the recorded video?
The mouse cursor not in video
>> +@item use_captureblt
>> +gdigrab use CAPTUREBLT flag to capture window or desktop by default,
>> which may make Windows mouse cursor flickering.
>> +If not capture layered window you can set value @code{0} disable
>> CAPTUREBLT flag, to fix Windows cursor flickering.
>> +Default value is @code{1}
>> +
>> +Note the value @code{1} is essential to capture layered  window
> @item use_captureblt
>
> By default, this is set to @code{1}, which means that gdigrab will use
> the CAPTUREBLT flag when grabbing images of a window. With this flag
> set, gdigrab will capture the entire contents of a window even if it is
> covered by other windows on the screen.
>
> If this option is set to @code{0}, the image captured will match what
> you see on the screen: the contents of any windows covering the
> selected window will be visible in the capture.
>
> Depending on your Windows version and graphics settings, you may see
> the mouse cursor flicker on your screen while capturing with this
> option set to @code{1}. If that happens, you can disable CAPTUREBLT by
> setting this option to @code{0}.
>
Thanks for you suggestion, but there is issue, without the CAPTUREBLT 
flag not change any thing for normal window in captured video, the worke 
same like use CAPTUREBLT flag. So the can capture window even if it is 
covered.

fgodt
fgodtdev@hotmail.com Jan. 16, 2020, 1:11 a.m. UTC | #5
On 2020/1/14 上午7:24, Carl Eugen Hoyos wrote:
> Am Mo., 13. Jan. 2020 um 17:10 Uhr schrieb Derek Buitenhuis
> <derek.buitenhuis@gmail.com>:
>> On 11/01/2020 09:18, fgodtdev@hotmail.com wrote:
>>> From: FgoDt <fgodtdev@hotmail.com>
>>>
>>> Add use_captureblt option for disable or use CAPTUREBLT flag, when useing the bitblt function with CAPTUREBLT may caused the Windows mouse cursor flicker. most time we don't need this flag to capture window
>>> I tested on Windows 10 works fine
>>>
>>> Signed-off-by: fgodt <fgodtdev@hotmail.com>
>>> ---
>>>   doc/indevs.texi       |  7 +++++++
>>>   libavdevice/gdigrab.c | 10 +++++++++-
>>>   2 files changed, 16 insertions(+), 1 deletion(-)
>> Does it make sense to name this something like 'capature_layered_windows'?
>>
>> Using the name of the flag is a bit unintuitive from a user perspective.
> Not sure if "capture_layered_windows" is more intuitive than using the name
> of an os flag but ...
Agree with it
>> Same for the description.
> Shouldn't the description explain that this option helps against mouse
> cursor flicker?
I think explain is necessary, most people don't know this flag will make 
mouse flicker. If user find mouse cursor flicker they will find solution 
on doc

fgodt
Calvin Walton Jan. 16, 2020, 6 p.m. UTC | #6
On Thu, 2020-01-16 at 09:08 +0800, fgodt wrote:

> > By default, this is set to @code{1}, which means that gdigrab will
> > use
> > the CAPTUREBLT flag when grabbing images of a window. With this
> > flag
> > set, gdigrab will capture the entire contents of a window even if
> > it is
> > covered by other windows on the screen.
> > 
> > If this option is set to @code{0}, the image captured will match
> > what
> > you see on the screen: the contents of any windows covering the
> > selected window will be visible in the capture.
> > 
> > Depending on your Windows version and graphics settings, you may
> > see
> > the mouse cursor flicker on your screen while capturing with this
> > option set to @code{1}. If that happens, you can disable CAPTUREBLT
> > by
> > setting this option to @code{0}.
> > 
> Thanks for you suggestion, but there is issue, without the
> CAPTUREBLT 
> flag not change any thing for normal window in captured video, the
> worke 
> same like use CAPTUREBLT flag. So the can capture window even if it
> is 
> covered.

Ah, fun, this is based on a misinterpretation of the windows
documentation:

CAPTUREBLT
Includes any windows that are layered on top of your window in the 
resulting image. By default, the image only contains your window. 

But according to this StackOverflow response:
https://stackoverflow.com/a/4646999

What that actually means is that CAPTUREBLT includes windows with the
"WS_EX_LAYERED" window style that overlap the window, not *any* window.

Layered windows are described in: 
https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#layered-windows


I think we should unconditionally remove the CAPTUREBLT flag, there's
no need for any options or documentation changes.
fgodtdev@hotmail.com Jan. 17, 2020, 2:04 a.m. UTC | #7
On 2020/1/17 上午2:00, Calvin Walton wrote:
> On Thu, 2020-01-16 at 09:08 +0800, fgodt wrote:
>
>>> By default, this is set to @code{1}, which means that gdigrab will
>>> use
>>> the CAPTUREBLT flag when grabbing images of a window. With this
>>> flag
>>> set, gdigrab will capture the entire contents of a window even if
>>> it is
>>> covered by other windows on the screen.
>>>
>>> If this option is set to @code{0}, the image captured will match
>>> what
>>> you see on the screen: the contents of any windows covering the
>>> selected window will be visible in the capture.
>>>
>>> Depending on your Windows version and graphics settings, you may
>>> see
>>> the mouse cursor flicker on your screen while capturing with this
>>> option set to @code{1}. If that happens, you can disable CAPTUREBLT
>>> by
>>> setting this option to @code{0}.
>>>
>> Thanks for you suggestion, but there is issue, without the
>> CAPTUREBLT
>> flag not change any thing for normal window in captured video, the
>> worke
>> same like use CAPTUREBLT flag. So the can capture window even if it
>> is
>> covered.
> Ah, fun, this is based on a misinterpretation of the windows
> documentation:
>
> CAPTUREBLT
> Includes any windows that are layered on top of your window in the
> resulting image. By default, the image only contains your window.
>
> But according to this StackOverflow response:
> https://stackoverflow.com/a/4646999
>
> What that actually means is that CAPTUREBLT includes windows with the
> "WS_EX_LAYERED" window style that overlap the window, not *any* window.
>
> Layered windows are described in:
> https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#layered-windows
>
>
> I think we should unconditionally remove the CAPTUREBLT flag, there's
> no need for any options or documentation changes.
>
Thanks, if we remove CAPTUREBLT flag the user may can't capture layered 
window(use WS_EX_LAYERED extended), it is ok for this?

fgodt
fgodtdev@hotmail.com Jan. 21, 2020, 1:32 a.m. UTC | #8
在 2020/1/17 10:04, fgodt 写道:
>
> On 2020/1/17 上午2:00, Calvin Walton wrote:
>> On Thu, 2020-01-16 at 09:08 +0800, fgodt wrote:
>>
>>>> By default, this is set to @code{1}, which means that gdigrab will
>>>> use
>>>> the CAPTUREBLT flag when grabbing images of a window. With this
>>>> flag
>>>> set, gdigrab will capture the entire contents of a window even if
>>>> it is
>>>> covered by other windows on the screen.
>>>>
>>>> If this option is set to @code{0}, the image captured will match
>>>> what
>>>> you see on the screen: the contents of any windows covering the
>>>> selected window will be visible in the capture.
>>>>
>>>> Depending on your Windows version and graphics settings, you may
>>>> see
>>>> the mouse cursor flicker on your screen while capturing with this
>>>> option set to @code{1}. If that happens, you can disable CAPTUREBLT
>>>> by
>>>> setting this option to @code{0}.
>>>>
>>> Thanks for you suggestion, but there is issue, without the
>>> CAPTUREBLT
>>> flag not change any thing for normal window in captured video, the
>>> worke
>>> same like use CAPTUREBLT flag. So the can capture window even if it
>>> is
>>> covered.
>> Ah, fun, this is based on a misinterpretation of the windows
>> documentation:
>>
>> CAPTUREBLT
>> Includes any windows that are layered on top of your window in the
>> resulting image. By default, the image only contains your window.
>>
>> But according to this StackOverflow response:
>> https://stackoverflow.com/a/4646999
>>
>> What that actually means is that CAPTUREBLT includes windows with the
>> "WS_EX_LAYERED" window style that overlap the window, not *any* window.
>>
>> Layered windows are described in:
>> https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#layered-windows 
>>
>>
>>
>> I think we should unconditionally remove the CAPTUREBLT flag, there's
>> no need for any options or documentation changes.
>>
> Thanks, if we remove CAPTUREBLT flag the user may can't capture 
> layered window(use WS_EX_LAYERED extended), it is ok for this?
>
Judging from this mail, remove CAPTUREBLT flag looks good for solve this 
issue.
diff mbox series

Patch

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 6f5afaf344..967ae22991 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -743,6 +743,13 @@  When capturing a region with @var{video_size}, set the distance from the top edg
 
 Note that the offset calculation is from the top left corner of the primary monitor on Windows. If you have a monitor positioned above your primary monitor, you will need to use a negative @var{offset_y} value to move the region to that monitor.
 
+@item use_captureblt
+gdigrab use CAPTUREBLT flag to capture window or desktop by default, which may make Windows mouse cursor flickering.
+If not capture layered window you can set value @code{0} disable CAPTUREBLT flag, to fix Windows cursor flickering.
+Default value is @code{1}
+
+Note the value @code{1} is essential to capture layered  window
+
 @end table
 
 @section iec61883
diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index f4444406fa..658719e929 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -53,6 +53,8 @@  struct gdigrab {
     int        offset_x;    /**< Capture x offset (private option) */
     int        offset_y;    /**< Capture y offset (private option) */
 
+    int        use_captureblt; /**< Capture gdi window with CAPTUREBLT flag (private option) */
+
     HWND       hwnd;        /**< Handle of the window for the grab */
     HDC        source_hdc;  /**< Source device context */
     HDC        dest_hdc;    /**< Destination, source-compatible DC */
@@ -542,6 +544,8 @@  static int gdigrab_read_packet(AVFormatContext *s1, AVPacket *pkt)
 
     int64_t curtime, delay;
 
+    unsigned long flag = SRCCOPY;
+
     /* Calculate the time of the next frame */
     time_frame += INT64_C(1000000);
 
@@ -570,12 +574,15 @@  static int gdigrab_read_packet(AVFormatContext *s1, AVPacket *pkt)
         return AVERROR(ENOMEM);
     pkt->pts = curtime;
 
+    if(gdigrab->use_captureblt)
+        flag |= CAPTUREBLT;
+
     /* Blit screen grab */
     if (!BitBlt(dest_hdc, 0, 0,
                 clip_rect.right - clip_rect.left,
                 clip_rect.bottom - clip_rect.top,
                 source_hdc,
-                clip_rect.left, clip_rect.top, SRCCOPY | CAPTUREBLT)) {
+                clip_rect.left, clip_rect.top, flag)) {
         WIN32_API_ERROR("Failed to capture image");
         return AVERROR(EIO);
     }
@@ -639,6 +646,7 @@  static const AVOption options[] = {
     { "video_size", "set video frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
     { "offset_x", "capture area x offset", OFFSET(offset_x), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC },
     { "offset_y", "capture area y offset", OFFSET(offset_y), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC },
+    { "use_captureblt", "capture gdi window use CAPTTUREBLT flag", OFFSET(use_captureblt), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, DEC },
     { NULL },
 };