Comments (12)
Happy to report that the issue is now fixed. Be sure to grab D3DShot 0.1.5 and let me know how it goes.
from d3dshot.
I believe I have found the source of the problem. At the garbled resolutions, the pitch of the DXGI_MAPPED_RECT
doesn't match width * 4
.
Example:
- 2560 x 1440 => DXGI_MAPPED_RECT.Pitch = 10240 = 2560 * 4 = Not Garbled
- 2160 x 1200 => DXGI_MAPPED_RECT.Pitch = 8704 != 2160 * 4 = Garbled
If I don't respect the pitch given by the IDXGISurface
, I start filling in the next row of pixels while still in the potential padding from the previous row. This causes the row offset or garbled effect in the screenshot you all shared.
Windows seems to pad the IDXGISurface
so the width will be divisible by 32. This is probably to enable all the neat tricks you can do with strides. If you check carefully in my resolution tests above, all the ones that are garbled don't have widths that are divisible by 32.
Fix on the way!
from d3dshot.
Possible hint in #11
For maximum performance, the buffer at the pointer returned by the Desktop Duplication API is left as is. NumPy is able to perform view manipulations to access the buffer differently without altering it. It's possible that whatever you pass your D3DShot output to tries to access the raw buffer of the array instead of its view. That would cause garbled images because the shape and stride information would be lost.
That wouldn't explain why @Ricky54326 only sees a garbled image at very high resolutions and it works otherwise though. Maybe the array is getting copied at some point? That forces an ordering of the new buffer to conform to the view.
from d3dshot.
Here's my attempt to reproduce the issue. I have tested d3dshot with two code snippets.
The first one uses the "numpy" output format and displays the image using OpenCV.
import cv2
import d3dshot
d = d3dshot.create(capture_output='numpy')
img = d.screenshot()
cv2.imshow('screenshot', img)
cv2.waitKey()
The second one uses the default capture output format (PIL) and just saves the screenshot to disk.
import d3dshot
d = d3dshot.create()
img = d.screenshot_to_disk()
In both cases, the output image is garbled and looks like this (it should be a Visual Studio Code window). Although I didn't test other output formats like @Disablez did, I am positive that the same problem happens.
Now some information about the environment in which I performed the tests above.
Operating System: Windows 10 Home Edition, version 1909 (build 18363.836)
Python Version: Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Resolution: 1366x768
GPU (integrated): Intel(R) HD Graphics 620 (python.exe was run with this graphics card)
GPU (discrete): NVIDIA GeForce 920MX
And this is the output for d.displays
.
[<Display name=Generic PnP Monitor adapter=Intel(R) HD Graphics 620 resolution=1366x768 rotation=0 scale_factor=1.0 primary=True>]
Edit:
I have just tested the same code with the same environment, except that I lowered the desktop resolution to 1360x768 and it works just fine. Actually, it works for any value lower than 1366x768. Maybe the issue happens only when the desktop is set to the maximum resolution?
from d3dshot.
Doing a D3DShot day tomorrow. I'm going to be trying to reproduce this. Seems like it's pretty widespread too.
from d3dshot.
It would appear the issue is only present with certain resolutions. I finally managed to get garbled output by forcing resolutions in the Nvidia Control Panel.
Here are my results:
- 2560 x 1440: OK
- 2160 x 1200: Garbled
- 1920 x 1440: OK
- 1920 x 1200: OK
- 1920 x 1080: OK
- 1768 x 992: Garbled
- 1680 x 1050: Garbled
- 1600 x 1200: OK
- 1600 x 1024: OK
- 1600 x 900: OK
- 1366 x 768: Garbled (matches @Gabriel-Dev)
- 1360 x 768: Garbled (doesn't match @Gabriel-Dev)
- 1280 x 1024: OK
- 1280 x 960: OK
- 1280 x 800: OK
- 1280 x 768: OK
- 1280 x 720: OK
- 1152 x 864: OK
- 1024 x 768: OK
- 800 x 600: OK
Now to figure out what's happening at those resolutions...
from d3dshot.
I am experiencing the same issue, did you come up with a solution?
from d3dshot.
So far nothing. I haven't actually tried any more. Easier to just find some other solution
from d3dshot.
On an nvidia 2080 Ti it happens at 3440x1440 resolution; lowering it fixes the problem, but obviously it's just a temporary workaround.
Tried all capture methods... pil, numpy, torch_gpu ... etc, same result.
from d3dshot.
Apologies for the late reply.
For everyone getting the garbled images, can you share a snippet of what you do with the output you get from D3DShot? Do you pass it to scikit-image, OpenCV, Pillow, Other?
Information about OS, Python, Resolution, GPUs is also useful.
I'd love to get this fixed but will need some examples to find a first clue.
from d3dshot.
I made a duplicate of this issue here #26, seems there hasn't be a solution yet...
from d3dshot.
Very cool. Great bug hunting and conclusion, @nbrochu ! :-)
from d3dshot.
Related Issues (20)
- Support OpenCV Mat as a capture format HOT 2
- Code doesn't work HOT 2
- No way to delete D3DShot instance. HOT 1
- 1,000,000+ fps in screen capture HOT 2
- Slow performance HOT 3
- Support for resizing (downscaling) the output HOT 2
- It randomly raises an indexerror. HOT 1
- Create an anaconda package
- Bump pillow version for Python 3.9 support on Windows HOT 9
- Sceenshot active monitor
- Is this maintained? feature query HOT 1
- monitor resolution not detected properly HOT 2
- Errors in Virtual Machines
- Feature to wait for any change
- Does not work with games HOT 2
- Screenshot from wrong display is sometimes returned
- pip install d3dshot isn't working HOT 1
- Bug? D3Dshot continously giving lower frames when benchmarked HOT 1
- d3dshot.create() cant work HOT 1
- can't capture full screen game
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3dshot.