@tmhs/screencast-mcp 0.45.0 → 0.46.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 +21 -8
- package/dist/prompts.js +16 -3
- package/dist/server.js +8 -0
- package/dist/tools/bugReport.js +1 -1
- package/dist/tools/cutByTranscript.js +86 -0
- package/dist/tools/indexRecording.js +173 -0
- package/dist/tools/pipeline.js +200 -19
- package/dist/tools/searchRecording.js +73 -0
- package/dist/tools/stepGuide.js +193 -0
- package/dist/tools/transcribe.js +4 -3
- package/dist/tools/zoom.js +1 -1
- package/dist/utils/audio.js +12 -4
- package/dist/utils/bugReport.js +1 -75
- package/dist/utils/captions.js +19 -6
- package/dist/utils/chapters.js +5 -0
- package/dist/utils/idle.js +10 -3
- package/dist/utils/keystrokes.js +2 -17
- package/dist/utils/pipeline.js +131 -14
- package/dist/utils/recipes.js +67 -0
- package/dist/utils/recordingIndex.js +266 -0
- package/dist/utils/stepGuide.js +205 -0
- package/dist/utils/steps.js +88 -0
- package/dist/utils/timeline.js +85 -0
- package/dist/utils/toolsets.js +10 -4
- package/dist/utils/transcriptCut.js +134 -0
- package/package.json +1 -1
package/dist/utils/audio.js
CHANGED
|
@@ -59,13 +59,18 @@ export function audioCodecFor(output) {
|
|
|
59
59
|
return ["-c:a", "aac", "-b:a", "192k"];
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
export function
|
|
62
|
+
export function loudnormFilter(t, m) {
|
|
63
|
+
if (!m)
|
|
64
|
+
return `loudnorm=${filterTarget(t)}`;
|
|
63
65
|
const measured = `measured_I=${m.input_i}:measured_TP=${m.input_tp}:measured_LRA=${m.input_lra}:` +
|
|
64
66
|
`measured_thresh=${m.input_thresh}:offset=${m.target_offset}`;
|
|
67
|
+
return `loudnorm=${filterTarget(t)}:${measured}:linear=true`;
|
|
68
|
+
}
|
|
69
|
+
export function buildLoudnessApplyArgs(input, output, t, m) {
|
|
65
70
|
return [
|
|
66
71
|
"-y", "-hide_banner", "-i", input,
|
|
67
72
|
...keepVideoArgs(output),
|
|
68
|
-
"-af",
|
|
73
|
+
"-af", `${loudnormFilter(t, m)}:print_format=json`,
|
|
69
74
|
"-ar", "48000",
|
|
70
75
|
...audioCodecFor(output),
|
|
71
76
|
output,
|
|
@@ -91,14 +96,17 @@ export function noiseFloorSetting(floorDb) {
|
|
|
91
96
|
return -50;
|
|
92
97
|
return Math.max(-80, Math.min(-20, Math.round(floorDb + 5)));
|
|
93
98
|
}
|
|
94
|
-
export function
|
|
99
|
+
export function denoiseFilter(strength, noiseFloorDb) {
|
|
95
100
|
const nr = DENOISE_NR[strength];
|
|
96
101
|
if (nr === undefined)
|
|
97
102
|
throw new ScreencastError(`Unknown denoise strength "${strength}".`);
|
|
103
|
+
return `afftdn=nr=${nr}:nf=${noiseFloorSetting(noiseFloorDb)}`;
|
|
104
|
+
}
|
|
105
|
+
export function buildDenoiseArgs(input, output, strength = "medium", noiseFloorDb = null) {
|
|
98
106
|
return [
|
|
99
107
|
"-y", "-i", input,
|
|
100
108
|
...keepVideoArgs(output),
|
|
101
|
-
"-af",
|
|
109
|
+
"-af", denoiseFilter(strength, noiseFloorDb),
|
|
102
110
|
...audioCodecFor(output),
|
|
103
111
|
output,
|
|
104
112
|
];
|
package/dist/utils/bugReport.js
CHANGED
|
@@ -42,81 +42,7 @@ export function clipWindow(durationSec, opts = {}) {
|
|
|
42
42
|
}
|
|
43
43
|
return { start: r3(start), end: r3(end) };
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
const DOUBLE_CLICK_PX = 6;
|
|
47
|
-
const SCROLL_JOIN_SEC = 1;
|
|
48
|
-
const GAP_WHY = {
|
|
49
|
-
input_not_seen: "input went to an elevated window or the lock screen, or the hook was removed",
|
|
50
|
-
helper_stalled: "the event logger paused",
|
|
51
|
-
helper_stopped: "the event logger stopped",
|
|
52
|
-
};
|
|
53
|
-
function clickText(button, double, e) {
|
|
54
|
-
const verb = double ? "double-click" : "click";
|
|
55
|
-
const which = button && button !== "left" ? `${button.charAt(0).toUpperCase()}${button.slice(1)} ${verb}` : `${verb.charAt(0).toUpperCase()}${verb.slice(1)}`;
|
|
56
|
-
return e.inFrame ? `${which} at (${e.x}, ${e.y})` : `${which} outside the recorded area`;
|
|
57
|
-
}
|
|
58
|
-
export function reconstructSteps(events) {
|
|
59
|
-
const steps = [];
|
|
60
|
-
const sorted = [...events].sort((a, b) => a.t - b.t);
|
|
61
|
-
let lastDown = null;
|
|
62
|
-
let scroll = null;
|
|
63
|
-
const scrollText = (axis, notches) => {
|
|
64
|
-
const dir = axis === "vertical" ? (notches >= 0 ? "up" : "down") : notches >= 0 ? "right" : "left";
|
|
65
|
-
const n = Math.abs(notches);
|
|
66
|
-
return `Scroll ${dir} ${n} notch${n === 1 ? "" : "es"}`;
|
|
67
|
-
};
|
|
68
|
-
for (const e of sorted) {
|
|
69
|
-
if (e.type === "move" || e.type === "up")
|
|
70
|
-
continue;
|
|
71
|
-
if (e.type !== "wheel")
|
|
72
|
-
scroll = null;
|
|
73
|
-
if (e.type === "down") {
|
|
74
|
-
const prev = lastDown;
|
|
75
|
-
if (prev &&
|
|
76
|
-
prev.e.button === e.button &&
|
|
77
|
-
e.t - prev.e.t <= DOUBLE_CLICK_SEC &&
|
|
78
|
-
Math.abs(e.x - prev.e.x) <= DOUBLE_CLICK_PX &&
|
|
79
|
-
Math.abs(e.y - prev.e.y) <= DOUBLE_CLICK_PX &&
|
|
80
|
-
prev.step.action === "click" &&
|
|
81
|
-
steps.at(-1) === prev.step) {
|
|
82
|
-
prev.step.action = "double_click";
|
|
83
|
-
prev.step.text = clickText(e.button, true, prev.e);
|
|
84
|
-
lastDown = null;
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
const step = { t: e.t, action: "click", text: clickText(e.button, false, e), x: e.x, y: e.y };
|
|
88
|
-
steps.push(step);
|
|
89
|
-
lastDown = { e, step };
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
lastDown = null;
|
|
93
|
-
if (e.type === "wheel") {
|
|
94
|
-
const axis = e.axis ?? "vertical";
|
|
95
|
-
const delta = e.delta ?? 0;
|
|
96
|
-
if (scroll && scroll.axis === axis && e.t - scroll.last <= SCROLL_JOIN_SEC && Math.sign(delta) === Math.sign(scroll.notches)) {
|
|
97
|
-
scroll.notches += delta;
|
|
98
|
-
scroll.last = e.t;
|
|
99
|
-
scroll.step.text = scrollText(axis, scroll.notches);
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
const step = { t: e.t, action: "scroll", text: scrollText(axis, delta), x: e.x, y: e.y };
|
|
103
|
-
steps.push(step);
|
|
104
|
-
scroll = { step, axis, notches: delta, last: e.t };
|
|
105
|
-
}
|
|
106
|
-
else if (e.type === "key") {
|
|
107
|
-
steps.push({ t: e.t, action: "shortcut", text: `Press ${e.keys ?? "a shortcut"}` });
|
|
108
|
-
}
|
|
109
|
-
else if (e.type === "typing") {
|
|
110
|
-
const d = e.durationSec ?? 0;
|
|
111
|
-
steps.push({ t: e.t, action: "typing", text: `Type${d > 0 ? ` for ${r3(d)} s` : ""} (keys are not logged)` });
|
|
112
|
-
}
|
|
113
|
-
else if (e.type === "gap") {
|
|
114
|
-
const why = GAP_WHY[e.reason ?? "input_not_seen"];
|
|
115
|
-
steps.push({ t: e.t, action: "gap", text: `Input may be missing for ${r3(e.durationSec ?? 0)} s (${why})` });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return steps;
|
|
119
|
-
}
|
|
45
|
+
export { reconstructSteps } from "./steps.js";
|
|
120
46
|
function mostlyOverlap(a, b) {
|
|
121
47
|
const w = Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x);
|
|
122
48
|
const h = Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y);
|
package/dist/utils/captions.js
CHANGED
|
@@ -14,7 +14,7 @@ export function resolveWhisperModel(arg, env = process.env) {
|
|
|
14
14
|
throw new ScreencastError(`Whisper model not found: ${model}`, MODEL_HINT);
|
|
15
15
|
return model;
|
|
16
16
|
}
|
|
17
|
-
export function buildTranscribeArgs(input, model, srtOut, language = "auto") {
|
|
17
|
+
export function buildTranscribeArgs(input, model, srtOut, language = "auto", words = false) {
|
|
18
18
|
if (!/^[a-z]{2,3}$|^auto$/.test(language)) {
|
|
19
19
|
throw new ScreencastError(`language must be a code like "en" or "auto", got "${language}".`);
|
|
20
20
|
}
|
|
@@ -22,10 +22,21 @@ export function buildTranscribeArgs(input, model, srtOut, language = "auto") {
|
|
|
22
22
|
"-y", "-v", "error", "-i", input, "-vn",
|
|
23
23
|
"-af",
|
|
24
24
|
`aresample=16000,whisper=model=${escapeFilterPath(model)}:language=${language}:format=srt:` +
|
|
25
|
-
`destination=${escapeFilterPath(srtOut)}:use_gpu=false
|
|
25
|
+
`destination=${escapeFilterPath(srtOut)}:use_gpu=false` + (words ? ":max_len=1" : ""),
|
|
26
26
|
"-f", "null", "-",
|
|
27
27
|
];
|
|
28
28
|
}
|
|
29
|
+
export function mergePunctuation(cues) {
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const c of cues) {
|
|
32
|
+
const prev = out[out.length - 1];
|
|
33
|
+
if (prev && !/[\p{L}\p{N}]/u.test(c.text))
|
|
34
|
+
prev.text += c.text.trim();
|
|
35
|
+
else
|
|
36
|
+
out.push({ ...c });
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
29
40
|
const TIME = /(\d+):(\d{2}):(\d{2})[,.](\d{3})/;
|
|
30
41
|
const toSec = (m) => Number(m[1]) * 3600 + Number(m[2]) * 60 + Number(m[3]) + Number(m[4]) / 1000;
|
|
31
42
|
function fmt(sec) {
|
|
@@ -72,15 +83,17 @@ export const CAPTION_STYLES = {
|
|
|
72
83
|
clean: "FontName=Inter,FontSize=16,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,BorderStyle=1,Outline=1.5,Shadow=0,MarginV=16",
|
|
73
84
|
social: "FontName=Inter,Bold=1,FontSize=22,PrimaryColour=&H00FFFFFF,BackColour=&H99000000,BorderStyle=3,Outline=6,Shadow=0,MarginV=40",
|
|
74
85
|
};
|
|
75
|
-
export function
|
|
86
|
+
export function subtitlesFilter(subtitles, fontsDir, style = "clean") {
|
|
76
87
|
const force = style === null ? null : CAPTION_STYLES[style];
|
|
77
88
|
if (force === undefined)
|
|
78
89
|
throw new ScreencastError(`Unknown caption style "${style}".`);
|
|
90
|
+
return (`subtitles=filename=${escapeFilterPath(subtitles)}:fontsdir=${escapeFilterPath(fontsDir)}` +
|
|
91
|
+
(force ? `:force_style='${force}'` : ""));
|
|
92
|
+
}
|
|
93
|
+
export function buildBurnSubtitlesArgs(input, subtitles, output, fontsDir, style = "clean", quality = "standard") {
|
|
79
94
|
return [
|
|
80
95
|
"-y", "-i", input,
|
|
81
|
-
"-vf",
|
|
82
|
-
`subtitles=filename=${escapeFilterPath(subtitles)}:fontsdir=${escapeFilterPath(fontsDir)}` +
|
|
83
|
-
(force ? `:force_style='${force}'` : ""),
|
|
96
|
+
"-vf", subtitlesFilter(subtitles, fontsDir, style),
|
|
84
97
|
...resolveQuality(quality),
|
|
85
98
|
"-c:a", "copy",
|
|
86
99
|
output,
|
package/dist/utils/chapters.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { ScreencastError } from "./errors.js";
|
|
3
3
|
import { requireFfmpeg, runCapture } from "./ffmpeg.js";
|
|
4
|
+
import { cutShift } from "./timeline.js";
|
|
4
5
|
export const MAX_MARKERS = 500;
|
|
5
6
|
export const MAX_LABEL = 200;
|
|
6
7
|
export const YOUTUBE_MIN_CHAPTERS = 3;
|
|
@@ -69,6 +70,10 @@ export function retimeMarkers(markers, ops) {
|
|
|
69
70
|
cur = cur.map((m) => ({ ...m, t: r3(m.t / op.factor) }));
|
|
70
71
|
continue;
|
|
71
72
|
}
|
|
73
|
+
if (op.op === "cut") {
|
|
74
|
+
cur = cur.map((m) => ({ ...m, t: r3(m.t - cutShift(m.t, op.spans)) }));
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
72
77
|
const inside = cur.filter((m) => m.t >= op.start && m.t < op.end).map((m) => ({ ...m, t: r3(m.t - op.start) }));
|
|
73
78
|
const carried = cur.filter((m) => m.t < op.start).at(-1);
|
|
74
79
|
cur = carried && !inside.some((m) => m.t < 0.001) ? [{ ...carried, t: 0 }, ...inside] : inside;
|
package/dist/utils/idle.js
CHANGED
|
@@ -66,17 +66,24 @@ export function cutsFor(idle, minIdleSec, keep) {
|
|
|
66
66
|
.filter((r) => r.end - r.start > 0.05)
|
|
67
67
|
.map((r) => ({ start: Number(r.start.toFixed(3)), end: Number(r.end.toFixed(3)) }));
|
|
68
68
|
}
|
|
69
|
-
export function
|
|
69
|
+
export function cutFilters(cuts) {
|
|
70
70
|
if (cuts.length === 0)
|
|
71
71
|
throw new ScreencastError("Nothing to cut.");
|
|
72
72
|
if (cuts.length > MAX_CUTS)
|
|
73
73
|
throw new ScreencastError(`Too many idle stretches (${cuts.length}); raise minIdleSec.`);
|
|
74
74
|
const drop = sumExpr(cuts.map((c) => `between(t,${c.start},${c.end})`));
|
|
75
75
|
const removed = sumExpr(cuts.map((c) => `clip(T-${c.start},0,${Number((c.end - c.start).toFixed(3))})`));
|
|
76
|
+
return {
|
|
77
|
+
video: `select='not(${drop})',setpts='(T-(${removed}))/TB'`,
|
|
78
|
+
audio: `asetnsamples=n=256:p=0,aselect='not(${drop})',asetpts=N/SR/TB`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function buildCutIdleArgs(input, output, cuts, withAudio, quality = "standard") {
|
|
82
|
+
const f = cutFilters(cuts);
|
|
76
83
|
return [
|
|
77
84
|
"-y", "-i", input,
|
|
78
|
-
"-vf",
|
|
79
|
-
...(withAudio ? ["-af",
|
|
85
|
+
"-vf", f.video,
|
|
86
|
+
...(withAudio ? ["-af", f.audio] : ["-an"]),
|
|
80
87
|
...resolveQuality(quality),
|
|
81
88
|
...(withAudio ? ["-c:a", "aac", "-b:a", "160k"] : []),
|
|
82
89
|
output,
|
package/dist/utils/keystrokes.js
CHANGED
|
@@ -3,6 +3,7 @@ import { escapeFilterPath } from "./fonts.js";
|
|
|
3
3
|
import { sumExpr } from "./expr.js";
|
|
4
4
|
import { resolveQuality } from "./targets.js";
|
|
5
5
|
import { validateColor } from "./validate.js";
|
|
6
|
+
import { mapWindow } from "./timeline.js";
|
|
6
7
|
export const BADGE_POSITIONS = ["bottom", "bottom-left", "bottom-right", "top", "top-left", "top-right"];
|
|
7
8
|
export const DEFAULT_LINGER_SEC = 1.2;
|
|
8
9
|
export const DOUBLE_CLICK_SEC = 0.5;
|
|
@@ -106,23 +107,7 @@ export function mapBadges(badges, map) {
|
|
|
106
107
|
});
|
|
107
108
|
}
|
|
108
109
|
export function retimeBadges(badges, ops) {
|
|
109
|
-
return mapBadges(badges, (from, to) =>
|
|
110
|
-
let a = from;
|
|
111
|
-
let b = to;
|
|
112
|
-
for (const op of ops) {
|
|
113
|
-
if (op.op === "trim") {
|
|
114
|
-
a = Math.max(a, op.start) - op.start;
|
|
115
|
-
b = Math.min(b, op.end) - op.start;
|
|
116
|
-
if (b <= a)
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
a /= op.factor;
|
|
121
|
-
b /= op.factor;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return [a, b];
|
|
125
|
-
});
|
|
110
|
+
return mapBadges(badges, (from, to) => mapWindow(from, to, ops));
|
|
126
111
|
}
|
|
127
112
|
export function badgeSize(frameH, size) {
|
|
128
113
|
if (size !== undefined) {
|
package/dist/utils/pipeline.js
CHANGED
|
@@ -2,12 +2,24 @@ import { ScreencastError } from "./errors.js";
|
|
|
2
2
|
import { atempoChain, cropFilter, redactSteps, scaleFilter, scaledSize } from "./media.js";
|
|
3
3
|
import { calloutSteps } from "./callout.js";
|
|
4
4
|
import { ASPECT_DIMS, exportPresetParts, reframeFilter } from "./produce.js";
|
|
5
|
-
import { keyframesToViews, zoomFilter, DEFAULT_TRANSITION_SEC } from "./zoom.js";
|
|
5
|
+
import { keyframesToViews, planClickZoom, zoomFilter, DEFAULT_TRANSITION_SEC } from "./zoom.js";
|
|
6
6
|
import { resolveQuality } from "./targets.js";
|
|
7
7
|
import { backdropSteps } from "./backdrop.js";
|
|
8
8
|
import { groupBadges, keystrokeSteps, retimeBadges } from "./keystrokes.js";
|
|
9
|
+
import { cutFilters, cutsFor, DEFAULT_KEEP_SEC, DEFAULT_MIN_IDLE_SEC } from "./idle.js";
|
|
10
|
+
import { denoiseFilter, loudnessTarget, loudnormFilter } from "./audio.js";
|
|
11
|
+
import { subtitlesFilter } from "./captions.js";
|
|
12
|
+
import { mapSpans, mapTime } from "./timeline.js";
|
|
9
13
|
export const MAX_PIPELINE_STEPS = 30;
|
|
10
14
|
const r3 = (v) => Math.round(v * 1000) / 1000;
|
|
15
|
+
export function probeArgs(args, p) {
|
|
16
|
+
const out = [...args];
|
|
17
|
+
const af = out.indexOf("-af");
|
|
18
|
+
if (af !== -1 && p.audio.length > 0)
|
|
19
|
+
out[af + 1] = `${p.audio.join(",")},${out[af + 1]}`;
|
|
20
|
+
out.splice(out.indexOf("-i"), 0, ...p.seek);
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
11
23
|
export function planPipeline(input, output, steps, src, assets = {}, quality = "standard", opts = {}) {
|
|
12
24
|
if (steps.length === 0)
|
|
13
25
|
throw new ScreencastError("Give at least one step.");
|
|
@@ -25,6 +37,8 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
25
37
|
"Put redact before zoom, in the source's coordinates.");
|
|
26
38
|
}
|
|
27
39
|
const redacts = steps.some((s) => s.op === "redact");
|
|
40
|
+
if (steps.filter((s) => s.op === "cut_idle").length > 1)
|
|
41
|
+
throw new ScreencastError("Use at most one cut_idle step.");
|
|
28
42
|
let W = src.width;
|
|
29
43
|
let H = src.height;
|
|
30
44
|
let fps = src.fps;
|
|
@@ -40,6 +54,8 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
40
54
|
let gif;
|
|
41
55
|
const summary = [];
|
|
42
56
|
const timeOps = [];
|
|
57
|
+
const pending = [];
|
|
58
|
+
let geo = { sx: 1, sy: 1, ox: 0, oy: 0 };
|
|
43
59
|
const trimRange = (s, at) => {
|
|
44
60
|
if (!Number.isFinite(s.start) || s.start < 0)
|
|
45
61
|
throw new ScreencastError(`step ${at}: trim start must be a non-negative number.`);
|
|
@@ -62,6 +78,7 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
62
78
|
graph.push(`${cur}${filter}${out}`);
|
|
63
79
|
cur = out;
|
|
64
80
|
};
|
|
81
|
+
const pend = (kind) => pending.push({ step: i, kind, seek: [...inputArgs], audio: [...audio], ops: [...timeOps] });
|
|
65
82
|
switch (s.op) {
|
|
66
83
|
case "trim": {
|
|
67
84
|
const { start, end } = trimRange(s, at);
|
|
@@ -81,13 +98,18 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
81
98
|
}
|
|
82
99
|
case "crop":
|
|
83
100
|
chain(cropFilter(s, { width: W, height: H }));
|
|
101
|
+
if (geo)
|
|
102
|
+
geo = { ...geo, ox: geo.ox - s.x, oy: geo.oy - s.y };
|
|
84
103
|
W = s.width;
|
|
85
104
|
H = s.height;
|
|
86
105
|
summary.push(`crop to ${W}x${H}`);
|
|
87
106
|
break;
|
|
88
107
|
case "scale": {
|
|
89
108
|
const f = scaleFilter(s);
|
|
109
|
+
const [w0, h0] = [W, H];
|
|
90
110
|
({ width: W, height: H } = scaledSize(W, H, s));
|
|
111
|
+
if (geo)
|
|
112
|
+
geo = { sx: (geo.sx * W) / w0, sy: (geo.sy * H) / h0, ox: (geo.ox * W) / w0, oy: (geo.oy * H) / h0 };
|
|
91
113
|
chain(f);
|
|
92
114
|
summary.push(`scale to ${W}x${H}`);
|
|
93
115
|
break;
|
|
@@ -127,20 +149,116 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
127
149
|
if (!dim)
|
|
128
150
|
throw new ScreencastError(`step ${at}: unknown aspect "${s.aspect}".`);
|
|
129
151
|
chain(`${reframeFilter(dim.w, dim.h, s.fit ?? "pad")},format=yuv420p`);
|
|
152
|
+
geo = null;
|
|
130
153
|
W = dim.w;
|
|
131
154
|
H = dim.h;
|
|
132
155
|
summary.push(`reframe to ${s.aspect} (${s.fit ?? "pad"})`);
|
|
133
156
|
break;
|
|
134
157
|
}
|
|
135
158
|
case "zoom": {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
159
|
+
const transition = s.transitionSec ?? DEFAULT_TRANSITION_SEC;
|
|
160
|
+
let kfs = s.keyframes;
|
|
161
|
+
let from = "";
|
|
162
|
+
if (s.follow === "clicks") {
|
|
163
|
+
if (kfs)
|
|
164
|
+
throw new ScreencastError(`step ${at}: zoom takes keyframes or follow, not both.`);
|
|
165
|
+
if (!geo) {
|
|
166
|
+
throw new ScreencastError(`step ${at}: zoom follow "clicks" must come before reframe, backdrop or another zoom; the logged click positions no longer match the frame.`);
|
|
167
|
+
}
|
|
168
|
+
const g = geo;
|
|
169
|
+
const logged = opts.clicks?.[i];
|
|
170
|
+
if (!logged)
|
|
171
|
+
throw new ScreencastError(`Internal: missing clicks for step ${at}.`);
|
|
172
|
+
const clicks = logged.flatMap((c) => {
|
|
173
|
+
const t = mapTime(c.t, timeOps);
|
|
174
|
+
const x = c.x * g.sx + g.ox;
|
|
175
|
+
const y = c.y * g.sy + g.oy;
|
|
176
|
+
return t !== null && x >= 0 && x < W && y >= 0 && y < H ? [{ t, x, y }] : [];
|
|
177
|
+
});
|
|
178
|
+
kfs = planClickZoom(clicks, W, H, { holdSec: s.holdSec, maxZoom: s.maxZoom, transition });
|
|
179
|
+
from = ` from ${clicks.length} click(s)`;
|
|
180
|
+
}
|
|
181
|
+
else if (!kfs || kfs.length === 0) {
|
|
182
|
+
throw new ScreencastError(`step ${at}: zoom needs keyframes, or follow: "clicks".`);
|
|
183
|
+
}
|
|
184
|
+
if (kfs.length === 0) {
|
|
185
|
+
summary.push("zoom: no clicks in this part of the video; skipped");
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
chain(zoomFilter(keyframesToViews(kfs, W, H), { width: W, height: H, fps }, transition));
|
|
189
|
+
geo = null;
|
|
190
|
+
summary.push(`zoom ${kfs.length} keyframe(s)${from}`);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case "cut_idle": {
|
|
194
|
+
if (!opts.idle)
|
|
195
|
+
throw new ScreencastError(`Internal: missing idle scan for step ${at}.`);
|
|
196
|
+
const cuts = cutsFor(mapSpans(opts.idle, timeOps), s.minIdleSec ?? DEFAULT_MIN_IDLE_SEC, s.keepSec ?? DEFAULT_KEEP_SEC);
|
|
197
|
+
if (cuts.length === 0) {
|
|
198
|
+
summary.push("cut_idle: no idle stretches here; nothing cut");
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
const f = cutFilters(cuts);
|
|
202
|
+
chain(f.video);
|
|
203
|
+
audio.push(f.audio);
|
|
204
|
+
audioReencode = true;
|
|
205
|
+
const removed = cuts.reduce((sum, c) => sum + (c.end - c.start), 0);
|
|
206
|
+
if (dur !== null)
|
|
207
|
+
dur -= removed;
|
|
208
|
+
timeOps.push({ op: "cut", spans: cuts });
|
|
209
|
+
summary.push(`cut_idle ${cuts.length} stretch(es), ${r3(removed)}s removed`);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case "audio": {
|
|
213
|
+
if (s.normalize === undefined && s.denoise === undefined)
|
|
214
|
+
throw new ScreencastError(`step ${at}: audio needs normalize and/or denoise.`);
|
|
215
|
+
if (!src.hasAudio) {
|
|
216
|
+
summary.push("audio: the input has no audio; skipped");
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
const m = opts.audio?.[i];
|
|
220
|
+
const did = [];
|
|
221
|
+
if (s.denoise !== undefined) {
|
|
222
|
+
if (m?.floorDb === undefined)
|
|
223
|
+
pend("noisefloor");
|
|
224
|
+
audio.push(denoiseFilter(s.denoise, m?.floorDb ?? null));
|
|
225
|
+
did.push(`denoise ${s.denoise}`);
|
|
226
|
+
}
|
|
227
|
+
if (s.normalize !== undefined && m?.silent)
|
|
228
|
+
did.push("silent, not normalized");
|
|
229
|
+
else if (s.normalize !== undefined) {
|
|
230
|
+
const t = loudnessTarget(s.normalize);
|
|
231
|
+
if (!m?.loudness)
|
|
232
|
+
pend("loudness");
|
|
233
|
+
audio.push(loudnormFilter(t, m?.loudness), "aresample=48000");
|
|
234
|
+
did.push(`normalize to ${t.i} LUFS${m?.loudness ? ` (measured ${m.loudness.input_i})` : ""}`);
|
|
235
|
+
}
|
|
236
|
+
audioReencode = true;
|
|
237
|
+
summary.push(`audio: ${did.join(", ")}`);
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case "burn_subtitles": {
|
|
241
|
+
if (!s.subtitles === !s.transcribe)
|
|
242
|
+
throw new ScreencastError(`step ${at}: burn_subtitles takes subtitles (a path) or transcribe: true.`);
|
|
243
|
+
if (s.transcribe && !src.hasAudio)
|
|
244
|
+
throw new ScreencastError(`step ${at}: transcribe needs audio, and the input has none.`);
|
|
245
|
+
const file = opts.subtitles?.[i];
|
|
246
|
+
if (file === "") {
|
|
247
|
+
summary.push("burn_subtitles: no cues in this part of the video; skipped");
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
if (file === undefined)
|
|
251
|
+
pend(s.transcribe ? "transcribe" : "subtitles");
|
|
252
|
+
const ass = !!s.subtitles && /\.(ass|ssa)$/i.test(s.subtitles);
|
|
253
|
+
const style = s.style ?? (ass ? null : "clean");
|
|
254
|
+
chain(subtitlesFilter(file ?? "<subtitles.srt>", opts.fontsDir ?? "<fonts>", style));
|
|
255
|
+
summary.push(`burn_subtitles ${s.transcribe ? "from a transcript" : "from a file"}, ${style ?? "file"} style`);
|
|
139
256
|
break;
|
|
140
257
|
}
|
|
141
258
|
case "backdrop": {
|
|
142
259
|
const { op: _op, ...bo } = s;
|
|
143
260
|
const { steps: st, out: o, extraInputs: ex, layout } = backdropSteps(bo, { width: W, height: H }, cur, nextInput, tag);
|
|
261
|
+
geo = null;
|
|
144
262
|
graph.push(...st);
|
|
145
263
|
extraInputs.push(...ex);
|
|
146
264
|
nextInput += ex.length / 2;
|
|
@@ -167,6 +285,7 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
167
285
|
}
|
|
168
286
|
case "export_preset": {
|
|
169
287
|
const p = exportPresetParts(s.platform, s.fit ?? "pad", tag);
|
|
288
|
+
geo = null;
|
|
170
289
|
chain(p.vf);
|
|
171
290
|
if (p.af)
|
|
172
291
|
audio.push(p.af);
|
|
@@ -190,16 +309,14 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
190
309
|
const chaptersInput = opts.chaptersFile ? args.filter((a) => a === "-i").length : -1;
|
|
191
310
|
if (opts.chaptersFile)
|
|
192
311
|
args.push("-f", "ffmetadata", "-i", opts.chaptersFile);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
args.push("-map", "0:v");
|
|
200
|
-
}
|
|
312
|
+
const audioGraph = src.hasAudio && audio.length > 0;
|
|
313
|
+
if (audioGraph)
|
|
314
|
+
graph.push(`[0:a]${audio.join(",")}[aout]`);
|
|
315
|
+
if (graph.length > 0)
|
|
316
|
+
args.push("-filter_complex", graph.join(";"));
|
|
317
|
+
args.push("-map", cur === "[0:v]" ? "0:v" : cur);
|
|
201
318
|
if (src.hasAudio)
|
|
202
|
-
args.push("-map",
|
|
319
|
+
args.push("-map", audioGraph ? "[aout]" : "0:a");
|
|
203
320
|
const finalEncode = encode;
|
|
204
321
|
if (finalEncode) {
|
|
205
322
|
args.push(...finalEncode);
|
|
@@ -213,5 +330,5 @@ export function planPipeline(input, output, steps, src, assets = {}, quality = "
|
|
|
213
330
|
if (chaptersInput !== -1)
|
|
214
331
|
args.push("-map_chapters", String(chaptersInput));
|
|
215
332
|
args.push(output);
|
|
216
|
-
return { args, width: W, height: H, fps, durationSec: dur === null ? null : r3(dur), gif, summary, timeOps };
|
|
333
|
+
return { args, width: W, height: H, fps, durationSec: dur === null ? null : r3(dur), gif, summary, timeOps, pending };
|
|
217
334
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ScreencastError } from "./errors.js";
|
|
2
|
+
export const RECIPES = ["pr_demo", "tutorial", "social_reel"];
|
|
3
|
+
export const PR_DEMO_MAX_BYTES = 10_000_000;
|
|
4
|
+
const EXPORTS = new Set(["export_preset", "export_gif"]);
|
|
5
|
+
export function recipeSteps(recipe, ctx) {
|
|
6
|
+
const notes = [];
|
|
7
|
+
const steps = [{ op: "cut_idle" }];
|
|
8
|
+
if (ctx.hasClicks)
|
|
9
|
+
steps.push({ op: "zoom", follow: "clicks" });
|
|
10
|
+
else
|
|
11
|
+
notes.push("zoom left out: no event log with clicks (record with start_recording events: true).");
|
|
12
|
+
const captions = (style) => {
|
|
13
|
+
if (!ctx.hasAudio)
|
|
14
|
+
return;
|
|
15
|
+
if (ctx.transcribeBlocker)
|
|
16
|
+
notes.push(`captions left out: ${ctx.transcribeBlocker}`);
|
|
17
|
+
else
|
|
18
|
+
steps.push({ op: "burn_subtitles", transcribe: true, style });
|
|
19
|
+
};
|
|
20
|
+
if (!ctx.hasAudio && recipe !== "pr_demo")
|
|
21
|
+
notes.push("audio and captions left out: the input has no audio.");
|
|
22
|
+
switch (recipe) {
|
|
23
|
+
case "pr_demo":
|
|
24
|
+
steps.push({ op: "export_gif", maxBytes: PR_DEMO_MAX_BYTES });
|
|
25
|
+
break;
|
|
26
|
+
case "tutorial":
|
|
27
|
+
if (ctx.hasAudio)
|
|
28
|
+
steps.push({ op: "audio", denoise: "light", normalize: "youtube" });
|
|
29
|
+
captions("clean");
|
|
30
|
+
steps.push({ op: "export_preset", platform: "youtube" });
|
|
31
|
+
break;
|
|
32
|
+
case "social_reel":
|
|
33
|
+
if (ctx.hasAudio)
|
|
34
|
+
steps.push({ op: "audio", normalize: "youtube" });
|
|
35
|
+
steps.push({ op: "reframe", aspect: "9:16" });
|
|
36
|
+
captions("social");
|
|
37
|
+
steps.push({ op: "export_preset", platform: "instagram_reel" });
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
throw new ScreencastError(`Unknown recipe "${String(recipe)}".`);
|
|
41
|
+
}
|
|
42
|
+
return { steps, notes };
|
|
43
|
+
}
|
|
44
|
+
export function applyOverrides(base, overrides) {
|
|
45
|
+
const out = [...base];
|
|
46
|
+
const tail = out.at(-1) && EXPORTS.has(out.at(-1).op) ? out.pop() : null;
|
|
47
|
+
let exportStep = tail;
|
|
48
|
+
const recipeLen = out.length;
|
|
49
|
+
const replaced = new Set();
|
|
50
|
+
const first = [];
|
|
51
|
+
for (const o of overrides) {
|
|
52
|
+
if (EXPORTS.has(o.op)) {
|
|
53
|
+
exportStep = o;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const i = out.findIndex((s, j) => j < recipeLen && !replaced.has(j) && s.op === o.op);
|
|
57
|
+
if (i === -1 && o.op === "trim")
|
|
58
|
+
first.push(o);
|
|
59
|
+
else if (i === -1)
|
|
60
|
+
out.push(o);
|
|
61
|
+
else {
|
|
62
|
+
out[i] = o;
|
|
63
|
+
replaced.add(i);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return [...first, ...out, ...(exportStep ? [exportStep] : [])];
|
|
67
|
+
}
|