I am working on a cloud gaming application and I need to capture screen in real time with high performance (At 60fps). I'm using MSS with two multiprocessing threads that captures top and bottom of screen. So it should be 2x faster but it gives 30fps at 1080p although my processor isn't bad. Does MSS usually give about this fps, or do I have a problem on my computer or my code. Here is my code to capture:
from mss import mss
from multiprocessing import Process, Queue, Value
from pygame.time import Clock
class Recorder():
def __init__(self):
self.x = Value("i",0)
self.y = Value("i",0)
self.w = Value("i",0)
self.h = Value("i",0)
self.queueTop = Queue(maxsize=1)
self.queueDown = Queue(maxsize=1)
self.running = Value("b",True)
def start_recording(self):
Process(target=self.grabber_top,args=()).start()
Process(target=self.grabber_down,args=()).start()
self.running = True
def stop_recording(self):
self.running = False
def grabber_top(self):
clock = Clock()
with mss() as sct:
while self.running.value:
clock.tick(60)
self.queueTop.put(sct.grab({"top": self.y.value, "left": self.x.value, "width": self.w.value, "height": self.h.value//2}).rgb)
def grabber_down(self):
clock = Clock()
with mss() as sct:
while self.running.value:
clock.tick(60)
self.queueDown.put(sct.grab({"top": self.y.value+self.h.value//2, "left": self.x.value, "width": self.w.value, "height": self.h.value//2}).rgb)
def get_pixels(self) -> bytes:
if not self.queueTop.empty() and not self.queueDown.empty():
return self.queueTop.get_nowait() + self.queueDown.get_nowait()
My second question is, can I capture screen with GPU? I have a RTX 3070 and Nvidia may have technology about that.