Skip to main content

Fastest Windows Screen Capture Library For Python 🔥

Project description

Windows Capture   Licence Build Status Latest Version Sponsors

Windows Capture is a highly efficient Rust and Python library that enables you to capture the screen using the Graphics Capture API effortlessly. This library allows you to easily capture the screen of your Windows-based computer and use it for various purposes, such as creating instructional videos, taking screenshots, or recording your gameplay. With its intuitive interface and robust functionality, Windows Capture is an excellent choice for anyone looking for a reliable, easy-to-use screen-capturing solution.

Note this README.md is for Python library Rust library can be found here

Features

  • Updates frames only when required
  • High performance
  • Easy to use
  • Uses the latest screen capture API
  • Optional DXGI Desktop Duplication capture pipeline

Installation

Install from PyPI:

pip install windows-capture

Usage

Graphics Capture API

from windows_capture import WindowsCapture, Frame, InternalCaptureControl

# Any error from on_closed and on_frame_arrived will surface here
capture = WindowsCapture(
    cursor_capture=None,
    draw_border=None,
    monitor_index=None,
    window_name=None,
)


# Called every time a new frame is available
@capture.event
def on_frame_arrived(frame: Frame, capture_control: InternalCaptureControl):
    print("New frame arrived")

    # Save the frame as an image to the specified path
    frame.save_as_image("image.png")

    # Gracefully stop the capture thread
    capture_control.stop()


# Called when the capture item closes (usually when the window closes).
# The capture session will end after this function returns.
@capture.event
def on_closed():
    print("Capture session closed")


capture.start()

DXGI Desktop Duplication API

from windows_capture import DxgiDuplicationSession

# Create a duplication session for the primary monitor
session = DxgiDuplicationSession()

# Grab a frame (returns None if no frame is available within the timeout)
frame = session.acquire_frame(timeout_ms=33)
if frame is not None:
    image = frame.to_numpy(copy=False)  # shape: (height, width, 4)

    # Save as PNG using OpenCV
    frame.save_as_image("duplication.png")

# Recreate the session if DXGI reports access loss
try:
    session.acquire_frame()
except RuntimeError:
    session.recreate()

Benchmark

Windows Capture Is The Fastest Python Screen Capture Library

Benchmark Showing Windows Capture Is The Fastest Python Screen Capture Library

Contributing

Contributions are welcome! If you find a bug or want to add new features to the library, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

windows_capture-2.0.0.tar.gz (68.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

windows_capture-2.0.0-cp39-abi3-win_amd64.whl (238.0 kB view details)

Uploaded CPython 3.9+Windows x86-64

File details

Details for the file windows_capture-2.0.0.tar.gz.

File metadata

  • Download URL: windows_capture-2.0.0.tar.gz
  • Upload date:
  • Size: 68.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for windows_capture-2.0.0.tar.gz
Algorithm Hash digest
SHA256 f1d587c182afa06c060e36ba2bd4f216a8ed03f320f51d7b6d5c8a2759469956
MD5 d8c22248a57adb20ac404426c1becdf4
BLAKE2b-256 7e601acdf4a4bb625bf04e94afde8bdb60a06997e644c6be7befe413dc5215ed

See more details on using hashes here.

File details

Details for the file windows_capture-2.0.0-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for windows_capture-2.0.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 62293537ddeb3a5fae76633ee87b12a8cf9cdc3dcf63fdef789184942169bd22
MD5 72c21b45140812bd4f24f42ab9227f1f
BLAKE2b-256 387b3ad456df8b23e363e36e2938158eeb1e740e4143de530b307b96a3a4ea68

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page