我正在尝试使用 python 和 pygame 制作共享屏幕,以及使用 d3dshot 拍摄的屏幕截图。 有谁知道我怎样才能让它变得更好并增加每秒的帧数?
这是我的代码: 服务器 - 与客户端共享屏幕
config.promise.then((args: any) => {
if (this._isCancelled) return;
this._isCompleted = true;
resolve(args);
}, (error)=>{
if (this._isCancelled) return;
this._isCompleted = false;
reject(error);
});
客户端 - 从服务器获取屏幕并显示服务器屏幕
""" Server """
from socket import socket
from threading import Thread
import pyautogui
import cv2
import numpy as np
import d3dshot
from lz4.frame import compress
WIDTH, HEIGHT = pyautogui.size()
def retreive_screenshot(conn):
d = d3dshot.create(capture_output="numpy")
while 'recording':
img = d.screenshot()
img = cv2.resize(img, (0, 0), fx=0.5, fy=0.5)
img = compress(img, 10)
# Send the size of the pixels length
size = len(img)
size_len = (size.bit_length() + 7) // 8
conn.send(bytes([size_len]))
# Send the actual pixels length
size_bytes = size.to_bytes(size_len, 'big')
conn.send(size_bytes)
# Send pixels
conn.sendall(img)
def main(host='0.0.0.0', port=5000):
sock = socket()
sock.bind((host, port))
try:
sock.listen(5)
print('Server started.')
while 'connected':
conn, addr = sock.accept()
print('Client connected IP:', addr)
thread = Thread(target=retreive_screenshot, args=(conn,))
thread.start()
finally:
sock.close()
if __name__ == '__main__':
main()