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
package/README.md
CHANGED
|
@@ -1,39 +1,140 @@
|
|
|
1
1
|
# Framepress
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Record your Mac's screen from an AI agent and get back a polished MP4: a backdrop, auto zoom and pan on clicks, a drawn cursor, motion blur and synthesized click sounds. A native ScreenCaptureKit recorder and a bundled MCP server do the work, so you can ask Claude Code or Codex to "record my screen for 20 seconds, then render it".
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Framepress also exports WebGL pages and scripted web takes to MP4, frame by frame. See [Web takes and WebGL export](#web-takes-and-webgl-export).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Free and MIT licensed.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Screen recordings on macOS
|
|
10
10
|
|
|
11
|
-
Requires Node 22+ and
|
|
11
|
+
Requires macOS 14+, Apple silicon, Node 22+ and Google Chrome (the compositor renders in headless Chrome).
|
|
12
|
+
|
|
13
|
+
### 1. Install
|
|
12
14
|
|
|
13
15
|
```sh
|
|
14
|
-
|
|
16
|
+
npm install -g framepress --allow-scripts=ffmpeg-static
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
npm 11 skips dependency install scripts unless you allow them, and `ffmpeg-static` uses one to download FFmpeg. Without `--allow-scripts=ffmpeg-static` the install still works and Framepress uses `ffmpeg` from your PATH instead (`brew install ffmpeg`). `FFMPEG_BIN=/path/to/ffmpeg` overrides both. npm 10 and earlier run the download by default.
|
|
20
|
+
|
|
21
|
+
### 2. Add the MCP server
|
|
22
|
+
|
|
23
|
+
Claude Code:
|
|
18
24
|
|
|
19
25
|
```sh
|
|
20
|
-
|
|
26
|
+
claude mcp add --transport stdio framepress -- framepress-mcp
|
|
21
27
|
```
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
Codex:
|
|
24
30
|
|
|
25
31
|
```sh
|
|
26
|
-
|
|
27
|
-
framepress --demo
|
|
32
|
+
codex mcp add framepress -- framepress-mcp
|
|
28
33
|
```
|
|
29
34
|
|
|
30
|
-
|
|
35
|
+
### 3. Grant permissions
|
|
36
|
+
|
|
37
|
+
In **System Settings → Privacy & Security**:
|
|
38
|
+
|
|
39
|
+
- **Screen & System Audio Recording**: allow the app that runs your agent (Terminal, iTerm, Ghostty, the Codex app). macOS attributes the capture to that host app; if it asks about `framepress-capture` itself, allow that.
|
|
40
|
+
- **Input Monitoring**: allow the same app. Without it, clicks, drags, scrolls and keys are not logged, so the camera has nothing to zoom on. The cursor path is still recorded.
|
|
41
|
+
|
|
42
|
+
Quit and reopen the app after changing either setting. If `list_displays` returns an empty list, the display is asleep or locked, or Screen Recording is not granted.
|
|
43
|
+
|
|
44
|
+
### 4. Ask
|
|
45
|
+
|
|
46
|
+
> Record my screen for 20 seconds, then render it.
|
|
47
|
+
|
|
48
|
+
The agent calls `start_recording` with `duration: 20`, then `stop_recording`, which waits for the recording to end, and passes the capture folder to `render`. You get an MP4 path. Recordings go to a private temporary folder; `render` writes `render.mp4` there unless you name an output.
|
|
49
|
+
|
|
50
|
+
> Record the Finder window for 15 seconds and render it on the halftone look with the soft-keys music.
|
|
51
|
+
|
|
52
|
+
| Tool | Purpose |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| `list_displays` | Active display IDs, sizes and origins. |
|
|
55
|
+
| `start_recording` | Start capture. Optional `display`, `window` (title or bundle ID), `fps` (default 60) and `duration` (seconds, then it stops on its own). Returns a recording ID and folder. |
|
|
56
|
+
| `stop_recording` | Finish a recording from the same session, or wait for a timed one to end. Returns the folder and duration. |
|
|
57
|
+
| `render` | Render a capture folder to MP4. Optional `out`, `look`, `zoom`, `parallax`, `aspect`, `trim`, `cursor`, `sound` (`on`, `clicks`, `keys`, `scroll`, `whoosh`, `music`, `music_level`), `force`. |
|
|
58
|
+
| `record_web_take` | Run a web take file (see Takes). Optional `out` and `log`. |
|
|
59
|
+
|
|
60
|
+
Codex users can also add the server in `~/.codex/config.toml`:
|
|
61
|
+
|
|
62
|
+
```toml
|
|
63
|
+
[mcp_servers.framepress]
|
|
64
|
+
command = "framepress-mcp"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Without an agent
|
|
31
68
|
|
|
32
69
|
```sh
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
70
|
+
framepress-video --in capture/ --out clip.mp4 --look acid-forest --trim 1.5:9
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
| Option | Default / behavior |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `--look` | `acid-forest`; also `none`, `#rrggbb`, `deep-green`, `halftone`, `walnut`, `sunburst` and the older looks (`steel`, `cobalt`, `cutting-mat`, ...). |
|
|
76
|
+
| `--zoom` | `1.75`; auto zoom on clicks, up to 2. `1` keeps the full frame. |
|
|
77
|
+
| `--parallax` | `0.5`; how far the backdrop follows the camera, 0 to 1, or `off`. |
|
|
78
|
+
| `--aspect` | `16:9` (1920 × 1080); also `16:10`, `4:5`, `1:1`. |
|
|
79
|
+
| `--pad` | Fraction of the short side kept around the recording: `0.08` for wide frames, `0.09` for window captures. |
|
|
80
|
+
| `--trim` | `start:end` seconds of the recording, e.g. `1.5:9` or `2:`. |
|
|
81
|
+
| `--cursor` | Built-in arrow. A PNG arrow in a 360 px box with the tip at 60,120 replaces it; `FRAMEPRESS_CURSOR` sets one for every render. |
|
|
82
|
+
| `--sound` | `on`; synthesized sound (below). `off` renders a silent MP4. |
|
|
83
|
+
| `--sound-clicks`, `--sound-keys`, `--sound-scroll`, `--sound-whoosh` | `1` each; level of that layer, `0` mutes it, up to `4`. |
|
|
84
|
+
| `--music` | Off. `soft-keys` adds a generated warm electric piano bed (76 BPM, four-chord loop, soft bass, slow pad, light room); `pad` a plain chord bed; a file path adds your own track, looped and faded. Framepress ships no music. |
|
|
85
|
+
| `--music-level` | `1`; level of the bed. At 1 the bed sits 14 LU under the effects' integrated loudness (about 17 dB under the loudest clicks), felt more than heard. |
|
|
86
|
+
| `--force` | Replace an existing output. |
|
|
87
|
+
|
|
88
|
+
#### Sound
|
|
89
|
+
|
|
90
|
+
Every sound is synthesized in `bin/sound.mjs` from the event log and the camera track; no samples ship with Framepress. Onsets land on the event sample, on the trimmed output timeline.
|
|
91
|
+
|
|
92
|
+
| Layer | Sound |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| Clicks | Press: a short bright transient (damped modes of a plastic shell, a band of noise) over a small low thump. Release: quieter, higher, shorter. Drag start and drop are a press and a release. Pitch, decay and level vary per click; slight pan follows the cursor. |
|
|
95
|
+
| Keys | A softer, lower tap per key event with a quieter key return 60 to 90 ms later, level humanized by up to 2.5 dB. |
|
|
96
|
+
| Scroll | A tiny tick every 28 points of scroll travel, very quiet. |
|
|
97
|
+
| Whoosh | Band-passed brown noise whose level and pitch follow camera speed (zoom rate plus pan speed). |
|
|
98
|
+
| Music | Optional, under the effects, 0.5 s fade in and 1 s fade out. |
|
|
99
|
+
|
|
100
|
+
The mix is normalized toward -18 LUFS integrated (BS.1770 gating) under a lookahead limiter at -1.5 dBFS, and the limiter never takes more than 6 dB. Sparse clicks alone therefore land quieter, around -22 LUFS, instead of being crushed. A quiet bed adds gated blocks and lowers the integrated figure further (about -26 LUFS on the synthetic demo); only a bed within about 10 LU of the effects reaches the target. Audio is AAC 48 kHz stereo. `examples/synthetic-desktop/check-sound.mjs render.mp4 run.json [waveform.png]` decodes the audio back, finds onsets blind, matches them to the cues in a `--log` run, reports loudness and true peak, and draws a waveform with the cue times on top.
|
|
101
|
+
|
|
102
|
+
`--debug` draws a crosshair on each click, `--probe` draws the cursor as a dot on its hotspot, and `--log run.json` writes the camera track. `examples/synthetic-desktop/make.mjs <dir> [--window]` writes a synthetic display or window capture for testing, and `check-alignment.mjs` measures the cursor against the click points from a `--probe --log` run.
|
|
103
|
+
|
|
104
|
+
### The recorder
|
|
105
|
+
|
|
106
|
+
The capture binary is `native/bin/framepress-capture` (arm64, ad hoc signed). Run it directly:
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
framepress-capture() { "$(npm root -g)/framepress/native/bin/framepress-capture" "$@"; }
|
|
110
|
+
framepress-capture displays
|
|
111
|
+
framepress-capture record --out ./capture --duration 5
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Use `--display <id>` for a secondary display or `--window <title or bundle id>` for one app window. A bundle ID picks that app's frontmost window. Omit `--duration` to record until Ctrl+C or SIGTERM.
|
|
115
|
+
|
|
116
|
+
A window capture holds only that window: no wallpaper, menu bar, other windows or system shadow. `render` draws it with its own rounded corners and a soft shadow on the backdrop, so there is one background, like Screen Studio's window recordings. The window may move during the take: events stay relative to it and `window.jsonl` logs its frame. Keep its size fixed; the movie keeps the size it had at the first frame.
|
|
117
|
+
|
|
118
|
+
A capture folder holds a cursor-free HEVC `screen.mov`, `events.jsonl` and `meta.json`, plus `window.jsonl` for window captures. Event times start at the first video frame. Coordinates are points from the top left of the captured display or window, at the time of the event; the cursor can leave a window, so window coordinates can be negative or past its size. `meta.json` has `source` (`display` or `window`); window captures add `window` (title, app, bundle ID), `corner_radius_points` and `corner_radius_source` (`measured` from the window's transparent corner, or `default` 10 pt). `window.jsonl` lines are `{t, x, y, w, h}` in global points, one at the start and one per change. Unknown cursor shapes are recorded as null.
|
|
119
|
+
|
|
120
|
+
## Web takes and WebGL export
|
|
121
|
+
|
|
122
|
+
Export a WebGL page to a silent H.264 MP4, advancing the animation one frame at a time. Comes with three original shader studies. Ember is the default.
|
|
123
|
+
|
|
124
|
+

|
|
125
|
+
|
|
126
|
+
[Watch the six-second Ember render](media/ember.mp4)
|
|
127
|
+
|
|
128
|
+
Requires Node 22+ and Google Chrome.
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
npx framepress --demo --out ember.mp4
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Record your own local page:
|
|
135
|
+
|
|
136
|
+
```sh
|
|
137
|
+
npx framepress http://localhost:3000 --seconds 8 --fps 60 --out demo.mp4
|
|
37
138
|
```
|
|
38
139
|
|
|
39
140
|
| Option | Default / behavior |
|
|
@@ -47,7 +148,37 @@ npm run demo
|
|
|
47
148
|
| `--ready` | Wait for a visible CSS selector, e.g. `--ready canvas`. |
|
|
48
149
|
| `--browser` | Chromium executable path. Also accepts `CHROME_PATH`. |
|
|
49
150
|
|
|
50
|
-
|
|
151
|
+
### Takes
|
|
152
|
+
|
|
153
|
+
A take is a short script for recording a real page. Camera cues can wait for what the page shows, so a shot lands on the frame the state appears, however long the app takes to get there.
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
npx framepress --take shot.take --log take.json --out take.mp4
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
open http://localhost:3000
|
|
161
|
+
viewport 864x1080 scale 1.25
|
|
162
|
+
type 21102015 on .keys button
|
|
163
|
+
hold #accelerator
|
|
164
|
+
wait until #message reads "Arrived"
|
|
165
|
+
camera on .glass pad 14 over 0.7s
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| Step | Behavior |
|
|
169
|
+
| --- | --- |
|
|
170
|
+
| `open <url or path>` | Page to record. Paths resolve from the take file. |
|
|
171
|
+
| `viewport 864x1080 scale 1.25` | CSS size and device scale; output is the scaled size. |
|
|
172
|
+
| `fps 60`, `cursor arrow.png` | Frame rate; optional pointer image drawn into the frame. |
|
|
173
|
+
| `camera on <selector> [pad 24] [over 0.6s]` | Frame an element, eased. `camera wide` returns to the full page. |
|
|
174
|
+
| `type <keys> on <selector>` | Click the matching button for each character, with travel time from real distance. |
|
|
175
|
+
| `click <selector>`, `hold <selector> [for 0.5s]`, `release` | Pointer input. |
|
|
176
|
+
| `wait until <selector> reads "<text>"` | Block until the element's text matches. `wait until js <expression>` takes any predicate. `timeout 15s` by default. |
|
|
177
|
+
| `pause 1s` | Hold. |
|
|
178
|
+
|
|
179
|
+
Steps run in order. A wait is checked every frame after the clock advances; when it passes, the next step starts on that same frame. `--log` writes each step's frame, plus a MutationObserver's independent frame for each wait. In take mode, CSS transitions and Web Animations also follow the virtual clock. `--seconds` becomes a safety limit (default 120). Steps act on the main frame only; iframes are not entered.
|
|
180
|
+
|
|
181
|
+
### Frame control
|
|
51
182
|
|
|
52
183
|
Before loading the page, the recorder replaces main-window `requestAnimationFrame` and `performance.now()`. Every captured frame gets its output timestamp, independent of how long rendering takes. Frames stream into FFmpeg without creating a frame folder. The CLI reports measured rendering speed.
|
|
53
184
|
|
|
@@ -64,7 +195,7 @@ The hook may return a promise. It replaces animation callback stepping. Wait for
|
|
|
64
195
|
|
|
65
196
|
CSS/Web Animations, native timers, Date, workers, video playback, audio and XR loops are outside the controlled clock. Network data and randomness are not seeded. This is a frame exporter for compatible scenes, not a universal browser-time simulator. Existing page cursors are captured; no pointer is injected.
|
|
66
197
|
|
|
67
|
-
|
|
198
|
+
### Included art
|
|
68
199
|
|
|
69
200
|
- **Ember:** warm luminous stipples, sparse engraved contours and bloom.
|
|
70
201
|
- **Indexed:** quarter-resolution, four-colour ordered dithering.
|
|
@@ -72,6 +203,22 @@ CSS/Web Animations, native timers, Date, workers, video playback, audio and XR l
|
|
|
72
203
|
|
|
73
204
|
Original ribbon geometry and shaders. Technical background: [Maxime Heckel's dithering and retro-shading article](https://blog.maximeheckel.com/posts/the-art-of-dithering-and-retro-shading-web/).
|
|
74
205
|
|
|
206
|
+
## Develop locally
|
|
207
|
+
|
|
208
|
+
```sh
|
|
209
|
+
git clone https://github.com/RajVarsani/framepress.git
|
|
210
|
+
cd framepress
|
|
211
|
+
npm ci
|
|
212
|
+
npm run demo
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
For the MCP server from a checkout, use `node /absolute/path/to/framepress/bin/mcp.mjs` in place of `framepress-mcp`. It prefers a local SwiftPM build of the recorder over the bundled binary. To rebuild the bundled binary on Apple silicon:
|
|
216
|
+
|
|
217
|
+
```sh
|
|
218
|
+
swift build -c release --package-path native
|
|
219
|
+
cp native/.build/release/framepress-capture native/bin/framepress-capture
|
|
220
|
+
```
|
|
221
|
+
|
|
75
222
|
## Licence
|
|
76
223
|
|
|
77
224
|
MIT for this source. Dependencies and the downloaded FFmpeg binary retain their own licences; `ffmpeg-static` provides the binary's licence alongside it.
|
|
Binary file
|
package/bin/camera.mjs
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Camera rig shared by web takes and screen recordings: spring camera, auto zoom and pan,
|
|
2
|
+
// drawn cursor, press spring and the subframe poses the compositor draws with motion blur.
|
|
3
|
+
// Web takes drive it from a script (take.mjs); recordings drive it from events (video.mjs).
|
|
4
|
+
//
|
|
5
|
+
// Motion is modelled on per-frame tracks of public Screen Studio exports (see the
|
|
6
|
+
// Framepress motion notes): the camera only retargets on cues, clicks, or when the
|
|
7
|
+
// cursor heads out of a dead zone.
|
|
8
|
+
|
|
9
|
+
// Measured on Screen Studio exports (motion notes, Nov 29):
|
|
10
|
+
// Camera: one spring for zoom in, zoom out and pans; k 53.5 to 55.9, zeta 1.09 to 1.11,
|
|
11
|
+
// 10 to 90% in 533 ms, within 2% at 0.94 s. omega times the 2% settle time is 6.97.
|
|
12
|
+
export const SPRING = { zeta: 1.1, settle: 0.94, omegaSettle: 6.97 };
|
|
13
|
+
// Cursor: raw minimum-jerk move, then a spring. hrje omega 9.7 zeta 0.84; hero-rec 13.7, 0.93.
|
|
14
|
+
export const CURSOR = { omega: 13, zeta: 0.9, arc: 0.025, fittsA: 0, fittsB: 0.24, jitter: 0.1, tipTolerance: 2 };
|
|
15
|
+
// Press: Screen Studio shrinks over about 200 ms and recovers over 170 ms. Depth stays at
|
|
16
|
+
// Raj's approved 0.93. omega 16 (critically damped) gives 10 to 90% in about 210 ms.
|
|
17
|
+
export const PRESS = { depth: 0.93, omega: 16, hold: 0.16 };
|
|
18
|
+
// Follow: no continuous follow; pan only when the cursor heads past 0.65 of the half-view,
|
|
19
|
+
// landing it at 0.3 (measured trigger 0.6 to 0.7, landing 0.2 to 0.4).
|
|
20
|
+
export const FOLLOW = { trigger: 0.65, land: 0.3 };
|
|
21
|
+
// Auto camera (Screen Studio style, camera-follow notes Nov 30): zoom starts 0.2 s after the
|
|
22
|
+
// cursor sets off for a click (measured 0.12 to 0.25 s), held zoom 1.75 to 2x, zoom out 0.45 s
|
|
23
|
+
// after the last action (measured 0.44 s). While zoomed the camera does not chase the cursor:
|
|
24
|
+
// it holds still while the click target sits inside a per-axis box of `zone` of the half-view
|
|
25
|
+
// (cursor seen up to 0.63 to 0.68 per axis with the camera still). A target outside the box
|
|
26
|
+
// gets one straight pan, `lead` after the cursor sets off (measured 0.24 s), moving only the
|
|
27
|
+
// axes that need it and landing the target `land` of the half-view from centre (measured
|
|
28
|
+
// 0.26 to 0.42). Pans are one critically damped spring on all axes (fits zeta 0.87 to 1.0,
|
|
29
|
+
// 2% settle 0.82 to 0.88 s; paths straight within 0.3% of the chord), so they never curve.
|
|
30
|
+
export const AUTO = { zoom: 1.9, idle: 0.45, lead: 0.2, zone: 0.65, land: 0.3, panZeta: 1.0, panSettle: 0.85 };
|
|
31
|
+
// Motion blur: 32 subframes across a full-frame shutter so pans smear visibly at feed size.
|
|
32
|
+
export const MAX_ZOOM = 2, SUB = 32, SHUTTER = 1.0, CURSOR_SHUTTER = 0.85;
|
|
33
|
+
export const REST_ANGLE = -135 - Math.atan2(120 - 178, (360 - 300) - (360 - 149)) * 180 / Math.PI;
|
|
34
|
+
|
|
35
|
+
// layout: studio layout. toComposite: source point to composite point. start: first cursor
|
|
36
|
+
// position in source points. cursorSize: drawn cursor box at zoom 1 in composite px (null hides it).
|
|
37
|
+
// Optional, for recordings: tipAt(t) gives the drawn tip at time t in source points, downAt(t)
|
|
38
|
+
// the button state, shapeAt(t) the cursor shape. Without them the tip is the raw path through
|
|
39
|
+
// the cursor spring and the press follows raw.down.
|
|
40
|
+
export function createRig({ layout: L, fps, toComposite, start, cursorSize, tipAt, downAt, shapeAt, log = [] }) {
|
|
41
|
+
const track = [];
|
|
42
|
+
const wide = { z: 1, x: L.W / 2, y: L.H / 2 };
|
|
43
|
+
// The spring acts on linear scale: one zeta (1.1) fits both zoom in and zoom out there,
|
|
44
|
+
// while log scale would need 1.24 in and 1.01 out (motion notes, svar.py).
|
|
45
|
+
const cam = { ...wide, panX: 0, panY: 0, vz: 0, vx: 0, vy: 0, vpanX: 0, vpanY: 0 };
|
|
46
|
+
let goal = { ...wide, panX: 0, panY: 0 }, omega = SPRING.omegaSettle / SPRING.settle, zeta = SPRING.zeta;
|
|
47
|
+
// Auto camera state. mode: off | wide | in.
|
|
48
|
+
const auto = { mode: 'off', zoom: AUTO.zoom, idle: AUTO.idle, zoomAt: null, panAt: null, lastActive: 0, aim: null };
|
|
49
|
+
// raw: where the real mouse is. drawn: what the viewer sees.
|
|
50
|
+
const raw = { ...start, down: false }, rawPrev = { ...start };
|
|
51
|
+
const drawn = { x: start.x, y: start.y, vx: 0, vy: 0 };
|
|
52
|
+
let angle = REST_ANGLE, press = 1, pressV = 0, prevDrawnX = start.x, lastShape = null;
|
|
53
|
+
const rig = { cam, auto, raw, rawPrev, drawn, wide, log, track, framed: null, get goal() { return goal; } };
|
|
54
|
+
|
|
55
|
+
const clampView = rig.clampView = (cx, cy, z) => {
|
|
56
|
+
const clamp = (c, half, lo, hi) => half * 2 <= hi - lo ? Math.min(hi - half, Math.max(lo + half, c)) : (lo + hi) / 2;
|
|
57
|
+
return { x: z <= 1.0001 ? L.W / 2 : clamp(cx, L.W / z / 2, L.win.x, L.win.x + L.win.w), y: z <= 1.0001 ? L.H / 2 : clamp(cy, L.H / z / 2, L.win.y, L.win.y + L.win.h) };
|
|
58
|
+
};
|
|
59
|
+
// One spring for every axis of a move, so the view travels in a straight line.
|
|
60
|
+
const setGoal = rig.setGoal = (to, over, z = SPRING.zeta, omegaSettle = SPRING.omegaSettle) => {
|
|
61
|
+
// Same-zoom retargets contribute only pan. A new zoom retargets the anchor.
|
|
62
|
+
const panning = to.z === goal.z;
|
|
63
|
+
goal = { z: to.z, x: to.x, y: to.y,
|
|
64
|
+
panX: panning ? goal.panX + to.x - goal.x : 0,
|
|
65
|
+
panY: panning ? goal.panY + to.y - goal.y : 0 };
|
|
66
|
+
if (to.rect !== undefined) rig.framed = to.rect;
|
|
67
|
+
omega = omegaSettle / (over ?? SPRING.settle);
|
|
68
|
+
zeta = z;
|
|
69
|
+
};
|
|
70
|
+
// Auto zoom-in aims at the click the cursor is heading for.
|
|
71
|
+
const aimPoint = () => { const r = auto.aim ?? raw; return toComposite(r.x, r.y); };
|
|
72
|
+
// Auto pan: keep the view still unless the target sits outside the box; then shift only
|
|
73
|
+
// the axes that need it so the target lands AUTO.land from centre.
|
|
74
|
+
const autoPan = () => {
|
|
75
|
+
const p = aimPoint(), z = goal.z, hw = L.W / z / 2, hh = L.H / z / 2;
|
|
76
|
+
const ox = (p.x - goal.x) / hw, oy = (p.y - goal.y) / hh;
|
|
77
|
+
if (Math.abs(ox) <= AUTO.zone && Math.abs(oy) <= AUTO.zone) return false;
|
|
78
|
+
const nx = Math.abs(ox) > AUTO.zone ? p.x - Math.sign(ox) * AUTO.land * hw : goal.x;
|
|
79
|
+
const ny = Math.abs(oy) > AUTO.zone ? p.y - Math.sign(oy) * AUTO.land * hh : goal.y;
|
|
80
|
+
const c = clampView(nx, ny, z);
|
|
81
|
+
if (Math.hypot(c.x - goal.x, c.y - goal.y) < 0.5) return false;
|
|
82
|
+
// Critical damping needs omega * settle = 5.83 for the 2% band.
|
|
83
|
+
setGoal({ z, ...c, rect: null }, AUTO.panSettle, AUTO.panZeta, 5.83);
|
|
84
|
+
return true;
|
|
85
|
+
};
|
|
86
|
+
// Pan only when the cursor heads out of the dead zone; land it at FOLLOW.land.
|
|
87
|
+
const follow = to => {
|
|
88
|
+
const z = goal.z;
|
|
89
|
+
if (z < 1.05) return false;
|
|
90
|
+
// A scripted shot frames its element on purpose; targets inside it never pan.
|
|
91
|
+
const f = rig.framed;
|
|
92
|
+
if (f && to.x >= f.x && to.x <= f.x + f.width && to.y >= f.y && to.y <= f.y + f.height) return false;
|
|
93
|
+
const p = toComposite(to.x, to.y), hw = L.W / z / 2, hh = L.H / z / 2;
|
|
94
|
+
const ox = (p.x - goal.x) / hw, oy = (p.y - goal.y) / hh;
|
|
95
|
+
if (Math.abs(ox) <= FOLLOW.trigger && Math.abs(oy) <= FOLLOW.trigger) return false;
|
|
96
|
+
const nx = Math.abs(ox) > FOLLOW.trigger ? p.x - Math.sign(ox) * FOLLOW.land * hw : goal.x;
|
|
97
|
+
const ny = Math.abs(oy) > FOLLOW.trigger ? p.y - Math.sign(oy) * FOLLOW.land * hh : goal.y;
|
|
98
|
+
setGoal({ z: goal.z, ...clampView(nx, ny, z), rect: null });
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
// The cursor sets off for a click at `to` on this frame. Returns true when a follow pan fired.
|
|
102
|
+
rig.aim = (to, frame) => {
|
|
103
|
+
if (auto.mode !== 'off') {
|
|
104
|
+
auto.aim = to;
|
|
105
|
+
if (auto.mode === 'wide' && auto.zoomAt === null) auto.zoomAt = frame + Math.round(AUTO.lead * fps);
|
|
106
|
+
else if (auto.mode === 'in') auto.panAt = frame + Math.round(AUTO.lead * fps);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return follow(to);
|
|
110
|
+
};
|
|
111
|
+
rig.startAuto = (zoom, idle, frame) => Object.assign(auto, { mode: goal.z > 1.05 ? 'in' : 'wide', zoom: Math.min(MAX_ZOOM, zoom), idle, lastActive: frame });
|
|
112
|
+
|
|
113
|
+
const isDown = t => downAt ? downAt(t) : raw.down;
|
|
114
|
+
const stepPhysics = (dt, rx, ry, t) => {
|
|
115
|
+
for (const a of ['z', 'x', 'y', 'panX', 'panY']) {
|
|
116
|
+
const k = omega * omega, c = 2 * zeta * omega, v = 'v' + a;
|
|
117
|
+
cam[v] += (-k * (cam[a] - goal[a]) - c * cam[v]) * dt; cam[a] += cam[v] * dt;
|
|
118
|
+
}
|
|
119
|
+
if (tipAt) {
|
|
120
|
+
const p = tipAt(t);
|
|
121
|
+
drawn.vx = (p.x - drawn.x) / dt; drawn.vy = (p.y - drawn.y) / dt; drawn.x = p.x; drawn.y = p.y;
|
|
122
|
+
} else {
|
|
123
|
+
const kc = CURSOR.omega ** 2, cc = 2 * CURSOR.zeta * CURSOR.omega;
|
|
124
|
+
drawn.vx += (-kc * (drawn.x - rx) - cc * drawn.vx) * dt; drawn.x += drawn.vx * dt;
|
|
125
|
+
drawn.vy += (-kc * (drawn.y - ry) - cc * drawn.vy) * dt; drawn.y += drawn.vy * dt;
|
|
126
|
+
}
|
|
127
|
+
const kp = PRESS.omega ** 2, cp = 2 * PRESS.omega;
|
|
128
|
+
pressV += (-kp * (press - (isDown(t) ? PRESS.depth : 1)) - cp * pressV) * dt; press += pressV * dt;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Zoom in when a click's travel has run for the lead time; zoom out after an idle pause.
|
|
132
|
+
// active: extra activity this frame that moves no cursor (typing, scrolling).
|
|
133
|
+
rig.autoCamera = (frame, active = false) => {
|
|
134
|
+
if (auto.mode === 'off') return;
|
|
135
|
+
if (active || raw.down || raw.x !== rawPrev.x || raw.y !== rawPrev.y || Math.hypot(drawn.vx, drawn.vy) > 30) auto.lastActive = frame;
|
|
136
|
+
if (auto.zoomAt !== null && frame >= auto.zoomAt) {
|
|
137
|
+
auto.zoomAt = null; auto.mode = 'in';
|
|
138
|
+
const f = aimPoint();
|
|
139
|
+
setGoal({ z: auto.zoom, ...clampView(f.x, f.y, auto.zoom), rect: null });
|
|
140
|
+
log.push({ line: 0, step: `auto zoom in ${auto.zoom}x`, frame, cameraStart: frame });
|
|
141
|
+
} else if (auto.mode === 'in' && auto.panAt !== null && frame >= auto.panAt) {
|
|
142
|
+
auto.panAt = null;
|
|
143
|
+
if (autoPan()) log.push({ line: 0, step: 'auto pan', frame, cameraStart: frame, to: { x: +goal.x.toFixed(1), y: +goal.y.toFixed(1) } });
|
|
144
|
+
} else if (auto.mode === 'in' && frame - auto.lastActive >= Math.round(auto.idle * fps)) {
|
|
145
|
+
auto.mode = 'wide'; auto.aim = null; auto.panAt = null;
|
|
146
|
+
setGoal({ ...wide, rect: null });
|
|
147
|
+
log.push({ line: 0, step: 'auto zoom out', frame, cameraStart: frame });
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Integrate SUB subframes across this frame; draw the ones inside the shutter.
|
|
152
|
+
// Each sub carries t, its time within the frame (0 is the previous frame, 1 this one).
|
|
153
|
+
rig.pose = (frame, caption) => {
|
|
154
|
+
const states = [];
|
|
155
|
+
for (let j = 1; j <= SUB; j++) {
|
|
156
|
+
const u = j / SUB, t = (frame - 1 + u) / fps;
|
|
157
|
+
if (frame > 0) stepPhysics(1 / (fps * SUB), rawPrev.x + (raw.x - rawPrev.x) * u, rawPrev.y + (raw.y - rawPrev.y) * u, t);
|
|
158
|
+
else if (tipAt) { const p = tipAt(0); Object.assign(drawn, { x: p.x, y: p.y }); }
|
|
159
|
+
else Object.assign(drawn, { x: raw.x, y: raw.y });
|
|
160
|
+
states.push({ cam: { x: cam.x, y: cam.y, z: cam.z, panX: cam.panX, panY: cam.panY }, tip: { x: drawn.x, y: drawn.y }, press, t: u });
|
|
161
|
+
}
|
|
162
|
+
const vx = (drawn.x - prevDrawnX) * fps; prevDrawnX = drawn.x;
|
|
163
|
+
const shape = shapeAt?.(frame / fps);
|
|
164
|
+
// Only the arrow banks with velocity; hand and I-beam stay upright and the arrow
|
|
165
|
+
// comes back at its resting angle instead of swinging in from upright.
|
|
166
|
+
const bank = REST_ANGLE + 40 * Math.tanh(vx / 400), upright = shape && shape !== 'arrow';
|
|
167
|
+
if (upright) angle = 0;
|
|
168
|
+
else if (lastShape && lastShape !== 'arrow') angle = bank;
|
|
169
|
+
else angle += (bank - angle) * .35;
|
|
170
|
+
lastShape = shape;
|
|
171
|
+
const at = t => { const f = Math.min(SUB - 1, Math.max(0, t * SUB - 1)), i = Math.floor(f), w = f - i, a = states[i], b = states[Math.min(SUB - 1, i + 1)];
|
|
172
|
+
return { x: a.tip.x + (b.tip.x - a.tip.x) * w, y: a.tip.y + (b.tip.y - a.tip.y) * w, press: a.press + (b.press - a.press) * w }; };
|
|
173
|
+
const open = states.slice(Math.round(SUB * (1 - SHUTTER)));
|
|
174
|
+
const toOut = (c, q) => ({ x: (q.x - c.x) * c.z + L.W / 2, y: (q.y - c.y) * c.z + L.H / 2 });
|
|
175
|
+
const subs = open.map(st => {
|
|
176
|
+
// The cursor smears over less of the frame than the camera does.
|
|
177
|
+
const ct = 1 - (1 - st.t) * CURSOR_SHUTTER / SHUTTER, q = at(ct), tip = toComposite(q.x, q.y), o = toOut(st.cam, tip);
|
|
178
|
+
const cursor = cursorSize && { x: o.x, y: o.y, size: cursorSize * st.cam.z, angle, press: q.press };
|
|
179
|
+
if (cursor && shape) cursor.shape = shape;
|
|
180
|
+
return shapeAt ? { cam: st.cam, cursor, t: st.t } : { cam: st.cam, cursor };
|
|
181
|
+
});
|
|
182
|
+
const last = states.at(-1);
|
|
183
|
+
track.push({ f: frame, rx: +raw.x.toFixed(2), ry: +raw.y.toFixed(2), dx: +last.tip.x.toFixed(3), dy: +last.tip.y.toFixed(3), down: (downAt ? downAt(frame / fps) : raw.down) ? 1 : 0, press: +last.press.toFixed(4),
|
|
184
|
+
cz: +last.cam.z.toFixed(5), cx: +last.cam.x.toFixed(3), cy: +last.cam.y.toFixed(3) });
|
|
185
|
+
const a = subs[0], z = subs.at(-1);
|
|
186
|
+
const moved = Math.hypot(a.cam.x - z.cam.x, a.cam.y - z.cam.y) * z.cam.z + Math.abs(a.cam.z - z.cam.z) * L.W / 2 + (a.cursor && z.cursor ? Math.hypot(a.cursor.x - z.cursor.x, a.cursor.y - z.cursor.y) : 0);
|
|
187
|
+
return { subs: moved > 0.35 ? subs : [z], caption };
|
|
188
|
+
};
|
|
189
|
+
return rig;
|
|
190
|
+
}
|
package/bin/ffmpeg.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Finds an FFmpeg binary: FFMPEG_BIN, then the ffmpeg-static download, then ffmpeg on PATH
|
|
2
|
+
// (plus the Homebrew prefixes, which GUI-launched agents often leave off PATH).
|
|
3
|
+
// npm 11 skips ffmpeg-static's install script unless it is allowed, so the download can be missing.
|
|
4
|
+
import { accessSync, constants } from 'node:fs';
|
|
5
|
+
import { delimiter, join } from 'node:path';
|
|
6
|
+
import ffmpegStatic from 'ffmpeg-static';
|
|
7
|
+
|
|
8
|
+
const runnable = (p) => { try { accessSync(p, constants.X_OK); return true; } catch { return false; } };
|
|
9
|
+
let found;
|
|
10
|
+
|
|
11
|
+
export function ffmpegPath() {
|
|
12
|
+
if (found) return found;
|
|
13
|
+
const dirs = [...(process.env.PATH ?? '').split(delimiter), '/opt/homebrew/bin', '/usr/local/bin'].filter(Boolean);
|
|
14
|
+
const candidates = [process.env.FFMPEG_BIN, ffmpegStatic, ...dirs.map((d) => join(d, 'ffmpeg'))];
|
|
15
|
+
found = candidates.find((p) => p && runnable(p));
|
|
16
|
+
if (!found) throw Error([
|
|
17
|
+
'FFmpeg not found. Framepress needs it to encode video. Any one of these fixes it:',
|
|
18
|
+
' npm install -g framepress --allow-scripts=ffmpeg-static (npm 11 skips the FFmpeg download without it)',
|
|
19
|
+
' brew install ffmpeg (or put any ffmpeg on PATH)',
|
|
20
|
+
' export FFMPEG_BIN=/path/to/ffmpeg',
|
|
21
|
+
].join('\n'));
|
|
22
|
+
return found;
|
|
23
|
+
}
|