Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fullscreen doesn't capture as expected with fullscreen game #28

Open
KiudLyrl opened this issue Sep 12, 2017 · 15 comments
Open

Fullscreen doesn't capture as expected with fullscreen game #28

KiudLyrl opened this issue Sep 12, 2017 · 15 comments

Comments

@KiudLyrl
Copy link

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.

@BoboTiG
Copy link
Owner

BoboTiG commented Sep 12, 2017

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?

@KiudLyrl
Copy link
Author

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

@BoboTiG
Copy link
Owner

BoboTiG commented Sep 12, 2017

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.

@KiudLyrl
Copy link
Author

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/

@BoboTiG
Copy link
Owner

BoboTiG commented Sep 12, 2017

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?

@KiudLyrl
Copy link
Author

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

@BoboTiG
Copy link
Owner

BoboTiG commented Sep 12, 2017

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.

@KiudLyrl
Copy link
Author

Alright, Thanks for your work.

@karanlyons
Copy link
Contributor

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.)

@BoboTiG
Copy link
Owner

BoboTiG commented Jan 2, 2018

Hello,

Could you try with the latest version from the master branch? I hope that fix will help with your case.

@BoboTiG
Copy link
Owner

BoboTiG commented May 9, 2018

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 ...

@BoboTiG BoboTiG changed the title Does not work for Elite dangerous Fullscreen doesn't capture as expected with fullscreen game May 9, 2018
@BoboTiG
Copy link
Owner

BoboTiG commented Jan 29, 2019

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

@ShiverPurple
Copy link

ShiverPurple commented Apr 11, 2021

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?

@ShiverPurple
Copy link

ShiverPurple commented Apr 11, 2021

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 ;)

@ra1nty
Copy link

ra1nty commented May 12, 2022

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

@BoboTiG BoboTiG unpinned this issue Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants