BoboTiG / python-mss

An ultra fast cross-platform multiple screenshots module in pure Python using ctypes.
https://pypi.org/project/mss/
MIT License
1.02k stars 93 forks source link

Mss screen grab makes screen responsiveness laggy (while gaming/moving a windows explorer) #71

Open vision34 opened 6 years ago

vision34 commented 6 years ago

General informations:

What i have done? Own implementation diy ambilight using mss screengrab

Full message

When i create a threaded class to capture the screen as fast as possible, it is makes my screen resposiveness very laggy... I can not play well. After making a sleep : Time.sleep(0.5), it does not slow down gaming, but reaction time for leds is too slow...

Pseudo code:

class Ambilight(Thread):
def __init__(self, LightController):
  self.screen = mss()
  self.imageCaptured = None
  self.LightController = LightController

# ...

def run(self):
 while True:
    self.imageCaptured = np.array(self.screen.grab( self.screen.monitors[0]))
    self.LightController.ImageUpdate( self.imageCaptured.copy() )

Upvote & Fund

Fund with Polar

BoboTiG commented 6 years ago

Hello,

If you remove all stuff non related to MSS, do you still see the lag?

vision34 commented 6 years ago

Yes (i have used webcam as the source and it works fluently), it looks like when screen is captured, it freeze display for a little time...

vision34 commented 6 years ago

of course webcam is much worse solution, in case of wrong color recognition...

BoboTiG commented 6 years ago

I reproduced but this is because MSS is too good :) Your best option is to reduce the number of screenshots. A time.sleep(0.01) or time.sleep(0.05).

The thing is to reduce the number of screenshots to the minimum required, e.g. the eye can get only 24 images per seconds. So if you can take only 24 screenshots by seconds, the whole thing will seem more fluid.

vision34 commented 6 years ago

Thank you very much, but using gtx 1080 and 4k resolution even 0.5 s time.sleep makes it laggy...

vision34 commented 6 years ago

https://github.com/vision34/AmbiPy/blob/master/AmbientLedProcessor.py here is my simple code

Seraphli commented 5 years ago

@vision34 I seem to experience the same issue. When I resize windows or drag windows or play games, the animation seems laggy. I'm also using gtx 1080, and capturing the screenshot every 0.4 s.