@tmhs/screencast-mcp 0.38.0 → 0.44.2
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 +58 -14
- package/assets/icon.png +0 -0
- package/assets/ui/player.html +38 -302
- package/assets/ui/player.js +382 -0
- package/dist/context.js +0 -5
- package/dist/index.js +7 -115
- package/dist/prompts.js +0 -7
- package/dist/resources.js +2 -14
- package/dist/server.js +129 -0
- package/dist/tools/assembleHighlights.js +12 -7
- package/dist/tools/burnSubtitles.js +12 -6
- package/dist/tools/callout.js +32 -16
- 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 +26 -22
- 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 +69 -65
- package/dist/tools/getMediaInfo.js +17 -3
- package/dist/tools/getSession.js +15 -3
- 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 +31 -22
- 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 +63 -22
- package/dist/tools/sampleFrames.js +33 -40
- 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 +48 -52
- package/dist/tools/stopRecording.js +10 -9
- 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/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/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/lifecycle.js +0 -29
- package/dist/utils/logging.js +75 -0
- package/dist/utils/media.js +11 -122
- package/dist/utils/monitors.js +7 -43
- package/dist/utils/ocr.js +53 -71
- package/dist/utils/paths.js +68 -31
- package/dist/utils/pipeline.js +0 -23
- package/dist/utils/player.js +50 -27
- package/dist/utils/produce.js +6 -66
- 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 +102 -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/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
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
|
package/dist/utils/callout.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Timed annotations (#121): boxes, text labels, and arrows that appear over a
|
|
3
|
-
* video between two timestamps. Boxes and text are drawbox / drawtext with an
|
|
4
|
-
* `enable` window. ffmpeg cannot draw an arbitrary line, so an arrow is drawn
|
|
5
|
-
* as an image (a shaft plus a triangular head, via geq), rotated to its angle,
|
|
6
|
-
* and overlaid centred on the arrow's midpoint. Builders are pure.
|
|
7
|
-
*/
|
|
8
1
|
import { ScreencastError } from "./errors.js";
|
|
9
2
|
import { escapeFilterPath } from "./fonts.js";
|
|
10
3
|
import { enableExpr } from "./media.js";
|
|
@@ -20,8 +13,6 @@ function enable(c) {
|
|
|
20
13
|
const e = enableExpr(c.from, c.to);
|
|
21
14
|
return e ? `:enable='${e}'` : "";
|
|
22
15
|
}
|
|
23
|
-
/** Geometry of an arrow image: its length, thickness, rotation (radians,
|
|
24
|
-
* clockwise in screen coordinates), and centre. Pure. */
|
|
25
16
|
export function arrowGeometry(a) {
|
|
26
17
|
const dx = a.x2 - a.x1;
|
|
27
18
|
const dy = a.y2 - a.y1;
|
|
@@ -31,14 +22,11 @@ export function arrowGeometry(a) {
|
|
|
31
22
|
throw new ScreencastError("An arrow must be at least three times as long as it is thick.");
|
|
32
23
|
return { length, thickness, angle: Math.atan2(dy, dx), cx: (a.x1 + a.x2) / 2, cy: (a.y1 + a.y2) / 2 };
|
|
33
24
|
}
|
|
34
|
-
/** Render one arrow, already rotated, as a transparent PNG. Pure args. */
|
|
35
25
|
export function buildArrowImageArgs(a, output) {
|
|
36
26
|
const { length, thickness, angle } = arrowGeometry(a);
|
|
37
27
|
const color = validateColor(a.color ?? "red");
|
|
38
28
|
const head = thickness * 3;
|
|
39
29
|
const ang = angle.toFixed(6);
|
|
40
|
-
// Opaque where: the shaft (|y - mid| < t/2 before the head), or inside the
|
|
41
|
-
// triangular head (|y - mid| < remaining length / 2).
|
|
42
30
|
const alpha = `if(lt(X,W-H),if(lt(abs(Y-H/2),${thickness}/2),255,0),if(lt(abs(Y-H/2),(W-X)/2),255,0))`;
|
|
43
31
|
return [
|
|
44
32
|
"-y", "-v", "error",
|
|
@@ -48,10 +36,6 @@ export function buildArrowImageArgs(a, output) {
|
|
|
48
36
|
...stillOutput(output),
|
|
49
37
|
];
|
|
50
38
|
}
|
|
51
|
-
/** Filter steps that draw every callout over the stream labelled `input`
|
|
52
|
-
* (later items on top). Arrow images become extra inputs numbered from
|
|
53
|
-
* `firstInput`; labels are prefixed with `tag`. Shared by callout and
|
|
54
|
-
* pipeline. Pure. */
|
|
55
39
|
export function calloutSteps(items, assets, input, firstInput, tag) {
|
|
56
40
|
if (items.length === 0)
|
|
57
41
|
throw new ScreencastError("Give at least one callout.");
|
|
@@ -73,7 +57,7 @@ export function calloutSteps(items, assets, input, firstInput, tag) {
|
|
|
73
57
|
const color = validateColor(c.color ?? "white");
|
|
74
58
|
const size = Math.max(8, Math.round(c.size ?? 32));
|
|
75
59
|
const panel = c.background === false ? "" : `:box=1:boxcolor=black@0.6:boxborderw=${Math.round(size / 3)}`;
|
|
76
|
-
steps.push(`${cur}drawtext=fontfile=${escapeFilterPath(assets.fontFile)}:textfile=${escapeFilterPath(file)}:expansion=none` +
|
|
60
|
+
steps.push(`${cur}drawtext=fontfile=${escapeFilterPath(assets.fontFiles?.[i] ?? assets.fontFile)}:textfile=${escapeFilterPath(file)}:expansion=none` +
|
|
77
61
|
`:x=${nonNeg(c.x, "x")}:y=${nonNeg(c.y, "y")}:fontsize=${size}:fontcolor=${color}${panel}${enable(c)}${out}`);
|
|
78
62
|
}
|
|
79
63
|
else {
|
|
@@ -89,7 +73,6 @@ export function calloutSteps(items, assets, input, firstInput, tag) {
|
|
|
89
73
|
});
|
|
90
74
|
return { steps, out: cur, extraInputs };
|
|
91
75
|
}
|
|
92
|
-
/** Draw every callout in order (later items on top). Pure. */
|
|
93
76
|
export function buildCalloutArgs(input, output, items, assets, quality = "standard") {
|
|
94
77
|
const { steps, out, extraInputs } = calloutSteps(items, assets, "[0:v]", 1, "");
|
|
95
78
|
return [
|
|
@@ -101,4 +84,3 @@ export function buildCalloutArgs(input, output, items, assets, quality = "standa
|
|
|
101
84
|
output,
|
|
102
85
|
];
|
|
103
86
|
}
|
|
104
|
-
//# sourceMappingURL=callout.js.map
|
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Files a callout render needs: each text item's text (drawtext reads it from a
|
|
3
|
-
* file, so no escaping is needed) and each arrow rendered to a PNG. Shared by
|
|
4
|
-
* callout and pipeline; the caller owns and removes `workDir`.
|
|
5
|
-
*/
|
|
6
1
|
import { join } from "node:path";
|
|
7
2
|
import { writeFileSync } from "node:fs";
|
|
8
3
|
import { runFfmpeg } from "./ffmpeg.js";
|
|
9
4
|
import { buildArrowImageArgs } from "./callout.js";
|
|
10
|
-
import { bundledFontPath } from "./fonts.js";
|
|
11
|
-
export
|
|
5
|
+
import { bundledFontPath, resolveTextFont } from "./fonts.js";
|
|
6
|
+
export function calloutFonts(items, fontFile) {
|
|
7
|
+
const out = { fontFiles: [], fallbackFonts: [], warnings: [] };
|
|
8
|
+
items.forEach((c, i) => {
|
|
9
|
+
if (c.type !== "text") {
|
|
10
|
+
out.fontFiles.push(null);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const font = resolveTextFont(c.text, { weight: "bold", fontFile });
|
|
14
|
+
out.fontFiles.push(font.fontFile);
|
|
15
|
+
if (font.fallback)
|
|
16
|
+
out.fallbackFonts.push({ item: i, fontFile: font.fontFile });
|
|
17
|
+
if (font.warning)
|
|
18
|
+
out.warnings.push(`Item ${i}: ${font.warning}`);
|
|
19
|
+
});
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
export async function prepareCalloutAssets(items, workDir, tag = "", fontFile) {
|
|
23
|
+
const fonts = calloutFonts(items, fontFile);
|
|
12
24
|
const textFiles = items.map((c, i) => {
|
|
13
25
|
if (c.type !== "text")
|
|
14
26
|
return null;
|
|
@@ -17,8 +29,7 @@ export async function prepareCalloutAssets(items, workDir, tag = "") {
|
|
|
17
29
|
return f;
|
|
18
30
|
});
|
|
19
31
|
const arrowFiles = [];
|
|
20
|
-
for (
|
|
21
|
-
const c = items[i];
|
|
32
|
+
for (const [i, c] of items.entries()) {
|
|
22
33
|
if (c.type !== "arrow") {
|
|
23
34
|
arrowFiles.push(null);
|
|
24
35
|
continue;
|
|
@@ -27,6 +38,5 @@ export async function prepareCalloutAssets(items, workDir, tag = "") {
|
|
|
27
38
|
await runFfmpeg(buildArrowImageArgs(c, f), 30_000);
|
|
28
39
|
arrowFiles.push(f);
|
|
29
40
|
}
|
|
30
|
-
return { fontFile: bundledFontPath("bold"), textFiles, arrowFiles };
|
|
41
|
+
return { fontFile: bundledFontPath("bold"), textFiles, arrowFiles, ...fonts };
|
|
31
42
|
}
|
|
32
|
-
//# sourceMappingURL=calloutAssets.js.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { isAbsolute } from "node:path";
|
|
3
|
+
import { runPowerShell, psTimeoutMs } from "./monitors.js";
|
|
4
|
+
export const FFMPEG_FEATURE_MAJOR = 8;
|
|
5
|
+
export function parseFfmpegVersion(text) {
|
|
6
|
+
const version = /^ff(?:mpeg|probe) version (\S+)/m.exec(text)?.[1] ?? null;
|
|
7
|
+
const release = version ? /^n?(\d+)\.\d+/.exec(version) : null;
|
|
8
|
+
if (release)
|
|
9
|
+
return { version, major: Number(release[1]), inferred: false };
|
|
10
|
+
const avutil = /^\s*libavutil\s+(\d+)\./m.exec(text);
|
|
11
|
+
if (avutil && Number(avutil[1]) >= 56)
|
|
12
|
+
return { version, major: Number(avutil[1]) - 52, inferred: true };
|
|
13
|
+
return { version, major: null, inferred: false };
|
|
14
|
+
}
|
|
15
|
+
export function parseDevices(text) {
|
|
16
|
+
const out = new Set();
|
|
17
|
+
const body = text.split(/^\s*---\s*$/m).slice(1).join("\n") || text;
|
|
18
|
+
for (const line of body.split(/\r?\n/)) {
|
|
19
|
+
const m = /^\s{0,2}[D ][E ]\s?[d ]?\s+([a-z0-9_,]+)\s/i.exec(line);
|
|
20
|
+
if (m?.[1])
|
|
21
|
+
for (const name of m[1].split(","))
|
|
22
|
+
out.add(name);
|
|
23
|
+
}
|
|
24
|
+
return [...out];
|
|
25
|
+
}
|
|
26
|
+
function run(bin, args) {
|
|
27
|
+
try {
|
|
28
|
+
const res = spawnSync(bin, args, { encoding: "utf8", windowsHide: true, timeout: 10_000 });
|
|
29
|
+
if (res.status !== 0)
|
|
30
|
+
return null;
|
|
31
|
+
return `${res.stdout ?? ""}${res.stderr ?? ""}`;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function versionText(bin) {
|
|
38
|
+
return run(bin, ["-version"]);
|
|
39
|
+
}
|
|
40
|
+
export function devicesText(ffmpeg) {
|
|
41
|
+
return run(ffmpeg, ["-hide_banner", "-devices"]);
|
|
42
|
+
}
|
|
43
|
+
export function locate(bin) {
|
|
44
|
+
if (isAbsolute(bin))
|
|
45
|
+
return bin;
|
|
46
|
+
const out = run(process.platform === "win32" ? "where" : "which", [bin]);
|
|
47
|
+
return out?.split(/\r?\n/).map((l) => l.trim()).find((l) => l.length > 0) ?? null;
|
|
48
|
+
}
|
|
49
|
+
const PS_OCR_STATUS = `
|
|
50
|
+
$ErrorActionPreference = 'Stop'
|
|
51
|
+
$null = [Windows.Media.Ocr.OcrEngine, Windows.Foundation, ContentType = WindowsRuntime]
|
|
52
|
+
$e = [Windows.Media.Ocr.OcrEngine]::TryCreateFromUserProfileLanguages()
|
|
53
|
+
[pscustomobject]@{ available = ($null -ne $e); language = $(if ($e) { $e.RecognizerLanguage.LanguageTag } else { $null }); languages = @([Windows.Media.Ocr.OcrEngine]::AvailableRecognizerLanguages | ForEach-Object { $_.LanguageTag }) } | ConvertTo-Json -Compress
|
|
54
|
+
`;
|
|
55
|
+
export async function ocrStatus() {
|
|
56
|
+
if (process.platform !== "win32") {
|
|
57
|
+
return { available: false, language: null, languages: [], error: "The Windows OCR engine is available on Windows only." };
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const raw = JSON.parse(await runPowerShell(PS_OCR_STATUS, "OCR languages", { timeoutMs: psTimeoutMs(15_000) }));
|
|
61
|
+
const languages = Array.isArray(raw.languages) ? raw.languages : raw.languages ? [raw.languages] : [];
|
|
62
|
+
return { available: raw.available === true, language: raw.language ?? null, languages };
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
return { available: false, language: null, languages: [], error: err.message };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export const ENV_SETTINGS = [
|
|
69
|
+
"SCREENCAST_HOME",
|
|
70
|
+
"SCREENCAST_ALLOWED_DIRS",
|
|
71
|
+
"FFMPEG_PATH",
|
|
72
|
+
"FFPROBE_PATH",
|
|
73
|
+
"SCREENCAST_WHISPER_MODEL",
|
|
74
|
+
"SCREENCAST_MAX_RECORDING_SEC",
|
|
75
|
+
"SCREENCAST_JOB_TIMEOUT_MS",
|
|
76
|
+
"SCREENCAST_PS_TIMEOUT_MS",
|
|
77
|
+
"SCREENCAST_RETENTION_DAYS",
|
|
78
|
+
"SCREENCAST_CONFIRM_CAPTURE",
|
|
79
|
+
"SCREENCAST_TOOLSETS",
|
|
80
|
+
];
|
|
81
|
+
export function envSettings(env = process.env) {
|
|
82
|
+
return Object.fromEntries(ENV_SETTINGS.map((name) => {
|
|
83
|
+
const value = env[name];
|
|
84
|
+
return [name, value && value.trim().length > 0 ? value : null];
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
export const KEY_FILTERS = [
|
|
88
|
+
{ filter: "whisper", tools: "transcribe", why: `FFmpeg ${FFMPEG_FEATURE_MAJOR}+ built with whisper.cpp` },
|
|
89
|
+
{ filter: "gfxcapture", tools: 'backend: "wgc" (screenshot, start_recording, find_text)', why: `FFmpeg ${FFMPEG_FEATURE_MAJOR}+ on Windows` },
|
|
90
|
+
{ filter: "subtitles", tools: "burn_subtitles", why: "libass" },
|
|
91
|
+
{ filter: "drawtext", tools: "title_card, callout, contact_sheet labels, produce", why: "libfreetype" },
|
|
92
|
+
{ filter: "afftdn", tools: "denoise", why: "a standard build" },
|
|
93
|
+
{ filter: "loudnorm", tools: "normalize_audio", why: "a standard build" },
|
|
94
|
+
{ filter: "xfade", tools: "xfade_transition, assemble_highlights", why: "FFmpeg 4.3+" },
|
|
95
|
+
];
|