framepress 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -18
- package/assets/backdrops/river-dusk.jpg +0 -0
- package/bin/camera.mjs +190 -0
- package/bin/ffmpeg.mjs +23 -0
- package/bin/mcp.mjs +233 -0
- package/bin/record.mjs +58 -13
- package/bin/sound.mjs +372 -0
- package/bin/studio-video.mjs +282 -0
- package/bin/studio.mjs +494 -0
- package/bin/take.mjs +251 -0
- package/examples/synthetic-desktop/check-alignment.mjs +28 -0
- package/examples/synthetic-desktop/check-sound.mjs +104 -0
- package/examples/synthetic-desktop/desktop.html +343 -0
- package/examples/synthetic-desktop/make.mjs +102 -0
- package/native/Package.swift +9 -0
- package/native/Sources/FramepressCapture/Capture.swift +325 -0
- package/native/Sources/FramepressCapture/Command.swift +219 -0
- package/native/Sources/FramepressCapture/Input.swift +202 -0
- package/native/bin/framepress-capture +0 -0
- package/package.json +17 -6
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import AppKit
|
|
2
|
+
import CoreGraphics
|
|
3
|
+
import CoreMedia
|
|
4
|
+
|
|
5
|
+
final class Input {
|
|
6
|
+
private struct Event {
|
|
7
|
+
let time: Double
|
|
8
|
+
let fields: [String: Any]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
private let file: FileHandle
|
|
12
|
+
private let epoch: Double
|
|
13
|
+
private let window: CGWindowID?
|
|
14
|
+
private let states: AsyncStream<CaptureState>.Continuation
|
|
15
|
+
private var origin: CGPoint
|
|
16
|
+
private var frame: CGRect
|
|
17
|
+
private let frames: FileHandle?
|
|
18
|
+
private var pending: [Event] = []
|
|
19
|
+
private var flushed = -Double.infinity
|
|
20
|
+
private var failure: Error?
|
|
21
|
+
private var timer: DispatchSourceTimer?
|
|
22
|
+
private var tap: CFMachPort?
|
|
23
|
+
private var tapSource: CFRunLoopSource?
|
|
24
|
+
private var nextRefresh = 0.0
|
|
25
|
+
private var cursor: String?
|
|
26
|
+
private let standardCursors = [
|
|
27
|
+
("arrow", NSCursor.arrow), ("pointer", NSCursor.pointingHand), ("ibeam", NSCursor.iBeam),
|
|
28
|
+
].map { ($0.0, $0.1.hotSpot, $0.1.image.tiffRepresentation) }
|
|
29
|
+
|
|
30
|
+
// windowFile: window captures log the window frame to window.jsonl whenever it changes.
|
|
31
|
+
init(file: URL, windowFile: URL?, source: Source, epoch: CMTime, states: AsyncStream<CaptureState>.Continuation) throws {
|
|
32
|
+
guard FileManager.default.createFile(atPath: file.path, contents: nil) else {
|
|
33
|
+
throw CaptureError("Cannot create events.jsonl.")
|
|
34
|
+
}
|
|
35
|
+
self.file = try FileHandle(forWritingTo: file)
|
|
36
|
+
self.epoch = epoch.seconds
|
|
37
|
+
self.states = states
|
|
38
|
+
origin = source.bounds.origin
|
|
39
|
+
frame = source.bounds
|
|
40
|
+
window = source.window?.windowID
|
|
41
|
+
if let windowFile, window != nil {
|
|
42
|
+
guard FileManager.default.createFile(atPath: windowFile.path, contents: nil) else {
|
|
43
|
+
throw CaptureError("Cannot create window.jsonl.")
|
|
44
|
+
}
|
|
45
|
+
frames = try FileHandle(forWritingTo: windowFile)
|
|
46
|
+
try logFrame(time: 0)
|
|
47
|
+
} else {
|
|
48
|
+
frames = nil
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private func logFrame(time: Double) throws {
|
|
53
|
+
try frames?.write(contentsOf: jsonData([
|
|
54
|
+
"t": max(0, time), "x": frame.minX, "y": frame.minY, "w": frame.width, "h": frame.height,
|
|
55
|
+
]))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func start() {
|
|
59
|
+
if CGPreflightListenEventAccess() {
|
|
60
|
+
let types: [CGEventType] = [
|
|
61
|
+
.leftMouseDown, .leftMouseUp, .leftMouseDragged,
|
|
62
|
+
.rightMouseDown, .rightMouseUp, .rightMouseDragged,
|
|
63
|
+
.otherMouseDown, .otherMouseUp, .otherMouseDragged, .scrollWheel, .keyDown,
|
|
64
|
+
]
|
|
65
|
+
let mask = types.reduce(CGEventMask(0)) { $0 | (1 << $1.rawValue) }
|
|
66
|
+
tap = CGEvent.tapCreate(tap: .cgSessionEventTap, place: .headInsertEventTap, options: .listenOnly,
|
|
67
|
+
eventsOfInterest: mask, callback: { _, type, event, context in
|
|
68
|
+
if let context {
|
|
69
|
+
Unmanaged<Input>.fromOpaque(context).takeUnretainedValue().receive(type, event)
|
|
70
|
+
}
|
|
71
|
+
return Unmanaged.passUnretained(event)
|
|
72
|
+
}, userInfo: Unmanaged.passUnretained(self).toOpaque())
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if let tap {
|
|
76
|
+
tapSource = CFMachPortCreateRunLoopSource(nil, tap, 0)
|
|
77
|
+
CFRunLoopAddSource(CFRunLoopGetMain(), tapSource, .commonModes)
|
|
78
|
+
} else {
|
|
79
|
+
diagnostic("Input Monitoring permission unavailable. Continuing with cursor position only. To log clicks, drags and scrolls, allow framepress-capture (or its terminal) in System Settings > Privacy & Security > Input Monitoring.")
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let timer = DispatchSource.makeTimerSource(queue: .main)
|
|
83
|
+
timer.schedule(deadline: .now(), repeating: .nanoseconds(1_000_000_000 / 150), leeway: .microseconds(300))
|
|
84
|
+
timer.setEventHandler { [weak self] in
|
|
85
|
+
autoreleasepool { self?.sample() }
|
|
86
|
+
}
|
|
87
|
+
self.timer = timer
|
|
88
|
+
timer.resume()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private func sample() {
|
|
92
|
+
guard failure == nil else { return }
|
|
93
|
+
let position = NSEvent.mouseLocation
|
|
94
|
+
let now = hostTime().seconds
|
|
95
|
+
// A window can move at any moment; follow it every sample so events stay window-relative.
|
|
96
|
+
if window != nil { refreshGeometry(now) }
|
|
97
|
+
if now >= nextRefresh {
|
|
98
|
+
let system = NSCursor.currentSystem
|
|
99
|
+
let image = system?.image.tiffRepresentation
|
|
100
|
+
cursor = standardCursors.first { $0.1 == system?.hotSpot && image != nil && $0.2 == image }?.0
|
|
101
|
+
nextRefresh = now + 1.0 / 30
|
|
102
|
+
}
|
|
103
|
+
let point = CGPoint(x: position.x, y: CGDisplayBounds(CGMainDisplayID()).height - position.y)
|
|
104
|
+
add(time: now, type: "move", point: point)
|
|
105
|
+
if pending.count >= 150 {
|
|
106
|
+
do {
|
|
107
|
+
try flush(through: now - epoch - 0.25)
|
|
108
|
+
} catch {
|
|
109
|
+
failure = error
|
|
110
|
+
states.yield(.failed(error))
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private func refreshGeometry(_ now: Double) {
|
|
116
|
+
guard let window,
|
|
117
|
+
let info = (CGWindowListCopyWindowInfo(.optionIncludingWindow, window) as? [[String: Any]])?.first,
|
|
118
|
+
let bounds = info[kCGWindowBounds as String] as? [String: Any],
|
|
119
|
+
let current = CGRect(dictionaryRepresentation: bounds as CFDictionary) else { return }
|
|
120
|
+
origin = current.origin
|
|
121
|
+
let moved = abs(current.minX - frame.minX) + abs(current.minY - frame.minY)
|
|
122
|
+
+ abs(current.width - frame.width) + abs(current.height - frame.height)
|
|
123
|
+
guard moved > 0.01 else { return }
|
|
124
|
+
frame = current
|
|
125
|
+
do {
|
|
126
|
+
try logFrame(time: now - epoch)
|
|
127
|
+
} catch {
|
|
128
|
+
failure = error
|
|
129
|
+
states.yield(.failed(error))
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private func receive(_ type: CGEventType, _ event: CGEvent) {
|
|
134
|
+
let button: String?
|
|
135
|
+
let kind: String
|
|
136
|
+
switch type {
|
|
137
|
+
case .tapDisabledByTimeout, .tapDisabledByUserInput:
|
|
138
|
+
if let tap { CGEvent.tapEnable(tap: tap, enable: true) }
|
|
139
|
+
return
|
|
140
|
+
case .leftMouseDown: (kind, button) = ("down", "left")
|
|
141
|
+
case .rightMouseDown: (kind, button) = ("down", "right")
|
|
142
|
+
case .otherMouseDown: (kind, button) = ("down", nil)
|
|
143
|
+
case .leftMouseUp: (kind, button) = ("up", "left")
|
|
144
|
+
case .rightMouseUp: (kind, button) = ("up", "right")
|
|
145
|
+
case .otherMouseUp: (kind, button) = ("up", nil)
|
|
146
|
+
case .leftMouseDragged: (kind, button) = ("drag", "left")
|
|
147
|
+
case .rightMouseDragged: (kind, button) = ("drag", "right")
|
|
148
|
+
case .otherMouseDragged: (kind, button) = ("drag", nil)
|
|
149
|
+
case .scrollWheel: (kind, button) = ("scroll", nil)
|
|
150
|
+
case .keyDown: (kind, button) = ("key", nil)
|
|
151
|
+
default: return
|
|
152
|
+
}
|
|
153
|
+
let dx: Double
|
|
154
|
+
let dy: Double
|
|
155
|
+
switch type {
|
|
156
|
+
case .scrollWheel:
|
|
157
|
+
dx = event.getDoubleValueField(.scrollWheelEventPointDeltaAxis2)
|
|
158
|
+
dy = event.getDoubleValueField(.scrollWheelEventPointDeltaAxis1)
|
|
159
|
+
case .leftMouseDragged, .rightMouseDragged, .otherMouseDragged:
|
|
160
|
+
dx = event.getDoubleValueField(.mouseEventDeltaX)
|
|
161
|
+
dy = event.getDoubleValueField(.mouseEventDeltaY)
|
|
162
|
+
default:
|
|
163
|
+
(dx, dy) = (0, 0)
|
|
164
|
+
}
|
|
165
|
+
// A key event only marks timing. No key code, modifier or text is recorded.
|
|
166
|
+
add(time: Double(event.timestamp) / 1e9, type: kind, point: event.location, button: button, dx: dx, dy: dy)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private func add(time: Double, type: String, point: CGPoint, button: String? = nil, dx: Double = 0, dy: Double = 0) {
|
|
170
|
+
let elapsed = time - epoch
|
|
171
|
+
guard failure == nil, elapsed >= 0, elapsed >= flushed else { return }
|
|
172
|
+
pending.append(Event(time: elapsed, fields: [
|
|
173
|
+
"t": elapsed, "type": type, "x": point.x - origin.x, "y": point.y - origin.y,
|
|
174
|
+
"button": button as Any? ?? NSNull(), "dx": dx, "dy": dy, "cursor": cursor as Any? ?? NSNull(),
|
|
175
|
+
]))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private func flush(through time: Double) throws {
|
|
179
|
+
var data = Data()
|
|
180
|
+
pending.sort { $0.time < $1.time }
|
|
181
|
+
let end = pending.firstIndex { $0.time > time } ?? pending.endIndex
|
|
182
|
+
for event in pending[..<end] {
|
|
183
|
+
data.append(try jsonData(event.fields))
|
|
184
|
+
flushed = event.time
|
|
185
|
+
}
|
|
186
|
+
try file.write(contentsOf: data)
|
|
187
|
+
pending.removeFirst(end)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
func stop() {
|
|
191
|
+
timer?.cancel()
|
|
192
|
+
if let tap { CFMachPortInvalidate(tap) }
|
|
193
|
+
if let tapSource { CFRunLoopRemoveSource(CFRunLoopGetMain(), tapSource, .commonModes) }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
func finish(duration: Double) throws {
|
|
197
|
+
if let failure { throw failure }
|
|
198
|
+
try flush(through: duration)
|
|
199
|
+
try file.close()
|
|
200
|
+
try frames?.close()
|
|
201
|
+
}
|
|
202
|
+
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "framepress",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Frame-by-frame WebGL to MP4
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Frame-by-frame WebGL to MP4, and native macOS screen recordings rendered with a studio look over MCP.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"framepress": "bin/record.mjs"
|
|
7
|
+
"framepress": "bin/record.mjs",
|
|
8
|
+
"framepress-mcp": "bin/mcp.mjs",
|
|
9
|
+
"framepress-video": "bin/studio-video.mjs"
|
|
8
10
|
},
|
|
9
11
|
"files": [
|
|
10
12
|
"bin",
|
|
13
|
+
"assets",
|
|
11
14
|
"examples",
|
|
12
15
|
"README.md",
|
|
13
|
-
"LICENSE"
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"native/Package.swift",
|
|
18
|
+
"native/Sources",
|
|
19
|
+
"native/bin/framepress-capture"
|
|
14
20
|
],
|
|
15
21
|
"engines": {
|
|
16
22
|
"node": ">=22"
|
|
@@ -19,8 +25,10 @@
|
|
|
19
25
|
"demo": "node bin/record.mjs --demo --style ember --out ember.mp4"
|
|
20
26
|
},
|
|
21
27
|
"dependencies": {
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
29
|
+
"ffmpeg-static": "5.3.0",
|
|
22
30
|
"playwright-core": "1.65.1",
|
|
23
|
-
"
|
|
31
|
+
"zod": "^4.6.7"
|
|
24
32
|
},
|
|
25
33
|
"license": "MIT",
|
|
26
34
|
"author": "Raj Varsani",
|
|
@@ -37,7 +45,10 @@
|
|
|
37
45
|
"mp4",
|
|
38
46
|
"threejs",
|
|
39
47
|
"recorder",
|
|
40
|
-
"shader"
|
|
48
|
+
"shader",
|
|
49
|
+
"screen-recording",
|
|
50
|
+
"macos",
|
|
51
|
+
"mcp"
|
|
41
52
|
],
|
|
42
53
|
"publishConfig": {
|
|
43
54
|
"access": "public",
|