diff --git a/docs/tutorial.md b/docs/tutorial.md index c1722a51..5c40d99f 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -53,7 +53,8 @@ - **Direct3D Desktop Duplication** (slower, bound to display) Duplicates the desktop using Direct3D. It can record OpenGL and Hardware Accelerated windows. - About 10-15x slower than BitBlt. Not affected by window size. + Up to 15x slower than BitBlt for tiny regions. Not affected by window size. + Limited by the target window and monitor's refresh rate. Overlapping windows will show up and can't record across displays. This option may not be available for hybrid GPU laptops, see [D3DDD-Note-Laptops.md](/docs/D3DDD-Note-Laptops.md) for a solution. - **Force Full Content Rendering** (very slow, can affect rendering) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index f6ed7bec..3d416c9f 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -17,8 +17,9 @@ $arguments = @( '--exclude=pytweening', '--exclude=mouseinfo') if ($IsWindows) { + # These are used on Linux $arguments += @( - # Installed by PyAutoGUI, but used by linux + # Installed by PyAutoGUI '--exclude=pyscreeze' # Installed by D3DShot '--exclude=PIL') diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 9144f38e..f7bd1bcd 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -48,9 +48,7 @@ If ($IsLinux) { # These libraries install extra requirements we don't want # Open suggestion for support in requirements files: https://github.com/pypa/pip/issues/9948 & https://github.com/pypa/pip/pull/10837 # PyAutoGUI: We only use it for hotkeys -# D3DShot: Will install Pillow, which we don't use on Windows. -# Even then, PyPI with Pillow>=7.2.0 will install 0.1.3 instead of 0.1.5 -&"$python" -m pip install PyAutoGUI "D3DShot>=0.1.5 ; sys_platform == 'win32'" --no-deps --upgrade +&"$python" -m pip install PyAutoGUI --no-deps --upgrade # Uninstall optional dependencies if PyAutoGUI or D3DShot was installed outside this script # PyScreeze -> pyscreenshot -> mss deps call SetProcessDpiAwareness, used to be installed on Windows diff --git a/scripts/requirements-dev.txt b/scripts/requirements-dev.txt index 526ebb85..913108e0 100644 --- a/scripts/requirements-dev.txt +++ b/scripts/requirements-dev.txt @@ -15,7 +15,6 @@ ruff>=0.6.8 # Pre-commit fix # Must match .pre-commit-config.yaml # # Types -types-D3DShot ; sys_platform == 'win32' types-keyboard types-psutil types-PyAutoGUI diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 3405f2b4..1897d5a6 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -36,7 +36,7 @@ winrt-Windows.Graphics.DirectX.Direct3D11>=2.2.0 ; sys_platform == 'win32' # Py winrt-Windows.Graphics.Imaging>=2.2.0 ; sys_platform == 'win32' # Python 3.13 support winrt-Windows.Graphics>=2.2.0 ; sys_platform == 'win32' # Python 3.13 support winrt-Windows.Media.Capture>=2.2.0 ; sys_platform == 'win32' # Python 3.13 support -# D3DShot # See install.ps1 +typed-D3DShot[numpy]>=1.0.1 ; sys_platform == 'win32' # # Linux-only dependencies PyScreeze ; sys_platform == 'linux' diff --git a/src/capture_method/DesktopDuplicationCaptureMethod.py b/src/capture_method/DesktopDuplicationCaptureMethod.py index 827f443c..e13ff11c 100644 --- a/src/capture_method/DesktopDuplicationCaptureMethod.py +++ b/src/capture_method/DesktopDuplicationCaptureMethod.py @@ -2,14 +2,13 @@ if sys.platform != "win32": raise OSError -from typing import TYPE_CHECKING, cast +from typing import TYPE_CHECKING import cv2 import d3dshot import win32api import win32con import win32gui -from cv2.typing import MatLike from typing_extensions import override from capture_method.BitBltCaptureMethod import BitBltCaptureMethod @@ -25,7 +24,8 @@ class DesktopDuplicationCaptureMethod(BitBltCaptureMethod): description = f""" Duplicates the desktop using Direct3D. It can record OpenGL and Hardware Accelerated windows. -About 10-15x slower than BitBlt. Not affected by window size. +Up to 15x slower than BitBlt for tiny regions. Not affected by window size. +Limited by the target window and monitor's refresh rate. Overlapping windows will show up and can't record across displays. This option may not be available for hybrid GPU laptops, see D3DDD-Note-Laptops.md for a solution. @@ -57,10 +57,7 @@ def get_frame(self): top = selection["y"] + offset_y + top_bounds right = selection["width"] + left bottom = selection["height"] + top - screenshot = cast( - MatLike | None, - self.desktop_duplication.screenshot((left, top, right, bottom)), - ) + screenshot = self.desktop_duplication.screenshot((left, top, right, bottom)) if screenshot is None: return None return cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGRA)