@tmhs/screencast-mcp 0.10.0 → 0.28.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 +56 -11
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -1
- package/dist/prompts.d.ts +10 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +72 -0
- package/dist/prompts.js.map +1 -0
- package/dist/resources.d.ts +3 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +71 -0
- package/dist/resources.js.map +1 -0
- package/dist/tools/assembleHighlights.d.ts.map +1 -1
- package/dist/tools/assembleHighlights.js +4 -3
- package/dist/tools/assembleHighlights.js.map +1 -1
- package/dist/tools/burnSubtitles.d.ts +3 -0
- package/dist/tools/burnSubtitles.d.ts.map +1 -0
- package/dist/tools/burnSubtitles.js +48 -0
- package/dist/tools/burnSubtitles.js.map +1 -0
- package/dist/tools/callout.d.ts +3 -0
- package/dist/tools/callout.d.ts.map +1 -0
- package/dist/tools/callout.js +106 -0
- package/dist/tools/callout.js.map +1 -0
- package/dist/tools/clip.d.ts.map +1 -1
- package/dist/tools/clip.js +4 -3
- package/dist/tools/clip.js.map +1 -1
- package/dist/tools/compress.d.ts.map +1 -1
- package/dist/tools/compress.js +4 -3
- package/dist/tools/compress.js.map +1 -1
- package/dist/tools/concat.d.ts.map +1 -1
- package/dist/tools/concat.js +6 -3
- package/dist/tools/concat.js.map +1 -1
- package/dist/tools/contactSheet.d.ts +3 -0
- package/dist/tools/contactSheet.d.ts.map +1 -0
- package/dist/tools/contactSheet.js +128 -0
- package/dist/tools/contactSheet.js.map +1 -0
- package/dist/tools/convert.d.ts.map +1 -1
- package/dist/tools/convert.js +4 -3
- package/dist/tools/convert.js.map +1 -1
- package/dist/tools/crop.d.ts.map +1 -1
- package/dist/tools/crop.js +5 -4
- package/dist/tools/crop.js.map +1 -1
- package/dist/tools/cutIdle.d.ts +3 -0
- package/dist/tools/cutIdle.d.ts.map +1 -0
- package/dist/tools/cutIdle.js +77 -0
- package/dist/tools/cutIdle.js.map +1 -0
- package/dist/tools/denoise.d.ts +3 -0
- package/dist/tools/denoise.d.ts.map +1 -0
- package/dist/tools/denoise.js +53 -0
- package/dist/tools/denoise.js.map +1 -0
- package/dist/tools/exportGif.d.ts +3 -0
- package/dist/tools/exportGif.d.ts.map +1 -0
- package/dist/tools/exportGif.js +100 -0
- package/dist/tools/exportGif.js.map +1 -0
- package/dist/tools/exportPreset.d.ts.map +1 -1
- package/dist/tools/exportPreset.js +4 -3
- package/dist/tools/exportPreset.js.map +1 -1
- package/dist/tools/extractAudio.d.ts.map +1 -1
- package/dist/tools/extractAudio.js +4 -3
- package/dist/tools/extractAudio.js.map +1 -1
- package/dist/tools/findText.d.ts +3 -0
- package/dist/tools/findText.d.ts.map +1 -0
- package/dist/tools/findText.js +120 -0
- package/dist/tools/findText.js.map +1 -0
- package/dist/tools/musicBed.d.ts.map +1 -1
- package/dist/tools/musicBed.js +4 -3
- package/dist/tools/musicBed.js.map +1 -1
- package/dist/tools/normalizeAudio.d.ts +3 -0
- package/dist/tools/normalizeAudio.d.ts.map +1 -0
- package/dist/tools/normalizeAudio.js +55 -0
- package/dist/tools/normalizeAudio.js.map +1 -0
- package/dist/tools/overlay.d.ts.map +1 -1
- package/dist/tools/overlay.js +4 -3
- package/dist/tools/overlay.js.map +1 -1
- package/dist/tools/readEvents.d.ts +6 -0
- package/dist/tools/readEvents.d.ts.map +1 -0
- package/dist/tools/readEvents.js +79 -0
- package/dist/tools/readEvents.js.map +1 -0
- package/dist/tools/redactRegion.d.ts.map +1 -1
- package/dist/tools/redactRegion.js +5 -4
- package/dist/tools/redactRegion.js.map +1 -1
- package/dist/tools/reframe.d.ts.map +1 -1
- package/dist/tools/reframe.js +4 -3
- package/dist/tools/reframe.js.map +1 -1
- package/dist/tools/sampleFrames.d.ts.map +1 -1
- package/dist/tools/sampleFrames.js +125 -12
- package/dist/tools/sampleFrames.js.map +1 -1
- package/dist/tools/scale.d.ts.map +1 -1
- package/dist/tools/scale.js +4 -3
- package/dist/tools/scale.js.map +1 -1
- package/dist/tools/screenDiff.d.ts +3 -0
- package/dist/tools/screenDiff.d.ts.map +1 -0
- package/dist/tools/screenDiff.js +72 -0
- package/dist/tools/screenDiff.js.map +1 -0
- package/dist/tools/screenshot.d.ts.map +1 -1
- package/dist/tools/screenshot.js +39 -7
- package/dist/tools/screenshot.js.map +1 -1
- package/dist/tools/speed.d.ts.map +1 -1
- package/dist/tools/speed.js +5 -4
- package/dist/tools/speed.js.map +1 -1
- package/dist/tools/startRecording.d.ts.map +1 -1
- package/dist/tools/startRecording.js +65 -3
- package/dist/tools/startRecording.js.map +1 -1
- package/dist/tools/stopRecording.d.ts.map +1 -1
- package/dist/tools/stopRecording.js +3 -0
- package/dist/tools/stopRecording.js.map +1 -1
- package/dist/tools/titleCard.d.ts.map +1 -1
- package/dist/tools/titleCard.js +5 -4
- package/dist/tools/titleCard.js.map +1 -1
- package/dist/tools/transcribe.d.ts +3 -0
- package/dist/tools/transcribe.d.ts.map +1 -0
- package/dist/tools/transcribe.js +59 -0
- package/dist/tools/transcribe.js.map +1 -0
- package/dist/tools/trim.d.ts.map +1 -1
- package/dist/tools/trim.js +8 -3
- package/dist/tools/trim.js.map +1 -1
- package/dist/tools/waitForChange.d.ts +3 -0
- package/dist/tools/waitForChange.d.ts.map +1 -0
- package/dist/tools/waitForChange.js +127 -0
- package/dist/tools/waitForChange.js.map +1 -0
- package/dist/tools/xfadeTransition.d.ts.map +1 -1
- package/dist/tools/xfadeTransition.js +4 -3
- package/dist/tools/xfadeTransition.js.map +1 -1
- package/dist/tools/zoom.d.ts +3 -0
- package/dist/tools/zoom.d.ts.map +1 -0
- package/dist/tools/zoom.js +94 -0
- package/dist/tools/zoom.js.map +1 -0
- package/dist/utils/anim.d.ts +33 -0
- package/dist/utils/anim.d.ts.map +1 -0
- package/dist/utils/anim.js +74 -0
- package/dist/utils/anim.js.map +1 -0
- package/dist/utils/audio.d.ts +49 -0
- package/dist/utils/audio.d.ts.map +1 -0
- package/dist/utils/audio.js +128 -0
- package/dist/utils/audio.js.map +1 -0
- package/dist/utils/callout.d.ts +63 -0
- package/dist/utils/callout.d.ts.map +1 -0
- package/dist/utils/callout.js +95 -0
- package/dist/utils/callout.js.map +1 -0
- package/dist/utils/captions.d.ts +26 -0
- package/dist/utils/captions.d.ts.map +1 -0
- package/dist/utils/captions.js +105 -0
- package/dist/utils/captions.js.map +1 -0
- package/dist/utils/diff.d.ts +66 -0
- package/dist/utils/diff.d.ts.map +1 -0
- package/dist/utils/diff.js +176 -0
- package/dist/utils/diff.js.map +1 -0
- package/dist/utils/errors.d.ts +17 -9
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +7 -6
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/events.d.ts +109 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +289 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/ffmpeg.d.ts +14 -1
- package/dist/utils/ffmpeg.d.ts.map +1 -1
- package/dist/utils/ffmpeg.js +105 -5
- package/dist/utils/ffmpeg.js.map +1 -1
- package/dist/utils/idle.d.ts +23 -0
- package/dist/utils/idle.d.ts.map +1 -0
- package/dist/utils/idle.js +96 -0
- package/dist/utils/idle.js.map +1 -0
- package/dist/utils/images.d.ts +21 -0
- package/dist/utils/images.d.ts.map +1 -0
- package/dist/utils/images.js +55 -0
- package/dist/utils/images.js.map +1 -0
- package/dist/utils/jobs.d.ts +44 -0
- package/dist/utils/jobs.d.ts.map +1 -0
- package/dist/utils/jobs.js +135 -0
- package/dist/utils/jobs.js.map +1 -0
- package/dist/utils/lifecycle.d.ts.map +1 -1
- package/dist/utils/lifecycle.js +3 -0
- package/dist/utils/lifecycle.js.map +1 -1
- package/dist/utils/media.d.ts +35 -2
- package/dist/utils/media.d.ts.map +1 -1
- package/dist/utils/media.js +75 -3
- package/dist/utils/media.js.map +1 -1
- package/dist/utils/monitors.d.ts +18 -2
- package/dist/utils/monitors.d.ts.map +1 -1
- package/dist/utils/monitors.js +50 -12
- package/dist/utils/monitors.js.map +1 -1
- package/dist/utils/ocr.d.ts +44 -0
- package/dist/utils/ocr.d.ts.map +1 -0
- package/dist/utils/ocr.js +215 -0
- package/dist/utils/ocr.js.map +1 -0
- package/dist/utils/produce.d.ts +1 -0
- package/dist/utils/produce.d.ts.map +1 -1
- package/dist/utils/produce.js +3 -2
- package/dist/utils/produce.js.map +1 -1
- package/dist/utils/resolveTarget.d.ts +5 -1
- package/dist/utils/resolveTarget.d.ts.map +1 -1
- package/dist/utils/resolveTarget.js +4 -4
- package/dist/utils/resolveTarget.js.map +1 -1
- package/dist/utils/sessions.d.ts +33 -0
- package/dist/utils/sessions.d.ts.map +1 -1
- package/dist/utils/sessions.js +154 -15
- package/dist/utils/sessions.js.map +1 -1
- package/dist/utils/sheet.d.ts +26 -0
- package/dist/utils/sheet.d.ts.map +1 -0
- package/dist/utils/sheet.js +77 -0
- package/dist/utils/sheet.js.map +1 -0
- package/dist/utils/still.d.ts +4 -0
- package/dist/utils/still.d.ts.map +1 -0
- package/dist/utils/still.js +28 -0
- package/dist/utils/still.js.map +1 -0
- package/dist/utils/targets.d.ts +17 -0
- package/dist/utils/targets.d.ts.map +1 -1
- package/dist/utils/targets.js +35 -1
- package/dist/utils/targets.js.map +1 -1
- package/dist/utils/windows.d.ts +25 -6
- package/dist/utils/windows.d.ts.map +1 -1
- package/dist/utils/windows.js +59 -20
- package/dist/utils/windows.js.map +1 -1
- package/dist/utils/zoom.d.ts +60 -0
- package/dist/utils/zoom.d.ts.map +1 -0
- package/dist/utils/zoom.js +167 -0
- package/dist/utils/zoom.js.map +1 -0
- package/package.json +6 -5
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Quality } from "./targets.js";
|
|
2
|
+
interface Timed {
|
|
3
|
+
/** Show from this second (default: start of video). */
|
|
4
|
+
from?: number;
|
|
5
|
+
/** Hide after this second (default: end of video). */
|
|
6
|
+
to?: number;
|
|
7
|
+
color?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface BoxCallout extends Timed {
|
|
10
|
+
type: "box";
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
/** Outline thickness in px (default 4); ignored when fill is set. */
|
|
16
|
+
thickness?: number;
|
|
17
|
+
/** Fill the box instead of outlining it. */
|
|
18
|
+
fill?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface TextCallout extends Timed {
|
|
21
|
+
type: "text";
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
text: string;
|
|
25
|
+
/** Font size in px (default 32). */
|
|
26
|
+
size?: number;
|
|
27
|
+
/** Draw a translucent dark panel behind the text (default true). */
|
|
28
|
+
background?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface ArrowCallout extends Timed {
|
|
31
|
+
type: "arrow";
|
|
32
|
+
/** Tail. */
|
|
33
|
+
x1: number;
|
|
34
|
+
y1: number;
|
|
35
|
+
/** Head (the point the arrow points at). */
|
|
36
|
+
x2: number;
|
|
37
|
+
y2: number;
|
|
38
|
+
/** Shaft thickness in px (default 8). */
|
|
39
|
+
thickness?: number;
|
|
40
|
+
}
|
|
41
|
+
export type Callout = BoxCallout | TextCallout | ArrowCallout;
|
|
42
|
+
/** Geometry of an arrow image: its length, thickness, rotation (radians,
|
|
43
|
+
* clockwise in screen coordinates), and centre. Pure. */
|
|
44
|
+
export declare function arrowGeometry(a: ArrowCallout): {
|
|
45
|
+
length: number;
|
|
46
|
+
thickness: number;
|
|
47
|
+
angle: number;
|
|
48
|
+
cx: number;
|
|
49
|
+
cy: number;
|
|
50
|
+
};
|
|
51
|
+
/** Render one arrow, already rotated, as a transparent PNG. Pure args. */
|
|
52
|
+
export declare function buildArrowImageArgs(a: ArrowCallout, output: string): string[];
|
|
53
|
+
export interface CalloutAssets {
|
|
54
|
+
fontFile: string;
|
|
55
|
+
/** Per item: the text file for a text callout, else null. */
|
|
56
|
+
textFiles: Array<string | null>;
|
|
57
|
+
/** Per item: the rendered arrow PNG for an arrow callout, else null. */
|
|
58
|
+
arrowFiles: Array<string | null>;
|
|
59
|
+
}
|
|
60
|
+
/** Draw every callout in order (later items on top). Pure. */
|
|
61
|
+
export declare function buildCalloutArgs(input: string, output: string, items: Callout[], assets: CalloutAssets, quality?: Quality): string[];
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=callout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callout.d.ts","sourceRoot":"","sources":["../../src/utils/callout.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5D,UAAU,KAAK;IACb,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,UAAW,SAAQ,KAAK;IACvC,IAAI,EAAE,KAAK,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AACD,MAAM,WAAW,WAAY,SAAQ,KAAK;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AACD,MAAM,WAAW,YAAa,SAAQ,KAAK;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,YAAY;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC;AAY9D;yDACyD;AACzD,wBAAgB,aAAa,CAAC,CAAC,EAAE,YAAY,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAO3H;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAe7E;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAChC,wEAAwE;IACxE,UAAU,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAClC;AAED,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EAAE,EAChB,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,OAAoB,GAC5B,MAAM,EAAE,CA0CV"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timed annotations (#121): boxes, text labels, and arrows that appear over a
|
|
3
|
+
* video between two timestamps. Boxes and text are drawbox / drawtext with an
|
|
4
|
+
* `enable` window. ffmpeg cannot draw an arbitrary line, so an arrow is drawn
|
|
5
|
+
* as an image (a shaft plus a triangular head, via geq), rotated to its angle,
|
|
6
|
+
* and overlaid centred on the arrow's midpoint. Builders are pure.
|
|
7
|
+
*/
|
|
8
|
+
import { ScreencastError } from "./errors.js";
|
|
9
|
+
import { escapeFilterPath } from "./fonts.js";
|
|
10
|
+
import { enableExpr } from "./media.js";
|
|
11
|
+
import { resolveQuality } from "./targets.js";
|
|
12
|
+
import { validateColor } from "./validate.js";
|
|
13
|
+
const nonNeg = (v, label) => {
|
|
14
|
+
if (!Number.isFinite(v) || v < 0)
|
|
15
|
+
throw new ScreencastError(`${label} must be a non-negative number.`);
|
|
16
|
+
return Math.round(v);
|
|
17
|
+
};
|
|
18
|
+
function enable(c) {
|
|
19
|
+
const e = enableExpr(c.from, c.to);
|
|
20
|
+
return e ? `:enable='${e}'` : "";
|
|
21
|
+
}
|
|
22
|
+
/** Geometry of an arrow image: its length, thickness, rotation (radians,
|
|
23
|
+
* clockwise in screen coordinates), and centre. Pure. */
|
|
24
|
+
export function arrowGeometry(a) {
|
|
25
|
+
const dx = a.x2 - a.x1;
|
|
26
|
+
const dy = a.y2 - a.y1;
|
|
27
|
+
const length = Math.round(Math.hypot(dx, dy));
|
|
28
|
+
const thickness = Math.max(2, Math.round(a.thickness ?? 8));
|
|
29
|
+
if (length < thickness * 3)
|
|
30
|
+
throw new ScreencastError("An arrow must be at least three times as long as it is thick.");
|
|
31
|
+
return { length, thickness, angle: Math.atan2(dy, dx), cx: (a.x1 + a.x2) / 2, cy: (a.y1 + a.y2) / 2 };
|
|
32
|
+
}
|
|
33
|
+
/** Render one arrow, already rotated, as a transparent PNG. Pure args. */
|
|
34
|
+
export function buildArrowImageArgs(a, output) {
|
|
35
|
+
const { length, thickness, angle } = arrowGeometry(a);
|
|
36
|
+
const color = validateColor(a.color ?? "red");
|
|
37
|
+
const head = thickness * 3;
|
|
38
|
+
const ang = angle.toFixed(6);
|
|
39
|
+
// Opaque where: the shaft (|y - mid| < t/2 before the head), or inside the
|
|
40
|
+
// triangular head (|y - mid| < remaining length / 2).
|
|
41
|
+
const alpha = `if(lt(X,W-H),if(lt(abs(Y-H/2),${thickness}/2),255,0),if(lt(abs(Y-H/2),(W-X)/2),255,0))`;
|
|
42
|
+
return [
|
|
43
|
+
"-y", "-v", "error",
|
|
44
|
+
"-f", "lavfi", "-i", `color=c=${color}:s=${length}x${head}`,
|
|
45
|
+
"-vf", `format=rgba,geq=r='r(X,Y)':g='g(X,Y)':b='b(X,Y)':a='${alpha}',rotate=a=${ang}:ow=rotw(${ang}):oh=roth(${ang}):c=none`,
|
|
46
|
+
"-frames:v", "1",
|
|
47
|
+
output,
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
/** Draw every callout in order (later items on top). Pure. */
|
|
51
|
+
export function buildCalloutArgs(input, output, items, assets, quality = "standard") {
|
|
52
|
+
if (items.length === 0)
|
|
53
|
+
throw new ScreencastError("Give at least one callout.");
|
|
54
|
+
const extraInputs = [];
|
|
55
|
+
const steps = [];
|
|
56
|
+
let cur = "[0:v]";
|
|
57
|
+
items.forEach((c, i) => {
|
|
58
|
+
const out = `[c${i}]`;
|
|
59
|
+
if (c.type === "box") {
|
|
60
|
+
const color = validateColor(c.color ?? "red");
|
|
61
|
+
const t = c.fill ? "fill" : String(Math.max(1, Math.round(c.thickness ?? 4)));
|
|
62
|
+
steps.push(`${cur}drawbox=x=${nonNeg(c.x, "x")}:y=${nonNeg(c.y, "y")}:w=${nonNeg(c.width, "width")}:h=${nonNeg(c.height, "height")}` +
|
|
63
|
+
`:color=${color}:t=${t}${enable(c)}${out}`);
|
|
64
|
+
}
|
|
65
|
+
else if (c.type === "text") {
|
|
66
|
+
const file = assets.textFiles[i];
|
|
67
|
+
if (!file)
|
|
68
|
+
throw new ScreencastError("Internal: missing text file for a text callout.");
|
|
69
|
+
const color = validateColor(c.color ?? "white");
|
|
70
|
+
const size = Math.max(8, Math.round(c.size ?? 32));
|
|
71
|
+
const panel = c.background === false ? "" : `:box=1:boxcolor=black@0.6:boxborderw=${Math.round(size / 3)}`;
|
|
72
|
+
steps.push(`${cur}drawtext=fontfile=${escapeFilterPath(assets.fontFile)}:textfile=${escapeFilterPath(file)}:expansion=none` +
|
|
73
|
+
`:x=${nonNeg(c.x, "x")}:y=${nonNeg(c.y, "y")}:fontsize=${size}:fontcolor=${color}${panel}${enable(c)}${out}`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const file = assets.arrowFiles[i];
|
|
77
|
+
if (!file)
|
|
78
|
+
throw new ScreencastError("Internal: missing image for an arrow callout.");
|
|
79
|
+
const { cx, cy } = arrowGeometry(c);
|
|
80
|
+
const n = 1 + extraInputs.length / 4;
|
|
81
|
+
extraInputs.push("-loop", "1", "-i", file);
|
|
82
|
+
steps.push(`${cur}[${n}:v]overlay=x=${cx.toFixed(1)}-w/2:y=${cy.toFixed(1)}-h/2:shortest=1${enable(c)}${out}`);
|
|
83
|
+
}
|
|
84
|
+
cur = out;
|
|
85
|
+
});
|
|
86
|
+
return [
|
|
87
|
+
"-y", "-i", input, ...extraInputs,
|
|
88
|
+
"-filter_complex", steps.join(";"),
|
|
89
|
+
"-map", cur, "-map", "0:a?",
|
|
90
|
+
...resolveQuality(quality),
|
|
91
|
+
"-c:a", "copy",
|
|
92
|
+
output,
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=callout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callout.js","sourceRoot":"","sources":["../../src/utils/callout.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,cAAc,EAAgB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AA2C9C,MAAM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AC,OAAO,CAAC;QAC1B,MAAM,EAAE,MAAM;QACd,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Quality } from "./targets.js";
|
|
2
|
+
/** Env var naming the default whisper.cpp model file. */
|
|
3
|
+
export declare const WHISPER_MODEL_ENV = "SCREENCAST_WHISPER_MODEL";
|
|
4
|
+
/** The model to use: the argument, else the env var. It must exist. */
|
|
5
|
+
export declare function resolveWhisperModel(arg: string | undefined, env?: NodeJS.ProcessEnv): string;
|
|
6
|
+
/** Transcribe the input's audio to an SRT file (whisper wants 16 kHz). */
|
|
7
|
+
export declare function buildTranscribeArgs(input: string, model: string, srtOut: string, language?: string): string[];
|
|
8
|
+
export interface Cue {
|
|
9
|
+
start: number;
|
|
10
|
+
end: number;
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
/** Parse SRT into cues (tolerant of CRLF, 0-based numbering, blank lines). */
|
|
14
|
+
export declare function parseSrt(srt: string): Cue[];
|
|
15
|
+
/** Renumber from 1, sort by start, and end each cue no later than the next
|
|
16
|
+
* one starts, so cues never overlap. Pure. */
|
|
17
|
+
export declare function normalizeCues(cues: Cue[]): Cue[];
|
|
18
|
+
export declare function formatSrt(cues: Cue[]): string;
|
|
19
|
+
export type CaptionStyle = "clean" | "social";
|
|
20
|
+
/** libass force_style overrides. SRT is laid out on a 288 px-tall canvas, so
|
|
21
|
+
* sizes are relative to that: "clean" is a modest outlined line at the bottom;
|
|
22
|
+
* "social" is large, bold, on a dark box, raised clear of app UI. */
|
|
23
|
+
export declare const CAPTION_STYLES: Record<CaptionStyle, string>;
|
|
24
|
+
/** Burn an SRT/ASS file into the video with the bundled font. */
|
|
25
|
+
export declare function buildBurnSubtitlesArgs(input: string, subtitles: string, output: string, fontsDir: string, style?: CaptionStyle, quality?: Quality): string[];
|
|
26
|
+
//# sourceMappingURL=captions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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(#120): transcribe speech to SRT with FFmpeg 8's built-in whisper
|
|
3
|
+
* filter (whisper.cpp, runs locally), and burn subtitles into a video.
|
|
4
|
+
*
|
|
5
|
+
* Whisper's SRT needs tidying: it numbers cues from 0 and lets consecutive
|
|
6
|
+
* cues overlap (one starting before the previous ends), which some players
|
|
7
|
+
* render as two stacked lines. normalizeSrt fixes both. Builders and the SRT
|
|
8
|
+
* handling are pure.
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
import { ScreencastError } from "./errors.js";
|
|
12
|
+
import { escapeFilterPath } from "./fonts.js";
|
|
13
|
+
import { resolveQuality } from "./targets.js";
|
|
14
|
+
/** Env var naming the default whisper.cpp model file. */
|
|
15
|
+
export const WHISPER_MODEL_ENV = "SCREENCAST_WHISPER_MODEL";
|
|
16
|
+
const MODEL_HINT = `Download a whisper.cpp model (ggml-base.en.bin is a good start; ggml-tiny.en.bin is fastest) from ` +
|
|
17
|
+
`https://huggingface.co/ggerganov/whisper.cpp and pass its path as model, or set ${WHISPER_MODEL_ENV}.`;
|
|
18
|
+
/** The model to use: the argument, else the env var. It must exist. */
|
|
19
|
+
export function resolveWhisperModel(arg, env = process.env) {
|
|
20
|
+
const model = arg ?? env[WHISPER_MODEL_ENV];
|
|
21
|
+
if (!model || model.trim().length === 0) {
|
|
22
|
+
throw new ScreencastError("No whisper model given.", MODEL_HINT);
|
|
23
|
+
}
|
|
24
|
+
if (!existsSync(model))
|
|
25
|
+
throw new ScreencastError(`Whisper model not found: ${model}`, MODEL_HINT);
|
|
26
|
+
return model;
|
|
27
|
+
}
|
|
28
|
+
/** Transcribe the input's audio to an SRT file (whisper wants 16 kHz). */
|
|
29
|
+
export function buildTranscribeArgs(input, model, srtOut, language = "auto") {
|
|
30
|
+
if (!/^[a-z]{2,3}$|^auto$/.test(language)) {
|
|
31
|
+
throw new ScreencastError(`language must be a code like "en" or "auto", got "${language}".`);
|
|
32
|
+
}
|
|
33
|
+
return [
|
|
34
|
+
"-y", "-v", "error", "-i", input, "-vn",
|
|
35
|
+
"-af",
|
|
36
|
+
`aresample=16000,whisper=model=${escapeFilterPath(model)}:language=${language}:format=srt:` +
|
|
37
|
+
`destination=${escapeFilterPath(srtOut)}:use_gpu=false`,
|
|
38
|
+
"-f", "null", "-",
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
const TIME = /(\d+):(\d{2}):(\d{2})[,.](\d{3})/;
|
|
42
|
+
const toSec = (m) => Number(m[1]) * 3600 + Number(m[2]) * 60 + Number(m[3]) + Number(m[4]) / 1000;
|
|
43
|
+
function fmt(sec) {
|
|
44
|
+
const ms = Math.round(sec * 1000);
|
|
45
|
+
const h = Math.floor(ms / 3_600_000);
|
|
46
|
+
const m = Math.floor((ms % 3_600_000) / 60_000);
|
|
47
|
+
const s = Math.floor((ms % 60_000) / 1000);
|
|
48
|
+
const pad = (n, w = 2) => String(n).padStart(w, "0");
|
|
49
|
+
return `${pad(h)}:${pad(m)}:${pad(s)},${pad(ms % 1000, 3)}`;
|
|
50
|
+
}
|
|
51
|
+
/** Parse SRT into cues (tolerant of CRLF, 0-based numbering, blank lines). */
|
|
52
|
+
export function parseSrt(srt) {
|
|
53
|
+
const cues = [];
|
|
54
|
+
for (const block of srt.replace(/\r\n/g, "\n").split(/\n\s*\n/)) {
|
|
55
|
+
const lines = block.split("\n").map((l) => l.trim()).filter((l) => l.length > 0);
|
|
56
|
+
const i = lines.findIndex((l) => l.includes("-->"));
|
|
57
|
+
if (i === -1)
|
|
58
|
+
continue;
|
|
59
|
+
const [a, b] = lines[i].split("-->");
|
|
60
|
+
const sa = a.match(TIME);
|
|
61
|
+
const sb = b?.match(TIME);
|
|
62
|
+
if (!sa || !sb)
|
|
63
|
+
continue;
|
|
64
|
+
const text = lines.slice(i + 1).join("\n");
|
|
65
|
+
if (text)
|
|
66
|
+
cues.push({ start: toSec(sa), end: toSec(sb), text });
|
|
67
|
+
}
|
|
68
|
+
return cues;
|
|
69
|
+
}
|
|
70
|
+
/** Renumber from 1, sort by start, and end each cue no later than the next
|
|
71
|
+
* one starts, so cues never overlap. Pure. */
|
|
72
|
+
export function normalizeCues(cues) {
|
|
73
|
+
const sorted = [...cues].sort((p, q) => p.start - q.start);
|
|
74
|
+
return sorted
|
|
75
|
+
.map((c, i) => {
|
|
76
|
+
const next = sorted[i + 1];
|
|
77
|
+
const end = next ? Math.min(c.end, next.start) : c.end;
|
|
78
|
+
return { ...c, end };
|
|
79
|
+
})
|
|
80
|
+
.filter((c) => c.end > c.start);
|
|
81
|
+
}
|
|
82
|
+
export function formatSrt(cues) {
|
|
83
|
+
return cues.map((c, i) => `${i + 1}\n${fmt(c.start)} --> ${fmt(c.end)}\n${c.text}\n`).join("\n");
|
|
84
|
+
}
|
|
85
|
+
/** libass force_style overrides. SRT is laid out on a 288 px-tall canvas, so
|
|
86
|
+
* sizes are relative to that: "clean" is a modest outlined line at the bottom;
|
|
87
|
+
* "social" is large, bold, on a dark box, raised clear of app UI. */
|
|
88
|
+
export const CAPTION_STYLES = {
|
|
89
|
+
clean: "FontName=Inter,FontSize=16,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=1.5,Shadow=0,MarginV=16",
|
|
90
|
+
social: "FontName=Inter,Bold=1,FontSize=22,PrimaryColour=&H00FFFFFF,BackColour=&H99000000,BorderStyle=3,Outline=6,Shadow=0,MarginV=40",
|
|
91
|
+
};
|
|
92
|
+
/** Burn an SRT/ASS file into the video with the bundled font. */
|
|
93
|
+
export function buildBurnSubtitlesArgs(input, subtitles, output, fontsDir, style = "clean", quality = "standard") {
|
|
94
|
+
const force = CAPTION_STYLES[style];
|
|
95
|
+
if (!force)
|
|
96
|
+
throw new ScreencastError(`Unknown caption style "${style}".`);
|
|
97
|
+
return [
|
|
98
|
+
"-y", "-i", input,
|
|
99
|
+
"-vf", `subtitles=filename=${escapeFilterPath(subtitles)}:fontsdir=${escapeFilterPath(fontsDir)}:force_style='${force}'`,
|
|
100
|
+
...resolveQuality(quality),
|
|
101
|
+
"-c:a", "copy",
|
|
102
|
+
output,
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=captions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captions.js","sourceRoot":"","sources":["../../src/utils/captions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAgB,MAAM,cAAc,CAAC;AAE5D,yDAAyD;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAE5D,MAAM,UAAU,GACd,oGAAoG;IACpG,mFAAmF,iBAAiB,GAAG,CAAC;AAE1G,uEAAuE;AACvE,MAAM,UAAU,mBAAmB,CAAC,GAAuB,EAAE,MAAyB,OAAO,CAAC,GAAG;IAC/F,MAAM,KAAK,GAAG,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC5C,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,eAAe,CAAC,yBAAyB,EAAE,UAAU,CAAC,CAAC;IACnE,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,eAAe,CAAC,4BAA4B,KAAK,EAAE,EAAE,UAAU,CAAC,CAAC;IACnG,OAAO,KAAK,CAAC;AACf,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CAAC,KAAa,EAAE,KAAa,EAAE,MAAc,EAAE,QAAQ,GAAG,MAAM;IACjG,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,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E,8HAA8H;CACvI,CAAC;AAEF,iEAAiE;AACjE,MAAM,UAAU,sBAAsB,CACpC,KAAa,EACb,SAAiB,EACjB,MAAc,EACd,QAAgB,EAChB,QAAsB,OAAO,EAC7B,UAAmB,UAAU;IAE7B,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,eAAe,CAAC,0BAA0B,KAAK,IAAI,CAAC,CAAC;IAC3E,OAAO;QACL,IAAI,EAAE,IAAI,EAAE,KAAK;QACjB,KAAK,EAAE,sBAAsB,gBAAgB,CAAC,SAAS,CAAC,aAAa,gBAAgB,CAAC,QAAQ,CAAC,iBAAiB,KAAK,GAAG;QACxH,GAAG,cAAc,CAAC,OAAO,CAAC;QAC1B,MAAM,EAAE,MAAM;QACd,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Monitor } from "./monitors.js";
|
|
2
|
+
import { type Target } from "./targets.js";
|
|
3
|
+
/** Width frames are analysed at. */
|
|
4
|
+
export declare const ANALYSIS_WIDTH = 320;
|
|
5
|
+
/** Cell size in analysis pixels. */
|
|
6
|
+
export declare const CELL = 8;
|
|
7
|
+
/** A cell's mean |a - b| (0-255) above this counts as changed. Low enough to
|
|
8
|
+
* catch a text caret or a button highlight, high enough to ignore encoder noise. */
|
|
9
|
+
export declare const DEFAULT_PIXEL_THRESHOLD = 12;
|
|
10
|
+
export interface Rect {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}
|
|
16
|
+
/** Analysis size for a source of `width` x `height`: at most ANALYSIS_WIDTH
|
|
17
|
+
* wide, aspect kept, both sides even and at least 2. */
|
|
18
|
+
export declare function analysisSize(width: number, height: number): {
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
};
|
|
22
|
+
/** Pixel size of a resolved capture target (`full` is the union of monitors). */
|
|
23
|
+
export declare function targetSize(target: Target, monitors: Monitor[]): Rect;
|
|
24
|
+
/** Mean |a - b| over two equal-size grayscale bitmaps, as a 0-1 fraction. */
|
|
25
|
+
export declare function meanDifference(a: Uint8Array, b: Uint8Array): number;
|
|
26
|
+
export interface DiffResult {
|
|
27
|
+
/** Mean absolute difference, 0 (identical) to 1. */
|
|
28
|
+
meanDiff: number;
|
|
29
|
+
/** Share of grid cells that changed, 0-1. */
|
|
30
|
+
changedFraction: number;
|
|
31
|
+
/** Bounding boxes of changed areas, in source pixels (offset by `origin`). */
|
|
32
|
+
regions: Rect[];
|
|
33
|
+
}
|
|
34
|
+
/** Compare two `width` x `height` grayscale bitmaps. `scale` maps analysis
|
|
35
|
+
* pixels to source pixels; `origin` offsets the boxes (e.g. a region's x/y). */
|
|
36
|
+
export declare function diffFrames(a: Uint8Array, b: Uint8Array, width: number, height: number, opts?: {
|
|
37
|
+
scale?: number;
|
|
38
|
+
origin?: {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
};
|
|
42
|
+
pixelThreshold?: number;
|
|
43
|
+
maxRegions?: number;
|
|
44
|
+
}): DiffResult;
|
|
45
|
+
/** Grab args that decode one frame of a still or video file to a raw gray
|
|
46
|
+
* bitmap at the analysis size on stdout. */
|
|
47
|
+
export declare function buildRawFrameArgs(input: string, size: {
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
}): string[];
|
|
51
|
+
/** Grab one live frame of a resolved target as a raw gray bitmap at the
|
|
52
|
+
* analysis size on stdout (gdigrab at 30 fps; see SCREENSHOT_GRAB_FPS). */
|
|
53
|
+
export declare function buildRawGrabArgs(target: Target, monitors: Monitor[], size: {
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
}): string[];
|
|
57
|
+
/** SSIM between two images, both scaled to `size`; score printed to stderr. */
|
|
58
|
+
export declare function buildSsimArgs(a: string, b: string, size: {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
}): string[];
|
|
62
|
+
/** Draw each changed region as a red outline on `input`, for a quick visual. */
|
|
63
|
+
export declare function buildHighlightArgs(input: string, regions: Rect[], output: string): string[];
|
|
64
|
+
/** Parse the `All:` score from ffmpeg's ssim filter output, or null. */
|
|
65
|
+
export declare function parseSsim(stderr: string): number | null;
|
|
66
|
+
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/utils/diff.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAwC,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAEjF,oCAAoC;AACpC,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,oCAAoC;AACpC,eAAO,MAAM,IAAI,IAAI,CAAC;AACtB;oFACoF;AACpF,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;wDACwD;AACxD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAK7F;AAED,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,CAoBpE;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAKnE;AAED,MAAM,WAAW,UAAU;IACzB,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,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AG,IAAI,CAGvD"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame differencing for screen_diff and wait_for_change (#116).
|
|
3
|
+
*
|
|
4
|
+
* Frames are compared as small grayscale bitmaps (about 320 px wide). The image
|
|
5
|
+
* is split into a grid of cells; a cell counts as changed when its mean
|
|
6
|
+
* absolute difference passes a threshold, and touching changed cells are
|
|
7
|
+
* grouped into bounding boxes mapped back to the source's pixel coordinates.
|
|
8
|
+
* Everything here is pure, so it is unit-tested on synthetic bitmaps.
|
|
9
|
+
*/
|
|
10
|
+
import { ScreencastError } from "./errors.js";
|
|
11
|
+
import { targetInputArgs, SCREENSHOT_GRAB_FPS } from "./targets.js";
|
|
12
|
+
/** Width frames are analysed at. */
|
|
13
|
+
export const ANALYSIS_WIDTH = 320;
|
|
14
|
+
/** Cell size in analysis pixels. */
|
|
15
|
+
export const CELL = 8;
|
|
16
|
+
/** A cell's mean |a - b| (0-255) above this counts as changed. Low enough to
|
|
17
|
+
* catch a text caret or a button highlight, high enough to ignore encoder noise. */
|
|
18
|
+
export const DEFAULT_PIXEL_THRESHOLD = 12;
|
|
19
|
+
/** Analysis size for a source of `width` x `height`: at most ANALYSIS_WIDTH
|
|
20
|
+
* wide, aspect kept, both sides even and at least 2. */
|
|
21
|
+
export function analysisSize(width, height) {
|
|
22
|
+
if (!(width > 0) || !(height > 0))
|
|
23
|
+
throw new ScreencastError("Image has no size.");
|
|
24
|
+
const w = Math.min(ANALYSIS_WIDTH, width);
|
|
25
|
+
const h = Math.max(2, Math.round((height * w) / width / 2) * 2);
|
|
26
|
+
return { width: Math.max(2, Math.round(w / 2) * 2), height: h };
|
|
27
|
+
}
|
|
28
|
+
/** Pixel size of a resolved capture target (`full` is the union of monitors). */
|
|
29
|
+
export function targetSize(target, monitors) {
|
|
30
|
+
switch (target.kind) {
|
|
31
|
+
case "region":
|
|
32
|
+
return { x: target.x, y: target.y, width: target.w, height: target.h };
|
|
33
|
+
case "monitor": {
|
|
34
|
+
const m = monitors.find((mm) => mm.index === target.index);
|
|
35
|
+
if (!m)
|
|
36
|
+
throw new ScreencastError(`No monitor ${target.index}.`);
|
|
37
|
+
return { x: m.x, y: m.y, width: m.width, height: m.height };
|
|
38
|
+
}
|
|
39
|
+
case "full": {
|
|
40
|
+
if (monitors.length === 0)
|
|
41
|
+
throw new ScreencastError("No monitors found.");
|
|
42
|
+
const left = Math.min(...monitors.map((m) => m.x));
|
|
43
|
+
const top = Math.min(...monitors.map((m) => m.y));
|
|
44
|
+
const right = Math.max(...monitors.map((m) => m.x + m.width));
|
|
45
|
+
const bottom = Math.max(...monitors.map((m) => m.y + m.height));
|
|
46
|
+
return { x: left, y: top, width: right - left, height: bottom - top };
|
|
47
|
+
}
|
|
48
|
+
default:
|
|
49
|
+
throw new ScreencastError("Internal: resolve window targets to a region first.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Mean |a - b| over two equal-size grayscale bitmaps, as a 0-1 fraction. */
|
|
53
|
+
export function meanDifference(a, b) {
|
|
54
|
+
if (a.length !== b.length || a.length === 0)
|
|
55
|
+
throw new ScreencastError("Frames differ in size.");
|
|
56
|
+
let sum = 0;
|
|
57
|
+
for (let i = 0; i < a.length; i++)
|
|
58
|
+
sum += Math.abs(a[i] - b[i]);
|
|
59
|
+
return sum / a.length / 255;
|
|
60
|
+
}
|
|
61
|
+
/** Compare two `width` x `height` grayscale bitmaps. `scale` maps analysis
|
|
62
|
+
* pixels to source pixels; `origin` offsets the boxes (e.g. a region's x/y). */
|
|
63
|
+
export function diffFrames(a, b, width, height, opts = {}) {
|
|
64
|
+
if (a.length !== width * height || b.length !== width * height) {
|
|
65
|
+
throw new ScreencastError("Frame size does not match its dimensions.");
|
|
66
|
+
}
|
|
67
|
+
const threshold = opts.pixelThreshold ?? DEFAULT_PIXEL_THRESHOLD;
|
|
68
|
+
const cols = Math.ceil(width / CELL);
|
|
69
|
+
const rows = Math.ceil(height / CELL);
|
|
70
|
+
const changed = new Uint8Array(cols * rows);
|
|
71
|
+
for (let cy = 0; cy < rows; cy++) {
|
|
72
|
+
for (let cx = 0; cx < cols; cx++) {
|
|
73
|
+
let sum = 0;
|
|
74
|
+
let n = 0;
|
|
75
|
+
for (let y = cy * CELL; y < Math.min(height, (cy + 1) * CELL); y++) {
|
|
76
|
+
for (let x = cx * CELL; x < Math.min(width, (cx + 1) * CELL); x++) {
|
|
77
|
+
const i = y * width + x;
|
|
78
|
+
sum += Math.abs(a[i] - b[i]);
|
|
79
|
+
n++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (sum / n > threshold)
|
|
83
|
+
changed[cy * cols + cx] = 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Group touching changed cells (8-neighbour flood fill) into boxes.
|
|
87
|
+
const seen = new Uint8Array(cols * rows);
|
|
88
|
+
const boxes = [];
|
|
89
|
+
for (let start = 0; start < changed.length; start++) {
|
|
90
|
+
if (!changed[start] || seen[start])
|
|
91
|
+
continue;
|
|
92
|
+
const box = { x0: Infinity, y0: Infinity, x1: -1, y1: -1, cells: 0 };
|
|
93
|
+
const stack = [start];
|
|
94
|
+
seen[start] = 1;
|
|
95
|
+
while (stack.length > 0) {
|
|
96
|
+
const c = stack.pop();
|
|
97
|
+
const cx = c % cols;
|
|
98
|
+
const cy = Math.floor(c / cols);
|
|
99
|
+
box.x0 = Math.min(box.x0, cx);
|
|
100
|
+
box.y0 = Math.min(box.y0, cy);
|
|
101
|
+
box.x1 = Math.max(box.x1, cx);
|
|
102
|
+
box.y1 = Math.max(box.y1, cy);
|
|
103
|
+
box.cells++;
|
|
104
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
105
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
106
|
+
const nx = cx + dx;
|
|
107
|
+
const ny = cy + dy;
|
|
108
|
+
if (nx < 0 || ny < 0 || nx >= cols || ny >= rows)
|
|
109
|
+
continue;
|
|
110
|
+
const nc = ny * cols + nx;
|
|
111
|
+
if (changed[nc] && !seen[nc]) {
|
|
112
|
+
seen[nc] = 1;
|
|
113
|
+
stack.push(nc);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
boxes.push(box);
|
|
119
|
+
}
|
|
120
|
+
const scale = opts.scale ?? 1;
|
|
121
|
+
const ox = opts.origin?.x ?? 0;
|
|
122
|
+
const oy = opts.origin?.y ?? 0;
|
|
123
|
+
const regions = boxes
|
|
124
|
+
.sort((p, q) => q.cells - p.cells)
|
|
125
|
+
.slice(0, opts.maxRegions ?? 20)
|
|
126
|
+
.map((bx) => {
|
|
127
|
+
const x = bx.x0 * CELL;
|
|
128
|
+
const y = bx.y0 * CELL;
|
|
129
|
+
const w = Math.min(width, (bx.x1 + 1) * CELL) - x;
|
|
130
|
+
const h = Math.min(height, (bx.y1 + 1) * CELL) - y;
|
|
131
|
+
return {
|
|
132
|
+
x: ox + Math.round(x * scale),
|
|
133
|
+
y: oy + Math.round(y * scale),
|
|
134
|
+
width: Math.round(w * scale),
|
|
135
|
+
height: Math.round(h * scale),
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const changedCount = changed.reduce((s, v) => s + v, 0);
|
|
139
|
+
return { meanDiff: meanDifference(a, b), changedFraction: changedCount / changed.length, regions };
|
|
140
|
+
}
|
|
141
|
+
/** Grab args that decode one frame of a still or video file to a raw gray
|
|
142
|
+
* bitmap at the analysis size on stdout. */
|
|
143
|
+
export function buildRawFrameArgs(input, size) {
|
|
144
|
+
return [
|
|
145
|
+
"-v", "error", "-i", input, "-frames:v", "1",
|
|
146
|
+
"-vf", `scale=${size.width}:${size.height}:flags=area,format=gray`,
|
|
147
|
+
"-f", "rawvideo", "-",
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
/** Grab one live frame of a resolved target as a raw gray bitmap at the
|
|
151
|
+
* analysis size on stdout (gdigrab at 30 fps; see SCREENSHOT_GRAB_FPS). */
|
|
152
|
+
export function buildRawGrabArgs(target, monitors, size) {
|
|
153
|
+
return [
|
|
154
|
+
"-v", "error", "-f", "gdigrab", "-framerate", String(SCREENSHOT_GRAB_FPS),
|
|
155
|
+
...targetInputArgs(target, monitors),
|
|
156
|
+
"-frames:v", "1",
|
|
157
|
+
"-vf", `scale=${size.width}:${size.height}:flags=area,format=gray`,
|
|
158
|
+
"-f", "rawvideo", "-",
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
/** SSIM between two images, both scaled to `size`; score printed to stderr. */
|
|
162
|
+
export function buildSsimArgs(a, b, size) {
|
|
163
|
+
const s = `scale=${size.width}:${size.height}:flags=area,format=gray`;
|
|
164
|
+
return ["-v", "info", "-i", a, "-i", b, "-lavfi", `[0]${s}[x];[1]${s}[y];[x][y]ssim`, "-frames:v", "1", "-f", "null", "-"];
|
|
165
|
+
}
|
|
166
|
+
/** Draw each changed region as a red outline on `input`, for a quick visual. */
|
|
167
|
+
export function buildHighlightArgs(input, regions, output) {
|
|
168
|
+
const boxes = regions.map((r) => `drawbox=x=${r.x}:y=${r.y}:w=${r.width}:h=${r.height}:color=red@0.9:t=3`);
|
|
169
|
+
return ["-y", "-v", "error", "-i", input, "-frames:v", "1", ...(boxes.length ? ["-vf", boxes.join(",")] : []), output];
|
|
170
|
+
}
|
|
171
|
+
/** Parse the `All:` score from ffmpeg's ssim filter output, or null. */
|
|
172
|
+
export function parseSsim(stderr) {
|
|
173
|
+
const m = stderr.match(/All:([\d.]+)/);
|
|
174
|
+
return m ? Number(m[1]) : null;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=diff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/utils/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAe,MAAM,cAAc,CAAC;AAEjF,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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACjC,CAAC"}
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared error type and MCP response helpers.
|
|
3
3
|
*
|
|
4
|
-
* Every tool returns
|
|
5
|
-
* surfaced as `isError: true` so
|
|
6
|
-
* a transport-level failure.
|
|
4
|
+
* Every tool returns a JSON text block first; tools that produce frames may
|
|
5
|
+
* append image blocks after it (#79). Errors are surfaced as `isError: true` so
|
|
6
|
+
* an agent sees an actionable message instead of a transport-level failure.
|
|
7
7
|
*/
|
|
8
8
|
export declare class ScreencastError extends Error {
|
|
9
9
|
/** Optional remediation hint shown to the caller (e.g. an install command). */
|
|
10
10
|
readonly hint?: string;
|
|
11
11
|
constructor(message: string, hint?: string);
|
|
12
12
|
}
|
|
13
|
+
export interface TextContent {
|
|
14
|
+
type: "text";
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
/** A base64-encoded image block, shown to the model by MCP clients. */
|
|
18
|
+
export interface ImageContent {
|
|
19
|
+
type: "image";
|
|
20
|
+
data: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
}
|
|
13
23
|
export interface ToolResult {
|
|
14
|
-
content: Array<
|
|
15
|
-
type: "text";
|
|
16
|
-
text: string;
|
|
17
|
-
}>;
|
|
24
|
+
content: Array<TextContent | ImageContent>;
|
|
18
25
|
isError?: true;
|
|
19
26
|
[key: string]: unknown;
|
|
20
27
|
}
|
|
21
|
-
/** Wrap a JSON-serializable value as a successful tool result
|
|
22
|
-
|
|
28
|
+
/** Wrap a JSON-serializable value as a successful tool result, optionally
|
|
29
|
+
* followed by image blocks. */
|
|
30
|
+
export declare function okResponse(value: unknown, images?: ImageContent[]): ToolResult;
|
|
23
31
|
/** Wrap any thrown value as an error tool result, appending a hint if present. */
|
|
24
32
|
export declare function errorResponse(error: unknown): ToolResult;
|
|
25
33
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAK3C;AAED,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAK3C;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,KAAK,CAAC,WAAW,GAAG,YAAY,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,IAAI,CAAC;IAGf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;+BAC+B;AAC/B,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,GAAE,YAAY,EAAO,GAAG,UAAU,CAIlF;AAED,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAUxD"}
|