@openvidstudio/capture 0.0.0-stage → 1.4.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the
45
+ purposes of this License, Derivative Works shall not include works
46
+ that remain separable from, or merely link (or bind by name) to the
47
+ interfaces of, the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including the
50
+ original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Anay Dhawan
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,93 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @openvidstudio/capture
2
+
3
+ Getting a true frame out of a running product. No Remotion, no React, no video pipeline.
4
+
5
+ This is the half of [openvidstudio](https://github.com/AnayDhawan/openvidstudio) that is
6
+ hard, and it is useful on its own. If you want reliable captures of your app and you are
7
+ not making a video, take this package and ignore the rest.
8
+
9
+ ## What is in it
10
+
11
+ **Browser capture that measures the zoom instead of assuming it.** Chrome keeps zoom
12
+ per origin, so `setViewportSize(1600x1000)` can leave you with an effective viewport that
13
+ is not 1600x1000, and every crop rect computed against the requested size is then wrong.
14
+ Nothing errors. `detectAndCompensateZoom` measures `window.innerWidth` live, re-requests a
15
+ compensated size, verifies convergence, and throws rather than proceed with a crop measured
16
+ against the wrong viewport. The ratio is never hardcoded: it differs per machine and per
17
+ profile.
18
+
19
+ **Interaction replay.** A small declarative `Interaction[]` (click, fill, select, hover,
20
+ scroll, wait) with a zod schema, replayed in array order, so two capture callers cannot
21
+ drift apart in how they drive the page.
22
+
23
+ **Backends for what a browser cannot reach.** Desktop windows and regions through ffmpeg
24
+ (`gdigrab`, `avfoundation`, `x11grab`, `pipewiregrab`), Android through `adb screenrecord`,
25
+ the iOS Simulator through `simctl io recordVideo`, and terminals through a recorded cast.
26
+ These are pure argv builders plus a thin spawn wrapper, so they are testable without a
27
+ screen attached and safe with argument values containing spaces.
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ npm install @openvidstudio/capture
33
+ npx playwright install chromium # browser capture only
34
+ ```
35
+
36
+ `ffmpeg` on PATH is required for the native backends, `adb` for Android, Xcode command
37
+ line tools for the iOS Simulator.
38
+
39
+ Terminal recording works out of the box through pipes. For a faithful recording, with the
40
+ program's colour and cursor addressing intact, also install `node-pty`:
41
+
42
+ ```bash
43
+ npm install node-pty
44
+ ```
45
+
46
+ It is deliberately not declared as a dependency of any kind here, not even an optional
47
+ peer: package managers install optional peers anyway, and `node-pty` compiles a native
48
+ addon. Requiring everyone to build one in order to record `npm test` is a bad trade. The
49
+ module is loaded at runtime if it is present, and `recordTerminal` reports which mode it
50
+ actually used.
51
+
52
+ ## Use
53
+
54
+ ```ts
55
+ import { launchChromium, detectAndCompensateZoom, replayInteractions } from "@openvidstudio/capture";
56
+
57
+ const browser = await launchChromium();
58
+ const page = await browser.newPage();
59
+ await page.setViewportSize({ width: 1600, height: 1000 });
60
+ await page.goto("http://localhost:3000");
61
+
62
+ const { zoom } = await detectAndCompensateZoom(page, { width: 1600, height: 1000 });
63
+ await replayInteractions(page, [{ type: "click", selector: "[data-tour=start]" }]);
64
+ await page.screenshot({ path: "shot.png" });
65
+ await browser.close();
66
+ ```
67
+
68
+ Save it as `capture.mjs`, start an app on `localhost:3000`, and run it. The click targets
69
+ `[data-tour=start]`, so change that selector to one that exists in your app (a missing
70
+ selector fails after a 30 second timeout). `browser.close()` matters: without it the script
71
+ writes `shot.png` and then never exits, because the open browser keeps Node alive.
72
+
73
+ ```bash
74
+ npx playwright install chromium
75
+ node capture.mjs
76
+ ```
77
+
78
+ ```ts
79
+ import { buildDesktopCaptureArgs } from "@openvidstudio/capture";
80
+
81
+ const args = buildDesktopCaptureArgs({
82
+ platform: "win32",
83
+ window: "My App",
84
+ framerate: 30,
85
+ durationSeconds: 8,
86
+ outPath: "out.mp4",
87
+ });
88
+ // spawn("ffmpeg", args)
89
+ ```
90
+
91
+ ## License
92
+
93
+ Apache-2.0
@@ -0,0 +1,161 @@
1
+ import type { Browser, Page } from "playwright";
2
+ import { chromium } from "playwright";
3
+ import type { CursorPoint } from "./cursor";
4
+ import { z } from "zod";
5
+ /**
6
+ * Shared building blocks for capture_screenshot and capture_screen_recording:
7
+ * the Interaction type both replay identically, and CAPTURE.md's zoom-desync
8
+ * detection/compensation math, extracted once so the two tools' protocols
9
+ * cannot silently drift apart from each other.
10
+ */
11
+ export interface Viewport {
12
+ width: number;
13
+ height: number;
14
+ }
15
+ /** CAPTURE.md's worked example. */
16
+ export declare const DEFAULT_VIEWPORT: Viewport;
17
+ /**
18
+ * Capture at twice the CSS resolution by default.
19
+ *
20
+ * This is the single biggest quality lever in the pipeline and it used to be missing.
21
+ * A capture taken at 1x is exactly as many pixels as the viewport, and the video then
22
+ * puts it on a 1920x1080 stage and pushes a camera into it. Every one of those steps
23
+ * is an upscale, so a 1440x900 capture shown at a 1.33 camera scale is being asked for
24
+ * roughly 1.8x the pixels it has, and the result is the soft, slightly smeared text
25
+ * that makes a demo look cheap.
26
+ *
27
+ * At 2x there are pixels to spare for both the stage and the push-in, so the frame stays
28
+ * sharp all the way through. The cost is memory and file size during capture, which is
29
+ * the right trade for an asset that gets rendered once and watched many times.
30
+ */
31
+ export declare const DEFAULT_DEVICE_SCALE = 2;
32
+ export declare const viewportSchema: z.ZodObject<{
33
+ width: z.ZodNumber;
34
+ height: z.ZodNumber;
35
+ }, z.core.$strip>;
36
+ export type Interaction = {
37
+ type: "click";
38
+ selector: string;
39
+ } | {
40
+ type: "fill";
41
+ selector: string;
42
+ value: string;
43
+ } | {
44
+ type: "select";
45
+ selector: string;
46
+ value: string;
47
+ } | {
48
+ type: "hover";
49
+ selector: string;
50
+ } | {
51
+ type: "scroll";
52
+ selector?: string;
53
+ x?: number;
54
+ y?: number;
55
+ durationMs?: number;
56
+ } | {
57
+ type: "wait";
58
+ ms?: number;
59
+ selector?: string;
60
+ } | {
61
+ type: "settle";
62
+ ms?: number;
63
+ };
64
+ export declare const interactionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
65
+ type: z.ZodLiteral<"click">;
66
+ selector: z.ZodString;
67
+ }, z.core.$strip>, z.ZodObject<{
68
+ type: z.ZodLiteral<"fill">;
69
+ selector: z.ZodString;
70
+ value: z.ZodString;
71
+ }, z.core.$strip>, z.ZodObject<{
72
+ type: z.ZodLiteral<"select">;
73
+ selector: z.ZodString;
74
+ value: z.ZodString;
75
+ }, z.core.$strip>, z.ZodObject<{
76
+ type: z.ZodLiteral<"hover">;
77
+ selector: z.ZodString;
78
+ }, z.core.$strip>, z.ZodObject<{
79
+ type: z.ZodLiteral<"scroll">;
80
+ selector: z.ZodOptional<z.ZodString>;
81
+ x: z.ZodOptional<z.ZodNumber>;
82
+ y: z.ZodOptional<z.ZodNumber>;
83
+ durationMs: z.ZodOptional<z.ZodNumber>;
84
+ }, z.core.$strip>, z.ZodObject<{
85
+ type: z.ZodLiteral<"wait">;
86
+ ms: z.ZodOptional<z.ZodNumber>;
87
+ selector: z.ZodOptional<z.ZodString>;
88
+ }, z.core.$strip>, z.ZodObject<{
89
+ type: z.ZodLiteral<"settle">;
90
+ ms: z.ZodOptional<z.ZodNumber>;
91
+ }, z.core.$strip>], "type">;
92
+ /**
93
+ * Replays a beat's interactions in array order. Shared verbatim by both capture
94
+ * tools so their replay semantics never drift apart -- called after navigation
95
+ * and (for both tools) after the zoom-desync compensation below, in the same
96
+ * effective CSS-pixel viewport CAPTURE.md measured.
97
+ *
98
+ * Returns every click/hover/fill/select target's real measured center, in replay order,
99
+ * for capture_screenshot/capture_screen_recording to persist as a cursor sidecar (see
100
+ * cursor.ts) -- this is what lets scaffold_scene's cursor overlay land on real coordinates
101
+ * instead of a hand-authored guess.
102
+ */
103
+ export declare function replayInteractions(page: Page, interactions: Interaction[] | undefined): Promise<CursorPoint[]>;
104
+ export declare const ZOOM_EPSILON = 0.01;
105
+ export interface ZoomCompensation {
106
+ /** The viewport actually in effect for capture: `target` unchanged, or the compensated size. */
107
+ viewport: Viewport;
108
+ /** Measured zoom = target.width / (effective width before compensation). 1 means no desync. */
109
+ zoom: number;
110
+ /** The last-measured `[window.innerWidth, window.innerHeight]`. */
111
+ effective: Viewport;
112
+ }
113
+ /**
114
+ * Thrown when a single compensation attempt doesn't converge -- CAPTURE.md
115
+ * doesn't explicitly cover this case (it assumes the desync ratio is
116
+ * consistent), so this is surfaced as a real error rather than silently
117
+ * proceeding with a crop rect measured against the wrong effective viewport.
118
+ */
119
+ export declare class ZoomCompensationError extends Error {
120
+ readonly target: Viewport;
121
+ readonly zoom: number;
122
+ readonly effective: Viewport;
123
+ constructor(target: Viewport, zoom: number, effective: Viewport);
124
+ }
125
+ /**
126
+ * CAPTURE.md's zoom-desync detection + compensation (protocol steps 1-2).
127
+ * Assumes the caller already called `page.setViewportSize(target)` and
128
+ * `page.goto(...)` -- this only measures and, if needed, re-requests a
129
+ * compensated viewport and re-verifies once.
130
+ *
131
+ * Never hardcodes a zoom constant (CAPTURE.md is explicit the ratio "can
132
+ * differ per machine/profile") -- it is measured live on every call. If the
133
+ * one compensation attempt doesn't bring the effective viewport back to
134
+ * `target` within `ZOOM_EPSILON`, throws `ZoomCompensationError` rather than
135
+ * silently proceeding.
136
+ */
137
+ export declare function detectAndCompensateZoom(page: Page, target: Viewport): Promise<ZoomCompensation>;
138
+ /**
139
+ * Playwright's bundled browser binary is not installed by a plain `npm
140
+ * install`/`pnpm install` (it needs a separate `npx playwright install
141
+ * chromium`, deliberately not wired as a postinstall script -- see this
142
+ * package's README/tool descriptions). Rather than let that surface as a
143
+ * cryptic native-binary launch error, catch it here and return a clear,
144
+ * actionable message.
145
+ */
146
+ export declare function launchChromium(): Promise<Browser>;
147
+ /**
148
+ * Re-exports the exact `chromium` BrowserType this file already imports from "playwright"
149
+ * above (the one launchChromium calls .launch() on), so preflight.ts's environment check can
150
+ * call chromium.executablePath() on the literal same resolution real capture uses, instead of
151
+ * a second "import playwright" of its own that could resolve a different installed copy
152
+ * (a different node_modules nesting, or a different PLAYWRIGHT_BROWSERS_PATH-relative build)
153
+ * and pass preflight while real capture still fails, or the reverse.
154
+ */
155
+ export { chromium };
156
+ /**
157
+ * The version of the `chromium` BrowserType re-exported above, read from that same resolved
158
+ * package rather than a fresh "playwright" lookup, so a report naming this version can never
159
+ * name a different install than the one executablePath() below actually resolved against.
160
+ */
161
+ export declare function resolvedPlaywrightVersion(): string;