memoir-capture
Windows-native screen capture module with Python bindings for real-time frame analysis and deterministic replay recording.
Memoir captures frames from a window or monitor using Windows Graphics Capture (WGC), delivers them to Python as NumPy arrays, and optionally records them to HEVC video with per-frame metadata — all without GPU-to-CPU roundtrips in the recording path.
Features
- WGC capture — continuous frame capture from any window or monitor
- NumPy delivery — BGRA frames as
(H, W, 4)uint8 arrays via bounded queue - Hardware-accelerated recording — lossless HEVC encoding (YUV 4:4:4) via NVENC or AMF
- Binary metadata —
.metasidecar with per-frame keyboard state, timestamps, and frame IDs - Dynamic recording — start/stop recording without restarting capture
- Frame-accurate keyboard — key state snapshot at the exact moment each frame is accepted
- Typed Python API — full type annotations, dataclasses, context managers
Requirements
- Windows 10 1903+ (for WGC
CreateFreeThreaded) - Python 3.10+
- NVIDIA GPU (NVENC) or AMD GPU (AMF) for recording
- Visual Studio 2022 (for building from source)
Installation
From PyPI (prebuilt)
pip install memoir-capture
From source
# Clone with vcpkg
git clone https://github.com/overlooker-dev/memoir-capture.git
cd Memoir
git clone https://github.com/microsoft/vcpkg.git vcpkg --depth 1
.\vcpkg\bootstrap-vcpkg.bat -disableMetrics
# Build
pip install build numpy
python -m build --wheel
# Install
pip install dist\memoir_capture-*.whl
The first build takes ~15 minutes (vcpkg builds FFmpeg). Subsequent builds use cached binaries.
For local development without installing:
.\scripts\build.ps1
# memoir_capture/ package is ready to import from the project root
Quick Start
Capture frames
import memoir_capture
engine = memoir_capture.CaptureEngine(
memoir_capture.MonitorTarget(0), # primary monitor
max_fps=10.0,
)
engine.start()
for packet in engine.frames():
with packet:
img = packet.cpu_bgra # numpy (H, W, 4) uint8
print(f"Frame {packet.frame_id}: {img.shape}")
print(f"Keys: 0x{packet.keyboard_mask:016x}")
break
engine.stop()
Capture a specific window
engine = memoir_capture.CaptureEngine(
memoir_capture.WindowTitleTarget(r"(?i)notepad"),
max_fps=30.0,
)
Record to MP4
engine = memoir_capture.CaptureEngine(
memoir_capture.MonitorTarget(0),
max_fps=10.0,
record_width=1920,
record_height=1080,
record_gop=1, # 1 = all-intra (frame-accurate seeking)
)
engine.start()
info = engine.start_recording("session_001")
print(f"Recording to {info.video_path}") # session_001.mp4
for i, packet in enumerate(engine.frames()):
packet.release()
if i >= 99:
break
engine.stop_recording() # finalizes .mp4 + .meta
engine.stop()
Read metadata
meta = memoir_capture.MetaReader.read("session_001.meta")
print(f"Keys tracked: {[k.name for k in meta.keys]}")
for row in meta.rows:
print(f"Frame {row.frame_id}: keyboard=0x{row.keyboard_mask:016x}")
Write metadata (for synthetic replays)
from memoir_capture import MetaWriter, MetaKeyEntry, MetaRow
keys = [MetaKeyEntry(0, 0x57, "W"), MetaKeyEntry(1, 0x41, "A")]
with MetaWriter("synthetic.meta", keys) as w:
w.write_row(MetaRow(
frame_id=0, record_frame_index=0,
capture_qpc=0, host_accept_qpc=0,
keyboard_mask=0b01,
width=1920, height=1080, analysis_stride=7680,
))
Context manager
with memoir_capture.CaptureEngine(memoir_capture.MonitorTarget(0)) as engine:
packet = engine.get_next_frame(timeout_ms=2000)
if packet:
with packet:
process(packet.cpu_bgra)
API Reference
CaptureEngine(target, *, max_fps, ...)
| Parameter | Default | Description |
|---|---|---|
target |
required | MonitorTarget(index), WindowTitleTarget(regex), or WindowExeTarget(regex) |
max_fps |
10.0 |
Maximum accepted frame rate |
analysis_queue_capacity |
1 |
Bounded queue size for Python delivery |
capture_cursor |
False |
Include cursor in capture |
record_width |
1920 |
Recording output width |
record_height |
1080 |
Recording output height |
record_gop |
1 |
GOP size (1 = all-intra, higher = smaller files) |
Methods: start(), stop(), get_next_frame(timeout_ms), frames(), start_recording(base_path, *, encoder=None), stop_recording(), is_recording(), stats()
FramePacket
| Property | Type | Description |
|---|---|---|
frame_id |
int |
Monotonic ID (only accepted frames get IDs) |
cpu_bgra |
np.ndarray |
(H, W, 4) uint8 BGRA pixel data |
keyboard_mask |
int |
64-bit bitmask of tracked keys |
capture_qpc |
int |
WGC capture timestamp (100ns units) |
width, height, stride |
int |
Frame dimensions |
Supports with packet: (auto-release) and explicit packet.release().
Recording
Encoding: lossless HEVC (QP=0), YUV 4:4:4, full color range. The encoder is selected automatically in priority order: hevc_nvenc (NVIDIA) → hevc_amf (AMD). A hardware HEVC encoder is required — no software fallback is bundled because libx265 is GPL. You can force a specific encoder:
info = engine.start_recording("session_001", encoder="hevc_amf")
| Setting | File size (10s, 1080p) |
|---|---|
| GOP=1 (all-intra) | ~52 MB |
| GOP=10 | ~17 MB |
| GOP=30 | ~14 MB |
Architecture
WGC FrameArrived (thread pool)
│
├─ FPS limiter → drop if too soon
├─ Queue check → drop if full (drop-new policy)
│
├─ Accept: assign frame_id, snapshot keyboard
├─ GPU→CPU: CopyResource → staging → Map → memcpy
├─ Recording: swscale (BGRA→YUV444) → HEVC encoder → MP4
└─ Enqueue → Python consumer
- Single
ID3D11DeviceContext+ mutex for all GPU ops - WGC
CreateFreeThreaded— no DispatcherQueue needed - Recording runs on the callback thread (well within budget at 10fps)
FramePacketowns its pixel buffer;release()frees it
Testing
# Full suite (requires display + supported GPU with NVENC or AMF)
pytest -v
# Headless (CI-safe)
pytest --headless -v
License
MIT. Links against FFmpeg (LGPL 2.1+).
Metadata
Release files for memoir-capture 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| memoir_capture-0.3.2-cp313-cp313-win_amd64.whl | CPython 3.13 | CPython 3.13 | Windows x86-64 | Details for memoir_capture-0.3.2-cp313-cp313-win_amd64.whl |
| memoir_capture-0.3.2-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details for memoir_capture-0.3.2-cp312-cp312-win_amd64.whl |
Total release size: 19.2 MB
Release files / memoir_capture-0.3.2-cp313-cp313-win_amd64.whl
| Download URL | memoir_capture-0.3.2-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 9.6 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2c8c4573d43d9573475cb7c2f7f90f45caff11977fe42970f3c03340b63746ec
|
|
BLAKE2b-256 checksum How to use checksums |
58231259e13fb0af0006179c266d3d19f4d7b93cfe4283e98d56fd8f70d96b94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logRelease files / memoir_capture-0.3.2-cp312-cp312-win_amd64.whl
| Download URL | memoir_capture-0.3.2-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 9.6 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
972eba23fe05bf10057a24de12e64ddd517c355ccf26d2ec88a918fc210d4ed8
|
|
BLAKE2b-256 checksum How to use checksums |
4ff6abed71c453a6db1d5868e1a576e737449c41f5d5b0461fa108e37cdfcf43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logSecurity for memoir-capture 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for memoir_capture-0.3.2-cp313-cp313-win_amd64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.