@tmhs/screencast-mcp 0.49.0 → 0.50.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 +13 -8
- package/dist/index.js +550 -106
- package/dist/wgcRecorder.js +15 -139
- package/package.json +8 -4
- package/assets/.gitkeep +0 -0
- package/assets/icon.png +0 -0
- package/dist/cli.js +0 -516
- package/dist/context.js +0 -50
- package/dist/prompts.js +0 -95
- package/dist/resources.js +0 -93
- package/dist/server.js +0 -174
- package/dist/setup.js +0 -438
- package/dist/tools/addMarker.js +0 -93
- package/dist/tools/assembleHighlights.js +0 -69
- package/dist/tools/backdrop.js +0 -89
- package/dist/tools/bugReport.js +0 -266
- package/dist/tools/burnSubtitles.js +0 -56
- package/dist/tools/callout.js +0 -103
- package/dist/tools/chapters.js +0 -156
- package/dist/tools/clip.js +0 -52
- package/dist/tools/compress.js +0 -51
- package/dist/tools/concat.js +0 -67
- package/dist/tools/contactSheet.js +0 -135
- package/dist/tools/convert.js +0 -46
- package/dist/tools/crop.js +0 -43
- package/dist/tools/cursor.js +0 -87
- package/dist/tools/cutByTranscript.js +0 -86
- package/dist/tools/cutIdle.js +0 -84
- package/dist/tools/deleteRecording.js +0 -119
- package/dist/tools/denoise.js +0 -60
- package/dist/tools/doctor.js +0 -146
- package/dist/tools/exportGif.js +0 -57
- package/dist/tools/exportPreset.js +0 -48
- package/dist/tools/extractAudio.js +0 -65
- package/dist/tools/findText.js +0 -196
- package/dist/tools/getMediaInfo.js +0 -36
- package/dist/tools/getSession.js +0 -40
- package/dist/tools/indexRecording.js +0 -195
- package/dist/tools/keystrokeOverlay.js +0 -131
- package/dist/tools/listAudioDevices.js +0 -35
- package/dist/tools/listSessions.js +0 -28
- package/dist/tools/listTargets.js +0 -76
- package/dist/tools/listVideoDevices.js +0 -26
- package/dist/tools/musicBed.js +0 -55
- package/dist/tools/narrate.js +0 -86
- package/dist/tools/normalizeAudio.js +0 -60
- package/dist/tools/overlay.js +0 -62
- package/dist/tools/pauseRecording.js +0 -44
- package/dist/tools/pipeline.js +0 -400
- package/dist/tools/readEvents.js +0 -98
- package/dist/tools/redactRegion.js +0 -70
- package/dist/tools/reframe.js +0 -46
- package/dist/tools/resumeRecording.js +0 -46
- package/dist/tools/reviewRecording.js +0 -163
- package/dist/tools/sampleFrames.js +0 -200
- package/dist/tools/saveReplay.js +0 -90
- package/dist/tools/scale.js +0 -44
- package/dist/tools/screenDiff.js +0 -86
- package/dist/tools/screenshot.js +0 -76
- package/dist/tools/searchRecording.js +0 -79
- package/dist/tools/speed.js +0 -46
- package/dist/tools/startRecording.js +0 -398
- package/dist/tools/stepGuide.js +0 -250
- package/dist/tools/stopRecording.js +0 -132
- package/dist/tools/titleCard.js +0 -67
- package/dist/tools/transcribe.js +0 -66
- package/dist/tools/trim.js +0 -57
- package/dist/tools/waitForChange.js +0 -128
- package/dist/tools/xfadeTransition.js +0 -58
- package/dist/tools/zoom.js +0 -149
- package/dist/utils/anim.js +0 -54
- package/dist/utils/animExport.js +0 -56
- package/dist/utils/argPaths.js +0 -39
- package/dist/utils/audio.js +0 -113
- package/dist/utils/audioDevices.js +0 -107
- package/dist/utils/backdrop.js +0 -151
- package/dist/utils/bugReport.js +0 -172
- package/dist/utils/callout.js +0 -90
- package/dist/utils/calloutAssets.js +0 -42
- package/dist/utils/capabilities.js +0 -96
- package/dist/utils/captions.js +0 -103
- package/dist/utils/chapters.js +0 -227
- package/dist/utils/consent.js +0 -29
- package/dist/utils/cursor.js +0 -317
- package/dist/utils/diff.js +0 -184
- package/dist/utils/errors.js +0 -29
- package/dist/utils/events.js +0 -403
- package/dist/utils/expr.js +0 -11
- package/dist/utils/ffmpeg.js +0 -285
- package/dist/utils/fontCoverage.js +0 -177
- package/dist/utils/fonts.js +0 -154
- package/dist/utils/gpu.js +0 -219
- package/dist/utils/idle.js +0 -91
- package/dist/utils/images.js +0 -38
- package/dist/utils/jobs.js +0 -129
- package/dist/utils/keystrokes.js +0 -155
- package/dist/utils/lifecycle.js +0 -233
- package/dist/utils/logging.js +0 -75
- package/dist/utils/media.js +0 -574
- package/dist/utils/monitors.js +0 -124
- package/dist/utils/narrate.js +0 -233
- package/dist/utils/ocr.js +0 -222
- package/dist/utils/ocrScan.js +0 -91
- package/dist/utils/paths.js +0 -155
- package/dist/utils/pause.js +0 -190
- package/dist/utils/pipeline.js +0 -361
- package/dist/utils/player.js +0 -85
- package/dist/utils/pool.js +0 -29
- package/dist/utils/produce.js +0 -298
- package/dist/utils/recipes.js +0 -71
- package/dist/utils/recorder.js +0 -173
- package/dist/utils/recordingFiles.js +0 -32
- package/dist/utils/recordingIndex.js +0 -312
- package/dist/utils/replay.js +0 -283
- package/dist/utils/resolveTarget.js +0 -25
- package/dist/utils/retention.js +0 -48
- package/dist/utils/roots.js +0 -43
- package/dist/utils/sessions.js +0 -499
- package/dist/utils/sheet.js +0 -59
- package/dist/utils/stepGuide.js +0 -231
- package/dist/utils/steps.js +0 -88
- package/dist/utils/still.js +0 -38
- package/dist/utils/targetList.js +0 -64
- package/dist/utils/targets.js +0 -265
- package/dist/utils/timeline.js +0 -85
- package/dist/utils/toolSpec.js +0 -31
- package/dist/utils/toolsets.js +0 -134
- package/dist/utils/transcriptCut.js +0 -149
- package/dist/utils/validate.js +0 -23
- package/dist/utils/waitLoop.js +0 -50
- package/dist/utils/wgc.js +0 -84
- package/dist/utils/windows.js +0 -192
- package/dist/utils/zoom.js +0 -234
package/dist/utils/media.js
DELETED
|
@@ -1,574 +0,0 @@
|
|
|
1
|
-
import { extname } from "node:path";
|
|
2
|
-
import { ScreencastError } from "./errors.js";
|
|
3
|
-
import { resolveQuality } from "./targets.js";
|
|
4
|
-
import { validateColor, validateEvenDimension } from "./validate.js";
|
|
5
|
-
import { isStillImage, stillOutput } from "./paths.js";
|
|
6
|
-
const DEFAULT_EDIT_QUALITY = "standard";
|
|
7
|
-
function numberOrNull(v) {
|
|
8
|
-
if (v === undefined)
|
|
9
|
-
return null;
|
|
10
|
-
const n = Number(v);
|
|
11
|
-
return Number.isFinite(n) ? n : null;
|
|
12
|
-
}
|
|
13
|
-
export function parseFrameRate(value) {
|
|
14
|
-
if (!value)
|
|
15
|
-
return null;
|
|
16
|
-
const [num, den] = value.split("/");
|
|
17
|
-
const n = Number(num);
|
|
18
|
-
const d = den === undefined ? 1 : Number(den);
|
|
19
|
-
if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0)
|
|
20
|
-
return null;
|
|
21
|
-
if (n === 0)
|
|
22
|
-
return null;
|
|
23
|
-
return Math.round((n / d) * 1000) / 1000;
|
|
24
|
-
}
|
|
25
|
-
function streamRotation(video) {
|
|
26
|
-
const side = video?.side_data_list?.find((d) => d.rotation !== undefined)?.rotation;
|
|
27
|
-
const raw = side ?? video?.tags?.rotate;
|
|
28
|
-
const n = raw === undefined ? NaN : Number(raw);
|
|
29
|
-
return Number.isFinite(n) ? Math.round(n) % 360 : null;
|
|
30
|
-
}
|
|
31
|
-
export function parseMediaInfo(probe) {
|
|
32
|
-
const streams = probe.streams ?? [];
|
|
33
|
-
const video = streams.find((s) => s.codec_type === "video");
|
|
34
|
-
const audio = streams.find((s) => s.codec_type === "audio");
|
|
35
|
-
const duration = probe.format?.duration;
|
|
36
|
-
const size = probe.format?.size;
|
|
37
|
-
const durationSec = duration !== undefined ? Number(duration) : null;
|
|
38
|
-
const rotation = streamRotation(video);
|
|
39
|
-
const turned = rotation !== null && Math.abs(rotation) % 180 === 90;
|
|
40
|
-
return {
|
|
41
|
-
durationSec,
|
|
42
|
-
videoDurationSec: video ? (numberOrNull(video.duration) ?? durationSec) : null,
|
|
43
|
-
width: (turned ? video?.height : video?.width) ?? null,
|
|
44
|
-
height: (turned ? video?.width : video?.height) ?? null,
|
|
45
|
-
...(rotation ? { rotation } : {}),
|
|
46
|
-
fps: parseFrameRate(video?.avg_frame_rate) ?? parseFrameRate(video?.r_frame_rate),
|
|
47
|
-
videoCodec: video?.codec_name ?? null,
|
|
48
|
-
audioCodec: audio?.codec_name ?? null,
|
|
49
|
-
format: probe.format?.format_name ?? null,
|
|
50
|
-
sizeBytes: size !== undefined ? Number(size) : null,
|
|
51
|
-
pixFmt: video?.pix_fmt ?? null,
|
|
52
|
-
videoFrames: numberOrNull(video?.nb_frames),
|
|
53
|
-
sampleRate: numberOrNull(audio?.sample_rate),
|
|
54
|
-
channels: audio?.channels ?? null,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
export function buildProbeArgs(input) {
|
|
58
|
-
return [
|
|
59
|
-
"-v", "quiet",
|
|
60
|
-
"-print_format", "json",
|
|
61
|
-
"-show_format",
|
|
62
|
-
"-show_streams",
|
|
63
|
-
input,
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
function validatePositive(value, label) {
|
|
67
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
68
|
-
throw new ScreencastError(`${label} must be a positive number.`);
|
|
69
|
-
}
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
export const DEFAULT_MAX_FRAMES = 100;
|
|
73
|
-
export const MAX_FRAMES_CEILING = 1000;
|
|
74
|
-
export function planFpsSampling(durationSec, fps, maxFrames) {
|
|
75
|
-
validatePositive(fps, "fps");
|
|
76
|
-
if (durationSec === null || !(durationSec > 0)) {
|
|
77
|
-
return { fps, requestedFrames: null, clamped: false };
|
|
78
|
-
}
|
|
79
|
-
const requested = Math.ceil(durationSec * fps);
|
|
80
|
-
if (requested <= maxFrames)
|
|
81
|
-
return { fps, requestedFrames: requested, clamped: false };
|
|
82
|
-
const clampedFps = Math.max(1e-4, Math.floor((maxFrames / durationSec) * 10_000) / 10_000);
|
|
83
|
-
return { fps: clampedFps, requestedFrames: requested, clamped: true };
|
|
84
|
-
}
|
|
85
|
-
export function pickFramePrefix(existing, unique) {
|
|
86
|
-
for (const f of existing)
|
|
87
|
-
if (/^frame_\d+\.png$/i.test(f))
|
|
88
|
-
return `frame_${unique}_`;
|
|
89
|
-
return "frame_";
|
|
90
|
-
}
|
|
91
|
-
export function buildSampleByFpsArgs(input, fps, outputPattern, maxFrames = DEFAULT_MAX_FRAMES, dedupe = false, range) {
|
|
92
|
-
validatePositive(fps, "fps");
|
|
93
|
-
const vf = dedupe ? `fps=${fps},mpdecimate` : `fps=${fps}`;
|
|
94
|
-
const seek = range
|
|
95
|
-
? ["-ss", String(range.start), ...(range.duration !== undefined ? ["-t", String(range.duration)] : [])]
|
|
96
|
-
: [];
|
|
97
|
-
return [
|
|
98
|
-
"-y", ...seek, "-i", input, "-vf", vf,
|
|
99
|
-
...(dedupe ? ["-fps_mode", "vfr"] : []),
|
|
100
|
-
"-frames:v", String(maxFrames), outputPattern,
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
export const DEFAULT_SCENE_THRESHOLD = 0.1;
|
|
104
|
-
export function buildSceneScanArgs(input, threshold = DEFAULT_SCENE_THRESHOLD) {
|
|
105
|
-
if (!Number.isFinite(threshold) || threshold <= 0 || threshold >= 1) {
|
|
106
|
-
throw new ScreencastError("sceneThreshold must be between 0 and 1 (exclusive).");
|
|
107
|
-
}
|
|
108
|
-
return [
|
|
109
|
-
"-v", "error", "-i", input, "-an",
|
|
110
|
-
"-vf", `scale=320:-2,select='gt(scene\\,${threshold})',metadata=print:file=-`,
|
|
111
|
-
"-f", "null", "-",
|
|
112
|
-
];
|
|
113
|
-
}
|
|
114
|
-
export function parseSceneScan(stdout) {
|
|
115
|
-
const out = [];
|
|
116
|
-
let time = null;
|
|
117
|
-
for (const line of stdout.split(/\r?\n/)) {
|
|
118
|
-
const t = line.match(/pts_time:\s*(-?[\d.]+)/);
|
|
119
|
-
if (t) {
|
|
120
|
-
time = Number(t[1]);
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
const s = line.match(/lavfi\.scene_score=([\d.]+)/);
|
|
124
|
-
if (s && time !== null) {
|
|
125
|
-
out.push({ timeSec: time, score: Number(s[1]) });
|
|
126
|
-
time = null;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return out;
|
|
130
|
-
}
|
|
131
|
-
export function pickSceneFrames(changes, maxFrames) {
|
|
132
|
-
const strongest = [...changes]
|
|
133
|
-
.filter((c) => c.timeSec > 0)
|
|
134
|
-
.sort((a, b) => b.score - a.score)
|
|
135
|
-
.slice(0, Math.max(0, maxFrames - 1))
|
|
136
|
-
.map((c) => c.timeSec);
|
|
137
|
-
return [0, ...strongest].sort((a, b) => a - b);
|
|
138
|
-
}
|
|
139
|
-
export function buildSampleAtTimestampArgs(input, timestampSec, output) {
|
|
140
|
-
if (!Number.isFinite(timestampSec) || timestampSec < 0) {
|
|
141
|
-
throw new ScreencastError("timestamp must be a non-negative number.");
|
|
142
|
-
}
|
|
143
|
-
return ["-y", "-ss", String(timestampSec), "-i", input, "-frames:v", "1", ...stillOutput(output)];
|
|
144
|
-
}
|
|
145
|
-
export function editOutputExt(input, opts = {}) {
|
|
146
|
-
const ext = extname(input).toLowerCase();
|
|
147
|
-
if (ext === ".mp4" || ext === ".mkv" || ext === ".mov")
|
|
148
|
-
return ext;
|
|
149
|
-
if (opts.audio && AUDIO_ONLY_EXTS.has(ext))
|
|
150
|
-
return ext;
|
|
151
|
-
return ".mp4";
|
|
152
|
-
}
|
|
153
|
-
const AUDIO_ONLY_EXTS = new Set([".wav", ".mp3", ".m4a"]);
|
|
154
|
-
export function isAudioOnlyPath(path) {
|
|
155
|
-
return AUDIO_ONLY_EXTS.has(extname(path).toLowerCase());
|
|
156
|
-
}
|
|
157
|
-
export function assertEditContainer(output) {
|
|
158
|
-
if (output === undefined)
|
|
159
|
-
return;
|
|
160
|
-
const ext = extname(output).toLowerCase();
|
|
161
|
-
if (ext === ".webm" || ext === ".gif") {
|
|
162
|
-
throw new ScreencastError(`This tool writes H.264/AAC, which a ${ext} file cannot hold. Use an .mp4, .mkv or .mov ` +
|
|
163
|
-
`output, then convert (format: "webm") or export_gif the result.`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
export function buildTrimArgs(input, output, opts) {
|
|
167
|
-
const start = opts.start;
|
|
168
|
-
if (!Number.isFinite(start) || start < 0) {
|
|
169
|
-
throw new ScreencastError("start must be a non-negative number.");
|
|
170
|
-
}
|
|
171
|
-
if (opts.end === undefined && opts.duration === undefined) {
|
|
172
|
-
throw new ScreencastError("trim requires either end or duration.");
|
|
173
|
-
}
|
|
174
|
-
if (opts.end !== undefined && opts.duration !== undefined) {
|
|
175
|
-
throw new ScreencastError("trim takes end OR duration, not both.");
|
|
176
|
-
}
|
|
177
|
-
const args = ["-y", "-ss", String(start), "-i", input];
|
|
178
|
-
if (opts.end !== undefined) {
|
|
179
|
-
if (opts.end <= start) {
|
|
180
|
-
throw new ScreencastError("end must be greater than start.");
|
|
181
|
-
}
|
|
182
|
-
args.push("-t", String(Math.round((opts.end - start) * 1000) / 1000));
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
args.push("-t", String(validatePositive(opts.duration, "duration")));
|
|
186
|
-
}
|
|
187
|
-
if (opts.exact === false)
|
|
188
|
-
args.push("-c", "copy", output);
|
|
189
|
-
else
|
|
190
|
-
args.push(...resolveQuality(DEFAULT_EDIT_QUALITY), "-c:a", "aac", output);
|
|
191
|
-
return args;
|
|
192
|
-
}
|
|
193
|
-
export function concatListContent(files) {
|
|
194
|
-
return files.map((p) => `file '${p.replace(/'/g, "'\\''")}'`).join("\n") + "\n";
|
|
195
|
-
}
|
|
196
|
-
export function buildConcatListContent(inputs) {
|
|
197
|
-
if (inputs.length < 2) {
|
|
198
|
-
throw new ScreencastError("concat requires at least two input files.");
|
|
199
|
-
}
|
|
200
|
-
return concatListContent(inputs);
|
|
201
|
-
}
|
|
202
|
-
export function buildConcatArgs(listFile, output, opts = {}) {
|
|
203
|
-
return ["-y", ...(opts.quiet ? ["-v", "error"] : []), "-f", "concat", "-safe", "0", "-i", listFile, "-c", "copy", output];
|
|
204
|
-
}
|
|
205
|
-
export function hasHiddenFrames(info) {
|
|
206
|
-
const { videoFrames: n, videoDurationSec: d, fps } = info;
|
|
207
|
-
if (n === null || d === null || fps === null)
|
|
208
|
-
return false;
|
|
209
|
-
return n > d * fps * 1.05 + 2;
|
|
210
|
-
}
|
|
211
|
-
export function concatCopyBlocker(paths, infos) {
|
|
212
|
-
const fields = [
|
|
213
|
-
["videoCodec", "video codec"],
|
|
214
|
-
["width", "width"],
|
|
215
|
-
["height", "height"],
|
|
216
|
-
["pixFmt", "pixel format"],
|
|
217
|
-
["fps", "frame rate"],
|
|
218
|
-
["audioCodec", "audio codec"],
|
|
219
|
-
["sampleRate", "audio sample rate"],
|
|
220
|
-
["channels", "audio channels"],
|
|
221
|
-
];
|
|
222
|
-
const first = infos[0];
|
|
223
|
-
for (const [i, info] of infos.entries()) {
|
|
224
|
-
if (hasHiddenFrames(info))
|
|
225
|
-
return `${paths[i]} holds hidden frames behind an edit list`;
|
|
226
|
-
if (i === 0 || !first)
|
|
227
|
-
continue;
|
|
228
|
-
for (const [key, label] of fields) {
|
|
229
|
-
if (info[key] !== first[key]) {
|
|
230
|
-
return `${label} differs: ${paths[0]} has ${first[key] ?? "none"}, ${paths[i]} has ${info[key] ?? "none"}`;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
export function buildConvertArgs(input, output, format, opts = {}) {
|
|
237
|
-
switch (format) {
|
|
238
|
-
case "gif": {
|
|
239
|
-
const fps = opts.fps ?? 12;
|
|
240
|
-
const width = opts.width ?? 720;
|
|
241
|
-
const filter = `fps=${fps},scale='min(${width},iw)':-1:flags=lanczos,split[s0][s1];` +
|
|
242
|
-
`[s0]palettegen[p];[s1][p]paletteuse`;
|
|
243
|
-
return ["-y", "-i", input, "-vf", filter, output];
|
|
244
|
-
}
|
|
245
|
-
case "webm":
|
|
246
|
-
return [
|
|
247
|
-
"-y", "-i", input,
|
|
248
|
-
"-c:v", "libvpx-vp9", "-b:v", "0", "-crf", "30",
|
|
249
|
-
"-deadline", "good", "-cpu-used", "4", "-row-mt", "1",
|
|
250
|
-
output,
|
|
251
|
-
];
|
|
252
|
-
case "mp4":
|
|
253
|
-
return [
|
|
254
|
-
"-y", "-i", input,
|
|
255
|
-
"-c:v", "libx264", "-preset", "veryfast", "-crf", "23",
|
|
256
|
-
"-pix_fmt", "yuv420p",
|
|
257
|
-
"-movflags", "+faststart",
|
|
258
|
-
output,
|
|
259
|
-
];
|
|
260
|
-
default:
|
|
261
|
-
throw new ScreencastError(`Unsupported convert format "${format}".`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
function requireNonNegativeInt(value, label) {
|
|
265
|
-
if (!Number.isInteger(value) || value < 0) {
|
|
266
|
-
throw new ScreencastError(`${label} must be a non-negative integer.`);
|
|
267
|
-
}
|
|
268
|
-
return value;
|
|
269
|
-
}
|
|
270
|
-
function requirePositiveInt(value, label) {
|
|
271
|
-
if (!Number.isInteger(value) || value <= 0) {
|
|
272
|
-
throw new ScreencastError(`${label} must be a positive integer.`);
|
|
273
|
-
}
|
|
274
|
-
return value;
|
|
275
|
-
}
|
|
276
|
-
export function enableExpr(start, end) {
|
|
277
|
-
if (start !== undefined && end !== undefined) {
|
|
278
|
-
if (end <= start)
|
|
279
|
-
throw new ScreencastError("end must be greater than start.");
|
|
280
|
-
return `between(t,${start},${end})`;
|
|
281
|
-
}
|
|
282
|
-
if (start !== undefined)
|
|
283
|
-
return `gte(t,${start})`;
|
|
284
|
-
if (end !== undefined)
|
|
285
|
-
return `lte(t,${end})`;
|
|
286
|
-
return "";
|
|
287
|
-
}
|
|
288
|
-
export function cropFilter(rect, dims) {
|
|
289
|
-
const x = requireNonNegativeInt(rect.x, "crop x");
|
|
290
|
-
const y = requireNonNegativeInt(rect.y, "crop y");
|
|
291
|
-
const w = validateEvenDimension(requirePositiveInt(rect.width, "crop width"), "crop width");
|
|
292
|
-
const h = validateEvenDimension(requirePositiveInt(rect.height, "crop height"), "crop height");
|
|
293
|
-
if (dims && dims.width != null && dims.height != null) {
|
|
294
|
-
if (x + w > dims.width || y + h > dims.height) {
|
|
295
|
-
throw new ScreencastError(`crop region ${w}x${h}+${x}+${y} falls outside the ` +
|
|
296
|
-
`${dims.width}x${dims.height} frame.`);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return `crop=${w}:${h}:${x}:${y}`;
|
|
300
|
-
}
|
|
301
|
-
export function buildCropArgs(input, output, rect, dims, quality = DEFAULT_EDIT_QUALITY) {
|
|
302
|
-
return [
|
|
303
|
-
"-y", "-i", input,
|
|
304
|
-
"-vf", cropFilter(rect, dims),
|
|
305
|
-
...resolveQuality(quality),
|
|
306
|
-
"-c:a", "copy",
|
|
307
|
-
output,
|
|
308
|
-
];
|
|
309
|
-
}
|
|
310
|
-
export function scaleFilter(opts) {
|
|
311
|
-
if (opts.width === undefined && opts.height === undefined) {
|
|
312
|
-
throw new ScreencastError("scale requires width or height (or both).");
|
|
313
|
-
}
|
|
314
|
-
if (opts.width !== undefined) {
|
|
315
|
-
validateEvenDimension(requirePositiveInt(opts.width, "scale width"), "scale width");
|
|
316
|
-
}
|
|
317
|
-
if (opts.height !== undefined) {
|
|
318
|
-
validateEvenDimension(requirePositiveInt(opts.height, "scale height"), "scale height");
|
|
319
|
-
}
|
|
320
|
-
return `scale=${opts.width ?? -2}:${opts.height ?? -2}`;
|
|
321
|
-
}
|
|
322
|
-
export function scaledSize(W, H, opts) {
|
|
323
|
-
const even = (v) => Math.max(2, Math.round(v / 2) * 2);
|
|
324
|
-
if (opts.width !== undefined && opts.height !== undefined)
|
|
325
|
-
return { width: opts.width, height: opts.height };
|
|
326
|
-
if (opts.width !== undefined)
|
|
327
|
-
return { width: opts.width, height: even((H * opts.width) / W) };
|
|
328
|
-
return { width: even((W * opts.height) / H), height: opts.height };
|
|
329
|
-
}
|
|
330
|
-
export function buildScaleArgs(input, output, opts, quality = DEFAULT_EDIT_QUALITY) {
|
|
331
|
-
return [
|
|
332
|
-
"-y", "-i", input,
|
|
333
|
-
"-vf", scaleFilter(opts),
|
|
334
|
-
...resolveQuality(quality),
|
|
335
|
-
"-c:a", "copy",
|
|
336
|
-
output,
|
|
337
|
-
];
|
|
338
|
-
}
|
|
339
|
-
export function atempoChain(factor) {
|
|
340
|
-
let remaining = factor;
|
|
341
|
-
const parts = [];
|
|
342
|
-
while (remaining > 2.0) {
|
|
343
|
-
parts.push("atempo=2.0");
|
|
344
|
-
remaining /= 2.0;
|
|
345
|
-
}
|
|
346
|
-
while (remaining < 0.5) {
|
|
347
|
-
parts.push("atempo=0.5");
|
|
348
|
-
remaining /= 0.5;
|
|
349
|
-
}
|
|
350
|
-
parts.push(`atempo=${Number(remaining.toFixed(6))}`);
|
|
351
|
-
return parts.join(",");
|
|
352
|
-
}
|
|
353
|
-
export function buildSpeedArgs(input, output, factor, hasAudio, quality = DEFAULT_EDIT_QUALITY) {
|
|
354
|
-
if (!Number.isFinite(factor) || factor <= 0) {
|
|
355
|
-
throw new ScreencastError("speed factor must be a positive number.");
|
|
356
|
-
}
|
|
357
|
-
const args = ["-y", "-i", input, "-filter:v", `setpts=PTS/${factor}`];
|
|
358
|
-
if (hasAudio)
|
|
359
|
-
args.push("-filter:a", atempoChain(factor));
|
|
360
|
-
args.push(...resolveQuality(quality));
|
|
361
|
-
if (hasAudio) {
|
|
362
|
-
args.push("-c:a", "aac");
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
args.push("-an");
|
|
366
|
-
}
|
|
367
|
-
args.push(output);
|
|
368
|
-
return args;
|
|
369
|
-
}
|
|
370
|
-
export const CIRCLE_MASK = "crop='min(iw,ih)':'min(iw,ih)',format=yuva420p," +
|
|
371
|
-
"geq=lum='p(X,Y)':cb='p(X,Y)':cr='p(X,Y)':a='if(lte(hypot(X-W/2,Y-H/2),W/2),255,0)'";
|
|
372
|
-
export function buildOverlayArgs(input, overlay, output, opts, quality = DEFAULT_EDIT_QUALITY) {
|
|
373
|
-
const x = requireNonNegativeInt(opts.x, "overlay x");
|
|
374
|
-
const y = requireNonNegativeInt(opts.y, "overlay y");
|
|
375
|
-
const expr = enableExpr(opts.start, opts.end);
|
|
376
|
-
const enable = expr ? `:enable='${expr}'` : "";
|
|
377
|
-
const shift = `setpts=PTS-STARTPTS+${opts.start ?? 0}/TB`;
|
|
378
|
-
let ovl = `[1:v]${shift}`;
|
|
379
|
-
if (opts.scale && (opts.scale.width !== undefined || opts.scale.height !== undefined)) {
|
|
380
|
-
if (opts.scale.width !== undefined)
|
|
381
|
-
requirePositiveInt(opts.scale.width, "overlay scale width");
|
|
382
|
-
if (opts.scale.height !== undefined)
|
|
383
|
-
requirePositiveInt(opts.scale.height, "overlay scale height");
|
|
384
|
-
const sw = opts.scale.width ?? -1;
|
|
385
|
-
const sh = opts.scale.height ?? -1;
|
|
386
|
-
ovl += `,scale=${sw}:${sh}`;
|
|
387
|
-
}
|
|
388
|
-
if (opts.shape === "circle")
|
|
389
|
-
ovl += `,${CIRCLE_MASK}`;
|
|
390
|
-
const filter = `${ovl}[ovl];[0:v][ovl]overlay=${x}:${y}${enable}[v]`;
|
|
391
|
-
const dur = opts.durationSec;
|
|
392
|
-
return [
|
|
393
|
-
"-y", "-i", input, "-i", overlay,
|
|
394
|
-
"-filter_complex", filter,
|
|
395
|
-
"-map", "[v]", "-map", "0:a?",
|
|
396
|
-
...resolveQuality(quality),
|
|
397
|
-
"-c:a", "copy",
|
|
398
|
-
...(dur != null && dur > 0 ? ["-t", String(dur)] : []),
|
|
399
|
-
output,
|
|
400
|
-
];
|
|
401
|
-
}
|
|
402
|
-
const COMPRESS_CRF = {
|
|
403
|
-
light: 23,
|
|
404
|
-
medium: 28,
|
|
405
|
-
heavy: 32,
|
|
406
|
-
};
|
|
407
|
-
export function buildCompressArgs(input, output, opts = {}) {
|
|
408
|
-
const level = opts.level ?? "medium";
|
|
409
|
-
const crf = COMPRESS_CRF[level];
|
|
410
|
-
if (crf === undefined)
|
|
411
|
-
throw new ScreencastError(`Unknown compress level "${level}".`);
|
|
412
|
-
const args = ["-y", "-i", input];
|
|
413
|
-
if (opts.maxWidth !== undefined) {
|
|
414
|
-
requirePositiveInt(opts.maxWidth, "maxWidth");
|
|
415
|
-
args.push("-vf", `scale='trunc(min(${opts.maxWidth},iw)/2)*2':-2`);
|
|
416
|
-
}
|
|
417
|
-
args.push("-c:v", "libx264", "-preset", "slow", "-crf", String(crf), "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "128k", "-movflags", "+faststart", output);
|
|
418
|
-
return args;
|
|
419
|
-
}
|
|
420
|
-
const AUDIO_CODEC = {
|
|
421
|
-
mp3: ["-c:a", "libmp3lame", "-q:a", "2"],
|
|
422
|
-
aac: ["-c:a", "aac", "-b:a", "192k"],
|
|
423
|
-
wav: ["-c:a", "pcm_s16le"],
|
|
424
|
-
copy: ["-c:a", "copy"],
|
|
425
|
-
};
|
|
426
|
-
export function copyAudioExtension(codec) {
|
|
427
|
-
switch (codec) {
|
|
428
|
-
case "aac":
|
|
429
|
-
case "alac":
|
|
430
|
-
return "m4a";
|
|
431
|
-
case "mp3":
|
|
432
|
-
return "mp3";
|
|
433
|
-
case "opus":
|
|
434
|
-
case "vorbis":
|
|
435
|
-
return "ogg";
|
|
436
|
-
case "flac":
|
|
437
|
-
return "flac";
|
|
438
|
-
default:
|
|
439
|
-
if (codec && codec.startsWith("pcm_"))
|
|
440
|
-
return "wav";
|
|
441
|
-
return "mka";
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
export function buildExtractAudioArgs(input, output, format) {
|
|
445
|
-
const codec = AUDIO_CODEC[format];
|
|
446
|
-
if (!codec)
|
|
447
|
-
throw new ScreencastError(`Unknown audio format "${format}".`);
|
|
448
|
-
return ["-y", "-i", input, "-vn", ...codec, output];
|
|
449
|
-
}
|
|
450
|
-
export function buildClipArgs(input, output, seg, quality = DEFAULT_EDIT_QUALITY) {
|
|
451
|
-
if (!Number.isFinite(seg.start) || seg.start < 0) {
|
|
452
|
-
throw new ScreencastError("clip start must be a non-negative number.");
|
|
453
|
-
}
|
|
454
|
-
if (!Number.isFinite(seg.end) || seg.end <= seg.start) {
|
|
455
|
-
throw new ScreencastError("clip end must be greater than start.");
|
|
456
|
-
}
|
|
457
|
-
return [
|
|
458
|
-
"-y", "-i", input,
|
|
459
|
-
"-ss", String(seg.start),
|
|
460
|
-
"-t", String(seg.end - seg.start),
|
|
461
|
-
...resolveQuality(quality),
|
|
462
|
-
"-c:a", "aac",
|
|
463
|
-
output,
|
|
464
|
-
];
|
|
465
|
-
}
|
|
466
|
-
function normalizeRegions(regions, pad, dims) {
|
|
467
|
-
return regions.map((r, i) => {
|
|
468
|
-
const x0 = requireNonNegativeInt(r.x, `region[${i}] x`);
|
|
469
|
-
const y0 = requireNonNegativeInt(r.y, `region[${i}] y`);
|
|
470
|
-
const w0 = requirePositiveInt(r.width, `region[${i}] width`);
|
|
471
|
-
const h0 = requirePositiveInt(r.height, `region[${i}] height`);
|
|
472
|
-
if (dims && dims.width != null && dims.height != null) {
|
|
473
|
-
if (x0 + w0 > dims.width || y0 + h0 > dims.height) {
|
|
474
|
-
throw new ScreencastError(`region[${i}] ${w0}x${h0}+${x0}+${y0} falls outside the ` +
|
|
475
|
-
`${dims.width}x${dims.height} frame.`);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
const x = Math.max(0, x0 - pad);
|
|
479
|
-
const y = Math.max(0, y0 - pad);
|
|
480
|
-
let right = x0 + w0 + pad;
|
|
481
|
-
let bottom = y0 + h0 + pad;
|
|
482
|
-
if (dims && dims.width != null)
|
|
483
|
-
right = Math.min(right, dims.width);
|
|
484
|
-
if (dims && dims.height != null)
|
|
485
|
-
bottom = Math.min(bottom, dims.height);
|
|
486
|
-
return { x, y, w: right - x, h: bottom - y, enable: enableExpr(r.start, r.end) };
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
export const MIN_BLUR_RADIUS = 8;
|
|
490
|
-
export const BLUR_PASSES = 3;
|
|
491
|
-
export const MIN_PIXEL_BLOCK = 16;
|
|
492
|
-
export function blurRadius(r) {
|
|
493
|
-
const m = Math.min(r.w, r.h);
|
|
494
|
-
const maxRadius = (side) => Math.max(0, Math.floor((side - 1) / 2));
|
|
495
|
-
const lr = Math.min(maxRadius(m), Math.max(MIN_BLUR_RADIUS, Math.min(20, Math.floor(m / 4))));
|
|
496
|
-
const cr = Math.min(lr, maxRadius(Math.ceil(m / 2)));
|
|
497
|
-
return `lr=${lr}:lp=${BLUR_PASSES}:cr=${cr}:cp=${BLUR_PASSES}`;
|
|
498
|
-
}
|
|
499
|
-
export function pixelateFilter(r) {
|
|
500
|
-
const block = Math.max(MIN_PIXEL_BLOCK, Math.ceil(Math.max(r.w, r.h) / 16));
|
|
501
|
-
const cols = Math.max(1, Math.round(r.w / block));
|
|
502
|
-
const rows = Math.max(1, Math.round(r.h / block));
|
|
503
|
-
return `scale=${cols}:${rows}:flags=area,scale=${r.w}:${r.h}:flags=neighbor`;
|
|
504
|
-
}
|
|
505
|
-
export function redactSteps(regions, opts, dims, input, tag) {
|
|
506
|
-
if (regions.length === 0) {
|
|
507
|
-
throw new ScreencastError("redact_region requires at least one region.");
|
|
508
|
-
}
|
|
509
|
-
const style = opts.style ?? "box";
|
|
510
|
-
const pad = opts.pad ?? 0;
|
|
511
|
-
if (!Number.isInteger(pad) || pad < 0) {
|
|
512
|
-
throw new ScreencastError("pad must be a non-negative integer.");
|
|
513
|
-
}
|
|
514
|
-
const color = validateColor(opts.color ?? "black", "color");
|
|
515
|
-
const rs = normalizeRegions(regions, pad, dims);
|
|
516
|
-
if (style === "box") {
|
|
517
|
-
const boxes = rs
|
|
518
|
-
.map((r) => {
|
|
519
|
-
const en = r.enable ? `:enable='${r.enable}'` : "";
|
|
520
|
-
return `drawbox=x=${r.x}:y=${r.y}:w=${r.w}:h=${r.h}:color=${color}:t=fill${en}`;
|
|
521
|
-
})
|
|
522
|
-
.join(",");
|
|
523
|
-
return { steps: [`${input}${boxes}[${tag}out]`], out: `[${tag}out]` };
|
|
524
|
-
}
|
|
525
|
-
const n = rs.length;
|
|
526
|
-
const steps = [];
|
|
527
|
-
const splitOuts = [`${tag}base`, ...rs.map((_, i) => `${tag}s${i}`)];
|
|
528
|
-
steps.push(`${input}split=${n + 1}[${splitOuts.join("][")}]`);
|
|
529
|
-
rs.forEach((r, i) => {
|
|
530
|
-
const crop = `crop=${r.w}:${r.h}:${r.x}:${r.y}`;
|
|
531
|
-
const soften = style === "blur"
|
|
532
|
-
? `boxblur=${blurRadius(r)}`
|
|
533
|
-
: pixelateFilter(r);
|
|
534
|
-
steps.push(`[${tag}s${i}]${crop},${soften}[${tag}b${i}]`);
|
|
535
|
-
});
|
|
536
|
-
let prev = `${tag}base`;
|
|
537
|
-
rs.forEach((r, i) => {
|
|
538
|
-
const en = r.enable ? `:enable='${r.enable}'` : "";
|
|
539
|
-
const out = i === n - 1 ? `${tag}out` : `${tag}c${i}`;
|
|
540
|
-
steps.push(`[${prev}][${tag}b${i}]overlay=${r.x}:${r.y}${en}[${out}]`);
|
|
541
|
-
prev = `${tag}c${i}`;
|
|
542
|
-
});
|
|
543
|
-
return { steps, out: `[${tag}out]` };
|
|
544
|
-
}
|
|
545
|
-
export function stillEdit(input, output) {
|
|
546
|
-
if (!isStillImage(input)) {
|
|
547
|
-
assertEditContainer(output);
|
|
548
|
-
return { still: false, ext: editOutputExt(input) };
|
|
549
|
-
}
|
|
550
|
-
if (output && !isStillImage(output)) {
|
|
551
|
-
throw new ScreencastError("An image input writes an image: give the output a .png or .jpg extension.");
|
|
552
|
-
}
|
|
553
|
-
return { still: true, ext: /\.jpe?g$/i.test(input) ? extname(input).toLowerCase() : ".png" };
|
|
554
|
-
}
|
|
555
|
-
export function buildRedactArgs(input, output, regions, opts = {}, dims, still = false) {
|
|
556
|
-
const rs = still ? regions.map(({ start: _s, end: _e, ...r }) => r) : regions;
|
|
557
|
-
const { steps, out } = redactSteps(rs, opts, dims, "[0:v]", "");
|
|
558
|
-
if (still) {
|
|
559
|
-
return ["-y", "-i", input, "-filter_complex", steps.join(";"), "-map", out, "-frames:v", "1", ...stillOutput(output)];
|
|
560
|
-
}
|
|
561
|
-
const [chain] = steps;
|
|
562
|
-
if ((opts.style ?? "box") === "box" && chain !== undefined) {
|
|
563
|
-
const vf = chain.slice("[0:v]".length, -out.length);
|
|
564
|
-
return ["-y", "-i", input, "-vf", vf, ...resolveQuality("high"), "-c:a", "copy", output];
|
|
565
|
-
}
|
|
566
|
-
return [
|
|
567
|
-
"-y", "-i", input,
|
|
568
|
-
"-filter_complex", steps.join(";"),
|
|
569
|
-
"-map", out, "-map", "0:a?",
|
|
570
|
-
...resolveQuality("high"),
|
|
571
|
-
"-c:a", "copy",
|
|
572
|
-
output,
|
|
573
|
-
];
|
|
574
|
-
}
|