@tmhs/screencast-mcp 0.39.0 → 0.45.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 +95 -17
- package/assets/icon.png +0 -0
- package/assets/ui/player.html +47 -302
- package/assets/ui/player.js +402 -0
- package/dist/context.js +0 -5
- package/dist/index.js +17 -21
- package/dist/prompts.js +18 -8
- package/dist/resources.js +2 -14
- package/dist/server.js +49 -11
- package/dist/tools/addMarker.js +89 -0
- package/dist/tools/assembleHighlights.js +12 -7
- package/dist/tools/backdrop.js +89 -0
- package/dist/tools/bugReport.js +266 -0
- package/dist/tools/burnSubtitles.js +12 -6
- package/dist/tools/callout.js +32 -16
- package/dist/tools/chapters.js +156 -0
- package/dist/tools/clip.js +12 -9
- package/dist/tools/compress.js +10 -5
- package/dist/tools/concat.js +16 -15
- package/dist/tools/contactSheet.js +39 -33
- package/dist/tools/convert.js +12 -6
- package/dist/tools/crop.js +12 -7
- package/dist/tools/cutIdle.js +15 -9
- package/dist/tools/denoise.js +12 -6
- package/dist/tools/doctor.js +133 -0
- package/dist/tools/exportGif.js +14 -10
- package/dist/tools/exportPreset.js +11 -8
- package/dist/tools/extractAudio.js +10 -8
- package/dist/tools/findText.js +52 -98
- package/dist/tools/getMediaInfo.js +17 -3
- package/dist/tools/getSession.js +15 -3
- package/dist/tools/keystrokeOverlay.js +131 -0
- package/dist/tools/listAudioDevices.js +14 -7
- package/dist/tools/listSessions.js +13 -3
- package/dist/tools/listTargets.js +76 -0
- package/dist/tools/musicBed.js +14 -10
- package/dist/tools/normalizeAudio.js +12 -8
- package/dist/tools/overlay.js +16 -12
- package/dist/tools/pipeline.js +86 -25
- package/dist/tools/readEvents.js +21 -12
- package/dist/tools/redactRegion.js +19 -17
- package/dist/tools/reframe.js +9 -5
- package/dist/tools/reviewRecording.js +75 -22
- package/dist/tools/sampleFrames.js +33 -40
- package/dist/tools/saveReplay.js +90 -0
- package/dist/tools/scale.js +9 -3
- package/dist/tools/screenDiff.js +23 -17
- package/dist/tools/screenshot.js +21 -17
- package/dist/tools/speed.js +15 -4
- package/dist/tools/startRecording.js +96 -59
- package/dist/tools/stopRecording.js +35 -10
- package/dist/tools/titleCard.js +19 -11
- package/dist/tools/transcribe.js +13 -7
- package/dist/tools/trim.js +11 -10
- package/dist/tools/waitForChange.js +37 -22
- package/dist/tools/xfadeTransition.js +12 -8
- package/dist/tools/zoom.js +26 -29
- package/dist/utils/anim.js +1 -21
- package/dist/utils/animExport.js +5 -10
- package/dist/utils/audio.js +4 -33
- package/dist/utils/audioDevices.js +1 -48
- package/dist/utils/backdrop.js +151 -0
- package/dist/utils/bugReport.js +246 -0
- package/dist/utils/callout.js +1 -19
- package/dist/utils/calloutAssets.js +21 -11
- package/dist/utils/capabilities.js +95 -0
- package/dist/utils/captions.js +9 -26
- package/dist/utils/chapters.js +222 -0
- package/dist/utils/consent.js +29 -0
- package/dist/utils/diff.js +0 -46
- package/dist/utils/errors.js +5 -13
- package/dist/utils/events.js +21 -77
- package/dist/utils/expr.js +11 -0
- package/dist/utils/ffmpeg.js +119 -48
- package/dist/utils/fontCoverage.js +177 -0
- package/dist/utils/fonts.js +139 -23
- package/dist/utils/idle.js +12 -24
- package/dist/utils/images.js +0 -17
- package/dist/utils/jobs.js +42 -41
- package/dist/utils/keystrokes.js +170 -0
- package/dist/utils/lifecycle.js +11 -31
- package/dist/utils/logging.js +75 -0
- package/dist/utils/media.js +16 -124
- package/dist/utils/monitors.js +7 -43
- package/dist/utils/ocr.js +53 -71
- package/dist/utils/ocrScan.js +77 -0
- package/dist/utils/paths.js +68 -31
- package/dist/utils/pipeline.js +39 -25
- package/dist/utils/player.js +50 -27
- package/dist/utils/produce.js +6 -66
- package/dist/utils/replay.js +278 -0
- package/dist/utils/resolveTarget.js +0 -19
- package/dist/utils/retention.js +1 -15
- package/dist/utils/roots.js +42 -0
- package/dist/utils/sessions.js +195 -160
- package/dist/utils/sheet.js +0 -19
- package/dist/utils/still.js +0 -15
- package/dist/utils/targetList.js +63 -0
- package/dist/utils/targets.js +5 -70
- package/dist/utils/toolSpec.js +25 -0
- package/dist/utils/toolsets.js +122 -0
- package/dist/utils/validate.js +0 -22
- package/dist/utils/wgc.js +0 -46
- package/dist/utils/windows.js +5 -50
- package/dist/utils/zoom.js +55 -85
- package/dist/wgcRecorder.js +1 -30
- package/package.json +7 -3
- package/dist/context.d.ts +0 -9
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/prompts.d.ts +0 -10
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js.map +0 -1
- package/dist/resources.d.ts +0 -3
- package/dist/resources.d.ts.map +0 -1
- package/dist/resources.js.map +0 -1
- package/dist/server.d.ts +0 -3
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/tools/assembleHighlights.d.ts +0 -3
- package/dist/tools/assembleHighlights.d.ts.map +0 -1
- package/dist/tools/assembleHighlights.js.map +0 -1
- package/dist/tools/burnSubtitles.d.ts +0 -3
- package/dist/tools/burnSubtitles.d.ts.map +0 -1
- package/dist/tools/burnSubtitles.js.map +0 -1
- package/dist/tools/callout.d.ts +0 -37
- package/dist/tools/callout.d.ts.map +0 -1
- package/dist/tools/callout.js.map +0 -1
- package/dist/tools/clip.d.ts +0 -3
- package/dist/tools/clip.d.ts.map +0 -1
- package/dist/tools/clip.js.map +0 -1
- package/dist/tools/compress.d.ts +0 -3
- package/dist/tools/compress.d.ts.map +0 -1
- package/dist/tools/compress.js.map +0 -1
- package/dist/tools/concat.d.ts +0 -3
- package/dist/tools/concat.d.ts.map +0 -1
- package/dist/tools/concat.js.map +0 -1
- package/dist/tools/contactSheet.d.ts +0 -3
- package/dist/tools/contactSheet.d.ts.map +0 -1
- package/dist/tools/contactSheet.js.map +0 -1
- package/dist/tools/convert.d.ts +0 -3
- package/dist/tools/convert.d.ts.map +0 -1
- package/dist/tools/convert.js.map +0 -1
- package/dist/tools/crop.d.ts +0 -3
- package/dist/tools/crop.d.ts.map +0 -1
- package/dist/tools/crop.js.map +0 -1
- package/dist/tools/cutIdle.d.ts +0 -3
- package/dist/tools/cutIdle.d.ts.map +0 -1
- package/dist/tools/cutIdle.js.map +0 -1
- package/dist/tools/denoise.d.ts +0 -3
- package/dist/tools/denoise.d.ts.map +0 -1
- package/dist/tools/denoise.js.map +0 -1
- package/dist/tools/exportGif.d.ts +0 -3
- package/dist/tools/exportGif.d.ts.map +0 -1
- package/dist/tools/exportGif.js.map +0 -1
- package/dist/tools/exportPreset.d.ts +0 -3
- package/dist/tools/exportPreset.d.ts.map +0 -1
- package/dist/tools/exportPreset.js.map +0 -1
- package/dist/tools/extractAudio.d.ts +0 -3
- package/dist/tools/extractAudio.d.ts.map +0 -1
- package/dist/tools/extractAudio.js.map +0 -1
- package/dist/tools/findText.d.ts +0 -6
- package/dist/tools/findText.d.ts.map +0 -1
- package/dist/tools/findText.js.map +0 -1
- package/dist/tools/getMediaInfo.d.ts +0 -3
- package/dist/tools/getMediaInfo.d.ts.map +0 -1
- package/dist/tools/getMediaInfo.js.map +0 -1
- package/dist/tools/getSession.d.ts +0 -3
- package/dist/tools/getSession.d.ts.map +0 -1
- package/dist/tools/getSession.js.map +0 -1
- package/dist/tools/listAudioDevices.d.ts +0 -3
- package/dist/tools/listAudioDevices.d.ts.map +0 -1
- package/dist/tools/listAudioDevices.js.map +0 -1
- package/dist/tools/listSessions.d.ts +0 -3
- package/dist/tools/listSessions.d.ts.map +0 -1
- package/dist/tools/listSessions.js.map +0 -1
- package/dist/tools/musicBed.d.ts +0 -3
- package/dist/tools/musicBed.d.ts.map +0 -1
- package/dist/tools/musicBed.js.map +0 -1
- package/dist/tools/normalizeAudio.d.ts +0 -3
- package/dist/tools/normalizeAudio.d.ts.map +0 -1
- package/dist/tools/normalizeAudio.js.map +0 -1
- package/dist/tools/overlay.d.ts +0 -3
- package/dist/tools/overlay.d.ts.map +0 -1
- package/dist/tools/overlay.js.map +0 -1
- package/dist/tools/pipeline.d.ts +0 -3
- package/dist/tools/pipeline.d.ts.map +0 -1
- package/dist/tools/pipeline.js.map +0 -1
- package/dist/tools/readEvents.d.ts +0 -6
- package/dist/tools/readEvents.d.ts.map +0 -1
- package/dist/tools/readEvents.js.map +0 -1
- package/dist/tools/redactRegion.d.ts +0 -13
- package/dist/tools/redactRegion.d.ts.map +0 -1
- package/dist/tools/redactRegion.js.map +0 -1
- package/dist/tools/reframe.d.ts +0 -3
- package/dist/tools/reframe.d.ts.map +0 -1
- package/dist/tools/reframe.js.map +0 -1
- package/dist/tools/reviewRecording.d.ts +0 -5
- package/dist/tools/reviewRecording.d.ts.map +0 -1
- package/dist/tools/reviewRecording.js.map +0 -1
- package/dist/tools/sampleFrames.d.ts +0 -3
- package/dist/tools/sampleFrames.d.ts.map +0 -1
- package/dist/tools/sampleFrames.js.map +0 -1
- package/dist/tools/scale.d.ts +0 -3
- package/dist/tools/scale.d.ts.map +0 -1
- package/dist/tools/scale.js.map +0 -1
- package/dist/tools/screenDiff.d.ts +0 -3
- package/dist/tools/screenDiff.d.ts.map +0 -1
- package/dist/tools/screenDiff.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -3
- package/dist/tools/screenshot.d.ts.map +0 -1
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/speed.d.ts +0 -3
- package/dist/tools/speed.d.ts.map +0 -1
- package/dist/tools/speed.js.map +0 -1
- package/dist/tools/startRecording.d.ts +0 -3
- package/dist/tools/startRecording.d.ts.map +0 -1
- package/dist/tools/startRecording.js.map +0 -1
- package/dist/tools/stopRecording.d.ts +0 -3
- package/dist/tools/stopRecording.d.ts.map +0 -1
- package/dist/tools/stopRecording.js.map +0 -1
- package/dist/tools/titleCard.d.ts +0 -3
- package/dist/tools/titleCard.d.ts.map +0 -1
- package/dist/tools/titleCard.js.map +0 -1
- package/dist/tools/transcribe.d.ts +0 -3
- package/dist/tools/transcribe.d.ts.map +0 -1
- package/dist/tools/transcribe.js.map +0 -1
- package/dist/tools/trim.d.ts +0 -3
- package/dist/tools/trim.d.ts.map +0 -1
- package/dist/tools/trim.js.map +0 -1
- package/dist/tools/waitForChange.d.ts +0 -3
- package/dist/tools/waitForChange.d.ts.map +0 -1
- package/dist/tools/waitForChange.js.map +0 -1
- package/dist/tools/xfadeTransition.d.ts +0 -3
- package/dist/tools/xfadeTransition.d.ts.map +0 -1
- package/dist/tools/xfadeTransition.js.map +0 -1
- package/dist/tools/zoom.d.ts +0 -15
- package/dist/tools/zoom.d.ts.map +0 -1
- package/dist/tools/zoom.js.map +0 -1
- package/dist/utils/anim.d.ts +0 -33
- package/dist/utils/anim.d.ts.map +0 -1
- package/dist/utils/anim.js.map +0 -1
- package/dist/utils/animExport.d.ts +0 -27
- package/dist/utils/animExport.d.ts.map +0 -1
- package/dist/utils/animExport.js.map +0 -1
- package/dist/utils/audio.d.ts +0 -49
- package/dist/utils/audio.d.ts.map +0 -1
- package/dist/utils/audio.js.map +0 -1
- package/dist/utils/audioDevices.d.ts +0 -33
- package/dist/utils/audioDevices.d.ts.map +0 -1
- package/dist/utils/audioDevices.js.map +0 -1
- package/dist/utils/callout.d.ts +0 -72
- package/dist/utils/callout.d.ts.map +0 -1
- package/dist/utils/callout.js.map +0 -1
- package/dist/utils/calloutAssets.d.ts +0 -3
- package/dist/utils/calloutAssets.d.ts.map +0 -1
- package/dist/utils/calloutAssets.js.map +0 -1
- package/dist/utils/captions.d.ts +0 -26
- package/dist/utils/captions.d.ts.map +0 -1
- package/dist/utils/captions.js.map +0 -1
- package/dist/utils/diff.d.ts +0 -112
- package/dist/utils/diff.d.ts.map +0 -1
- package/dist/utils/diff.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -33
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/events.d.ts +0 -143
- package/dist/utils/events.d.ts.map +0 -1
- package/dist/utils/events.js.map +0 -1
- package/dist/utils/ffmpeg.d.ts +0 -50
- package/dist/utils/ffmpeg.d.ts.map +0 -1
- package/dist/utils/ffmpeg.js.map +0 -1
- package/dist/utils/fonts.d.ts +0 -17
- package/dist/utils/fonts.d.ts.map +0 -1
- package/dist/utils/fonts.js.map +0 -1
- package/dist/utils/idle.d.ts +0 -23
- package/dist/utils/idle.d.ts.map +0 -1
- package/dist/utils/idle.js.map +0 -1
- package/dist/utils/images.d.ts +0 -21
- package/dist/utils/images.d.ts.map +0 -1
- package/dist/utils/images.js.map +0 -1
- package/dist/utils/jobs.d.ts +0 -44
- package/dist/utils/jobs.d.ts.map +0 -1
- package/dist/utils/jobs.js.map +0 -1
- package/dist/utils/lifecycle.d.ts +0 -29
- package/dist/utils/lifecycle.d.ts.map +0 -1
- package/dist/utils/lifecycle.js.map +0 -1
- package/dist/utils/media.d.ts +0 -272
- package/dist/utils/media.d.ts.map +0 -1
- package/dist/utils/media.js.map +0 -1
- package/dist/utils/monitors.d.ts +0 -47
- package/dist/utils/monitors.d.ts.map +0 -1
- package/dist/utils/monitors.js.map +0 -1
- package/dist/utils/ocr.d.ts +0 -50
- package/dist/utils/ocr.d.ts.map +0 -1
- package/dist/utils/ocr.js.map +0 -1
- package/dist/utils/paths.d.ts +0 -28
- package/dist/utils/paths.d.ts.map +0 -1
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/pipeline.d.ts +0 -69
- package/dist/utils/pipeline.d.ts.map +0 -1
- package/dist/utils/pipeline.js.map +0 -1
- package/dist/utils/player.d.ts +0 -30
- package/dist/utils/player.d.ts.map +0 -1
- package/dist/utils/player.js.map +0 -1
- package/dist/utils/produce.d.ts +0 -126
- package/dist/utils/produce.d.ts.map +0 -1
- package/dist/utils/produce.js.map +0 -1
- package/dist/utils/resolveTarget.d.ts +0 -32
- package/dist/utils/resolveTarget.d.ts.map +0 -1
- package/dist/utils/resolveTarget.js.map +0 -1
- package/dist/utils/retention.d.ts +0 -10
- package/dist/utils/retention.d.ts.map +0 -1
- package/dist/utils/retention.js.map +0 -1
- package/dist/utils/sessions.d.ts +0 -154
- package/dist/utils/sessions.d.ts.map +0 -1
- package/dist/utils/sessions.js.map +0 -1
- package/dist/utils/sheet.d.ts +0 -26
- package/dist/utils/sheet.d.ts.map +0 -1
- package/dist/utils/sheet.js.map +0 -1
- package/dist/utils/still.d.ts +0 -7
- package/dist/utils/still.d.ts.map +0 -1
- package/dist/utils/still.js.map +0 -1
- package/dist/utils/targets.d.ts +0 -113
- package/dist/utils/targets.d.ts.map +0 -1
- package/dist/utils/targets.js.map +0 -1
- package/dist/utils/validate.d.ts +0 -15
- package/dist/utils/validate.d.ts.map +0 -1
- package/dist/utils/validate.js.map +0 -1
- package/dist/utils/wgc.d.ts +0 -46
- package/dist/utils/wgc.d.ts.map +0 -1
- package/dist/utils/wgc.js.map +0 -1
- package/dist/utils/windows.d.ts +0 -94
- package/dist/utils/windows.d.ts.map +0 -1
- package/dist/utils/windows.js.map +0 -1
- package/dist/utils/zoom.d.ts +0 -95
- package/dist/utils/zoom.d.ts.map +0 -1
- package/dist/utils/zoom.js.map +0 -1
- package/dist/wgcRecorder.d.ts +0 -2
- package/dist/wgcRecorder.d.ts.map +0 -1
- package/dist/wgcRecorder.js.map +0 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { errorResponse, okResponse } from "../utils/errors.js";
|
|
3
|
+
import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
|
|
3
4
|
import { requireFfmpeg, runFfmpeg, runFfmpegBuffer } from "../utils/ffmpeg.js";
|
|
4
5
|
import { resolveCaptureTarget } from "../utils/resolveTarget.js";
|
|
5
6
|
import { buildScreenshotArgs } from "../utils/targets.js";
|
|
6
7
|
import { detectionSize, targetSize, diffFrames, buildRawGrabArgs, SettleTracker, targetDiffOptions, DEFAULT_PIXEL_THRESHOLD, } from "../utils/diff.js";
|
|
7
8
|
import { windowMatchReport } from "../utils/windows.js";
|
|
9
|
+
import { confirmCapture, describeTarget } from "../utils/consent.js";
|
|
8
10
|
import { subdir, stamp, rand } from "../utils/paths.js";
|
|
9
11
|
import { join } from "node:path";
|
|
10
12
|
import { rmSync } from "node:fs";
|
|
@@ -13,66 +15,73 @@ import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js"
|
|
|
13
15
|
const inputSchema = {
|
|
14
16
|
target: z
|
|
15
17
|
.string()
|
|
16
|
-
.describe("What to watch:
|
|
17
|
-
exactTitle: z.boolean().optional().describe("
|
|
18
|
+
.describe("What to watch: full | monitor:<i> | window:<title> (or exe=/hwnd=) | region:<x>,<y>,<w>,<h>."),
|
|
19
|
+
exactTitle: z.boolean().optional().describe("window: targets match the whole title only (default false)."),
|
|
18
20
|
mode: z
|
|
19
21
|
.enum(["change", "settle"])
|
|
20
22
|
.optional()
|
|
21
|
-
.describe("
|
|
22
|
-
"(a dialog opened, a page responded). 'settle' returns once the target has stopped " +
|
|
23
|
-
"changing for settleSec (a build finished, a page finished loading)."),
|
|
23
|
+
.describe("change (default): return once it differs from the start. settle: once it has been still for settleSec."),
|
|
24
24
|
timeoutSec: z
|
|
25
25
|
.number()
|
|
26
26
|
.positive()
|
|
27
27
|
.max(600)
|
|
28
28
|
.optional()
|
|
29
|
-
.describe("Give up after this many seconds (default 30
|
|
29
|
+
.describe("Give up after this many seconds (default 30; a timeout is a result, not an error)."),
|
|
30
30
|
settleSec: z
|
|
31
31
|
.number()
|
|
32
32
|
.positive()
|
|
33
33
|
.max(60)
|
|
34
34
|
.optional()
|
|
35
|
-
.describe("Mode
|
|
35
|
+
.describe("Mode settle: seconds of stillness (default 1)."),
|
|
36
36
|
intervalMs: z
|
|
37
37
|
.number()
|
|
38
38
|
.int()
|
|
39
39
|
.min(100)
|
|
40
40
|
.max(5000)
|
|
41
41
|
.optional()
|
|
42
|
-
.describe("Pause between checks in ms (default 250)
|
|
42
|
+
.describe("Pause between checks in ms (default 250)."),
|
|
43
43
|
pixelThreshold: z
|
|
44
44
|
.number()
|
|
45
45
|
.min(0)
|
|
46
46
|
.max(255)
|
|
47
47
|
.optional()
|
|
48
|
-
.describe(`
|
|
49
|
-
`(default ${DEFAULT_PIXEL_THRESHOLD}: catches a changed label or a toast).`),
|
|
48
|
+
.describe(`Mean 0-255 difference for a ~32x32 cell to count as changed (default ${DEFAULT_PIXEL_THRESHOLD}).`),
|
|
50
49
|
returnImage: z
|
|
51
50
|
.boolean()
|
|
52
51
|
.optional()
|
|
53
|
-
.describe("
|
|
52
|
+
.describe("Return the final state inline (default true)."),
|
|
54
53
|
keep: z
|
|
55
54
|
.boolean()
|
|
56
55
|
.optional()
|
|
57
|
-
.describe("Keep the final screenshot on disk and return its path (default false
|
|
56
|
+
.describe("Keep the final screenshot on disk and return its path (default false)."),
|
|
58
57
|
};
|
|
59
58
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
60
59
|
export function register(server) {
|
|
61
|
-
server.
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
60
|
+
server.registerTool("wait_for_change", {
|
|
61
|
+
title: "Wait for Screen Change",
|
|
62
|
+
description: "Wait until part of the screen changes or settles, instead of guessing a sleep. Returns the " +
|
|
63
|
+
"elapsed time, changed regions (screenshot pixels; add `origin` for desktop), and the final state.",
|
|
64
|
+
inputSchema,
|
|
65
|
+
outputSchema: looseOutput({
|
|
66
|
+
outcome: z.string(),
|
|
67
|
+
mode: z.string(),
|
|
68
|
+
elapsedSec: z.number(),
|
|
69
|
+
regions: z.array(z.unknown()),
|
|
70
|
+
origin: looseOutput({ x: z.number(), y: z.number() }),
|
|
71
|
+
}),
|
|
72
|
+
annotations: READ_ONLY,
|
|
73
|
+
}, async (args, extra) => {
|
|
65
74
|
try {
|
|
66
75
|
requireFfmpeg();
|
|
67
76
|
const mode = args.mode ?? "change";
|
|
68
77
|
const timeoutMs = (args.timeoutSec ?? 30) * 1000;
|
|
69
78
|
const settleMs = (args.settleSec ?? 1) * 1000;
|
|
70
79
|
const interval = args.intervalMs ?? 250;
|
|
71
|
-
// The target (and a window's rectangle) is resolved once, up front.
|
|
72
80
|
const { target, monitors, window } = await resolveCaptureTarget(args.target, { exactTitle: args.exactTitle });
|
|
81
|
+
await confirmCapture(server, `Watch ${describeTarget(args.target, window)} for up to ${timeoutMs / 1000} s, until it ${mode === "settle" ? "stops changing" : "changes"}?`, extra.signal);
|
|
73
82
|
const area = targetSize(target, monitors);
|
|
74
83
|
const size = detectionSize(area.width, area.height);
|
|
75
|
-
const grab = () => runFfmpegBuffer(buildRawGrabArgs(target, monitors, size), 15_000);
|
|
84
|
+
const grab = () => runFfmpegBuffer(buildRawGrabArgs(target, monitors, size), 15_000, { signal: extra.signal });
|
|
76
85
|
const opts = targetDiffOptions(area, size, args.pixelThreshold);
|
|
77
86
|
const started = Date.now();
|
|
78
87
|
const baseline = await grab();
|
|
@@ -87,7 +96,15 @@ export function register(server) {
|
|
|
87
96
|
break;
|
|
88
97
|
}
|
|
89
98
|
await sleep(interval);
|
|
90
|
-
const current = await grab()
|
|
99
|
+
const current = await grab().catch((error) => {
|
|
100
|
+
if (extra.signal.aborted)
|
|
101
|
+
return null;
|
|
102
|
+
throw error;
|
|
103
|
+
});
|
|
104
|
+
if (!current) {
|
|
105
|
+
outcome = "cancelled";
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
91
108
|
if (mode === "change") {
|
|
92
109
|
const d = diffFrames(baseline, current, size.width, size.height, opts);
|
|
93
110
|
if (d.regions.length > 0) {
|
|
@@ -120,12 +137,11 @@ export function register(server) {
|
|
|
120
137
|
};
|
|
121
138
|
const images = [];
|
|
122
139
|
if (args.returnImage !== false && outcome !== "cancelled") {
|
|
123
|
-
// Not kept by default, so screenshots do not pile up on disk (#209).
|
|
124
140
|
const shot = args.keep
|
|
125
141
|
? join(subdir("screenshots"), `wait-${stamp()}-${rand()}.png`)
|
|
126
142
|
: join(tmpdir(), `screencast-wait-${stamp()}-${rand()}.png`);
|
|
127
143
|
try {
|
|
128
|
-
await runFfmpeg(buildScreenshotArgs(target, shot, monitors), 60_000);
|
|
144
|
+
await runFfmpeg(buildScreenshotArgs(target, shot, monitors), 60_000, { signal: extra.signal });
|
|
129
145
|
if (args.keep)
|
|
130
146
|
result.screenshotPath = shot;
|
|
131
147
|
images.push(...(await encodeInlineImages([shot], DEFAULT_MAX_IMAGE_WIDTH, 1)).images);
|
|
@@ -142,4 +158,3 @@ export function register(server) {
|
|
|
142
158
|
}
|
|
143
159
|
});
|
|
144
160
|
}
|
|
145
|
-
//# sourceMappingURL=waitForChange.js.map
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
4
|
+
import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
|
|
4
5
|
import { requireFfmpeg, probeMedia } from "../utils/ffmpeg.js";
|
|
5
6
|
import { runEditJob } from "../utils/jobs.js";
|
|
6
7
|
import { buildXfadeArgs, clipLength, DEFAULT_TRANSITION_DUR } from "../utils/produce.js";
|
|
7
8
|
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
8
9
|
const inputSchema = {
|
|
9
|
-
inputA: z.string().min(1).describe("
|
|
10
|
-
inputB: z.string().min(1).describe("
|
|
10
|
+
inputA: z.string().min(1).describe("Outgoing video."),
|
|
11
|
+
inputB: z.string().min(1).describe("Incoming video."),
|
|
11
12
|
transition: z
|
|
12
13
|
.string()
|
|
13
14
|
.optional()
|
|
14
|
-
.describe("xfade
|
|
15
|
+
.describe("xfade name (default fade): fade, wipeleft, slideup, circleopen, dissolve, ..."),
|
|
15
16
|
duration: z
|
|
16
17
|
.number()
|
|
17
18
|
.positive()
|
|
@@ -21,10 +22,14 @@ const inputSchema = {
|
|
|
21
22
|
overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
|
|
22
23
|
};
|
|
23
24
|
export function register(server) {
|
|
24
|
-
server.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
25
|
+
server.registerTool("xfade_transition", {
|
|
26
|
+
title: "Crossfade Transition",
|
|
27
|
+
description: "Join two videos with an xfade transition (audio crossfaded); they need not match in size, " +
|
|
28
|
+
"fps, or audio. For more clips use assemble_highlights.",
|
|
29
|
+
inputSchema,
|
|
30
|
+
outputSchema: OUTPUT_PATH,
|
|
31
|
+
annotations: WRITES_FILE,
|
|
32
|
+
}, async (args, extra) => {
|
|
28
33
|
try {
|
|
29
34
|
requireFfmpeg();
|
|
30
35
|
for (const f of [args.inputA, args.inputB]) {
|
|
@@ -49,4 +54,3 @@ export function register(server) {
|
|
|
49
54
|
}
|
|
50
55
|
});
|
|
51
56
|
}
|
|
52
|
-
//# sourceMappingURL=xfadeTransition.js.map
|
package/dist/tools/zoom.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
4
|
-
import {
|
|
4
|
+
import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
|
|
5
|
+
import { requireFfmpeg, runFfmpegFrames, probeMedia } from "../utils/ffmpeg.js";
|
|
5
6
|
import { runEditJob, jobTimeoutMs } from "../utils/jobs.js";
|
|
6
7
|
import { analysisSize } from "../utils/diff.js";
|
|
7
|
-
import { keyframesToViews, buildZoomArgs,
|
|
8
|
+
import { keyframesToViews, buildZoomArgs, createAutoZoomPlanner, planClickZoom, buildAnalysisArgs, DEFAULT_TRANSITION_SEC, DEFAULT_AUTO_MAX_ZOOM, DEFAULT_RING_COLOR, MAX_ZOOM, } from "../utils/zoom.js";
|
|
8
9
|
import { eventPaths, parseEventsJsonl } from "../utils/events.js";
|
|
9
10
|
import { validateColor } from "../utils/validate.js";
|
|
10
|
-
/** Most clicks one render will ring; more would make a very long filter graph. */
|
|
11
11
|
export const MAX_RINGS = 200;
|
|
12
|
-
/** In-frame clicks (mouse down) from an event log, or null if there is none. */
|
|
13
12
|
function readClicks(path) {
|
|
14
13
|
if (!existsSync(path))
|
|
15
14
|
return null;
|
|
@@ -19,14 +18,13 @@ function readClicks(path) {
|
|
|
19
18
|
}
|
|
20
19
|
import { editOutputExt, assertEditContainer } from "../utils/media.js";
|
|
21
20
|
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
22
|
-
/** One zoom keyframe; shared with pipeline. */
|
|
23
21
|
export const zoomKeyframeSchema = z.object({
|
|
24
|
-
t: z.number().nonnegative()
|
|
22
|
+
t: z.number().nonnegative(),
|
|
25
23
|
x: z.number().optional(),
|
|
26
24
|
y: z.number().optional(),
|
|
27
25
|
width: z.number().positive().optional(),
|
|
28
26
|
height: z.number().positive().optional(),
|
|
29
|
-
full: z.boolean().optional()
|
|
27
|
+
full: z.boolean().optional(),
|
|
30
28
|
});
|
|
31
29
|
const inputSchema = {
|
|
32
30
|
input: z.string().min(1).describe("Path to the source video."),
|
|
@@ -34,24 +32,23 @@ const inputSchema = {
|
|
|
34
32
|
.array(zoomKeyframeSchema)
|
|
35
33
|
.max(100)
|
|
36
34
|
.optional()
|
|
37
|
-
.describe("Views
|
|
38
|
-
"
|
|
35
|
+
.describe("Views reached by time t: a source rectangle (x, y, width, height), or { t, full: true } to " +
|
|
36
|
+
"zoom out. Omit to plan them (see follow)."),
|
|
39
37
|
follow: z
|
|
40
38
|
.enum(["auto", "clicks", "changes"])
|
|
41
39
|
.optional()
|
|
42
|
-
.describe("Without keyframes: clicks
|
|
43
|
-
"(
|
|
44
|
-
"where the screen changed. auto (default) uses clicks when the log has any, else changes."),
|
|
40
|
+
.describe("Without keyframes: clicks (from the events log of start_recording events: true) or changes " +
|
|
41
|
+
"(where the screen changed). auto (default): clicks if logged, else changes."),
|
|
45
42
|
events: z
|
|
46
43
|
.string()
|
|
47
44
|
.optional()
|
|
48
|
-
.describe("
|
|
49
|
-
"
|
|
45
|
+
.describe("Events log (default: the input's .events.jsonl); must match the input's timing and size, so " +
|
|
46
|
+
"use the original recording."),
|
|
50
47
|
highlightClicks: z
|
|
51
48
|
.boolean()
|
|
52
49
|
.optional()
|
|
53
|
-
.describe("
|
|
54
|
-
highlightColor: z.string().optional().describe("Ring color
|
|
50
|
+
.describe("Ring each logged click (default false)."),
|
|
51
|
+
highlightColor: z.string().optional().describe("Ring color (default #FF4545)."),
|
|
55
52
|
transitionSec: z
|
|
56
53
|
.number()
|
|
57
54
|
.positive()
|
|
@@ -64,16 +61,20 @@ const inputSchema = {
|
|
|
64
61
|
.max(MAX_ZOOM)
|
|
65
62
|
.optional()
|
|
66
63
|
.describe(`Auto mode: the furthest it zooms in (default ${DEFAULT_AUTO_MAX_ZOOM}).`),
|
|
67
|
-
holdSec: z.number().positive().max(30).optional().describe("Auto mode: stay zoomed this long after activity
|
|
68
|
-
dryRun: z.boolean().optional().describe("
|
|
64
|
+
holdSec: z.number().positive().max(30).optional().describe("Auto mode: stay zoomed this long after activity (default 2)."),
|
|
65
|
+
dryRun: z.boolean().optional().describe("Return the planned keyframes only (editable, pass back)."),
|
|
69
66
|
output: z.string().optional().describe("Optional output path. Defaults under SCREENCAST_HOME/edits."),
|
|
70
67
|
overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
|
|
71
68
|
};
|
|
72
69
|
export function register(server) {
|
|
73
|
-
server.
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
70
|
+
server.registerTool("zoom", {
|
|
71
|
+
title: "Zoom and Pan",
|
|
72
|
+
description: "Smooth animated zoom-and-pan into the action and back out, from keyframes or planned from " +
|
|
73
|
+
"logged clicks or screen changes.",
|
|
74
|
+
inputSchema,
|
|
75
|
+
outputSchema: looseOutput({ keyframes: z.array(z.unknown()) }),
|
|
76
|
+
annotations: WRITES_FILE,
|
|
77
|
+
}, async (args, extra) => {
|
|
77
78
|
try {
|
|
78
79
|
requireFfmpeg();
|
|
79
80
|
if (!existsSync(args.input))
|
|
@@ -105,17 +106,14 @@ export function register(server) {
|
|
|
105
106
|
if (!keyframes) {
|
|
106
107
|
const size = analysisSize(W, H);
|
|
107
108
|
const step = 0.25;
|
|
108
|
-
const
|
|
109
|
-
const frameBytes = size.width * size.height;
|
|
110
|
-
const frames = [];
|
|
111
|
-
for (let o = 0; o + frameBytes <= raw.length; o += frameBytes)
|
|
112
|
-
frames.push(raw.subarray(o, o + frameBytes));
|
|
113
|
-
keyframes = planAutoZoom(frames, size.width, size.height, W, H, {
|
|
109
|
+
const planner = createAutoZoomPlanner(size.width, size.height, W, H, {
|
|
114
110
|
step,
|
|
115
111
|
holdSec: args.holdSec,
|
|
116
112
|
maxZoom: args.maxZoom,
|
|
117
113
|
transition,
|
|
118
114
|
});
|
|
115
|
+
await runFfmpegFrames(buildAnalysisArgs(args.input, size, step), size.width * size.height, (f) => planner.push(f), jobTimeoutMs(durationSec), { signal: extra.signal });
|
|
116
|
+
keyframes = planner.finish();
|
|
119
117
|
if (keyframes.length === 0) {
|
|
120
118
|
return okResponse({ keyframes: [], note: "No localised changes found to zoom into; nothing written." });
|
|
121
119
|
}
|
|
@@ -149,4 +147,3 @@ export function register(server) {
|
|
|
149
147
|
}
|
|
150
148
|
});
|
|
151
149
|
}
|
|
152
|
-
//# sourceMappingURL=zoom.js.map
|
package/dist/utils/anim.js
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Animated GIF / WebP export with a file-size budget (#124).
|
|
3
|
-
*
|
|
4
|
-
* The usual home for a developer's screen recording is an animated image in a
|
|
5
|
-
* PR, issue, or README. A plain GIF conversion bands and balloons, so export
|
|
6
|
-
* uses a two-stage palette (diff stats, sierra dithering, rectangle diff mode)
|
|
7
|
-
* or animated WebP, and steps down a quality ladder until the file fits
|
|
8
|
-
* `maxBytes` (GitHub's limit for images is 10 MB). Builders here are pure.
|
|
9
|
-
*/
|
|
10
1
|
import { ScreencastError } from "./errors.js";
|
|
11
2
|
export const DEFAULT_ANIM_FPS = 12;
|
|
12
3
|
export const DEFAULT_ANIM_WIDTH = 960;
|
|
13
|
-
/** Fits under GitHub's 10 MB limit for images in issues, PRs, and READMEs. */
|
|
14
4
|
export const DEFAULT_MAX_BYTES = 10_000_000;
|
|
15
|
-
/** Most encode attempts before settling for the smallest one made. */
|
|
16
5
|
export const MAX_ATTEMPTS = 5;
|
|
17
|
-
/** Quality ladder from the caller's fps/width. Each step roughly halves the
|
|
18
|
-
* file size (measured on a high-motion 960 px clip: 6.0 -> 3.4 -> 1.7 ->
|
|
19
|
-
* 0.7 MB for GIF). */
|
|
20
6
|
export function animLadder(format, fps, width) {
|
|
21
7
|
const steps = format === "gif"
|
|
22
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]]
|
|
@@ -27,9 +13,6 @@ export function animLadder(format, fps, width) {
|
|
|
27
13
|
...(format === "gif" ? { colors: q } : { quality: q }),
|
|
28
14
|
}));
|
|
29
15
|
}
|
|
30
|
-
/** Which ladder step to try next after an attempt of `size` bytes at step
|
|
31
|
-
* `index` missed the budget: one step per ~1.8x over, at least one, but never
|
|
32
|
-
* past the last (smallest) step. Returns null when that step was just tried. */
|
|
33
16
|
export function nextLadderIndex(index, size, maxBytes, ladderLength) {
|
|
34
17
|
const last = ladderLength - 1;
|
|
35
18
|
if (index >= last)
|
|
@@ -37,8 +20,6 @@ export function nextLadderIndex(index, size, maxBytes, ladderLength) {
|
|
|
37
20
|
const jump = Math.max(1, Math.ceil(Math.log(size / maxBytes) / Math.log(1.8)));
|
|
38
21
|
return Math.min(last, index + jump);
|
|
39
22
|
}
|
|
40
|
-
/** Encode one attempt. GIF uses a palette built from frame differences
|
|
41
|
-
* (stats_mode=diff), which suits screen recordings where little changes. */
|
|
42
23
|
export function buildAnimArgs(input, output, format, s, clip = {}) {
|
|
43
24
|
if (!(s.fps > 0) || !Number.isInteger(s.width) || s.width < 16) {
|
|
44
25
|
throw new ScreencastError("fps must be positive and width an integer of at least 16.");
|
|
@@ -51,7 +32,7 @@ export function buildAnimArgs(input, output, format, s, clip = {}) {
|
|
|
51
32
|
...(clip.start ? ["-ss", String(clip.start)] : []),
|
|
52
33
|
...(clip.duration ? ["-t", String(clip.duration)] : []),
|
|
53
34
|
];
|
|
54
|
-
const base = `fps=${s.fps},scale
|
|
35
|
+
const base = `fps=${s.fps},scale='min(${s.width},iw)':-1:flags=lanczos`;
|
|
55
36
|
if (format === "gif") {
|
|
56
37
|
const colors = s.colors ?? 256;
|
|
57
38
|
return [
|
|
@@ -71,4 +52,3 @@ export function buildAnimArgs(input, output, format, s, clip = {}) {
|
|
|
71
52
|
output,
|
|
72
53
|
];
|
|
73
54
|
}
|
|
74
|
-
//# sourceMappingURL=anim.js.map
|
package/dist/utils/animExport.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Export an animated GIF or WebP under a size budget (#124): encode, measure,
|
|
3
|
-
* step down the settings ladder, and keep the first attempt that fits (or the
|
|
4
|
-
* smallest). Shared by export_gif and pipeline.
|
|
5
|
-
*/
|
|
6
1
|
import { basename, dirname, extname, join } from "node:path";
|
|
7
2
|
import { renameSync, rmSync, statSync } from "node:fs";
|
|
8
3
|
import { runEditJob, probeDuration } from "./jobs.js";
|
|
@@ -13,23 +8,24 @@ export async function exportAnimation(input, output, opts, extra) {
|
|
|
13
8
|
const full = await probeDuration(input);
|
|
14
9
|
const clipSec = opts.duration ?? (full !== null ? full - (opts.start ?? 0) : null);
|
|
15
10
|
const ladder = animLadder(format, opts.fps ?? DEFAULT_ANIM_FPS, opts.width ?? DEFAULT_ANIM_WIDTH);
|
|
16
|
-
// Each attempt is its own sibling file so a later, smaller attempt never
|
|
17
|
-
// has to overwrite an earlier one; the winner is renamed onto output.
|
|
18
11
|
const ext = extname(output);
|
|
19
12
|
const attemptPath = (i) => join(dirname(output), `${basename(output, ext)}.try${i}${ext}`);
|
|
20
13
|
const attempts = [];
|
|
21
14
|
try {
|
|
22
15
|
let index = 0;
|
|
23
16
|
while (index !== null && attempts.length < MAX_ATTEMPTS) {
|
|
17
|
+
const settings = ladder[index];
|
|
18
|
+
if (!settings)
|
|
19
|
+
break;
|
|
24
20
|
const path = attemptPath(attempts.length);
|
|
25
21
|
const clip = { start: opts.start, duration: opts.duration };
|
|
26
|
-
await runEditJob(buildAnimArgs(input, path, format,
|
|
22
|
+
await runEditJob(buildAnimArgs(input, path, format, settings, clip), {
|
|
27
23
|
output: path,
|
|
28
24
|
durationSec: clipSec,
|
|
29
25
|
extra,
|
|
30
26
|
});
|
|
31
27
|
const size = statSync(path).size;
|
|
32
|
-
attempts.push({ path, size, settings
|
|
28
|
+
attempts.push({ path, size, settings });
|
|
33
29
|
if (size <= maxBytes)
|
|
34
30
|
break;
|
|
35
31
|
index = nextLadderIndex(index, size, maxBytes, ladder.length);
|
|
@@ -58,4 +54,3 @@ export async function exportAnimation(input, output, opts, extra) {
|
|
|
58
54
|
rmSync(a.path, { force: true });
|
|
59
55
|
}
|
|
60
56
|
}
|
|
61
|
-
//# sourceMappingURL=animExport.js.map
|
package/dist/utils/audio.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Audio polish (#123): EBU R128 loudness normalization and noise reduction.
|
|
3
|
-
*
|
|
4
|
-
* Normalization is two-pass loudnorm: the first pass measures the input, the
|
|
5
|
-
* second applies a linear gain using those measurements, so the result hits
|
|
6
|
-
* the target without the pumping of single-pass (dynamic) mode. Video, when
|
|
7
|
-
* present, is stream-copied. Builders and the parser are pure.
|
|
8
|
-
*/
|
|
9
1
|
import { extname } from "node:path";
|
|
10
2
|
import { ScreencastError } from "./errors.js";
|
|
11
3
|
import { isAudioOnlyPath } from "./media.js";
|
|
12
|
-
/** Common delivery targets: YouTube/streaming, spoken-word podcasts, and EBU
|
|
13
|
-
* R128 broadcast. */
|
|
14
4
|
export const LOUDNESS_PRESETS = {
|
|
15
5
|
youtube: { i: -14, tp: -1, lra: 11 },
|
|
16
6
|
podcast: { i: -16, tp: -1.5, lra: 11 },
|
|
17
7
|
broadcast: { i: -23, tp: -1, lra: 7 },
|
|
18
8
|
};
|
|
19
|
-
/** Resolve a preset name or a LUFS number to a full target. Pure. */
|
|
20
9
|
export function loudnessTarget(target) {
|
|
21
10
|
if (target === undefined)
|
|
22
11
|
return LOUDNESS_PRESETS.youtube;
|
|
@@ -32,16 +21,15 @@ export function loudnessTarget(target) {
|
|
|
32
21
|
return p;
|
|
33
22
|
}
|
|
34
23
|
const filterTarget = (t) => `I=${t.i}:TP=${t.tp}:LRA=${t.lra}`;
|
|
35
|
-
/** Pass 1: measure the input; the JSON block lands on stderr. */
|
|
36
24
|
export function buildLoudnessMeasureArgs(input, t) {
|
|
37
25
|
return ["-hide_banner", "-nostats", "-i", input, "-vn", "-af", `loudnorm=${filterTarget(t)}:print_format=json`, "-f", "null", "-"];
|
|
38
26
|
}
|
|
39
|
-
/** Pull the last loudnorm JSON block out of ffmpeg's stderr. Pure. */
|
|
40
27
|
export function parseLoudnorm(stderr) {
|
|
41
28
|
const blocks = stderr.match(/\{[^{}]*"input_i"[^{}]*\}/g);
|
|
42
|
-
|
|
29
|
+
const lastBlock = blocks?.at(-1);
|
|
30
|
+
if (lastBlock === undefined)
|
|
43
31
|
throw new ScreencastError("Could not measure loudness (no loudnorm report). Does the file have audio?");
|
|
44
|
-
const raw = JSON.parse(
|
|
32
|
+
const raw = JSON.parse(lastBlock);
|
|
45
33
|
const num = (k) => Number(raw[k]);
|
|
46
34
|
const m = {
|
|
47
35
|
input_i: num("input_i"),
|
|
@@ -56,14 +44,11 @@ export function parseLoudnorm(stderr) {
|
|
|
56
44
|
}
|
|
57
45
|
return m;
|
|
58
46
|
}
|
|
59
|
-
/** Copy the video through, unless the output is audio-only (.wav/.mp3/.m4a),
|
|
60
|
-
* where a video map makes the muxer fail (#187). */
|
|
61
47
|
function keepVideoArgs(output) {
|
|
62
48
|
return isAudioOnlyPath(output)
|
|
63
49
|
? ["-map", "0:a:0", "-vn"]
|
|
64
50
|
: ["-map", "0:v?", "-map", "0:a:0", "-c:v", "copy"];
|
|
65
51
|
}
|
|
66
|
-
/** Audio encoder for an output path: PCM for .wav, MP3 for .mp3, else AAC. */
|
|
67
52
|
export function audioCodecFor(output) {
|
|
68
53
|
switch (extname(output).toLowerCase()) {
|
|
69
54
|
case ".wav":
|
|
@@ -74,8 +59,6 @@ export function audioCodecFor(output) {
|
|
|
74
59
|
return ["-c:a", "aac", "-b:a", "192k"];
|
|
75
60
|
}
|
|
76
61
|
}
|
|
77
|
-
/** Pass 2: apply a linear correction from the measurement. loudnorm works at
|
|
78
|
-
* 192 kHz internally, so the output rate is set back to 48 kHz. */
|
|
79
62
|
export function buildLoudnessApplyArgs(input, output, t, m) {
|
|
80
63
|
const measured = `measured_I=${m.input_i}:measured_TP=${m.input_tp}:measured_LRA=${m.input_lra}:` +
|
|
81
64
|
`measured_thresh=${m.input_thresh}:offset=${m.target_offset}`;
|
|
@@ -88,10 +71,7 @@ export function buildLoudnessApplyArgs(input, output, t, m) {
|
|
|
88
71
|
output,
|
|
89
72
|
];
|
|
90
73
|
}
|
|
91
|
-
/** afftdn noise-reduction amount (dB) per strength. */
|
|
92
74
|
export const DENOISE_NR = { light: 6, medium: 12, strong: 20 };
|
|
93
|
-
/** Measure the audio's RMS level in 100 ms windows (printed to stdout), to
|
|
94
|
-
* estimate its noise floor. */
|
|
95
75
|
export function buildNoiseFloorArgs(input) {
|
|
96
76
|
return [
|
|
97
77
|
"-hide_banner", "-nostats", "-i", input, "-vn",
|
|
@@ -99,26 +79,18 @@ export function buildNoiseFloorArgs(input) {
|
|
|
99
79
|
"-f", "null", "-",
|
|
100
80
|
];
|
|
101
81
|
}
|
|
102
|
-
/** The noise floor: the 10th-percentile window RMS (dBFS), i.e. the level of
|
|
103
|
-
* the quietest moments, which are mostly noise. Null for silence. Pure. */
|
|
104
82
|
export function parseNoiseFloor(stdout) {
|
|
105
83
|
const levels = [...stdout.matchAll(/RMS_level=(-?[\d.]+)/g)].map((m) => Number(m[1])).filter(Number.isFinite);
|
|
106
84
|
if (levels.length === 0)
|
|
107
85
|
return null;
|
|
108
86
|
levels.sort((a, b) => a - b);
|
|
109
|
-
return levels[Math.floor(levels.length * 0.1)];
|
|
87
|
+
return levels[Math.floor(levels.length * 0.1)] ?? null;
|
|
110
88
|
}
|
|
111
|
-
/** afftdn's `nf` for a measured floor. afftdn only removes what it believes is
|
|
112
|
-
* at or under nf, so a fixed value misses most real noise: white noise at
|
|
113
|
-
* -25 dBFS was untouched with nf=-25 but cut 12-20 dB with nf set 5 dB above
|
|
114
|
-
* the measured floor. Clamped to afftdn's range [-80, -20]. Pure. */
|
|
115
89
|
export function noiseFloorSetting(floorDb) {
|
|
116
90
|
if (floorDb === null)
|
|
117
91
|
return -50;
|
|
118
92
|
return Math.max(-80, Math.min(-20, Math.round(floorDb + 5)));
|
|
119
93
|
}
|
|
120
|
-
/** Reduce steady background noise (fans, hum, hiss) with afftdn, using the
|
|
121
|
-
* floor measured by buildNoiseFloorArgs. Pure. */
|
|
122
94
|
export function buildDenoiseArgs(input, output, strength = "medium", noiseFloorDb = null) {
|
|
123
95
|
const nr = DENOISE_NR[strength];
|
|
124
96
|
if (nr === undefined)
|
|
@@ -131,4 +103,3 @@ export function buildDenoiseArgs(input, output, strength = "medium", noiseFloorD
|
|
|
131
103
|
output,
|
|
132
104
|
];
|
|
133
105
|
}
|
|
134
|
-
//# sourceMappingURL=audio.js.map
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DirectShow audio device discovery for system-audio capture.
|
|
3
|
-
*
|
|
4
|
-
* gdigrab is video-only, so capturing what is playing on the machine needs a
|
|
5
|
-
* separate dshow audio input. Windows has no native loopback device, so system
|
|
6
|
-
* audio requires a virtual-audio device (Stereo Mix, or a driver such as
|
|
7
|
-
* screen-capture-recorder's virtual-audio-capturer or VB-CABLE). This module
|
|
8
|
-
* enumerates the dshow audio devices ffmpeg can see and picks a loopback one.
|
|
9
|
-
*
|
|
10
|
-
* Microphone capture is intentionally not supported.
|
|
11
|
-
*
|
|
12
|
-
* The parsing and selection helpers are pure (string in, names out) so they are
|
|
13
|
-
* unit-tested without ffmpeg or Windows present.
|
|
14
|
-
*/
|
|
15
1
|
import { ScreencastError } from "./errors.js";
|
|
16
2
|
import { requireFfmpeg, runCapture } from "./ffmpeg.js";
|
|
17
|
-
/** Names that identify a system-audio loopback device, matched case-insensitively
|
|
18
|
-
* as a substring. */
|
|
19
3
|
export const LOOPBACK_HINTS = [
|
|
20
4
|
"virtual-audio-capturer",
|
|
21
5
|
"stereo mix",
|
|
@@ -29,11 +13,6 @@ export const NO_LOOPBACK_HINT = "System audio capture needs a virtual-audio loop
|
|
|
29
13
|
"a loopback driver (for example screen-capture-recorder's " +
|
|
30
14
|
"virtual-audio-capturer, or VB-CABLE). Then pass its name as `device`, or run " +
|
|
31
15
|
"list_audio_devices to see what is available. Microphone capture is not supported.";
|
|
32
|
-
/**
|
|
33
|
-
* Parse the stderr of `ffmpeg -list_devices true -f dshow -i dummy` into the
|
|
34
|
-
* list of audio device names. Handles both the sectioned layout (a "DirectShow
|
|
35
|
-
* audio devices" header) and the inline "(audio)" tag used by newer ffmpeg.
|
|
36
|
-
*/
|
|
37
16
|
export function parseDshowAudioDevices(stderr) {
|
|
38
17
|
const names = [];
|
|
39
18
|
let section = null;
|
|
@@ -46,7 +25,6 @@ export function parseDshowAudioDevices(stderr) {
|
|
|
46
25
|
section = "video";
|
|
47
26
|
continue;
|
|
48
27
|
}
|
|
49
|
-
// The "Alternative name" lines also carry a quoted string; skip them.
|
|
50
28
|
if (/Alternative name/i.test(line))
|
|
51
29
|
continue;
|
|
52
30
|
const quoted = line.match(/"([^"]+)"/);
|
|
@@ -55,16 +33,11 @@ export function parseDshowAudioDevices(stderr) {
|
|
|
55
33
|
const inlineAudio = /\(audio\)/i.test(line);
|
|
56
34
|
const inlineVideo = /\(video\)/i.test(line);
|
|
57
35
|
const isAudio = inlineAudio || (!inlineVideo && section === "audio");
|
|
58
|
-
if (isAudio)
|
|
36
|
+
if (isAudio && quoted[1])
|
|
59
37
|
names.push(quoted[1]);
|
|
60
38
|
}
|
|
61
39
|
return [...new Set(names)];
|
|
62
40
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Choose a loopback device. With an explicit name, return it only if ffmpeg
|
|
65
|
-
* actually lists it (so a typo fails loudly). Otherwise return the first device
|
|
66
|
-
* whose name matches a known loopback hint, or null when none qualifies.
|
|
67
|
-
*/
|
|
68
41
|
export function pickLoopbackDevice(devices, explicit) {
|
|
69
42
|
if (explicit && explicit.trim().length > 0) {
|
|
70
43
|
return devices.includes(explicit) ? explicit : null;
|
|
@@ -72,24 +45,11 @@ export function pickLoopbackDevice(devices, explicit) {
|
|
|
72
45
|
const lower = (s) => s.toLowerCase();
|
|
73
46
|
return (devices.find((d) => LOOPBACK_HINTS.some((h) => lower(d).includes(h))) ?? null);
|
|
74
47
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Device enumeration must not block a recording start for long. The dshow
|
|
77
|
-
* `-list_devices` probe hangs on some setups (a misbehaving audio driver, no
|
|
78
|
-
* audio hardware), so it is capped well below the normal ffmpeg job timeout.
|
|
79
|
-
*/
|
|
80
48
|
export const ENUM_TIMEOUT_MS = 12_000;
|
|
81
49
|
const ENUM_FAILED_HINT = "Enumerating DirectShow audio devices timed out or failed - usually a " +
|
|
82
50
|
"misbehaving audio driver, or no audio device present. Record without system " +
|
|
83
51
|
"audio, or fix the device, then retry. " + NO_LOOPBACK_HINT;
|
|
84
|
-
// A successful enumeration is cached for the process lifetime so an audio
|
|
85
|
-
// recording does not re-pay the cost (or risk the hang) on every start. The
|
|
86
|
-
// list_audio_devices tool forces a refresh, so a device enabled mid-session is
|
|
87
|
-
// still discoverable.
|
|
88
52
|
let cachedDevices = null;
|
|
89
|
-
/** Run ffmpeg's device list and return the audio device names. ffmpeg exits
|
|
90
|
-
* non-zero for the dummy input by design, so the exit code is ignored and the
|
|
91
|
-
* names are read from stderr. A timeout or spawn failure becomes a clear,
|
|
92
|
-
* actionable error rather than the raw "ffmpeg timed out" text. */
|
|
93
53
|
export async function listDshowAudioDevices(forceRefresh = false) {
|
|
94
54
|
if (!forceRefresh && cachedDevices)
|
|
95
55
|
return cachedDevices;
|
|
@@ -99,21 +59,15 @@ export async function listDshowAudioDevices(forceRefresh = false) {
|
|
|
99
59
|
res = await runCapture(ffmpeg, ["-hide_banner", "-list_devices", "true", "-f", "dshow", "-i", "dummy"], ENUM_TIMEOUT_MS, { closeStdin: true });
|
|
100
60
|
}
|
|
101
61
|
catch (err) {
|
|
102
|
-
// runCapture rejects on timeout (and on spawn error); ffmpeg's by-design
|
|
103
|
-
// non-zero exit for the dummy input resolves instead, so reaching here is a
|
|
104
|
-
// genuine failure, not the expected exit code.
|
|
105
62
|
throw new ScreencastError(`Could not enumerate audio devices (${err.message}).`, ENUM_FAILED_HINT);
|
|
106
63
|
}
|
|
107
64
|
const devices = parseDshowAudioDevices(res.stderr);
|
|
108
65
|
cachedDevices = devices;
|
|
109
66
|
return devices;
|
|
110
67
|
}
|
|
111
|
-
/** Drop the cached device list (test seam; also lets a caller force a re-probe). */
|
|
112
68
|
export function clearAudioDeviceCache() {
|
|
113
69
|
cachedDevices = null;
|
|
114
70
|
}
|
|
115
|
-
/** Resolve the loopback device to use, throwing a clear, actionable error when
|
|
116
|
-
* an explicit name is not present or no loopback device exists. */
|
|
117
71
|
export async function resolveLoopbackDevice(explicit) {
|
|
118
72
|
const devices = await listDshowAudioDevices();
|
|
119
73
|
const picked = pickLoopbackDevice(devices, explicit);
|
|
@@ -125,4 +79,3 @@ export async function resolveLoopbackDevice(explicit) {
|
|
|
125
79
|
}
|
|
126
80
|
throw new ScreencastError("No system-audio loopback device found.", NO_LOOPBACK_HINT);
|
|
127
81
|
}
|
|
128
|
-
//# sourceMappingURL=audioDevices.js.map
|