@tmhs/screencast-mcp 0.49.1 → 0.51.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 +15 -9
- package/dist/index.js +551 -106
- package/dist/wgcRecorder.js +15 -139
- package/package.json +9 -5
- 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 -79
- package/dist/tools/bugReport.js +0 -243
- package/dist/tools/burnSubtitles.js +0 -56
- package/dist/tools/callout.js +0 -62
- 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 -113
- package/dist/tools/convert.js +0 -46
- package/dist/tools/crop.js +0 -43
- package/dist/tools/cursor.js +0 -67
- 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 -194
- 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 -90
- 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 -59
- package/dist/tools/overlay.js +0 -62
- package/dist/tools/pauseRecording.js +0 -44
- package/dist/tools/pipeline.js +0 -397
- package/dist/tools/readEvents.js +0 -98
- package/dist/tools/redactRegion.js +0 -62
- 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 -249
- 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 -142
- package/dist/tools/xfadeTransition.js +0 -58
- package/dist/tools/zoom.js +0 -134
- 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 -117
- package/dist/utils/audioDevices.js +0 -107
- package/dist/utils/backdrop.js +0 -162
- package/dist/utils/bugReport.js +0 -195
- package/dist/utils/callout.js +0 -132
- package/dist/utils/calloutAssets.js +0 -42
- package/dist/utils/capabilities.js +0 -96
- package/dist/utils/captions.js +0 -104
- package/dist/utils/chapters.js +0 -227
- package/dist/utils/consent.js +0 -29
- package/dist/utils/cursor.js +0 -338
- package/dist/utils/diff.js +0 -186
- 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/frameQueue.js +0 -50
- 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 -198
- package/dist/utils/lifecycle.js +0 -233
- package/dist/utils/logging.js +0 -75
- package/dist/utils/media.js +0 -584
- 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 -93
- 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 -300
- 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 -82
- 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 -252
package/dist/utils/anim.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { ScreencastError } from "./errors.js";
|
|
2
|
-
export const DEFAULT_ANIM_FPS = 12;
|
|
3
|
-
export const DEFAULT_ANIM_WIDTH = 960;
|
|
4
|
-
export const DEFAULT_MAX_BYTES = 10_000_000;
|
|
5
|
-
export const MAX_ATTEMPTS = 5;
|
|
6
|
-
export function animLadder(format, fps, width) {
|
|
7
|
-
const steps = format === "gif"
|
|
8
|
-
? [[1, 1, 256], [0.83, 0.8, 256], [0.67, 0.67, 128], [0.5, 0.5, 64], [0.4, 0.4, 32], [0.33, 0.33, 16]]
|
|
9
|
-
: [[1, 1, 75], [0.83, 0.8, 65], [0.67, 0.67, 55], [0.5, 0.5, 45], [0.4, 0.4, 35], [0.33, 0.33, 25]];
|
|
10
|
-
return steps.map(([f, w, q]) => ({
|
|
11
|
-
fps: Math.max(1, Math.round(fps * f * 10) / 10),
|
|
12
|
-
width: Math.max(64, Math.round((width * w) / 2) * 2),
|
|
13
|
-
...(format === "gif" ? { colors: q } : { quality: q }),
|
|
14
|
-
}));
|
|
15
|
-
}
|
|
16
|
-
export function nextLadderIndex(index, size, maxBytes, ladderLength) {
|
|
17
|
-
const last = ladderLength - 1;
|
|
18
|
-
if (index >= last)
|
|
19
|
-
return null;
|
|
20
|
-
const jump = Math.max(1, Math.ceil(Math.log(size / maxBytes) / Math.log(1.8)));
|
|
21
|
-
return Math.min(last, index + jump);
|
|
22
|
-
}
|
|
23
|
-
export function buildAnimArgs(input, output, format, s, clip = {}) {
|
|
24
|
-
if (!(s.fps > 0) || !Number.isInteger(s.width) || s.width < 16) {
|
|
25
|
-
throw new ScreencastError("fps must be positive and width an integer of at least 16.");
|
|
26
|
-
}
|
|
27
|
-
if (clip.start !== undefined && !(clip.start >= 0))
|
|
28
|
-
throw new ScreencastError("start must be >= 0.");
|
|
29
|
-
if (clip.duration !== undefined && !(clip.duration > 0))
|
|
30
|
-
throw new ScreencastError("duration must be > 0.");
|
|
31
|
-
const window = [
|
|
32
|
-
...(clip.start ? ["-ss", String(clip.start)] : []),
|
|
33
|
-
...(clip.duration ? ["-t", String(clip.duration)] : []),
|
|
34
|
-
];
|
|
35
|
-
const base = `fps=${s.fps},scale='min(${s.width},iw)':-1:flags=lanczos`;
|
|
36
|
-
if (format === "gif") {
|
|
37
|
-
const colors = s.colors ?? 256;
|
|
38
|
-
return [
|
|
39
|
-
"-y", ...window, "-i", input, "-an",
|
|
40
|
-
"-vf",
|
|
41
|
-
`${base},split[a][b];[a]palettegen=stats_mode=diff:max_colors=${colors}[p];` +
|
|
42
|
-
"[b][p]paletteuse=dither=sierra2_4a:diff_mode=rectangle",
|
|
43
|
-
"-loop", "0",
|
|
44
|
-
output,
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
return [
|
|
48
|
-
"-y", ...window, "-i", input, "-an",
|
|
49
|
-
"-vf", base,
|
|
50
|
-
"-c:v", "libwebp_anim", "-lossless", "0", "-q:v", String(s.quality ?? 75),
|
|
51
|
-
"-compression_level", "4", "-loop", "0",
|
|
52
|
-
output,
|
|
53
|
-
];
|
|
54
|
-
}
|
package/dist/utils/animExport.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { basename, dirname, extname, join } from "node:path";
|
|
2
|
-
import { renameSync, rmSync, statSync } from "node:fs";
|
|
3
|
-
import { runEditJob, probeDuration } from "./jobs.js";
|
|
4
|
-
import { animLadder, nextLadderIndex, buildAnimArgs, DEFAULT_ANIM_FPS, DEFAULT_ANIM_WIDTH, DEFAULT_MAX_BYTES, MAX_ATTEMPTS, } from "./anim.js";
|
|
5
|
-
export async function exportAnimation(input, output, opts, extra) {
|
|
6
|
-
const format = opts.format ?? "gif";
|
|
7
|
-
const maxBytes = opts.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
8
|
-
const full = await probeDuration(input);
|
|
9
|
-
const clipSec = opts.duration ?? (full !== null ? full - (opts.start ?? 0) : null);
|
|
10
|
-
const ladder = animLadder(format, opts.fps ?? DEFAULT_ANIM_FPS, opts.width ?? DEFAULT_ANIM_WIDTH);
|
|
11
|
-
const ext = extname(output);
|
|
12
|
-
const attemptPath = (i) => join(dirname(output), `${basename(output, ext)}.try${i}${ext}`);
|
|
13
|
-
const attempts = [];
|
|
14
|
-
try {
|
|
15
|
-
let index = 0;
|
|
16
|
-
while (index !== null && attempts.length < MAX_ATTEMPTS) {
|
|
17
|
-
const settings = ladder[index];
|
|
18
|
-
if (!settings)
|
|
19
|
-
break;
|
|
20
|
-
const path = attemptPath(attempts.length);
|
|
21
|
-
const clip = { start: opts.start, duration: opts.duration };
|
|
22
|
-
await runEditJob(buildAnimArgs(input, path, format, settings, clip), {
|
|
23
|
-
output: path,
|
|
24
|
-
durationSec: clipSec,
|
|
25
|
-
extra,
|
|
26
|
-
});
|
|
27
|
-
const size = statSync(path).size;
|
|
28
|
-
attempts.push({ path, size, settings });
|
|
29
|
-
if (size <= maxBytes)
|
|
30
|
-
break;
|
|
31
|
-
index = nextLadderIndex(index, size, maxBytes, ladder.length);
|
|
32
|
-
}
|
|
33
|
-
const fits = attempts.find((a) => a.size <= maxBytes);
|
|
34
|
-
const chosen = fits ?? attempts.reduce((a, b) => (b.size < a.size ? b : a));
|
|
35
|
-
renameSync(chosen.path, output);
|
|
36
|
-
return {
|
|
37
|
-
outputPath: output,
|
|
38
|
-
format,
|
|
39
|
-
sizeBytes: chosen.size,
|
|
40
|
-
maxBytes,
|
|
41
|
-
withinBudget: chosen.size <= maxBytes,
|
|
42
|
-
settings: chosen.settings,
|
|
43
|
-
attempts: attempts.map((a) => ({ ...a.settings, sizeBytes: a.size })),
|
|
44
|
-
...(fits
|
|
45
|
-
? {}
|
|
46
|
-
: {
|
|
47
|
-
note: `Could not get under ${maxBytes} bytes; kept the smallest attempt. ` +
|
|
48
|
-
"Export a shorter clip (start/duration), or try format: 'webp'.",
|
|
49
|
-
}),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
finally {
|
|
53
|
-
for (const a of attempts)
|
|
54
|
-
rmSync(a.path, { force: true });
|
|
55
|
-
}
|
|
56
|
-
}
|
package/dist/utils/argPaths.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { assertInputAllowed, assertLocalPath } from "./paths.js";
|
|
2
|
-
const INPUT_KEYS = new Set([
|
|
3
|
-
"input", "inputs", "inputA", "inputB", "clips", "a", "b", "image", "overlay",
|
|
4
|
-
"music", "video", "subtitles", "srt", "transcript", "events",
|
|
5
|
-
]);
|
|
6
|
-
const LOCAL_ONLY_KEYS = new Set(["output", "outputDir", "model", "fontFile"]);
|
|
7
|
-
const KEYWORDS = new Set(["whisper"]);
|
|
8
|
-
function strings(value) {
|
|
9
|
-
if (typeof value === "string")
|
|
10
|
-
return [value];
|
|
11
|
-
if (Array.isArray(value))
|
|
12
|
-
return value.filter((v) => typeof v === "string");
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
export function assertArgPaths(args) {
|
|
16
|
-
const visit = (node) => {
|
|
17
|
-
if (Array.isArray(node)) {
|
|
18
|
-
node.forEach(visit);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (!node || typeof node !== "object")
|
|
22
|
-
return;
|
|
23
|
-
for (const [key, value] of Object.entries(node)) {
|
|
24
|
-
if (INPUT_KEYS.has(key)) {
|
|
25
|
-
for (const s of strings(value)) {
|
|
26
|
-
if (s.trim().length > 0 && !KEYWORDS.has(s))
|
|
27
|
-
assertInputAllowed(s, `Input "${key}"`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else if (LOCAL_ONLY_KEYS.has(key)) {
|
|
31
|
-
for (const s of strings(value))
|
|
32
|
-
assertLocalPath(s, `"${key}"`);
|
|
33
|
-
}
|
|
34
|
-
if (value && typeof value === "object")
|
|
35
|
-
visit(value);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
visit(args);
|
|
39
|
-
}
|
package/dist/utils/audio.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { extname } from "node:path";
|
|
2
|
-
import { ScreencastError } from "./errors.js";
|
|
3
|
-
import { isAudioOnlyPath } from "./media.js";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
export const LOUDNESS_PRESET_NAMES = ["youtube", "podcast", "broadcast"];
|
|
6
|
-
export const loudnessTargetSchema = z.union([z.enum(LOUDNESS_PRESET_NAMES), z.number().min(-70).max(-5)]);
|
|
7
|
-
export const LOUDNESS_PRESETS = {
|
|
8
|
-
youtube: { i: -14, tp: -1, lra: 11 },
|
|
9
|
-
podcast: { i: -16, tp: -1.5, lra: 11 },
|
|
10
|
-
broadcast: { i: -23, tp: -1, lra: 7 },
|
|
11
|
-
};
|
|
12
|
-
export function loudnessTarget(target) {
|
|
13
|
-
if (target === undefined)
|
|
14
|
-
return LOUDNESS_PRESETS.youtube;
|
|
15
|
-
if (typeof target === "number") {
|
|
16
|
-
if (!Number.isFinite(target) || target < -70 || target > -5) {
|
|
17
|
-
throw new ScreencastError("target LUFS must be between -70 and -5 (e.g. -14).");
|
|
18
|
-
}
|
|
19
|
-
return { i: target, tp: -1, lra: 11 };
|
|
20
|
-
}
|
|
21
|
-
const p = LOUDNESS_PRESETS[target];
|
|
22
|
-
if (!p)
|
|
23
|
-
throw new ScreencastError(`Unknown loudness target "${target}".`);
|
|
24
|
-
return p;
|
|
25
|
-
}
|
|
26
|
-
const filterTarget = (t) => `I=${t.i}:TP=${t.tp}:LRA=${t.lra}`;
|
|
27
|
-
export function buildLoudnessMeasureArgs(input, t) {
|
|
28
|
-
return ["-hide_banner", "-nostats", "-i", input, "-vn", "-af", `loudnorm=${filterTarget(t)}:print_format=json`, "-f", "null", "-"];
|
|
29
|
-
}
|
|
30
|
-
export function parseLoudnorm(stderr) {
|
|
31
|
-
const blocks = stderr.match(/\{[^{}]*"input_i"[^{}]*\}/g);
|
|
32
|
-
const lastBlock = blocks?.at(-1);
|
|
33
|
-
if (lastBlock === undefined)
|
|
34
|
-
throw new ScreencastError("Could not measure loudness (no loudnorm report). Does the file have audio?");
|
|
35
|
-
const raw = JSON.parse(lastBlock);
|
|
36
|
-
const num = (k) => Number(raw[k]);
|
|
37
|
-
const m = {
|
|
38
|
-
input_i: num("input_i"),
|
|
39
|
-
input_tp: num("input_tp"),
|
|
40
|
-
input_lra: num("input_lra"),
|
|
41
|
-
input_thresh: num("input_thresh"),
|
|
42
|
-
target_offset: num("target_offset"),
|
|
43
|
-
...(raw.output_i !== undefined ? { output_i: num("output_i") } : {}),
|
|
44
|
-
};
|
|
45
|
-
if (!Number.isFinite(m.input_i)) {
|
|
46
|
-
throw new ScreencastError("The audio is silent (loudness is -inf), so there is nothing to normalize.");
|
|
47
|
-
}
|
|
48
|
-
return m;
|
|
49
|
-
}
|
|
50
|
-
function keepVideoArgs(output) {
|
|
51
|
-
return isAudioOnlyPath(output)
|
|
52
|
-
? ["-map", "0:a:0", "-vn"]
|
|
53
|
-
: ["-map", "0:v?", "-map", "0:a:0", "-c:v", "copy"];
|
|
54
|
-
}
|
|
55
|
-
export function audioCodecFor(output) {
|
|
56
|
-
switch (extname(output).toLowerCase()) {
|
|
57
|
-
case ".wav":
|
|
58
|
-
return ["-c:a", "pcm_s16le"];
|
|
59
|
-
case ".mp3":
|
|
60
|
-
return ["-c:a", "libmp3lame", "-b:a", "192k"];
|
|
61
|
-
default:
|
|
62
|
-
return ["-c:a", "aac", "-b:a", "192k"];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export function loudnormFilter(t, m) {
|
|
66
|
-
if (!m)
|
|
67
|
-
return `loudnorm=${filterTarget(t)}`;
|
|
68
|
-
const measured = `measured_I=${m.input_i}:measured_TP=${m.input_tp}:measured_LRA=${m.input_lra}:` +
|
|
69
|
-
`measured_thresh=${m.input_thresh}:offset=${m.target_offset}`;
|
|
70
|
-
return `loudnorm=${filterTarget(t)}:${measured}:linear=true`;
|
|
71
|
-
}
|
|
72
|
-
export function buildLoudnessApplyArgs(input, output, t, m) {
|
|
73
|
-
return [
|
|
74
|
-
"-y", "-hide_banner", "-i", input,
|
|
75
|
-
...keepVideoArgs(output),
|
|
76
|
-
"-af", `${loudnormFilter(t, m)}:print_format=json`,
|
|
77
|
-
"-ar", "48000",
|
|
78
|
-
...audioCodecFor(output),
|
|
79
|
-
output,
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
export const DENOISE_STRENGTHS = ["light", "medium", "strong"];
|
|
83
|
-
export const DENOISE_NR = { light: 6, medium: 12, strong: 20 };
|
|
84
|
-
export function buildNoiseFloorArgs(input) {
|
|
85
|
-
return [
|
|
86
|
-
"-hide_banner", "-nostats", "-i", input, "-vn",
|
|
87
|
-
"-af", "aresample=48000,asetnsamples=4800,astats=metadata=1:reset=1,ametadata=print:key=lavfi.astats.Overall.RMS_level:file=-",
|
|
88
|
-
"-f", "null", "-",
|
|
89
|
-
];
|
|
90
|
-
}
|
|
91
|
-
export function parseNoiseFloor(stdout) {
|
|
92
|
-
const levels = [...stdout.matchAll(/RMS_level=(-?[\d.]+)/g)].map((m) => Number(m[1])).filter(Number.isFinite);
|
|
93
|
-
if (levels.length === 0)
|
|
94
|
-
return null;
|
|
95
|
-
levels.sort((a, b) => a - b);
|
|
96
|
-
return levels[Math.floor(levels.length * 0.1)] ?? null;
|
|
97
|
-
}
|
|
98
|
-
export function noiseFloorSetting(floorDb) {
|
|
99
|
-
if (floorDb === null)
|
|
100
|
-
return -50;
|
|
101
|
-
return Math.max(-80, Math.min(-20, Math.round(floorDb + 5)));
|
|
102
|
-
}
|
|
103
|
-
export function denoiseFilter(strength, noiseFloorDb) {
|
|
104
|
-
const nr = DENOISE_NR[strength];
|
|
105
|
-
if (nr === undefined)
|
|
106
|
-
throw new ScreencastError(`Unknown denoise strength "${strength}".`);
|
|
107
|
-
return `afftdn=nr=${nr}:nf=${noiseFloorSetting(noiseFloorDb)}`;
|
|
108
|
-
}
|
|
109
|
-
export function buildDenoiseArgs(input, output, strength = "medium", noiseFloorDb = null) {
|
|
110
|
-
return [
|
|
111
|
-
"-y", "-i", input,
|
|
112
|
-
...keepVideoArgs(output),
|
|
113
|
-
"-af", denoiseFilter(strength, noiseFloorDb),
|
|
114
|
-
...audioCodecFor(output),
|
|
115
|
-
output,
|
|
116
|
-
];
|
|
117
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { errorMessage, ScreencastError } from "./errors.js";
|
|
2
|
-
import { requireFfmpeg, runCapture } from "./ffmpeg.js";
|
|
3
|
-
export const LOOPBACK_HINTS = [
|
|
4
|
-
"virtual-audio-capturer",
|
|
5
|
-
"stereo mix",
|
|
6
|
-
"what u hear",
|
|
7
|
-
"wave out mix",
|
|
8
|
-
"cable output",
|
|
9
|
-
"voicemeeter output",
|
|
10
|
-
];
|
|
11
|
-
export const NO_LOOPBACK_HINT = "System audio capture needs a virtual-audio loopback device, which Windows " +
|
|
12
|
-
"does not provide natively. Enable 'Stereo Mix' in Sound settings, or install " +
|
|
13
|
-
"a loopback driver (for example screen-capture-recorder's " +
|
|
14
|
-
"virtual-audio-capturer, or VB-CABLE). Then pass its name as `device`, or run " +
|
|
15
|
-
"list_audio_devices to see what is available. Microphone capture is not supported.";
|
|
16
|
-
export function parseDshowAudioDevices(stderr) {
|
|
17
|
-
return parseDshowDevices(stderr, "audio");
|
|
18
|
-
}
|
|
19
|
-
export function parseDshowVideoDevices(stderr) {
|
|
20
|
-
return parseDshowDevices(stderr, "video");
|
|
21
|
-
}
|
|
22
|
-
function parseDshowDevices(stderr, kind) {
|
|
23
|
-
const names = [];
|
|
24
|
-
let section = null;
|
|
25
|
-
for (const line of stderr.split(/\r?\n/)) {
|
|
26
|
-
if (/DirectShow audio devices/i.test(line)) {
|
|
27
|
-
section = "audio";
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (/DirectShow video devices/i.test(line)) {
|
|
31
|
-
section = "video";
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (/Alternative name/i.test(line))
|
|
35
|
-
continue;
|
|
36
|
-
const quoted = line.match(/"([^"]+)"/);
|
|
37
|
-
if (!quoted)
|
|
38
|
-
continue;
|
|
39
|
-
const inlineAudio = /\(audio\)/i.test(line);
|
|
40
|
-
const inlineVideo = /\(video\)/i.test(line);
|
|
41
|
-
const isAudio = inlineAudio || (!inlineVideo && section === "audio");
|
|
42
|
-
const isVideo = inlineVideo || (!inlineAudio && section === "video");
|
|
43
|
-
if ((kind === "audio" ? isAudio : isVideo) && quoted[1])
|
|
44
|
-
names.push(quoted[1]);
|
|
45
|
-
}
|
|
46
|
-
return [...new Set(names)];
|
|
47
|
-
}
|
|
48
|
-
export function pickLoopbackDevice(devices, explicit) {
|
|
49
|
-
if (explicit && explicit.trim().length > 0) {
|
|
50
|
-
return devices.includes(explicit) ? explicit : null;
|
|
51
|
-
}
|
|
52
|
-
const lower = (s) => s.toLowerCase();
|
|
53
|
-
return (devices.find((d) => LOOPBACK_HINTS.some((h) => lower(d).includes(h))) ?? null);
|
|
54
|
-
}
|
|
55
|
-
export const ENUM_TIMEOUT_MS = 12_000;
|
|
56
|
-
const ENUM_FAILED_HINT = "Enumerating DirectShow audio devices timed out or failed - usually a " +
|
|
57
|
-
"misbehaving audio driver, or no audio device present. Record without system " +
|
|
58
|
-
"audio, or fix the device, then retry. " + NO_LOOPBACK_HINT;
|
|
59
|
-
let cachedDevices = null;
|
|
60
|
-
let cachedVideo = null;
|
|
61
|
-
export async function listDshowAudioDevices(forceRefresh = false) {
|
|
62
|
-
if (!forceRefresh && cachedDevices)
|
|
63
|
-
return cachedDevices;
|
|
64
|
-
await enumerateDshow();
|
|
65
|
-
return cachedDevices ?? [];
|
|
66
|
-
}
|
|
67
|
-
export async function listDshowVideoDevices(forceRefresh = false) {
|
|
68
|
-
if (!forceRefresh && cachedVideo)
|
|
69
|
-
return cachedVideo;
|
|
70
|
-
await enumerateDshow();
|
|
71
|
-
return cachedVideo ?? [];
|
|
72
|
-
}
|
|
73
|
-
export async function resolveVideoDevice(explicit) {
|
|
74
|
-
const devices = await listDshowVideoDevices();
|
|
75
|
-
if (explicit && explicit.trim().length > 0) {
|
|
76
|
-
if (devices.includes(explicit))
|
|
77
|
-
return explicit;
|
|
78
|
-
throw new ScreencastError(`Video device "${explicit}" not found. Available dshow video devices: ${devices.join(", ") || "none"}.`);
|
|
79
|
-
}
|
|
80
|
-
const first = devices[0];
|
|
81
|
-
if (!first)
|
|
82
|
-
throw new ScreencastError("No webcam (dshow video device) found.", "Connect a camera, then run list_video_devices.");
|
|
83
|
-
return first;
|
|
84
|
-
}
|
|
85
|
-
async function enumerateDshow() {
|
|
86
|
-
const { ffmpeg } = requireFfmpeg();
|
|
87
|
-
let res;
|
|
88
|
-
try {
|
|
89
|
-
res = await runCapture(ffmpeg, ["-hide_banner", "-list_devices", "true", "-f", "dshow", "-i", "dummy"], ENUM_TIMEOUT_MS, { closeStdin: true });
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
throw new ScreencastError(`Could not enumerate audio devices (${errorMessage(err)}).`, ENUM_FAILED_HINT);
|
|
93
|
-
}
|
|
94
|
-
cachedDevices = parseDshowAudioDevices(res.stderr);
|
|
95
|
-
cachedVideo = parseDshowVideoDevices(res.stderr);
|
|
96
|
-
}
|
|
97
|
-
export async function resolveLoopbackDevice(explicit) {
|
|
98
|
-
const devices = await listDshowAudioDevices();
|
|
99
|
-
const picked = pickLoopbackDevice(devices, explicit);
|
|
100
|
-
if (picked)
|
|
101
|
-
return picked;
|
|
102
|
-
if (explicit && explicit.trim().length > 0) {
|
|
103
|
-
const available = devices.length > 0 ? devices.join(", ") : "none";
|
|
104
|
-
throw new ScreencastError(`Audio device "${explicit}" not found. Available dshow audio devices: ${available}.`, NO_LOOPBACK_HINT);
|
|
105
|
-
}
|
|
106
|
-
throw new ScreencastError("No system-audio loopback device found.", NO_LOOPBACK_HINT);
|
|
107
|
-
}
|
package/dist/utils/backdrop.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { ScreencastError } from "./errors.js";
|
|
2
|
-
import { validateColor } from "./validate.js";
|
|
3
|
-
import { ASPECT_DIMS, ASPECTS } from "./produce.js";
|
|
4
|
-
import { resolveQuality } from "./targets.js";
|
|
5
|
-
import { stillOutput } from "./paths.js";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
export const BACKDROP_PRESETS = {
|
|
8
|
-
desktop: ["#1B2330", "#0A0D12"],
|
|
9
|
-
rec: ["#FF4545", "#5C0F1A"],
|
|
10
|
-
amber: ["#FFB454", "#FF4545"],
|
|
11
|
-
light: ["#F4F7FA", "#B9C4D0"],
|
|
12
|
-
};
|
|
13
|
-
export const BACKDROP_PRESET_NAMES = Object.keys(BACKDROP_PRESETS);
|
|
14
|
-
export const DEFAULT_BACKDROP_PRESET = "desktop";
|
|
15
|
-
export const MAX_BACKDROP_COLORS = 4;
|
|
16
|
-
export const DEFAULT_SHADOW_OPACITY = 0.5;
|
|
17
|
-
const even = (n) => 2 * Math.round(n / 2);
|
|
18
|
-
const evenDown = (n) => 2 * Math.floor(n / 2);
|
|
19
|
-
function nonNegInt(v, label, max) {
|
|
20
|
-
if (v === undefined)
|
|
21
|
-
return undefined;
|
|
22
|
-
if (!Number.isFinite(v) || v < 0 || v > max)
|
|
23
|
-
throw new ScreencastError(`${label} must be between 0 and ${max}.`);
|
|
24
|
-
return Math.round(v);
|
|
25
|
-
}
|
|
26
|
-
export function backdropLayout(W, H, opts = {}) {
|
|
27
|
-
if (!(W > 0 && H > 0))
|
|
28
|
-
throw new ScreencastError("The input has no frame size.");
|
|
29
|
-
const padOpt = nonNegInt(opts.padding, "padding", 2000);
|
|
30
|
-
const radiusOpt = nonNegInt(opts.radius, "radius", 1000);
|
|
31
|
-
const shadowOpt = nonNegInt(opts.shadow, "shadow", 200);
|
|
32
|
-
let canvasW;
|
|
33
|
-
let canvasH;
|
|
34
|
-
let contentW = W;
|
|
35
|
-
let contentH = H;
|
|
36
|
-
let x;
|
|
37
|
-
let y;
|
|
38
|
-
let padding;
|
|
39
|
-
let scaled = false;
|
|
40
|
-
if (opts.aspect) {
|
|
41
|
-
const dim = ASPECT_DIMS[opts.aspect];
|
|
42
|
-
if (!dim)
|
|
43
|
-
throw new ScreencastError(`Unknown aspect "${opts.aspect}".`);
|
|
44
|
-
canvasW = dim.w;
|
|
45
|
-
canvasH = dim.h;
|
|
46
|
-
padding = even(padOpt ?? Math.max(canvasW, canvasH) * 0.06);
|
|
47
|
-
const availW = canvasW - 2 * padding;
|
|
48
|
-
const availH = canvasH - 2 * padding;
|
|
49
|
-
if (availW < 16 || availH < 16)
|
|
50
|
-
throw new ScreencastError(`padding ${padding} leaves no room on a ${opts.aspect} canvas.`);
|
|
51
|
-
const s = Math.min(availW / W, availH / H);
|
|
52
|
-
contentW = Math.max(2, evenDown(W * s));
|
|
53
|
-
contentH = Math.max(2, evenDown(H * s));
|
|
54
|
-
scaled = contentW !== W || contentH !== H;
|
|
55
|
-
x = evenDown((canvasW - contentW) / 2);
|
|
56
|
-
y = evenDown((canvasH - contentH) / 2);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
padding = even(padOpt ?? Math.max(W, H) * 0.06);
|
|
60
|
-
canvasW = W + 2 * padding + (W % 2);
|
|
61
|
-
canvasH = H + 2 * padding + (H % 2);
|
|
62
|
-
x = padding;
|
|
63
|
-
y = padding;
|
|
64
|
-
}
|
|
65
|
-
const longer = Math.max(contentW, contentH);
|
|
66
|
-
const radius = Math.min(radiusOpt ?? Math.round(longer * 0.012), Math.floor(Math.min(contentW, contentH) / 2));
|
|
67
|
-
const shadow = shadowOpt ?? Math.round(longer * 0.025);
|
|
68
|
-
const below = canvasH - y - contentH;
|
|
69
|
-
const shadowOffset = shadow > 0 ? Math.max(0, Math.min(Math.round(shadow / 2), below)) : 0;
|
|
70
|
-
return { canvasW, canvasH, contentW, contentH, x, y, padding, radius, shadow, shadowOffset, scaled };
|
|
71
|
-
}
|
|
72
|
-
export function backdropColors(opts) {
|
|
73
|
-
if (opts.colors !== undefined) {
|
|
74
|
-
if (opts.colors.length < 1 || opts.colors.length > MAX_BACKDROP_COLORS) {
|
|
75
|
-
throw new ScreencastError(`colors takes 1 to ${MAX_BACKDROP_COLORS} colors.`);
|
|
76
|
-
}
|
|
77
|
-
return opts.colors.map((c, i) => validateColor(c, `colors[${i}]`));
|
|
78
|
-
}
|
|
79
|
-
const preset = opts.preset ?? DEFAULT_BACKDROP_PRESET;
|
|
80
|
-
const colors = BACKDROP_PRESETS[preset];
|
|
81
|
-
if (!colors)
|
|
82
|
-
throw new ScreencastError(`Unknown backdrop preset "${preset}".`);
|
|
83
|
-
return [...colors];
|
|
84
|
-
}
|
|
85
|
-
export function roundedMaskExpr(radius, invert = false) {
|
|
86
|
-
const r = radius;
|
|
87
|
-
const dx = `max(max(${r}-X-0.5,X+0.5-(W-${r})),0)`;
|
|
88
|
-
const dy = `max(max(${r}-Y-0.5,Y+0.5-(H-${r})),0)`;
|
|
89
|
-
const inside = `clip(${r}+0.5-hypot(${dx},${dy}),0,1)`;
|
|
90
|
-
return invert ? `255-255*${inside}` : `255*${inside}`;
|
|
91
|
-
}
|
|
92
|
-
export function backdropSteps(opts, src, input, firstInput, tag, still = false) {
|
|
93
|
-
const L = backdropLayout(src.width, src.height, opts);
|
|
94
|
-
if (opts.shadowOpacity !== undefined && !(opts.shadowOpacity >= 0 && opts.shadowOpacity <= 1)) {
|
|
95
|
-
throw new ScreencastError("shadowOpacity must be between 0 and 1.");
|
|
96
|
-
}
|
|
97
|
-
const opacity = opts.shadowOpacity ?? DEFAULT_SHADOW_OPACITY;
|
|
98
|
-
const { canvasW: CW, canvasH: CH, contentW: w, contentH: h, x, y } = L;
|
|
99
|
-
const one = ":r=1:d=1";
|
|
100
|
-
const steps = [];
|
|
101
|
-
const extraInputs = [];
|
|
102
|
-
const bg = `[${tag}bg]`;
|
|
103
|
-
if (opts.image) {
|
|
104
|
-
extraInputs.push("-i", opts.image);
|
|
105
|
-
steps.push(`[${firstInput}:v]scale=${CW}:${CH}:force_original_aspect_ratio=increase,crop=${CW}:${CH},setsar=1,trim=end_frame=1,format=rgba${bg}`);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
const colors = backdropColors(opts);
|
|
109
|
-
if (colors.length === 1) {
|
|
110
|
-
steps.push(`color=c=${colors[0]}:s=${CW}x${CH}${one},format=rgba${bg}`);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
const cs = colors.map((c, i) => `c${i}=${c}`).join(":");
|
|
114
|
-
steps.push(`gradients=s=${CW}x${CH}:${cs}:n=${colors.length}:x0=0:y0=0:x1=${CW}:y1=${CH}:r=1,trim=end_frame=1,format=rgba${bg}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
let base = bg;
|
|
118
|
-
if (L.shadow > 0 && opacity > 0) {
|
|
119
|
-
const sa = `[${tag}sa]`;
|
|
120
|
-
const sc = `[${tag}sc]`;
|
|
121
|
-
const sh = `[${tag}sh]`;
|
|
122
|
-
const bs = `[${tag}bs]`;
|
|
123
|
-
const shape = L.radius > 0 ? `format=gray,geq=lum='${roundedMaskExpr(L.radius)}'` : "format=gray";
|
|
124
|
-
steps.push(`color=c=white:s=${w}x${h}${one},${shape},pad=${CW}:${CH}:${x}:${y + L.shadowOffset}:color=black,` +
|
|
125
|
-
`gblur=sigma=${(L.shadow / 2).toFixed(2)}${sa}`);
|
|
126
|
-
steps.push(`color=c=black:s=${CW}x${CH}${one}${sc}`);
|
|
127
|
-
steps.push(`${sc}${sa}alphamerge,format=rgba,colorchannelmixer=aa=${opacity}${sh}`);
|
|
128
|
-
steps.push(`${base}${sh}overlay=0:0:format=rgb${bs}`);
|
|
129
|
-
base = bs;
|
|
130
|
-
}
|
|
131
|
-
const hole = `[${tag}hole]`;
|
|
132
|
-
const frame = `[${tag}frame]`;
|
|
133
|
-
const holeShape = L.radius > 0 ? `format=gray,geq=lum='${roundedMaskExpr(L.radius, true)}'` : "format=gray";
|
|
134
|
-
steps.push(`color=c=black:s=${w}x${h}${one},${holeShape},pad=${CW}:${CH}:${x}:${y}:color=white${hole}`);
|
|
135
|
-
steps.push(`${base}${hole}alphamerge,format=rgba${frame}`);
|
|
136
|
-
const padded = `[${tag}pad]`;
|
|
137
|
-
const out = `[${tag}bd]`;
|
|
138
|
-
const fit = L.scaled ? `scale=${w}:${h},setsar=1,` : "";
|
|
139
|
-
steps.push(`${input}${fit}pad=${CW}:${CH}:${x}:${y}:color=black${padded}`);
|
|
140
|
-
steps.push(`${padded}${frame}overlay=0:0${still ? ":format=rgb" : ""}${out}`);
|
|
141
|
-
return { steps, out, extraInputs, layout: L };
|
|
142
|
-
}
|
|
143
|
-
export function buildBackdropArgs(input, output, opts, src, still = false, quality = "standard") {
|
|
144
|
-
const { steps, out, extraInputs, layout } = backdropSteps(opts, src, "[0:v]", 1, "", still);
|
|
145
|
-
const final = "[vout]";
|
|
146
|
-
steps.push(`${out}format=${still ? "rgb24" : "yuv420p"}${final}`);
|
|
147
|
-
const head = ["-y", "-i", input, ...extraInputs, "-filter_complex", steps.join(";"), "-map", final];
|
|
148
|
-
const args = still
|
|
149
|
-
? [...head, "-frames:v", "1", ...stillOutput(output)]
|
|
150
|
-
: [...head, "-map", "0:a?", ...resolveQuality(quality), "-c:a", "copy", "-movflags", "+faststart", output];
|
|
151
|
-
return { args, layout };
|
|
152
|
-
}
|
|
153
|
-
export const backdropOptionsSchema = {
|
|
154
|
-
preset: z.enum(BACKDROP_PRESET_NAMES).optional(),
|
|
155
|
-
colors: z.array(z.string()).min(1).max(MAX_BACKDROP_COLORS).optional(),
|
|
156
|
-
image: z.string().min(1).optional(),
|
|
157
|
-
padding: z.number().int().nonnegative().max(2000).optional(),
|
|
158
|
-
radius: z.number().int().nonnegative().max(1000).optional(),
|
|
159
|
-
shadow: z.number().int().nonnegative().max(200).optional(),
|
|
160
|
-
shadowOpacity: z.number().min(0).max(1).optional(),
|
|
161
|
-
aspect: z.enum(ASPECTS).optional(),
|
|
162
|
-
};
|