Opened 19 months ago

#10383 new defect

GDI grab mouse vertical offset

Reported by: zboubida Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords: gdigrab, mouse
Cc: zboubida Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
When using gdi grab on Windows, the mouse cursor Y position is wrong. It seems to be offset by the size of the window decoration. All the reports I've seen about gdi mouse issues are about high DPI: I think the problem here is different (I'm not using high DPI).

In the following example, capturing calc.exe gives a video without the window header/title nor the application menu. That's about 50px height. The cursor is offset down by this amount.
It's like the cursor coordinates are relative to the source window rather than the video output.

Ffmpeg version:

ffmpeg version 2023-04-24-git-2aad9765ef-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enab
le-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enabl
e-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 -
-enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation
 --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llv
m --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable
-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libt
wolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladsp
a --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil      58.  6.100 / 58.  6.100
libavcodec     60. 10.100 / 60. 10.100
libavformat    60.  5.100 / 60.  5.100
libavdevice    60.  2.100 / 60.  2.100
libavfilter     9.  5.100 /  9.  5.100
libswscale      7.  2.100 /  7.  2.100
libswresample   4. 11.100 /  4. 11.100
libpostproc    57.  2.100 / 57.  2.100

How to reproduce:
Capturing 3 different applications, as they exhibit different behaviours.

  • calc.exe (title bar + menu removed)
  • blender.exe (only title bar removed)
  • explorer.exe (nothing removed, the video size is the same as the input size)

With calc, the removed header is about 50px and the mouse offset is about the same. With blender, only the title bar is removed (about 25px), which correspond to the mouse offset. With explorer, the window size and video size match, and the cursor is positioned correctly.

% ffmpeg -y -t 10 -f gdigrab -framerate 30 -i title="Calculator" -c:v libx264 -crf 22 calc.mkv

[gdigrab @ 000001d2e68e2940] Found window Calculator, capturing 407x264x32 at (0,0)
Input #0, gdigrab, from 'title=Calculator':
  Duration: N/A, start: 1684916015.520521, bitrate: 103163 kb/s
  Stream #0:0: Video: bmp, bgra, 407x264, 103163 kb/s, 30 fps, 30 tbr, 1000k tbn
Stream mapping:
  Stream #0:0 -> #0:0 (bmp (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 000001d2e6ea7380] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001d2e6ea7380] profile High 4:4:4 Predictive, level 2.1, 4:4:4, 8-bit
[libx264 @ 000001d2e6ea7380] 264 - core 164 r3106 eaa68fa - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0
 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=8 loo
kahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=
2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=22.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'calc.mkv':
  Metadata:
    encoder         : Lavf60.5.100
  Stream #0:0: Video: h264 (H264 / 0x34363248), yuv444p(tv, progressive), 407x264, q=2-31, 30 fps, 1k tbn
    Metadata:
      encoder         : Lavc60.10.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
[out#0/matroska @ 000001d2e6912dc0] video:77kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3.277654%
frame=  300 fps= 31 q=-1.0 Lsize=      80kB time=00:00:09.93 bitrate=  65.9kbits/s speed=1.03x
[libx264 @ 000001d2e6ea7380] frame I:2     Avg QP:19.09  size: 18290
[libx264 @ 000001d2e6ea7380] frame P:100   Avg QP:21.27  size:   329
[libx264 @ 000001d2e6ea7380] frame B:198   Avg QP:28.77  size:    46
[libx264 @ 000001d2e6ea7380] consecutive B-frames:  6.7% 13.3%  8.0% 72.0%
[libx264 @ 000001d2e6ea7380] mb I  I16..4: 21.9%  9.3% 68.8%
[libx264 @ 000001d2e6ea7380] mb P  I16..4:  0.1%  0.0%  0.4%  P16..4:  2.7%  0.5%  0.3%  0.0%  0.0%    skip:96.1%
[libx264 @ 000001d2e6ea7380] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  1.8%  0.1%  0.0%  direct: 0.0%  skip:98.1%  L0:37.1% L1:62.2% BI: 0.7%
[libx264 @ 000001d2e6ea7380] 8x8 transform intra:7.7% inter:48.1%
[libx264 @ 000001d2e6ea7380] coded y,u,v intra: 48.3% 32.3% 28.5% inter: 0.4% 0.3% 0.2%
[libx264 @ 000001d2e6ea7380] i16 v,h,dc,p:  3% 94%  0%  3%
[libx264 @ 000001d2e6ea7380] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 46% 47%  6%  0%  0%  0%  0%  0%  1%
[libx264 @ 000001d2e6ea7380] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 50%  6%  1%  2%  2%  2%  2%  2%
[libx264 @ 000001d2e6ea7380] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 000001d2e6ea7380] ref P L0: 49.9%  5.7% 29.3% 15.0%
[libx264 @ 000001d2e6ea7380] ref B L0: 80.5% 16.8%  2.7%
[libx264 @ 000001d2e6ea7380] ref B L1: 93.5%  6.5%
[libx264 @ 000001d2e6ea7380] kb/s:62.60
% ffmpeg -y -t 10 -f gdigrab -framerate 30 -i title='Blender' -c:v libx264 -crf 22 blender.mkv

[gdigrab @ 0000024eb8312940] Found window Blender, capturing 1468x808x32 at (0,0)
% ffmpeg -y -t 10 -f gdigrab -framerate 30 -i title='H:\share\test' -c:v libx264 -crf 22 explorer.mkv

[gdigrab @ 000002117ed62940] Found window H:\share\test, capturing 1231x772x32 at (0,0)

Side note: with explorer.exe, the window decoration is black instead of white, for some reason. But that's another issue.

The attached files show both a screenshot of the application window and the result of gdigrab capture.

Attachments (6)

calc.png (19.0 KB ) - added by zboubida 19 months ago.
Screenshot of Calculator
calc.mkv (79.9 KB ) - added by zboubida 19 months ago.
Video recording of Calculator
blender.png (427.0 KB ) - added by zboubida 19 months ago.
Blender screenshot
blender.mkv (377.0 KB ) - added by zboubida 19 months ago.
Blender video window capture
explorer.png (28.3 KB ) - added by zboubida 19 months ago.
Explorer screenshot
explorer.mkv (140.9 KB ) - added by zboubida 19 months ago.
Explorer video capture

Download all attachments as: .zip

Change History (6)

by zboubida, 19 months ago

Attachment: calc.png added

Screenshot of Calculator

by zboubida, 19 months ago

Attachment: calc.mkv added

Video recording of Calculator

by zboubida, 19 months ago

Attachment: blender.png added

Blender screenshot

by zboubida, 19 months ago

Attachment: blender.mkv added

Blender video window capture

by zboubida, 19 months ago

Attachment: explorer.png added

Explorer screenshot

by zboubida, 19 months ago

Attachment: explorer.mkv added

Explorer video capture

Note: See TracTickets for help on using tickets.