NiiightmareXD / windows-capture

Fastest Windows Screen Capture Library For Rust And Python 🔥
MIT License
222 stars 33 forks source link

[FEATURE ⭐] Capture a certain area #80

Open NeuralAIM opened 1 month ago

NeuralAIM commented 1 month ago

How can I capture a certain area? I can use crop() now, but I'm the only one losing FPS. How can I capture a part of the screen, similar to how it works when specifying window_name, where the application window is smaller than the screen size.

With window_name="Calculator":

FPS: 88.39
FPS: 84.82
FPS: 93.16
FPS: 80.45

With window_name=None:

FPS: 34.94
FPS: 47.99
FPS: 48.00
FPS: 48.28

Code:

from windows_capture import WindowsCapture, Frame, InternalCaptureControl
from time import time

capture = WindowsCapture(
    cursor_capture=False,
    draw_border=False,
    monitor_index=None,
    #window_name="Calculator",
)

i = 0
s_time = time()
fps = 0

@capture.event
def on_frame_arrived(frame: Frame, capture_control: InternalCaptureControl):
    global i, s_time, fps
    i += 1
    elapsed_time = time() - s_time

    if elapsed_time >= 1:  # Output FPS every second
        fps = i / elapsed_time
        print(f"FPS: {fps:.2f}")
        i = 0  # Reset frame count
        s_time = time()  # Reset start time

@capture.event
def on_closed():
    print("Capture Session Closed")

# capture.on_frame_arrived(width=128, height=128) - Well... I tried)
capture.start()
WHalcyon commented 1 month ago

I'm not sure if there's a way to do this but as a workaround have you tried creating an entirely transparent and click-through application with your desired capture size and targeting that? Let me know if it works

NiiightmareXD commented 1 month ago

Hey, I'm not sure what causes the FPS drop, and crop() should be performant.

Cyanide0210 commented 1 month ago

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator

Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

NiiightmareXD commented 1 month ago

Ok, I'll check the performance to see if it's a API optimization or I can do it in the library itself because for now the underlying API doesn't allow capturing an area.

Cyanide0210 commented 1 month ago

Ok, I'll check the performance to see if it's a API optimization or I can do it in the library itself because for now the underlying API doesn't allow capturing an area.

CopySubresourceRegion?

Edit: ahh, that is probably the same as Crop

JiaPai12138 commented 1 month ago

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator

Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

Cyanide0210 commented 1 month ago

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

probably its because my laptop has a 3070 RTX, or because my monitor is set to 540Hz? not sure

JiaPai12138 commented 1 month ago

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

probably its because my laptop has a 3070 RTX, or because my monitor is set to 540Hz? not sure

Mine is 4060 RTX and 144hz monitor... should as least 100 fps any way

NiiightmareXD commented 1 month ago

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

probably its because my laptop has a 3070 RTX, or because my monitor is set to 540Hz? not sure

Mine is 4060 RTX and 144hz monitor... should as least 100 fps any way

Sounds like some sort of bug somewhere

JiaPai12138 commented 1 month ago

Yeah I can confirm this, I just tried his python script and the FPS is like 900 for me when im targeting the calculator Edit: Using crop isn't useful because that needs to be done AFTER the frame was taken which just adds even more overhead

Bro how you get 900? I never get over 50 FPS on all my laptops using the same script...

probably its because my laptop has a 3070 RTX, or because my monitor is set to 540Hz? not sure

Mine is 4060 RTX and 144hz monitor... should as least 100 fps any way

Sounds like some sort of bug somewhere

I tried modified version of dxcam and get like 400 fps tops but there seems to be some problems in my environment, some games will just crashed but runs fine on another one with gtx 1660 ti; plus when i install any software/driver from nvidia, it will just jump to installer failed instantly and i dont know how to fix i will do a fresh reinstall of windows this weekend and retry