Skip to content

Commit 65b24d6

Browse files
authored
Migrate to typed-D3DShot (#302)
1 parent aa63fff commit 65b24d6

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

docs/tutorial.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
- **Direct3D Desktop Duplication** (slower, bound to display)
5454
Duplicates the desktop using Direct3D.
5555
It can record OpenGL and Hardware Accelerated windows.
56-
About 10-15x slower than BitBlt. Not affected by window size.
56+
Up to 15x slower than BitBlt for tiny regions. Not affected by window size.
57+
Limited by the target window and monitor's refresh rate.
5758
Overlapping windows will show up and can't record across displays.
5859
This option may not be available for hybrid GPU laptops, see [D3DDD-Note-Laptops.md](/docs/D3DDD-Note-Laptops.md) for a solution.
5960
- **Force Full Content Rendering** (very slow, can affect rendering)

scripts/build.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ $arguments = @(
1717
'--exclude=pytweening',
1818
'--exclude=mouseinfo')
1919
if ($IsWindows) {
20+
# These are used on Linux
2021
$arguments += @(
21-
# Installed by PyAutoGUI, but used by linux
22+
# Installed by PyAutoGUI
2223
'--exclude=pyscreeze'
2324
# Installed by D3DShot
2425
'--exclude=PIL')

scripts/install.ps1

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ If ($IsLinux) {
4848
# These libraries install extra requirements we don't want
4949
# Open suggestion for support in requirements files: https://github.com/pypa/pip/issues/9948 & https://github.com/pypa/pip/pull/10837
5050
# PyAutoGUI: We only use it for hotkeys
51-
# D3DShot: Will install Pillow, which we don't use on Windows.
52-
# Even then, PyPI with Pillow>=7.2.0 will install 0.1.3 instead of 0.1.5
53-
&"$python" -m pip install PyAutoGUI "D3DShot>=0.1.5 ; sys_platform == 'win32'" --no-deps --upgrade
51+
&"$python" -m pip install PyAutoGUI --no-deps --upgrade
5452

5553
# Uninstall optional dependencies if PyAutoGUI or D3DShot was installed outside this script
5654
# PyScreeze -> pyscreenshot -> mss deps call SetProcessDpiAwareness, used to be installed on Windows

scripts/requirements-dev.txt

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
ruff>=0.6.8 # Pre-commit fix # Must match .pre-commit-config.yaml
1616
#
1717
# Types
18-
types-D3DShot ; sys_platform == 'win32'
1918
types-keyboard
2019
types-psutil
2120
types-PyAutoGUI

scripts/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ winrt-Windows.Graphics.DirectX.Direct3D11>=2.2.0 ; sys_platform == 'win32' # Py
3636
winrt-Windows.Graphics.Imaging>=2.2.0 ; sys_platform == 'win32' # Python 3.13 support
3737
winrt-Windows.Graphics>=2.2.0 ; sys_platform == 'win32' # Python 3.13 support
3838
winrt-Windows.Media.Capture>=2.2.0 ; sys_platform == 'win32' # Python 3.13 support
39-
# D3DShot # See install.ps1
39+
typed-D3DShot[numpy]>=1.0.1 ; sys_platform == 'win32'
4040
#
4141
# Linux-only dependencies
4242
PyScreeze ; sys_platform == 'linux'

src/capture_method/DesktopDuplicationCaptureMethod.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
if sys.platform != "win32":
44
raise OSError
5-
from typing import TYPE_CHECKING, cast
5+
from typing import TYPE_CHECKING
66

77
import cv2
88
import d3dshot
99
import win32api
1010
import win32con
1111
import win32gui
12-
from cv2.typing import MatLike
1312
from typing_extensions import override
1413

1514
from capture_method.BitBltCaptureMethod import BitBltCaptureMethod
@@ -25,7 +24,8 @@ class DesktopDuplicationCaptureMethod(BitBltCaptureMethod):
2524
description = f"""
2625
Duplicates the desktop using Direct3D.
2726
It can record OpenGL and Hardware Accelerated windows.
28-
About 10-15x slower than BitBlt. Not affected by window size.
27+
Up to 15x slower than BitBlt for tiny regions. Not affected by window size.
28+
Limited by the target window and monitor's refresh rate.
2929
Overlapping windows will show up and can't record across displays.
3030
This option may not be available for hybrid GPU laptops,
3131
see D3DDD-Note-Laptops.md for a solution.
@@ -57,10 +57,7 @@ def get_frame(self):
5757
top = selection["y"] + offset_y + top_bounds
5858
right = selection["width"] + left
5959
bottom = selection["height"] + top
60-
screenshot = cast(
61-
MatLike | None,
62-
self.desktop_duplication.screenshot((left, top, right, bottom)),
63-
)
60+
screenshot = self.desktop_duplication.screenshot((left, top, right, bottom))
6461
if screenshot is None:
6562
return None
6663
return cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGRA)

0 commit comments

Comments
 (0)