GStreamer Environment¶
High-performance screen capture and multimedia processing (6x faster than alternatives).
Requirements
- OS: Windows (Linux/macOS support planned)
- GPU: NVIDIA GPU required (our GStreamer implementation is NVIDIA-specific)
Components¶
Component | Type | Description |
---|---|---|
gst/screen |
Listener | Real-time screen capture with callbacks |
gst/screen_capture |
Runnable | On-demand screen capture |
gst/omnimodal.appsink_recorder |
Listener | Omnimodal recording with appsink |
gst/omnimodal.subprocess_recorder |
Runnable | Omnimodal recording via subprocess |
Performance¶
Powered by GStreamer and Windows API, our implementation is 6x faster than alternatives:
Library | Avg. Time per Frame | Relative Speed |
---|---|---|
owa.env.gst | 5.7 ms | β‘ 1Γ (Fastest) |
pyscreenshot |
33 ms | πΆββοΈ 5.8Γ slower |
PIL |
34 ms | πΆββοΈ 6.0Γ slower |
MSS |
37 ms | πΆββοΈ 6.5Γ slower |
PyQt5 |
137 ms | π’ 24Γ slower |
π Tested on: Intel i5-11400, GTX 1650
Not only does owa.env.gst
achieve higher FPS, but it also maintains lower CPU/GPU usage, making it the ideal choice for screen recording. Same applies for ocap
, since it internally imports owa.env.gst
.
Benchmark Details
These performance measurements were generated using our comprehensive benchmark script: benchmark_screen_captures.py
The script tests multiple screen capture libraries under identical conditions to ensure fair comparison. You can run it yourself to verify performance on your hardware.
Usage Examples¶
Known Limitations¶
Current Limitations
- Windows only (Linux/macOS support planned)
- NVIDIA GPU required (our GStreamer implementation is NVIDIA-specific)
Windows Graphics Capture API (WGC) Issues¶
When capturing some screen with WGC
(Windows Graphics Capture API, activated when you specify window handle), the following issues are observed:
- FPS Limitation: Maximum FPS can't exceed maximum Hz of physical monitor
-
Variable FPS with specific applications: When capturing
Windows Terminal
andDiscord
, the following behavior was reported:- When there's no change in window, FPS drops to 1-5 frames
- When there's change (e.g. mouse movement) in window, FPS immediately recovers to 60+
This phenomenon is likely due to WGC's optimization behavior.
Implementation
See owa-env-gst source for detailed implementation.
API Reference¶
gst plugin 0.5.7 ¶
High-performance GStreamer-based screen capture and recording plugin
Author: OWA Development Team
Listeners ¶
Usage: To use listener components, import LISTENERS
from owa.core
and call the configure()
method with a callback
function:
from owa.core import LISTENERS
# Configure a listener component (replace 'component_name' with actual name)
listener = LISTENERS["gst/component_name"]
listener.configure(callback=my_callback, your_other_arguments)
# Use the listener in a context manager
with listener.session as active_listener:
# The listener is now running and will call my_callback when events occur
pass # Your main code here
Note: The callback
argument is required. The on_configure()
method shown in the documentation is an internal method called by configure()
.
screen ¶
Bases: GstPipelineRunner
High-performance GStreamer-based screen capture listener for real-time frame processing.
Captures screen content and delivers frames to a callback function. Can capture specific windows, monitors, or the entire screen.
Example:
from owa.core.registry import LISTENERS
import cv2
import numpy as np
# Define a callback to process frames
def process_frame(frame):
# Display the frame
cv2.imshow("Screen Capture", frame.frame_arr)
cv2.waitKey(1)
# Create and configure the listener
screen = LISTENERS["screen"]().configure(
callback=process_frame,
fps=30,
show_cursor=True
)
# Run the screen capture
with screen.session:
input("Press Enter to stop")
For performance metrics:
def process_with_metrics(frame, metrics):
print(f"FPS: {metrics.fps:.2f}, Latency: {metrics.latency*1000:.2f} ms")
cv2.imshow("Screen", frame.frame_arr)
cv2.waitKey(1)
screen.configure(callback=process_with_metrics)
on_configure ¶
on_configure(
*,
callback: Callable,
show_cursor: bool = True,
fps: float = 60,
window_name: str | None = None,
monitor_idx: int | None = None,
additional_properties: dict | None = None,
) -> bool
Configure the GStreamer pipeline for screen capture.
Other Parameters:
Name | Type | Description |
---|---|---|
callback |
Callable
|
Function to call with each captured frame |
show_cursor |
bool
|
Whether to show the cursor in the capture. |
fps |
float
|
Frames per second. |
window_name |
str | None
|
(Optional) specific window to capture. |
monitor_idx |
int | None
|
(Optional) specific monitor index. |
additional_properties |
dict | None
|
(Optional) additional arguments to pass to the pipeline. |
Source code in projects/owa-env-gst/owa/env/gst/screen/listeners.py
omnimodal.appsink_recorder ¶
Bases: GstPipelineRunner
High-performance screen recorder using GStreamer appsink for real-time processing.
This recorder captures screen content and saves it to a file while providing real-time frame notifications through a callback mechanism. It supports hardware acceleration and various output formats.
Examples:
Basic screen recording to file:
>>> def on_frame(screen_data):
... print(f"Recording frame at {screen_data.utc_ns}")
>>>
>>> recorder = AppsinkRecorder()
>>> recorder.configure(
... filesink_location="output.mkv",
... callback=on_frame
... )
>>> recorder.start()
Recording with custom resolution:
>>> recorder.configure(
... filesink_location="recording.mkv",
... callback=my_callback,
... width=1920,
... height=1080
... )
on_configure ¶
Configure the appsink recorder with output location and callback.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filesink_location
|
str
|
Path where the recording will be saved. |
required |
*args
|
Any
|
Additional positional arguments for pipeline configuration. |
()
|
callback
|
Callable
|
Function to call for each recorded frame. |
required |
**kwargs
|
Any
|
Additional keyword arguments for pipeline configuration. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
Configuration is applied to the recorder instance. |
Source code in projects/owa-env-gst/owa/env/gst/omnimodal/appsink_recorder.py
Runnables ¶
Usage: To use runnable components, import RUNNABLES
from owa.core
and call the configure()
method (not on_configure()
):
from owa.core import RUNNABLES
# Configure a runnable component (replace 'component_name' with actual name)
runnable = RUNNABLES["gst/component_name"]
runnable.configure(your_arguments)
# Use the runnable in a context manager
with runnable.session as active_runnable:
# The runnable is now running in the background
pass # Your main code here
Note: The on_configure()
method shown in the documentation is an internal method called by configure()
.
screen_capture ¶
Bases: ScreenListener
High-performance screen capture runnable using GStreamer pipeline for continuous frame grabbing.
Captures screen frames continuously and makes the latest frame available through a thread-safe interface.
Example:
from owa.core.registry import RUNNABLES
screen_capture = RUNNABLES["screen_capture"]().configure(fps=60)
with screen_capture.session:
for _ in range(10):
frame = screen_capture.grab()
print(f"Shape: {frame.frame_arr.shape}")
on_configure ¶
on_configure(*args: Any, **kwargs: Any) -> ScreenCapture
Configure and start the screen listener.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
Additional positional arguments for screen capture configuration. |
()
|
fps
|
float
|
Frames per second for capture. |
required |
window_name
|
str
|
Window to capture. If None, captures entire screen. |
required |
monitor_idx
|
int
|
Monitor index to capture. |
required |
**kwargs
|
Any
|
Additional keyword arguments for screen capture configuration. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
ScreenCapture |
ScreenCapture
|
Configured screen capture instance. |
Source code in projects/owa-env-gst/owa/env/gst/screen/runnable.py
grab ¶
Get the most recent frame (blocks until frame is available).
Returns:
Name | Type | Description |
---|---|---|
ScreenCaptured |
ScreenCaptured
|
Latest captured frame with timestamp. |
Raises:
Type | Description |
---|---|
TimeoutError
|
If no frame is received within 1 second. |
Source code in projects/owa-env-gst/owa/env/gst/screen/runnable.py
omnimodal.subprocess_recorder ¶
Bases: SubprocessRunner
High-performance screen and audio recorder using GStreamer subprocess.
This recorder runs GStreamer as a subprocess to capture screen content and audio, providing excellent performance and stability for long recordings. Supports various output formats and hardware acceleration.
Examples:
Basic screen recording with audio:
>>> recorder = SubprocessRecorder()
>>> recorder.configure(
... filesink_location="recording.mkv",
... record_audio=True,
... record_video=True,
... fps=30
... )
>>> recorder.start()
>>> # ... recording runs in background ...
>>> recorder.stop()
Video-only recording with custom settings:
>>> recorder.configure(
... filesink_location="video_only.mp4",
... record_audio=False,
... record_video=True,
... fps=60,
... show_cursor=False
... )
Source code in projects/owa-core/owa/core/runnable.py
on_configure ¶
on_configure(
filesink_location: str,
record_audio: bool = True,
record_video: bool = True,
record_timestamp: bool = True,
enable_fpsdisplaysink: bool = True,
show_cursor: bool = True,
fps: float = 60,
window_name: Optional[str] = None,
monitor_idx: Optional[int] = None,
additional_properties: Optional[dict] = None,
) -> None
Prepare the GStreamer pipeline command for subprocess recording.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filesink_location
|
str
|
Path where the recording will be saved. |
required |
record_audio
|
bool
|
Whether to include audio in the recording. |
True
|
record_video
|
bool
|
Whether to include video in the recording. |
True
|
record_timestamp
|
bool
|
Whether to include timestamp information. |
True
|
enable_fpsdisplaysink
|
bool
|
Whether to enable FPS display during recording. |
True
|
show_cursor
|
bool
|
Whether to show the cursor in the recording. |
True
|
fps
|
float
|
Frames per second for video recording. |
60
|
window_name
|
Optional[str]
|
Specific window to record (optional). |
None
|
monitor_idx
|
Optional[int]
|
Monitor index to record from (optional). |
None
|
additional_properties
|
Optional[dict]
|
Additional pipeline properties (optional). |
None
|
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
Configuration is stored internally for subprocess execution. |