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

fgodtdev at hotmail.com fgodtdev at hotmail.com
Sat Jan 11 11:18:08 EET 2020


From: FgoDt <fgodtdev at 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 at hotmail.com>
---
 doc/indevs.texi       |  7 +++++++
 libavdevice/gdigrab.c | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

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.
 
+ at 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 },
 };
 
-- 
2.23.0



More information about the ffmpeg-devel mailing list