python-mss icon indicating copy to clipboard operation
python-mss copied to clipboard

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

Open vision34 opened this issue 7 years ago • 7 comments

General informations:

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

  • OS name: Windows
  • OS version: 10
  • OS architecture: 64 bits
  • Resolutions (tested):
    • Monitor 1: 1080p@120Hz
  • Python version: _2.7
  • MSS version: last from pip
  • CPU: i7 4790k
  • GPU: GTX 1080

Description of the warning/error

Threaded screen capture is very laggy while gaming

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

vision34 avatar Sep 12 '18 07:09 vision34

Hello,

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

BoboTiG avatar Sep 12 '18 09:09 BoboTiG

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 avatar Sep 12 '18 09:09 vision34

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

vision34 avatar Sep 12 '18 09:09 vision34

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.

BoboTiG avatar Sep 22 '18 15:09 BoboTiG

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

vision34 avatar Sep 23 '18 14:09 vision34

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

vision34 avatar Sep 23 '18 14:09 vision34

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

Seraphli avatar Sep 08 '19 15:09 Seraphli