SerpentAI / D3DShot

Extremely fast and robust screen capture on Windows with the Desktop Duplication API
MIT License
323 stars 73 forks source link

Bug? D3Dshot continously giving lower frames when benchmarked #53

Open Avnsx opened 2 years ago

Avnsx commented 2 years ago

Out of d3dshot's ReadMe Is robust and very stable. You can run it for hours / days without performance degradation

I was trying to compare d3dshot to python mss and pyautogui (backend pillow). My frametest works fine for these other two libraries, but when I try to apply it onto d3dshot, my average frames continously get lower the longer the while loop runs ... Why?

Hardware: monitor 2560 x 1440p 144hz cpu amd ryzen 5 5600x 6x core @ 4.3 ghz

meaning optimal results would be 144 frames per second

import time, cv2, mss, numpy, d3dshot, pyautogui

# d3dshot (supports capture outputs: pil, numpy, numpy_float, pytorch, pytorch_float)
img = d3dshot.create(capture_output='numpy')

number_list = []

while True:
    last_time = time.perf_counter()

    # MSS get raw pixels from the screen, save it to a Numpy array
    # img = numpy.array(mss.mss().grab({"top": 40, "left": 0, "width": 800, "height": 640})) # getting 144 fps

    # d3dshot
    img.screenshot(region=(0,40, 800, 640))

    # pyautogui (pillow)
    # img = pyautogui.screenshot(region=(0,40, 800, 640)) # 31 fps

    fps = 1 / (time.perf_counter() - last_time)
    # print(f"fps: {fps}")

    # calc avg
    number_list.append(fps)
    avg = sum(number_list)/len(number_list)
    print(f"averages {round(avg, 2)} fps")

python 3.10.2 | windows 10 64 bit

ra1nty commented 2 years ago

There are some flaws for the benchmark:

My own benchmark: (5900X + 3090; 240hz monitor)

DXcam python-mss D3DShot
Average FPS 238.79 75.87 118.36
Std Dev 1.25 0.5447 0.3224

Ok tbh that sounds more like a self-advertising: For DXcam see -> https://github.com/ra1nty/DXcam