python-mss
python-mss copied to clipboard
Fullscreen doesn't capture as expected with fullscreen game
Hi,
I was under the impression that this package should be able to make game screenshot. I did the following :
import time
#launch script then alt+tab to game
n_seconds = 5
for x in range(n_seconds):
print "taking screenshot in {}".format(n_seconds-x)
time.sleep(1)
from mss.windows import MSS as mss
sct = mss()
filename = sct.shot(output='test.png')
However all I'm getting is this :
https://www.dropbox.com/s/yy5qnltobdp02v6/test.png?dl=0
Is this what is expected? Thanks.
Hello,
Could you provide a minimal script I can run for testing? Which version of Windows?
If you replace filename = sct.shot(output='test.png') with:
for filename in sct.save():
print(filename)
filename = sct.shot(mon=-1, output='fullscreen.png')
What are the resulting screenshots?
Hi,
I'm running it on windows 8.1 x64 the minimal script is in my first post, I run it then there is a 5 seconds loop that allows me to switch back to the game.
Which by the way is a fullscreen directX game.
Here are the 2 screenshot produced by your modification
https://www.dropbox.com/s/olptmi5mqisgdhf/fullscreen.png?dl=0 https://www.dropbox.com/s/b53xt8byet2h8xx/monitor-1.png?dl=0
Screenshots are good. The issue may occur when running the game. This is the code I will need to test, at least the minimal snippet to create a window and take screenshots. Here, I see that all works as excpected.
I don't think it's working as expected.
I runned the script 2 more times and got this :
run 2 : https://www.dropbox.com/s/l5nw25lw9zamj4s/monitor-1.png?dl=0 run 3 : https://www.dropbox.com/s/o7c09y5lwqbtp7e/monitor-1.png?dl=0
It's not always producing the same result.
When you ask about the minimal snippet do you ask about the game code? this is not my game, it's a commercial game : https://www.elitedangerous.com/
I see, you launched the game in fullscreenmode and then the Python script to capture the screen, right? I will need to try from my side, the 2nd run worked well ...
If you take a screenshot every seconde while playing, do you have constant good results?
yes, sorry if I was not clear
Launch the game alt+tab to windows Launch the script alt+tab to game wait 5 seconds alt+tab to windows and look at the screenshot
I just took 100 screenchots while playing th game using this :
import time
import cv2
import numpy
#launch script then alt+tab to game
n_seconds = 5
for x in range(n_seconds):
print "taking screenshot in {}".format(n_seconds-x)
time.sleep(1)
from mss.windows import MSS as mss
sct = mss()
counter = 0
for x in range(100):
sct.shot(mon=-1, output='fullscreen{}.png'.format(x))
time.sleep(0.5)
they all show the desktop, not the game
OK, thank you for the report. I do not know if it is related to MSS or the Windows'windows management. I will have a look later.
Alright, Thanks for your work.
I’d guess this is because “Fullscreen” in games (versus “Borderless Window” or the like) uses “Exclusive Mode”/“Active Rendering” wherein the application itself works directly with the GPU to write to the screen, as opposed to to working with the window manager.
It’s not impossible to take screenshots per se, but you won’t be able to do so through the window manager APIs. In the case of video games (or anything using DirectX in exclusive mode) it’s usually done through DLL injection to hook into DirectX drawcalls.
(A cursory examination of windows.py appears to indicate as well that only capturing of the first screen is supported as well, owing to the hardcoded argument to ctypes.windll.user32.GetWindowDC.)
Hello,
Could you try with the latest version from the master branch? I hope that fix will help with your case.
In the same mood as @karanlyons I just found this link for one MS developer: Ways to capture the screen. And without DLL injection it seems compromised. To continue ...
An idea could be to test using DirectX via ctypes (I have no idea if this is doable). As source of instpiration: https://github.com/kwhat/libscreenshot/blob/master/src/windows/directx.c
Any solution? Tried with 6.1.0 and i still can't get screenshot in games, even if they're not fullscreen - but isn't windowed either - the command is just ignored.
It's working perfectly on desktop and other applications like Photoshop. Any ideas?
Turns out that it was a problem with Pynput keyboard listener, i used a shortcut to take the screenshot, it needed elevated privileges to work with games (Why?). All good, friend, sorry ;)
An idea could be to test using DirectX via ctypes (I have no idea if this is doable). As source of instpiration:
Hi Mickael, thanks for the great library -- always been a big fan. I know this is an old issue but this is one of the biggest reason that made me to build a wheel. Capturing of DirectX fullscreen apps can definitely be done via ctypes: For reference -> https://github.com/ra1nty/DXcam
Also, the capturing speed can be vastly improved by doing so. (See benchmarks section of DXcam).
Drawback: probably need to add comtypes to dependency on win32