Have you ever needed a lightning-fast screen capture solution in your Python projects? Look no further than BetterCam—the World’s Fastest Python screenshot library for Windows. Built on top of DXCam, BetterCam is specifically designed for deep learning pipelines in FPS games, making it a game-changer for developers and researchers.
What Makes BetterCam So Special?
BetterCam offers a wide range of features that set it apart from other Python screen capture libraries. Here are some of its superpowers:
🚅 Insanely fast screen capturing: With BetterCam, you can achieve over 240Hz screen capturing using the Desktop Duplication API. This incredible speed allows you to capture frames at an unprecedented rate, enabling real-time analysis and processing.
🎮 Capture from Direct3D exclusive full-screen apps: Unlike other solutions, BetterCam can capture screens from Direct3D exclusive full-screen applications without interruption, even during alt+tab. This makes it perfect for analyzing and manipulating FPS games.
🔧 Auto-adjusts to scaled/stretched resolutions: BetterCam intelligently adapts to scaled or stretched resolutions, ensuring accurate and consistent captures across different display configurations.
🎯 Precise FPS targeting for Video output: BetterCam provides precise FPS targeting, allowing you to capture frames at your desired frame rate. This feature is essential for video output and ensures smooth and high-quality recordings.
👌 Smooth integration with popular libraries: BetterCam seamlessly integrates with popular libraries like NumPy, OpenCV, PyTorch, and more. This makes it easy to incorporate screen captures into your existing pipelines and workflows.
💞 Community contributions are warmly invited: BetterCam is an open-source project, and the developer community is encouraged to contribute to its growth and improvement. Your feedback and contributions can help shape the future of this powerful screen capture library.
Getting Started with BetterCam
Installing BetterCam is a breeze. Simply use the following command to install it from PyPI:
pip install bettercam
Please ensure that you have the OpenCV library installed as well. If not, you can install it with the following command:
pip install opencv-python
Once installed, you can start using BetterCam in your Python projects. Each monitor is paired with a BetterCam
instance. Here’s a basic usage example to get you started:
import bettercam
camera = bettercam.create() # Primary monitor's BetterCam instance
Capturing Screenshots with BetterCam
To capture a quick snapshot, you can use the .grab()
method:
frame = camera.grab()
The captured frame is returned as a numpy.ndarray
in the (Height, Width, 3[RGB])
format by default. You can display the screenshot using libraries like PIL:
from PIL import Image
Image.fromarray(frame).show()
If you want to capture a specific region of the screen, you can provide the region
parameter with the bounding box coordinates:
left, top = (1920 - 640) // 2, (1080 - 640) // 2
right, bottom = left + 640, top + 640
region = (left, top, right, bottom)
frame = camera.grab(region=region)
Screen Capture and Video Recording
In addition to capturing screenshots, BetterCam also allows you to start and stop screen capture using the .start()
and .stop()
methods:
camera.start(region=(left, top, right, bottom)) # Capture a specific region (optional)
camera.is_capturing # True
# ... Your Code
camera.stop()
camera.is_capturing # False
To retrieve the latest frame while capturing, you can use the .get_latest_frame()
method:
camera.start()
for i in range(1000):
image = camera.get_latest_frame() # Waits for a new frame
camera.stop()
You can also use video_mode=True
during the .start()
method to record constant frame rate videos:
camera.start(target_fps=target_fps, video_mode=True)
# ... Video writing code goes here
Advanced Usage and Notes
BetterCam offers advanced features and customization options to suit your specific needs. Here are a few notable ones:
🖥️ Multiple Monitors / GPUs: You can create multiple BetterCam
instances for different devices and outputs, allowing you to capture frames from multiple monitors or GPUs simultaneously.
🎨 Output Format: BetterCam allows you to select your desired color mode when creating an instance. Options include “RGB,” “RGBA,” “BGR,” “BGRA,” and “GRAY” for grayscale.
🔄 Video Buffer: Frames are stored in a fixed-size ring buffer. You can customize the maximum buffer length using the max_buffer_len
parameter during instance creation.
🎥 Target FPS: BetterCam provides precise FPS targeting using the high-resolution CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
feature. This allows you to capture frames at your desired frame rate.
🛠️ Resource Management: To stop captures and free resources, you can call the .release()
method or manually delete the BetterCam
instance.
Benchmarks: Unleash the Power of BetterCam
To showcase the exceptional performance of BetterCam, let’s compare it to other popular screen capture libraries. Here are the benchmark results:
Max FPS Achievement:
BetterCam Nvidia GPU | BetterCam | DXCam | python-mss | D3DShot | |
---|---|---|---|---|---|
Avg FPS | 111.667 | 123.667 | 39 | 34.667 | N/A |
Std Dev | 0.889 | 1.778 | 1.333 | 2.222 | N/A |
FPS Targeting:
Target/Result | BetterCam Nvidia GPU | BetterCam | DXCam | python-mss | D3DShot |
---|---|---|---|---|---|
120fps | 111.667, 0.889 | 88.333, 2.444 | 36.667, 0.889 | N/A | N/A |
60fps | 60, 0 | 60, 0 | 35, 5.3 | N/A | N/A |
As you can see from the benchmarks, BetterCam consistently outperforms other libraries in terms of capturing speed and frame rate stability. This makes it a top choice for any application that requires high-quality, real-time screen captures.
Conclusion
BetterCam is the ultimate solution for lightning-fast screen capture in Python. Whether you are building deep learning pipelines for FPS games, conducting research, or developing video recording applications, BetterCam’s speed, precision, and integration capabilities make it a valuable tool. With its advanced features and outstanding performance, BetterCam is set to revolutionize the way screen capture is done in Python.
So why wait? Give BetterCam a try today and unlock the full potential of Python screen capture!
📝 Referenced Work:
- DXCam: Our origin story.
- D3DShot: Provided foundational ctypes.
- OBS Studio: A treasure trove of knowledge.
Leave a Reply