@pixerate/editor 0.160.0 → 0.161.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.
Files changed (57) hide show
  1. package/dist/{chunk-VKF3PWKR.cjs → chunk-3OSXHLIT.cjs} +259 -28
  2. package/dist/chunk-6DM3PUQD.cjs +767 -0
  3. package/dist/{chunk-IQ6KKXOU.js → chunk-YN4AYYBJ.js} +243 -12
  4. package/dist/chunk-ZGOHKS3X.js +767 -0
  5. package/dist/effects/index.cjs +16 -767
  6. package/dist/effects/index.js +5 -756
  7. package/dist/paint-editor/index.cjs +2 -2
  8. package/dist/paint-editor/index.js +1 -1
  9. package/dist/video-editor/audio.d.cts +9 -0
  10. package/dist/video-editor/audio.d.ts +9 -0
  11. package/dist/video-editor/check.d.cts +1 -1
  12. package/dist/video-editor/check.d.ts +1 -1
  13. package/dist/video-editor/controller.d.cts +47 -0
  14. package/dist/video-editor/controller.d.ts +47 -0
  15. package/dist/video-editor/dialogue-tools.d.cts +19 -0
  16. package/dist/video-editor/dialogue-tools.d.ts +19 -0
  17. package/dist/video-editor/effect-authoring.d.cts +54 -0
  18. package/dist/video-editor/effect-authoring.d.ts +54 -0
  19. package/dist/video-editor/evaluate.d.cts +11 -0
  20. package/dist/video-editor/evaluate.d.ts +11 -0
  21. package/dist/video-editor/export.d.cts +7 -1
  22. package/dist/video-editor/export.d.ts +7 -1
  23. package/dist/video-editor/index.cjs +1853 -528
  24. package/dist/video-editor/index.d.cts +7 -0
  25. package/dist/video-editor/index.d.ts +7 -0
  26. package/dist/video-editor/index.js +1512 -187
  27. package/dist/video-editor/lut.d.cts +12 -2
  28. package/dist/video-editor/lut.d.ts +12 -2
  29. package/dist/video-editor/mask.d.cts +48 -0
  30. package/dist/video-editor/mask.d.ts +48 -0
  31. package/dist/video-editor/mix.d.cts +107 -0
  32. package/dist/video-editor/mix.d.ts +107 -0
  33. package/dist/video-editor/music-tools.d.cts +19 -0
  34. package/dist/video-editor/music-tools.d.ts +19 -0
  35. package/dist/video-editor/parse.d.cts +3 -1
  36. package/dist/video-editor/parse.d.ts +3 -1
  37. package/dist/video-editor/plan.d.cts +75 -0
  38. package/dist/video-editor/plan.d.ts +75 -0
  39. package/dist/video-editor/render.d.cts +1 -1
  40. package/dist/video-editor/render.d.ts +1 -1
  41. package/dist/video-editor/timeline.d.cts +2 -0
  42. package/dist/video-editor/timeline.d.ts +2 -0
  43. package/dist/video-editor/tools.d.cts +90 -0
  44. package/dist/video-editor/tools.d.ts +90 -0
  45. package/dist/video-editor/transcript-controller.d.cts +106 -0
  46. package/dist/video-editor/transcript-controller.d.ts +106 -0
  47. package/dist/video-editor/transcript.d.cts +40 -0
  48. package/dist/video-editor/transcript.d.ts +40 -0
  49. package/dist/video-editor/types.d.cts +62 -2
  50. package/dist/video-editor/types.d.ts +62 -2
  51. package/dist/video-editor/ui.d.cts +21 -1
  52. package/dist/video-editor/ui.d.ts +21 -1
  53. package/package.json +1 -1
  54. package/skills/README.md +2 -0
  55. package/skills/pixerate-bgm-alignment/SKILL.md +82 -0
  56. package/skills/pixerate-talking-head-edit/SKILL.md +80 -0
  57. package/skills/pixerate-video-editor/SKILL.md +40 -2
@@ -1,4 +1,8 @@
1
1
  import {
2
+ createEffectAuthoringSession
3
+ } from "../chunk-ZGOHKS3X.js";
4
+ import {
5
+ VIDEO_ADJUSTMENT_SCOPES,
2
6
  VIDEO_BLEND_MODES,
3
7
  VIDEO_CLIP_ANIMATION_DURATION,
4
8
  VIDEO_CLIP_ANIMATION_EFFECTS,
@@ -13,6 +17,8 @@ import {
13
17
  VIDEO_KEYFRAME_LIMITS,
14
18
  VIDEO_KEYFRAME_PROPERTIES,
15
19
  VIDEO_LUT_MAX_SIZE,
20
+ VIDEO_MASK_DEFAULTS,
21
+ VIDEO_MASK_SHAPES,
16
22
  VIDEO_PLACEMENT_MODES,
17
23
  VIDEO_TIME_EPSILON,
18
24
  VIDEO_TRANSFORM_PROPERTIES,
@@ -41,6 +47,7 @@ import {
41
47
  isVideoKeyframes,
42
48
  mixEffectPixels,
43
49
  nextFreeVideoSlot,
50
+ normalizeVideoClipMask,
44
51
  normalizeVideoGrade,
45
52
  normalizeVideoGradeLut,
46
53
  overEffectPixels,
@@ -75,6 +82,7 @@ import {
75
82
  videoClipSourceTime,
76
83
  videoClipSpeed,
77
84
  videoClipSpeedAt,
85
+ videoClipTypeLabel,
78
86
  videoClipsAt,
79
87
  videoContactSheetSvg,
80
88
  videoEaseBezier,
@@ -84,6 +92,7 @@ import {
84
92
  videoEffectValuesAt,
85
93
  videoFadeCurveGain,
86
94
  videoFfmpegUnsupportedEffects,
95
+ videoFfmpegUnsupportedFeatures,
87
96
  videoFrameAt,
88
97
  videoFrameDuration,
89
98
  videoFrameLeafLayers,
@@ -105,12 +114,16 @@ import {
105
114
  videoKeyframeBreakpoints,
106
115
  videoKeyframeFfmpegExpr,
107
116
  videoKeysOf,
117
+ videoLayerMask,
108
118
  videoLayersUseEffects,
109
119
  videoLayersWithoutTransitionEffects,
110
120
  videoLutFromFunction,
111
121
  videoLutSvgApproximation,
112
122
  videoLutSvgPrimitives,
113
123
  videoLutToCube,
124
+ videoMaskContains,
125
+ videoMaskPolygon,
126
+ videoMaskSvgPath,
114
127
  videoOverlap,
115
128
  videoProjectDuration,
116
129
  videoProjectEffects,
@@ -119,6 +132,7 @@ import {
119
132
  videoSequenceDuration,
120
133
  videoSequenceMap,
121
134
  videoShellQuote,
135
+ videoSkinToneWeight,
122
136
  videoSlowMotionRamp,
123
137
  videoSnapPoints,
124
138
  videoSpeedRampEdit,
@@ -134,7 +148,7 @@ import {
134
148
  videoTransitionEase,
135
149
  videoValueAt,
136
150
  videoWipeRect
137
- } from "../chunk-IQ6KKXOU.js";
151
+ } from "../chunk-YN4AYYBJ.js";
138
152
  import "../chunk-EHLOCVWB.js";
139
153
  import {
140
154
  namedWithSuggestion
@@ -155,7 +169,10 @@ import {
155
169
  import {
156
170
  AnimationPlayer
157
171
  } from "../chunk-AY65VQSU.js";
158
- import "../chunk-5UJHB3BW.js";
172
+ import {
173
+ CUBIC_BEZIER_PRESETS,
174
+ evaluateEasing
175
+ } from "../chunk-5UJHB3BW.js";
159
176
  import "../chunk-KY3FYKP3.js";
160
177
  import "../chunk-2WPNAGHI.js";
161
178
  import "../chunk-AA34BA7G.js";
@@ -260,9 +277,38 @@ function parseVideoGrade(v, path) {
260
277
  function parseVideoGradeLut(v, path) {
261
278
  if (v === void 0) return void 0;
262
279
  if (!isObject(v)) return fail(path, "must be an object { src, strength } naming a .cube file");
263
- const unknown = Object.keys(v).find((k) => !["src", "strength", "name"].includes(k));
264
- if (unknown) fail(`${path}.${unknown}`, "is not a LUT setting; use src, strength, name");
265
- return compact({ src: str(v.src, `${path}.src`), strength: num(v.strength, `${path}.strength`, { optional: true, min: 0, max: 1 }), name: str(v.name, `${path}.name`, true) });
280
+ const unknown = Object.keys(v).find((k) => !["src", "strength", "name", "preserveSkinTones"].includes(k));
281
+ if (unknown) fail(`${path}.${unknown}`, "is not a LUT setting; use src, strength, name, preserveSkinTones");
282
+ return compact({ src: str(v.src, `${path}.src`), strength: num(v.strength, `${path}.strength`, { optional: true, min: 0, max: 1 }), name: str(v.name, `${path}.name`, true), preserveSkinTones: num(v.preserveSkinTones, `${path}.preserveSkinTones`, { optional: true, min: 0, max: 1 }) });
283
+ }
284
+ var MASK_KEYS = ["shape", "x", "y", "width", "height", "rotation", "feather", "cornerRadius", "inverted", "points"];
285
+ function parseVideoClipMask(v, path) {
286
+ if (v === void 0) return void 0;
287
+ if (!isObject(v)) return fail(path, 'must be an object such as { shape: "ellipse", x: 0.5, y: 0.5, width: 0.4, height: 0.6, feather: 20 }');
288
+ const unknown = Object.keys(v).find((k) => !MASK_KEYS.includes(k));
289
+ if (unknown) fail(`${path}.${unknown}`, `is not a mask setting; use ${MASK_KEYS.join(", ")}`);
290
+ const shape = oneOf(v.shape, VIDEO_MASK_SHAPES, `${path}.shape`, false);
291
+ let points;
292
+ if (v.points !== void 0) {
293
+ if (shape !== "polygon") fail(`${path}.points`, "is only for polygon masks");
294
+ if (!Array.isArray(v.points) || v.points.length < 3) fail(`${path}.points`, "must be a list of at least 3 { x, y } points");
295
+ points = v.points.map((p, i) => {
296
+ if (!isObject(p)) return fail(`${path}.points[${i}]`, "must be an object { x, y }");
297
+ return { x: num(p.x, `${path}.points[${i}].x`), y: num(p.y, `${path}.points[${i}].y`) };
298
+ });
299
+ } else if (shape === "polygon") fail(`${path}.points`, "is required for a polygon mask: at least 3 { x, y } points as fractions of the picture");
300
+ return compact({
301
+ shape,
302
+ x: num(v.x, `${path}.x`, { optional: true }),
303
+ y: num(v.y, `${path}.y`, { optional: true }),
304
+ width: num(v.width, `${path}.width`, { optional: true, min: 0 }),
305
+ height: num(v.height, `${path}.height`, { optional: true, min: 0 }),
306
+ rotation: num(v.rotation, `${path}.rotation`, { optional: true }),
307
+ feather: num(v.feather, `${path}.feather`, { optional: true, min: 0 }),
308
+ cornerRadius: num(v.cornerRadius, `${path}.cornerRadius`, { optional: true, min: 0, max: 1 }),
309
+ inverted: bool(v.inverted, `${path}.inverted`),
310
+ points
311
+ });
266
312
  }
267
313
  function parseVideoTransition(v, path) {
268
314
  if (v === void 0) return void 0;
@@ -384,7 +430,8 @@ function parseVideoClip(v, path = "clip") {
384
430
  fadeIn: num(v.fadeIn, `${path}.fadeIn`, { optional: true, min: 0 }),
385
431
  fadeOut: num(v.fadeOut, `${path}.fadeOut`, { optional: true, min: 0 }),
386
432
  transition: parseVideoTransition(v.transition, `${path}.transition`),
387
- effects: parseVideoClipEffects(v.effects, `${path}.effects`)
433
+ effects: parseVideoClipEffects(v.effects, `${path}.effects`),
434
+ mask: parseVideoClipMask(v.mask, `${path}.mask`)
388
435
  };
389
436
  if (type === "media")
390
437
  return compact({
@@ -424,6 +471,13 @@ function parseVideoClip(v, path = "clip") {
424
471
  fontWeight: num(v.fontWeight, `${path}.fontWeight`, { optional: true, min: 100, max: 1e3 }),
425
472
  background: str(v.background, `${path}.background`, true)
426
473
  });
474
+ if (type === "adjustment") {
475
+ const scope = oneOf(v.scope, VIDEO_ADJUSTMENT_SCOPES, `${path}.scope`);
476
+ const targetTrack = str(v.targetTrack, `${path}.targetTrack`, true);
477
+ if (scope === "track" && !targetTrack) fail(`${path}.targetTrack`, 'is required when scope is "track": the id of the track whose pictures the adjustment changes');
478
+ if (targetTrack !== void 0 && scope !== "track") fail(`${path}.targetTrack`, 'is only for scope "track"');
479
+ return compact({ type, ...base, scope, targetTrack });
480
+ }
427
481
  if (type === "effect") {
428
482
  const ref = parseVideoEffectRef({ effect: v.effect, provider: v.provider, name: v.name === void 0 ? void 0 : v.name, values: v.values }, path);
429
483
  return compact({ type, ...base, ...ref, name: base.name });
@@ -545,6 +599,7 @@ var VIDEO_ISSUE_CODES = [
545
599
  "unused-asset",
546
600
  "unused-sequence",
547
601
  "marker-past-end",
602
+ "missing-target-track",
548
603
  "empty"
549
604
  ];
550
605
  var videoIssueKey = (i) => [i.code, i.sequence ?? "", i.track ?? "", i.clip ?? "", i.asset ?? "", i.marker ?? ""].join("|");
@@ -589,6 +644,8 @@ function checkVideoProject(project) {
589
644
  issues.push({ code: "source-overrun", severity: "error", ...at, message: `Clip "${clip.id}" plays to ${formatVideoSeconds(range.out)} of "${asset.id}", which is only ${formatVideoSeconds(asset.duration)} long; shorten the clip or move its in point.` });
590
645
  }
591
646
  } else if (track.kind === "audio") issues.push({ code: "wrong-track", severity: "error", ...at, message: `Clip "${clip.id}" is a ${clip.type} clip on audio track "${track.id}"; move it to a video track.` });
647
+ if (clip.type === "adjustment" && (clip.scope ?? "underneath") === "track" && !(sequence ? sequences.get(sequence)?.tracks ?? [] : project.tracks).some((t) => t.id === clip.targetTrack))
648
+ issues.push({ code: "missing-target-track", severity: "warning", ...at, message: `Adjustment clip "${clip.id}" changes track "${clip.targetTrack}", which is not ${sequence ? `in sequence "${sequence}"` : "in the project"}, so it changes nothing; set its targetTrack to a track beside it or change its scope.` });
592
649
  const next = clips[i + 1];
593
650
  if (next && next.start < videoClipEnd(clip) - VIDEO_TIME_EPSILON)
594
651
  issues.push({ code: "overlap", severity: "error", ...at, message: `Clips "${clip.id}" and "${next.id}" overlap on track "${track.id}"${where} from ${formatVideoSeconds(next.start)}; move one of them.` });
@@ -725,7 +782,7 @@ function retimeClipKeys(clip, fn) {
725
782
  if (isVideoKeyframes(v)) a.set(fn(v));
726
783
  }
727
784
  }
728
- var OPTIONAL_CLIP_FIELDS = ["name", "effects", "values", "provider", "opacity", "transform", "fit", "blend", "grade", "animateIn", "animateOut", "fadeIn", "fadeOut", "fadeInCurve", "fadeOutCurve", "transition", "in", "speed", "timeRemap", "volume", "muted", "color", "fontSize", "fontFamily", "fontWeight", "background"];
785
+ var OPTIONAL_CLIP_FIELDS = ["name", "effects", "mask", "scope", "targetTrack", "values", "provider", "opacity", "transform", "fit", "blend", "grade", "animateIn", "animateOut", "fadeIn", "fadeOut", "fadeInCurve", "fadeOutCurve", "transition", "in", "speed", "timeRemap", "volume", "muted", "color", "fontSize", "fontFamily", "fontWeight", "background"];
729
786
  var TIME_FIELDS = { slip_clip: ["delta"], roll_edit: ["delta"], slide_clip: ["delta"], lift_range: ["from", "to"], extract_range: ["from", "to"], split_at: ["at"] };
730
787
  var Editor = class {
731
788
  constructor(p) {
@@ -763,6 +820,12 @@ var Editor = class {
763
820
  refuse(`${what} at ${formatVideoSeconds(start)}\u2013${formatVideoSeconds(start + duration)} would overlap clip "${hit.id}" (${formatVideoSeconds(hit.start)}\u2013${formatVideoSeconds(videoClipEnd(hit))}) on track "${track.id}"; the next free place is ${formatVideoSeconds(free)}, or use mode "insert" to push later clips along or "overwrite" to replace what is there.`);
764
821
  }
765
822
  }
823
+ /** An adjustment clip's target track must exist. */
824
+ adjustmentTarget(clip) {
825
+ if (clip.type !== "adjustment" || clip.targetTrack === void 0) return;
826
+ const ids = allVideoTracks(this.p).map(({ track }) => track.id);
827
+ if (!ids.includes(clip.targetTrack)) refuse(`Adjustment clip "${clip.id}" targets track ${namedWithSuggestion(clip.targetTrack, ids)}, which does not exist; the tracks are ${ids.map((t) => `"${t}"`).join(", ")}.`);
828
+ }
766
829
  kindFits(track, clip) {
767
830
  const asset = clip.type === "media" ? this.asset(clip.asset) : null;
768
831
  if (clip.type === "sequence") {
@@ -1028,6 +1091,7 @@ var Editor = class {
1028
1091
  const end = sortedVideoClips(track).reduce((m, c) => Math.max(m, videoClipEnd(c)), 0);
1029
1092
  draft.start ??= end;
1030
1093
  const clip = parseVideoClip(draft, "clip");
1094
+ this.adjustmentTarget(clip);
1031
1095
  const outcome = { op: e.op, clip: clip.id, track: track.id };
1032
1096
  this.place(track, clip, mode, outcome);
1033
1097
  return this.outcomes.push(outcome);
@@ -1161,6 +1225,7 @@ var Editor = class {
1161
1225
  if (stretch !== 1) retimeClipKeys(next, (v) => retimeVideoAnimatable(v, 0, stretch));
1162
1226
  for (const k of e.remove ?? []) delete next[k];
1163
1227
  const clip = parseVideoClip(next, "set");
1228
+ this.adjustmentTarget(clip);
1164
1229
  if (clip.type === "media" && clip.asset !== at.clip.asset) this.kindFits(at.track, clip);
1165
1230
  if (clip.start !== at.clip.start || clip.duration !== at.clip.duration) this.fits(at.track, clip.start, clip.duration, /* @__PURE__ */ new Set([clip.id]), `Clip "${clip.id}"`);
1166
1231
  at.track.clips[at.index] = clip;
@@ -1171,7 +1236,7 @@ var Editor = class {
1171
1236
  const { track, clip } = this.clip(e.clip);
1172
1237
  this.unlocked(track);
1173
1238
  if (clip.type === "sequence") refuse(`Clip "${clip.id}" is a compound clip, which plays its sequence at normal speed; ramp the clips inside the sequence instead.`);
1174
- if (clip.type !== "media") refuse(`Clip "${clip.id}" is a ${clip.type === "text" ? "title" : clip.type === "effect" ? "effect clip" : "colour"}, so it has no source to ramp; only video and audio clips change speed.`);
1239
+ if (clip.type !== "media") refuse(`Clip "${clip.id}" is a ${videoClipTypeLabel(clip)}, so it has no source to ramp; only video and audio clips change speed.`);
1175
1240
  const asset = this.asset(clip.asset);
1176
1241
  if (asset.kind === "image") refuse(`Clip "${clip.id}" is a still ("${asset.id}"), so it has no motion to ramp.`);
1177
1242
  const media = clip;
@@ -1228,7 +1293,7 @@ var Editor = class {
1228
1293
  case "slip_clip": {
1229
1294
  const { track, clip } = this.clip(e.clip);
1230
1295
  this.unlocked(track);
1231
- if (clip.type !== "media" && clip.type !== "sequence") refuse(`Clip "${clip.id}" is a ${clip.type === "text" ? "title" : clip.type === "effect" ? "effect clip" : "colour"}, so it has no source to slip; only video, audio and compound clips slip.`);
1296
+ if (clip.type !== "media" && clip.type !== "sequence") refuse(`Clip "${clip.id}" is a ${videoClipTypeLabel(clip)}, so it has no source to slip; only video, audio and compound clips slip.`);
1232
1297
  const source = clip.type === "sequence" ? `sequence "${clip.sequence}"` : `"${this.asset(clip.asset).id}"`;
1233
1298
  if (clip.type === "media" && this.asset(clip.asset).kind === "image") refuse(`Clip "${clip.id}" is a still ("${clip.asset}"), so it has no source to slip; only video and audio clips slip.`);
1234
1299
  const handles = videoClipHandles(clip, videoAssetMap(this.p), videoSequenceMap(this.p));
@@ -1428,6 +1493,432 @@ function applyVideoEdits(project, edits) {
1428
1493
  return { ok: true, project: next, issues, outcomes: editor.outcomes };
1429
1494
  }
1430
1495
 
1496
+ // src/video-editor/transcript.ts
1497
+ var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1498
+ function cueTime(s) {
1499
+ const m = s.trim().match(/^(?:(\d+):)?(\d{1,2}):(\d{1,2})[.,](\d{1,3})$/);
1500
+ if (!m) throw new Error(`"${s.trim()}" is not a cue time (HH:MM:SS,mmm).`);
1501
+ return ((Number(m[1] ?? 0) * 60 + Number(m[2])) * 60 + Number(m[3])) * 1e3 + Number(m[4].padEnd(3, "0"));
1502
+ }
1503
+ function cueWords(text, start, end) {
1504
+ const words = text.replace(/<[^>]+>/g, "").split(/\s+/).filter(Boolean);
1505
+ const step = (end - start) / Math.max(1, words.length);
1506
+ return words.map((word, i) => ({ word, start: Math.round(start + i * step), end: Math.round(start + (i + 1) * step) }));
1507
+ }
1508
+ function parseVideoTranscript(input) {
1509
+ let data = input;
1510
+ if (typeof input === "string") {
1511
+ const text = input.replace(/^/, "").trim();
1512
+ if (text.startsWith("{") || text.startsWith("[")) {
1513
+ try {
1514
+ data = JSON.parse(text);
1515
+ } catch {
1516
+ throw new Error("The transcript looks like JSON but is not valid JSON.");
1517
+ }
1518
+ } else {
1519
+ const words2 = [];
1520
+ for (const block of text.replace(/\r\n?/g, "\n").split(/\n{2,}/)) {
1521
+ const lines = block.split("\n");
1522
+ const at = lines.findIndex((l) => l.includes("-->"));
1523
+ if (at < 0) continue;
1524
+ const [a, b] = lines[at].split("-->");
1525
+ words2.push(...cueWords(lines.slice(at + 1).join(" "), cueTime(a), cueTime(b.trim().split(/\s+/)[0])));
1526
+ }
1527
+ if (!words2.length) throw new Error("No words found: expected Whisper-style JSON with word timings, SubRip (.srt) or WebVTT.");
1528
+ return { words: words2, approximate: true };
1529
+ }
1530
+ }
1531
+ const seconds = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v * 1e3) : NaN;
1532
+ const fromList = (list, toMs) => list.map((w, i) => {
1533
+ if (!isRecord(w)) throw new Error(`Word ${i + 1} is not an object { word, start, end }.`);
1534
+ const word = String(w.word ?? w.text ?? "").trim();
1535
+ const start = toMs(w.start);
1536
+ const end = toMs(w.end);
1537
+ if (!word || !Number.isFinite(start) || !Number.isFinite(end)) throw new Error(`Word ${i + 1} needs a word and numeric start and end.`);
1538
+ return { word, start, end: Math.max(start, end) };
1539
+ });
1540
+ let words = [];
1541
+ if (Array.isArray(data)) words = fromList(data, (v) => typeof v === "number" ? v : NaN);
1542
+ else if (isRecord(data) && Array.isArray(data.words)) words = fromList(data.words, seconds);
1543
+ else if (isRecord(data) && Array.isArray(data.segments)) {
1544
+ const segments = data.segments.filter(isRecord);
1545
+ if (segments.some((s) => Array.isArray(s.words))) words = fromList(segments.flatMap((s) => Array.isArray(s.words) ? s.words : []), seconds);
1546
+ else {
1547
+ for (const s of segments) words.push(...cueWords(String(s.text ?? ""), seconds(s.start), seconds(s.end)));
1548
+ if (!words.length) throw new Error("No words found in the segments.");
1549
+ return { words, approximate: true };
1550
+ }
1551
+ }
1552
+ if (!words.length) throw new Error("No words found: expected Whisper-style JSON with word timings, SubRip (.srt) or WebVTT.");
1553
+ return { words: words.sort((a, b) => a.start - b.start), approximate: false };
1554
+ }
1555
+ function videoTranscriptTrack(project, track) {
1556
+ if (track !== void 0) {
1557
+ if (!project.tracks.some((t) => t.id === track)) throw new Error(`There is no track "${track}"; the tracks are ${project.tracks.map((t) => `"${t.id}"`).join(", ")}.`);
1558
+ return track;
1559
+ }
1560
+ const assets = videoAssetMap(project);
1561
+ const transcribed = (t) => t.clips.some((c) => c.type === "media" && assets.get(c.asset)?.transcript?.length);
1562
+ return (project.tracks.find((t) => t.kind === "audio" && transcribed(t)) ?? project.tracks.find(transcribed))?.id ?? null;
1563
+ }
1564
+ function videoTimelineTranscript(project, options = {}) {
1565
+ const id = videoTranscriptTrack(project, options.track);
1566
+ if (!id) return [];
1567
+ const track = project.tracks.find((t) => t.id === id);
1568
+ const assets = videoAssetMap(project);
1569
+ const out = [];
1570
+ for (const clip of sortedVideoClips(track)) {
1571
+ if (clip.type !== "media") continue;
1572
+ const words = assets.get(clip.asset)?.transcript;
1573
+ if (!words?.length) continue;
1574
+ const speed = videoClipSpeed(clip);
1575
+ const from = clip.in ?? 0;
1576
+ const to = from + clip.duration * speed;
1577
+ const toTimeline = (s) => Math.min(videoClipEnd(clip), Math.max(clip.start, clip.start + (s - from) / speed));
1578
+ words.forEach((w, index) => {
1579
+ const mid = (w.start + w.end) / 2;
1580
+ if (mid < from || mid >= to) return;
1581
+ out.push({ word: w.word, start: toTimeline(w.start), end: toTimeline(w.end), clip: clip.id, track: track.id, index });
1582
+ });
1583
+ }
1584
+ return out;
1585
+ }
1586
+ var normalizeVideoWord = (word) => word.toLowerCase().replace(/^[^\p{L}\p{N}']+|[^\p{L}\p{N}']+$/gu, "");
1587
+ var rangeOf = (words, i, n) => ({ from: words[i].start, to: words[i + n - 1].end, text: words.slice(i, i + n).map((w) => w.word).join(" ") });
1588
+ function findVideoTranscriptText(words, query) {
1589
+ const q = query.split(/\s+/).map(normalizeVideoWord).filter(Boolean);
1590
+ if (!q.length) throw new Error("Search for at least one word.");
1591
+ const norm = words.map((w) => normalizeVideoWord(w.word));
1592
+ const out = [];
1593
+ for (let i = 0; i + q.length <= norm.length; i++) if (q.every((x, k) => norm[i + k] === x)) out.push(rangeOf(words, i, q.length));
1594
+ return out;
1595
+ }
1596
+ var VIDEO_DEFAULT_FILLERS = ["um", "umm", "uh", "uhh", "uhm", "erm", "er", "ah", "hmm", "mm", "you know", "i mean"];
1597
+ function findVideoFillers(words, fillers = VIDEO_DEFAULT_FILLERS) {
1598
+ const phrases = fillers.map((f) => f.split(/\s+/).map(normalizeVideoWord).filter(Boolean)).filter((p) => p.length).sort((a, b) => b.length - a.length);
1599
+ const norm = words.map((w) => normalizeVideoWord(w.word));
1600
+ const out = [];
1601
+ for (let i = 0; i < norm.length; ) {
1602
+ const hit = phrases.find((p) => i + p.length <= norm.length && p.every((x, k) => norm[i + k] === x));
1603
+ if (hit) {
1604
+ out.push(rangeOf(words, i, hit.length));
1605
+ i += hit.length;
1606
+ } else i++;
1607
+ }
1608
+ return out;
1609
+ }
1610
+ function findVideoTranscriptPauses(words, options = {}) {
1611
+ const min = options.min ?? 700;
1612
+ const keep = options.keep ?? 150;
1613
+ const out = [];
1614
+ for (let i = 1; i < words.length; i++) {
1615
+ const a = words[i - 1];
1616
+ const b = words[i];
1617
+ if (a.clip !== b.clip || b.start - a.end < min) continue;
1618
+ let from = a.end + keep;
1619
+ let to = b.start - keep;
1620
+ if (options.fps) {
1621
+ const f = 1e3 / options.fps;
1622
+ from = snapToVideoFrame(Math.ceil(from / f - 1e-9) * f, options.fps);
1623
+ to = snapToVideoFrame(Math.floor(to / f + 1e-9) * f, options.fps);
1624
+ }
1625
+ if (to - from > VIDEO_TIME_EPSILON) out.push({ from, to, text: `(pause after "${a.word}")` });
1626
+ }
1627
+ return out;
1628
+ }
1629
+ function mergeVideoRanges(ranges) {
1630
+ const sorted = ranges.filter((r) => r.to - r.from > VIDEO_TIME_EPSILON).map((r) => ({ from: r.from, to: r.to })).sort((a, b) => a.from - b.from);
1631
+ const out = [];
1632
+ for (const r of sorted) {
1633
+ const last = out[out.length - 1];
1634
+ if (last && r.from <= last.to + VIDEO_TIME_EPSILON) last.to = Math.max(last.to, r.to);
1635
+ else out.push(r);
1636
+ }
1637
+ return out;
1638
+ }
1639
+ function videoRemoveRangesEdits(ranges, tracks) {
1640
+ return mergeVideoRanges(ranges).reverse().map((r) => ({ op: "extract_range", from: r.from, to: r.to, ...tracks ? { tracks } : {} }));
1641
+ }
1642
+ function videoWordsRange(words, a, b) {
1643
+ const [i, j] = a <= b ? [a, b] : [b, a];
1644
+ return { from: words[i].start, to: words[j].end };
1645
+ }
1646
+ function videoTranscriptEdit(assetId, text) {
1647
+ return { op: "update_asset", asset: assetId, set: { transcript: parseVideoTranscript(text).words } };
1648
+ }
1649
+ function videoWordAt(words, time) {
1650
+ let lo = 0;
1651
+ let hi = words.length - 1;
1652
+ while (lo <= hi) {
1653
+ const mid = lo + hi >> 1;
1654
+ if (words[mid].end <= time) lo = mid + 1;
1655
+ else if (words[mid].start > time) hi = mid - 1;
1656
+ else return mid;
1657
+ }
1658
+ return -1;
1659
+ }
1660
+ function findVideoRepetitions(words, options = {}) {
1661
+ const max = Math.max(1, options.maxPhrase ?? 3);
1662
+ const maxGap = options.maxGap ?? 1e3;
1663
+ const norm = words.map((w) => normalizeVideoWord(w.word));
1664
+ const out = [];
1665
+ for (let i = 0; i < norm.length; i++) {
1666
+ for (let n = Math.min(max, Math.floor((norm.length - i) / 2)); n >= 1; n--) {
1667
+ let same = true;
1668
+ for (let k = 0; k < n && same; k++) same = !!norm[i + k] && norm[i + k] === norm[i + n + k];
1669
+ if (!same || words[i + n].start - words[i + n - 1].end > maxGap) continue;
1670
+ out.push({ from: words[i].start, to: words[i + n].start, text: words.slice(i, i + n).map((w) => w.word).join(" ") });
1671
+ i += n - 1;
1672
+ break;
1673
+ }
1674
+ }
1675
+ return out;
1676
+ }
1677
+ var VIDEO_DISFLUENCY_KINDS = ["filler", "pause", "repetition"];
1678
+ function detectVideoDisfluencies(words, options = {}) {
1679
+ const kinds = new Set(options.kinds ?? VIDEO_DISFLUENCY_KINDS);
1680
+ const startIndex = (time) => Math.max(0, words.findIndex((w) => w.start >= time - VIDEO_TIME_EPSILON));
1681
+ const out = [];
1682
+ if (kinds.has("filler"))
1683
+ for (const r of findVideoFillers(words, options.fillers)) {
1684
+ const first = startIndex(r.from);
1685
+ out.push({ ...r, kind: "filler", words: [first, first + r.text.split(" ").length - 1] });
1686
+ }
1687
+ if (kinds.has("repetition"))
1688
+ for (const r of findVideoRepetitions(words, options.repetitions)) {
1689
+ const first = startIndex(r.from);
1690
+ out.push({ ...r, kind: "repetition", words: [first, first + r.text.split(" ").length - 1] });
1691
+ }
1692
+ if (kinds.has("pause"))
1693
+ for (const r of findVideoTranscriptPauses(words, options.pauses)) {
1694
+ const after = words.findIndex((w) => w.start >= r.to - VIDEO_TIME_EPSILON);
1695
+ out.push({ ...r, kind: "pause", words: [Math.max(0, after - 1), Math.max(0, after)] });
1696
+ }
1697
+ return out.sort((a, b) => a.from - b.from || a.to - b.to);
1698
+ }
1699
+ function videoCutsWithMargin(ranges, keep) {
1700
+ return ranges.map((r) => ({ ...r, from: r.from + keep, to: r.to - keep })).filter((r) => r.to - r.from > VIDEO_TIME_EPSILON);
1701
+ }
1702
+
1703
+ // src/video-editor/mix.ts
1704
+ var VIDEO_LOUDNESS_HOP = 100;
1705
+ function kWeighting(sampleRate) {
1706
+ let K = Math.tan(Math.PI * 1681.974450955533 / sampleRate);
1707
+ const Vh = 10 ** (3.999843853973347 / 20);
1708
+ const Vb = Vh ** 0.4996667741545416;
1709
+ let Q = 0.7071752369554196;
1710
+ let a0 = 1 + K / Q + K * K;
1711
+ const shelf = { b: [(Vh + Vb * K / Q + K * K) / a0, 2 * (K * K - Vh) / a0, (Vh - Vb * K / Q + K * K) / a0], a: [2 * (K * K - 1) / a0, (1 - K / Q + K * K) / a0] };
1712
+ K = Math.tan(Math.PI * 38.13547087602444 / sampleRate);
1713
+ Q = 0.5003270373238773;
1714
+ a0 = 1 + K / Q + K * K;
1715
+ const highPass = { b: [1, -2, 1], a: [2 * (K * K - 1) / a0, (1 - K / Q + K * K) / a0] };
1716
+ return [shelf, highPass];
1717
+ }
1718
+ function videoLoudnessEnergy(channels, sampleRate) {
1719
+ const length = channels.reduce((n, c) => Math.max(n, c.length), 0);
1720
+ const hopSamples = Math.max(1, Math.round(sampleRate * VIDEO_LOUDNESS_HOP / 1e3));
1721
+ const hops = Math.max(1, Math.ceil(length / hopSamples));
1722
+ const energy = new Float32Array(hops);
1723
+ const filters = kWeighting(sampleRate);
1724
+ for (const channel of channels) {
1725
+ const x1 = [0, 0];
1726
+ const x2 = [0, 0];
1727
+ const y1 = [0, 0];
1728
+ const y2 = [0, 0];
1729
+ for (let i = 0; i < channel.length; i++) {
1730
+ let v = Number.isFinite(channel[i]) ? channel[i] : 0;
1731
+ for (let f = 0; f < 2; f++) {
1732
+ const { b, a } = filters[f];
1733
+ const y = b[0] * v + b[1] * x1[f] + b[2] * x2[f] - a[0] * y1[f] - a[1] * y2[f];
1734
+ x2[f] = x1[f];
1735
+ x1[f] = v;
1736
+ y2[f] = y1[f];
1737
+ y1[f] = y;
1738
+ v = y;
1739
+ }
1740
+ energy[Math.floor(i / hopSamples)] += v * v;
1741
+ }
1742
+ }
1743
+ for (let h = 0; h < hops; h++) energy[h] /= Math.min(hopSamples, length - h * hopSamples) || 1;
1744
+ return { hop: VIDEO_LOUDNESS_HOP, energy };
1745
+ }
1746
+ var lufs = (meanSquare) => -0.691 + 10 * Math.log10(meanSquare);
1747
+ function videoLoudnessOf(loudness, from = 0, to = Infinity) {
1748
+ const { hop, energy } = loudness;
1749
+ const a = Math.max(0, Math.floor(from / hop));
1750
+ const b = Math.min(energy.length, Math.ceil(to / hop));
1751
+ if (b <= a) return null;
1752
+ const blocks = [];
1753
+ if (b - a < 4) {
1754
+ let sum = 0;
1755
+ for (let h = a; h < b; h++) sum += energy[h];
1756
+ blocks.push(sum / (b - a));
1757
+ } else
1758
+ for (let h = a; h + 4 <= b; h++) blocks.push((energy[h] + energy[h + 1] + energy[h + 2] + energy[h + 3]) / 4);
1759
+ const absolute = blocks.filter((z) => z > 0 && lufs(z) > -70);
1760
+ if (!absolute.length) return null;
1761
+ const threshold = lufs(absolute.reduce((s, z) => s + z, 0) / absolute.length) - 10;
1762
+ const gated = absolute.filter((z) => lufs(z) > threshold);
1763
+ if (!gated.length) return null;
1764
+ return Math.round(lufs(gated.reduce((s, z) => s + z, 0) / gated.length) * 10) / 10;
1765
+ }
1766
+ function measureVideoLoudness(channels, sampleRate) {
1767
+ return videoLoudnessOf(videoLoudnessEnergy(channels, sampleRate));
1768
+ }
1769
+ function videoAudioLoudness(peaks, from = 0, to = Infinity) {
1770
+ if (!peaks.loudness) throw new Error("These peaks have no loudness data; build them again with buildVideoAudioPeaks (or decodeVideoAudioPeaks), which measures it.");
1771
+ return videoLoudnessOf(peaks.loudness, from, to);
1772
+ }
1773
+ function videoLoudnessGain(measured, target = -14, options = {}) {
1774
+ let db = target - measured;
1775
+ let limitedBy;
1776
+ const maxDb = 20 * Math.log10(options.maxGain ?? 4);
1777
+ if (db > maxDb) {
1778
+ db = maxDb;
1779
+ limitedBy = "max-gain";
1780
+ }
1781
+ if (options.peakDb !== void 0 && options.peakDb > -100) {
1782
+ const room = (options.ceiling ?? -1) - options.peakDb;
1783
+ if (db > room) {
1784
+ db = room;
1785
+ limitedBy = "peak";
1786
+ }
1787
+ }
1788
+ return { gain: Math.round(10 ** (db / 20) * 1e3) / 1e3, gainDb: Math.round(db * 10) / 10, ...limitedBy ? { limitedBy } : {} };
1789
+ }
1790
+ function videoSpeechRanges(words, mergeGap = 500) {
1791
+ const merged = [];
1792
+ for (const r of mergeVideoRanges(words.map((w) => ({ from: w.start, to: w.end })))) {
1793
+ const last = merged[merged.length - 1];
1794
+ if (last && r.from - last.to < mergeGap) last.to = Math.max(last.to, r.to);
1795
+ else merged.push({ ...r });
1796
+ }
1797
+ return merged;
1798
+ }
1799
+ function videoDuckingKeys(clip, speech, options = {}) {
1800
+ const duckDb = options.duckDb ?? -14;
1801
+ const attack = Math.max(0, options.attack ?? 200);
1802
+ const release = Math.max(0, options.release ?? 400);
1803
+ const gap = Math.max(options.mergeGap ?? 600, attack + release);
1804
+ const base = options.base ?? 1;
1805
+ const low = Math.round(base * 10 ** (duckDb / 20) * 1e4) / 1e4;
1806
+ const end = videoClipEnd(clip);
1807
+ const ranges = [];
1808
+ for (const r of mergeVideoRanges(speech)) {
1809
+ if (r.to <= clip.start - release || r.from >= end + attack) continue;
1810
+ const last = ranges[ranges.length - 1];
1811
+ if (last && r.from - last.to < gap) last.to = Math.max(last.to, r.to);
1812
+ else ranges.push({ ...r });
1813
+ }
1814
+ if (!ranges.length) return [];
1815
+ const keys = [];
1816
+ const at = (t) => Math.round(Math.min(clip.duration, Math.max(0, t - clip.start)));
1817
+ const push = (t, v, ease) => {
1818
+ const last = keys[keys.length - 1];
1819
+ if (last && t <= last.t) {
1820
+ last.v = v;
1821
+ if (ease) last.ease = ease;
1822
+ else delete last.ease;
1823
+ return;
1824
+ }
1825
+ keys.push({ t, v, ...ease ? { ease } : {} });
1826
+ };
1827
+ for (const r of ranges) {
1828
+ const down = at(r.from - attack);
1829
+ const held = at(r.from);
1830
+ if (held > down) push(down, base, "ease-in-out");
1831
+ push(held, low);
1832
+ const hold = at(r.to);
1833
+ const up = at(r.to + release);
1834
+ if (up > hold) {
1835
+ push(hold, low, "ease-in-out");
1836
+ push(up, base);
1837
+ }
1838
+ }
1839
+ return keys;
1840
+ }
1841
+ function findVideoAudioBeats(peaks, from, to, options = {}) {
1842
+ const res = Math.max(1, options.resolution ?? 10);
1843
+ const n = Math.max(2, Math.ceil((to - from) / res));
1844
+ const spans = videoAudioPeakSpans(peaks, from, to, n);
1845
+ const env = new Float32Array(n);
1846
+ for (let i = 0; i < n; i++) env[i] = Math.max(Math.abs(spans[2 * i]), Math.abs(spans[2 * i + 1]));
1847
+ const onset = new Float32Array(n);
1848
+ for (let i = 1; i < n; i++) onset[i] = Math.max(0, env[i] - env[i - 1]);
1849
+ const win = Math.max(1, Math.round(500 / res));
1850
+ const k = options.sensitivity ?? 1.5;
1851
+ const minGap = Math.max(1, Math.round((options.minInterval ?? 250) / res));
1852
+ const onsets = [];
1853
+ const strength = [];
1854
+ let lastAt = -Infinity;
1855
+ for (let i = 1; i < n - 1; i++) {
1856
+ if (!(onset[i] > 0 && onset[i] >= onset[i - 1] && onset[i] >= onset[i + 1])) continue;
1857
+ let sum = 0;
1858
+ let sq = 0;
1859
+ let count = 0;
1860
+ for (let j = Math.max(0, i - win); j < Math.min(n, i + win + 1); j++) {
1861
+ sum += onset[j];
1862
+ sq += onset[j] * onset[j];
1863
+ count++;
1864
+ }
1865
+ const mean = sum / count;
1866
+ const sd = Math.sqrt(Math.max(0, sq / count - mean * mean));
1867
+ if (onset[i] < mean + k * sd || onset[i] < 0.02) continue;
1868
+ if (i - lastAt < minGap) {
1869
+ if (onset[i] > strength[strength.length - 1]) {
1870
+ onsets[onsets.length - 1] = from + i * res;
1871
+ strength[strength.length - 1] = onset[i];
1872
+ lastAt = i;
1873
+ }
1874
+ continue;
1875
+ }
1876
+ onsets.push(from + i * res);
1877
+ strength.push(onset[i]);
1878
+ lastAt = i;
1879
+ }
1880
+ const minLag = Math.max(1, Math.round(6e4 / (options.maxBpm ?? 200) / res));
1881
+ const maxLag = Math.min(n - 1, Math.round(6e4 / (options.minBpm ?? 60) / res));
1882
+ let bestLag = 0;
1883
+ let best = 0;
1884
+ let total = 0;
1885
+ for (let i = 0; i < n; i++) total += onset[i] * onset[i];
1886
+ for (let lag = minLag; lag <= maxLag; lag++) {
1887
+ let s = 0;
1888
+ for (let i = 0; i + lag < n; i++) s += onset[i] * onset[i + lag];
1889
+ s /= n - lag;
1890
+ if (s > best * 1.0001) {
1891
+ best = s;
1892
+ bestLag = lag;
1893
+ }
1894
+ }
1895
+ const repeats = onsets.length >= 3 && bestLag > 0 && best * n > 0.2 * total;
1896
+ if (!repeats) return { onsets, bpm: null, beats: [] };
1897
+ const period = bestLag * res;
1898
+ const bpm = Math.round(6e4 / period * 10) / 10;
1899
+ let phase = onsets[0];
1900
+ let agree = -1;
1901
+ for (const o of onsets) {
1902
+ let a = 0;
1903
+ for (const p of onsets) {
1904
+ const d = Math.abs(((p - o) % period + period) % period);
1905
+ if (Math.min(d, period - d) <= res * 2) a++;
1906
+ }
1907
+ if (a > agree) {
1908
+ agree = a;
1909
+ phase = o;
1910
+ }
1911
+ }
1912
+ const beats = [];
1913
+ for (let t = phase - Math.floor((phase - from) / period) * period; t <= to + 1e-6; t += period) if (t >= from - 1e-6) beats.push(Math.round(t * 10) / 10);
1914
+ return { onsets, bpm, beats };
1915
+ }
1916
+ function nearestVideoBeat(beats, time, tolerance = Infinity) {
1917
+ let best = null;
1918
+ for (const b of beats) if (Math.abs(b - time) <= tolerance && (best === null || Math.abs(b - time) < Math.abs(best - time))) best = b;
1919
+ return best;
1920
+ }
1921
+
1431
1922
  // src/video-editor/audio.ts
1432
1923
  var VIDEO_PEAK_BLOCK = 32;
1433
1924
  function buildVideoAudioPeaks(channels, sampleRate, blockSize = VIDEO_PEAK_BLOCK) {
@@ -1467,7 +1958,7 @@ function buildVideoAudioPeaks(channels, sampleRate, blockSize = VIDEO_PEAK_BLOCK
1467
1958
  }
1468
1959
  levels.push(up);
1469
1960
  }
1470
- return { sampleRate, length, blockSize, levels };
1961
+ return { sampleRate, length, blockSize, levels, loudness: videoLoudnessEnergy(channels, sampleRate) };
1471
1962
  }
1472
1963
  var videoAudioPeaksDuration = (peaks) => peaks.length * 1e3 / peaks.sampleRate;
1473
1964
  function videoAudioPeakRange(peaks, from, to) {
@@ -1645,6 +2136,50 @@ var VideoAudioPeaksCache = class {
1645
2136
  }
1646
2137
  };
1647
2138
 
2139
+ // src/video-editor/plan.ts
2140
+ function clipIndex(project) {
2141
+ const out = /* @__PURE__ */ new Map();
2142
+ for (const { track } of allVideoTracks(project)) for (const c of track.clips) out.set(c.id, c);
2143
+ return out;
2144
+ }
2145
+ function diffVideoProjects(before, after) {
2146
+ const a = clipIndex(before);
2147
+ const b = clipIndex(after);
2148
+ const clipsAdded = [...b.keys()].filter((id) => !a.has(id));
2149
+ const clipsRemoved = [...a.keys()].filter((id) => !b.has(id));
2150
+ const clipsChanged = [...b.keys()].filter((id) => a.has(id) && JSON.stringify(a.get(id)) !== JSON.stringify(b.get(id)));
2151
+ const durationBefore = videoProjectDuration(before);
2152
+ const durationAfter = videoProjectDuration(after);
2153
+ return { durationBefore, durationAfter, durationDelta: durationAfter - durationBefore, clipsAdded, clipsRemoved, clipsChanged };
2154
+ }
2155
+ function planVideoEdits(project, input) {
2156
+ if (!input.title?.trim()) return { ok: false, error: 'A plan needs a title saying what it does (e.g. "Remove 12 filler words").' };
2157
+ if (!input.edits.length) return { ok: false, error: "The plan has no edits; there is nothing to propose." };
2158
+ const result = applyVideoEdits(project, input.edits);
2159
+ if (!result.ok) return { ok: false, error: result.error };
2160
+ const known = new Set(checkVideoProject(project).map(videoIssueKey));
2161
+ const summary = { ...diffVideoProjects(project, result.project), newIssues: result.issues.filter((i) => !known.has(videoIssueKey(i))), edits: input.edits.length };
2162
+ const plan = {
2163
+ id: input.id ?? "plan",
2164
+ title: input.title.trim(),
2165
+ ...input.description ? { description: input.description } : {},
2166
+ ...input.source ? { source: input.source } : {},
2167
+ edits: structuredClone([...input.edits]),
2168
+ ...input.ranges?.length ? { ranges: input.ranges.map((r) => ({ ...r })) } : {},
2169
+ summary
2170
+ };
2171
+ return { ok: true, plan, project: result.project };
2172
+ }
2173
+ function describeVideoEditPlan(plan) {
2174
+ const s = plan.summary;
2175
+ const parts = [];
2176
+ if (plan.ranges?.length) parts.push(`${plan.ranges.length} stretch${plan.ranges.length > 1 ? "es" : ""}`);
2177
+ const delta = s.durationDelta;
2178
+ const length = Math.abs(delta) < 0.5 ? "same length" : `${(Math.abs(delta) / 1e3).toFixed(1)} s ${delta < 0 ? "shorter" : "longer"}`;
2179
+ const clips = [s.clipsAdded.length && `${s.clipsAdded.length} added`, s.clipsChanged.length && `${s.clipsChanged.length} changed`, s.clipsRemoved.length && `${s.clipsRemoved.length} removed`].filter(Boolean).join(", ");
2180
+ return `${plan.title} (${parts.length ? `${parts.join(", ")}, ` : ""}${length})${clips ? `: clips ${clips}` : ""}`;
2181
+ }
2182
+
1648
2183
  // src/video-editor/scopes.ts
1649
2184
  var VIDEO_SCOPE_KINDS = ["histogram", "waveform", "vectorscope"];
1650
2185
  var videoLuma = (r, g, b) => 0.2126 * r + 0.7152 * g + 0.0722 * b;
@@ -2014,174 +2549,178 @@ function readVideoScopesPanel(feed, kinds = VIDEO_SCOPE_KINDS, options = {}) {
2014
2549
  const opts = { maxPixels: options.maxPixels ?? 65536 };
2015
2550
  const images = {};
2016
2551
  for (const kind of kinds) images[kind] = videoScopeImage(kind, snap.pixels, width, height, opts);
2017
- const stats = videoExposureStats(snap.pixels, opts);
2018
- return { ok: true, time: snap.time, complete: snap.complete, images, stats, notes: videoExposureNotes(stats) };
2019
- }
2020
-
2021
- // src/video-editor/transcript.ts
2022
- var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2023
- function cueTime(s) {
2024
- const m = s.trim().match(/^(?:(\d+):)?(\d{1,2}):(\d{1,2})[.,](\d{1,3})$/);
2025
- if (!m) throw new Error(`"${s.trim()}" is not a cue time (HH:MM:SS,mmm).`);
2026
- return ((Number(m[1] ?? 0) * 60 + Number(m[2])) * 60 + Number(m[3])) * 1e3 + Number(m[4].padEnd(3, "0"));
2027
- }
2028
- function cueWords(text, start, end) {
2029
- const words = text.replace(/<[^>]+>/g, "").split(/\s+/).filter(Boolean);
2030
- const step = (end - start) / Math.max(1, words.length);
2031
- return words.map((word, i) => ({ word, start: Math.round(start + i * step), end: Math.round(start + (i + 1) * step) }));
2032
- }
2033
- function parseVideoTranscript(input) {
2034
- let data = input;
2035
- if (typeof input === "string") {
2036
- const text = input.replace(/^/, "").trim();
2037
- if (text.startsWith("{") || text.startsWith("[")) {
2038
- try {
2039
- data = JSON.parse(text);
2040
- } catch {
2041
- throw new Error("The transcript looks like JSON but is not valid JSON.");
2042
- }
2043
- } else {
2044
- const words2 = [];
2045
- for (const block of text.replace(/\r\n?/g, "\n").split(/\n{2,}/)) {
2046
- const lines = block.split("\n");
2047
- const at = lines.findIndex((l) => l.includes("-->"));
2048
- if (at < 0) continue;
2049
- const [a, b] = lines[at].split("-->");
2050
- words2.push(...cueWords(lines.slice(at + 1).join(" "), cueTime(a), cueTime(b.trim().split(/\s+/)[0])));
2051
- }
2052
- if (!words2.length) throw new Error("No words found: expected Whisper-style JSON with word timings, SubRip (.srt) or WebVTT.");
2053
- return { words: words2, approximate: true };
2054
- }
2055
- }
2056
- const seconds = (v) => typeof v === "number" && Number.isFinite(v) ? Math.round(v * 1e3) : NaN;
2057
- const fromList = (list, toMs) => list.map((w, i) => {
2058
- if (!isRecord(w)) throw new Error(`Word ${i + 1} is not an object { word, start, end }.`);
2059
- const word = String(w.word ?? w.text ?? "").trim();
2060
- const start = toMs(w.start);
2061
- const end = toMs(w.end);
2062
- if (!word || !Number.isFinite(start) || !Number.isFinite(end)) throw new Error(`Word ${i + 1} needs a word and numeric start and end.`);
2063
- return { word, start, end: Math.max(start, end) };
2064
- });
2065
- let words = [];
2066
- if (Array.isArray(data)) words = fromList(data, (v) => typeof v === "number" ? v : NaN);
2067
- else if (isRecord(data) && Array.isArray(data.words)) words = fromList(data.words, seconds);
2068
- else if (isRecord(data) && Array.isArray(data.segments)) {
2069
- const segments = data.segments.filter(isRecord);
2070
- if (segments.some((s) => Array.isArray(s.words))) words = fromList(segments.flatMap((s) => Array.isArray(s.words) ? s.words : []), seconds);
2071
- else {
2072
- for (const s of segments) words.push(...cueWords(String(s.text ?? ""), seconds(s.start), seconds(s.end)));
2073
- if (!words.length) throw new Error("No words found in the segments.");
2074
- return { words, approximate: true };
2075
- }
2076
- }
2077
- if (!words.length) throw new Error("No words found: expected Whisper-style JSON with word timings, SubRip (.srt) or WebVTT.");
2078
- return { words: words.sort((a, b) => a.start - b.start), approximate: false };
2079
- }
2080
- function videoTranscriptTrack(project, track) {
2081
- if (track !== void 0) {
2082
- if (!project.tracks.some((t) => t.id === track)) throw new Error(`There is no track "${track}"; the tracks are ${project.tracks.map((t) => `"${t.id}"`).join(", ")}.`);
2083
- return track;
2084
- }
2085
- const assets = videoAssetMap(project);
2086
- const transcribed = (t) => t.clips.some((c) => c.type === "media" && assets.get(c.asset)?.transcript?.length);
2087
- return (project.tracks.find((t) => t.kind === "audio" && transcribed(t)) ?? project.tracks.find(transcribed))?.id ?? null;
2088
- }
2089
- function videoTimelineTranscript(project, options = {}) {
2090
- const id = videoTranscriptTrack(project, options.track);
2091
- if (!id) return [];
2092
- const track = project.tracks.find((t) => t.id === id);
2093
- const assets = videoAssetMap(project);
2094
- const out = [];
2095
- for (const clip of sortedVideoClips(track)) {
2096
- if (clip.type !== "media") continue;
2097
- const words = assets.get(clip.asset)?.transcript;
2098
- if (!words?.length) continue;
2099
- const speed = videoClipSpeed(clip);
2100
- const from = clip.in ?? 0;
2101
- const to = from + clip.duration * speed;
2102
- const toTimeline = (s) => Math.min(videoClipEnd(clip), Math.max(clip.start, clip.start + (s - from) / speed));
2103
- words.forEach((w, index) => {
2104
- const mid = (w.start + w.end) / 2;
2105
- if (mid < from || mid >= to) return;
2106
- out.push({ word: w.word, start: toTimeline(w.start), end: toTimeline(w.end), clip: clip.id, track: track.id, index });
2107
- });
2108
- }
2109
- return out;
2110
- }
2111
- var normalizeVideoWord = (word) => word.toLowerCase().replace(/^[^\p{L}\p{N}']+|[^\p{L}\p{N}']+$/gu, "");
2112
- var rangeOf = (words, i, n) => ({ from: words[i].start, to: words[i + n - 1].end, text: words.slice(i, i + n).map((w) => w.word).join(" ") });
2113
- function findVideoTranscriptText(words, query) {
2114
- const q = query.split(/\s+/).map(normalizeVideoWord).filter(Boolean);
2115
- if (!q.length) throw new Error("Search for at least one word.");
2116
- const norm = words.map((w) => normalizeVideoWord(w.word));
2117
- const out = [];
2118
- for (let i = 0; i + q.length <= norm.length; i++) if (q.every((x, k) => norm[i + k] === x)) out.push(rangeOf(words, i, q.length));
2119
- return out;
2120
- }
2121
- var VIDEO_DEFAULT_FILLERS = ["um", "umm", "uh", "uhh", "uhm", "erm", "er", "ah", "hmm", "mm", "you know", "i mean"];
2122
- function findVideoFillers(words, fillers = VIDEO_DEFAULT_FILLERS) {
2123
- const phrases = fillers.map((f) => f.split(/\s+/).map(normalizeVideoWord).filter(Boolean)).filter((p) => p.length).sort((a, b) => b.length - a.length);
2124
- const norm = words.map((w) => normalizeVideoWord(w.word));
2125
- const out = [];
2126
- for (let i = 0; i < norm.length; ) {
2127
- const hit = phrases.find((p) => i + p.length <= norm.length && p.every((x, k) => norm[i + k] === x));
2128
- if (hit) {
2129
- out.push(rangeOf(words, i, hit.length));
2130
- i += hit.length;
2131
- } else i++;
2132
- }
2133
- return out;
2552
+ const stats = videoExposureStats(snap.pixels, opts);
2553
+ return { ok: true, time: snap.time, complete: snap.complete, images, stats, notes: videoExposureNotes(stats) };
2134
2554
  }
2135
- function findVideoTranscriptPauses(words, options = {}) {
2136
- const min = options.min ?? 700;
2137
- const keep = options.keep ?? 150;
2138
- const out = [];
2139
- for (let i = 1; i < words.length; i++) {
2140
- const a = words[i - 1];
2141
- const b = words[i];
2142
- if (a.clip !== b.clip || b.start - a.end < min) continue;
2143
- let from = a.end + keep;
2144
- let to = b.start - keep;
2145
- if (options.fps) {
2146
- const f = 1e3 / options.fps;
2147
- from = snapToVideoFrame(Math.ceil(from / f - 1e-9) * f, options.fps);
2148
- to = snapToVideoFrame(Math.floor(to / f + 1e-9) * f, options.fps);
2555
+
2556
+ // src/video-editor/transcript-controller.ts
2557
+ var TranscriptVideoController = class {
2558
+ constructor(controller, options = {}) {
2559
+ this.controller = controller;
2560
+ this.options = options;
2561
+ this.track = options.track;
2562
+ this.state = this.compute();
2563
+ this.connect();
2564
+ }
2565
+ controller;
2566
+ options;
2567
+ listeners = /* @__PURE__ */ new Set();
2568
+ unsubscribe = null;
2569
+ track;
2570
+ selection = null;
2571
+ error = null;
2572
+ state;
2573
+ /** Words and disfluencies are worked out once per project. */
2574
+ cache = null;
2575
+ getState = () => this.state;
2576
+ connect() {
2577
+ if (this.unsubscribe) return;
2578
+ this.unsubscribe = this.controller.subscribe(() => this.refresh());
2579
+ this.refresh();
2580
+ }
2581
+ /** Listens for changes. Subscribing after `destroy` follows the editor again (React StrictMode remounts). */
2582
+ subscribe = (listener) => {
2583
+ this.connect();
2584
+ this.listeners.add(listener);
2585
+ return () => {
2586
+ this.listeners.delete(listener);
2587
+ };
2588
+ };
2589
+ /** Stops following the editor. */
2590
+ destroy() {
2591
+ this.unsubscribe?.();
2592
+ this.unsubscribe = null;
2593
+ this.listeners.clear();
2594
+ }
2595
+ words(project) {
2596
+ const c = this.cache;
2597
+ if (c && c.project === project && c.track === this.track) return c;
2598
+ let words = [];
2599
+ let trackId = null;
2600
+ try {
2601
+ trackId = videoTranscriptTrack(project, this.track);
2602
+ words = videoTimelineTranscript(project, { track: this.track });
2603
+ } catch {
2149
2604
  }
2150
- if (to - from > VIDEO_TIME_EPSILON) out.push({ from, to, text: `(pause after "${a.word}")` });
2605
+ const disfluencies = detectVideoDisfluencies(words, { ...this.options.disfluencies, pauses: { fps: project.fps, ...this.options.disfluencies?.pauses } });
2606
+ const flags = {};
2607
+ for (const d of disfluencies)
2608
+ for (let i = d.words[0]; i <= d.words[1]; i++) {
2609
+ if (d.kind === "pause" && i !== d.words[0]) continue;
2610
+ const f = flags[i] ??= [];
2611
+ if (!f.includes(d.kind)) f.push(d.kind);
2612
+ }
2613
+ this.cache = { project, track: this.track, words, trackId, text: words.map((w) => w.word).join(" "), disfluencies, flags };
2614
+ return this.cache;
2615
+ }
2616
+ compute() {
2617
+ const editor = this.controller.getState();
2618
+ const c = this.words(editor.project);
2619
+ if (this.selection && (this.selection[0] >= c.words.length || this.selection[1] >= c.words.length)) this.selection = null;
2620
+ return { track: c.trackId, words: c.words, text: c.text, current: videoWordAt(c.words, editor.time), selection: this.selection, disfluencies: c.disfluencies, flags: c.flags, editable: !editor.readOnly, error: this.error };
2621
+ }
2622
+ refresh() {
2623
+ const next = this.compute();
2624
+ const prev = this.state;
2625
+ if (next.words === prev.words && next.current === prev.current && next.selection === prev.selection && next.editable === prev.editable && next.error === prev.error && next.disfluencies === prev.disfluencies) return;
2626
+ this.state = next;
2627
+ this.listeners.forEach((l) => l(next));
2628
+ }
2629
+ /** Follows another track's words (`undefined`: the default track). */
2630
+ setTrack(track) {
2631
+ this.track = track;
2632
+ this.selection = null;
2633
+ this.refresh();
2634
+ }
2635
+ /** Moves the playhead to the start of a word. */
2636
+ seekToWord(index) {
2637
+ const w = this.state.words[index];
2638
+ if (w) this.controller.seek(w.start);
2639
+ }
2640
+ /** Selects words `a` to `b` (either order), or clears the selection with `null`. */
2641
+ select(a, b = a) {
2642
+ const n = this.state.words.length;
2643
+ this.selection = a === null || b === null || a < 0 || b < 0 || a >= n || b >= n ? null : a <= b ? [a, b] : [b, a];
2644
+ this.error = null;
2645
+ this.refresh();
2646
+ }
2647
+ /** Index of the word playing at a timeline time, or -1. */
2648
+ wordAt(time) {
2649
+ return videoWordAt(this.state.words, time);
2650
+ }
2651
+ /** Where word `index` begins in `text` (characters). */
2652
+ textOffset(index) {
2653
+ let offset = 0;
2654
+ for (let i = 0; i < Math.min(index, this.state.words.length); i++) offset += this.state.words[i].word.length + 1;
2655
+ return offset;
2656
+ }
2657
+ /** The word a caret at `offset` characters into `text` is in (or just after), as an index; -1 when there are no words. */
2658
+ wordAtOffset(offset) {
2659
+ const { words } = this.state;
2660
+ let at = 0;
2661
+ for (let i = 0; i < words.length; i++) {
2662
+ at += words[i].word.length;
2663
+ if (offset <= at) return i;
2664
+ at += 1;
2665
+ }
2666
+ return words.length - 1;
2151
2667
  }
2152
- return out;
2153
- }
2154
- function mergeVideoRanges(ranges) {
2155
- const sorted = ranges.filter((r) => r.to - r.from > VIDEO_TIME_EPSILON).map((r) => ({ from: r.from, to: r.to })).sort((a, b) => a.from - b.from);
2156
- const out = [];
2157
- for (const r of sorted) {
2158
- const last = out[out.length - 1];
2159
- if (last && r.from <= last.to + VIDEO_TIME_EPSILON) last.to = Math.max(last.to, r.to);
2160
- else out.push(r);
2668
+ /** The timeline time a caret at `offset` characters into `text` stands for: the start of its word. */
2669
+ timeAtOffset(offset) {
2670
+ const i = this.wordAtOffset(offset);
2671
+ return i < 0 ? null : this.state.words[i].start;
2161
2672
  }
2162
- return out;
2163
- }
2164
- function videoRemoveRangesEdits(ranges, tracks) {
2165
- return mergeVideoRanges(ranges).reverse().map((r) => ({ op: "extract_range", from: r.from, to: r.to, ...tracks ? { tracks } : {} }));
2166
- }
2167
- function videoWordsRange(words, a, b) {
2168
- const [i, j] = a <= b ? [a, b] : [b, a];
2169
- return { from: words[i].start, to: words[j].end };
2170
- }
2171
- function videoTranscriptEdit(assetId, text) {
2172
- return { op: "update_asset", asset: assetId, set: { transcript: parseVideoTranscript(text).words } };
2173
- }
2174
- function videoWordAt(words, time) {
2175
- let lo = 0;
2176
- let hi = words.length - 1;
2177
- while (lo <= hi) {
2178
- const mid = lo + hi >> 1;
2179
- if (words[mid].end <= time) lo = mid + 1;
2180
- else if (words[mid].start > time) hi = mid - 1;
2181
- else return mid;
2673
+ fail(message) {
2674
+ this.error = message;
2675
+ this.refresh();
2676
+ return { ok: false, error: message };
2182
2677
  }
2183
- return -1;
2184
- }
2678
+ /** Cuts ranges out (or proposes a plan to, with `plan`), as one undo step. */
2679
+ cut(ranges, title, plan) {
2680
+ if (!ranges.length) return this.fail("There is nothing to cut.");
2681
+ const merged = mergeVideoRanges(ranges);
2682
+ const edits = videoRemoveRangesEdits(merged);
2683
+ if (plan) {
2684
+ const r2 = this.controller.proposePlan({ title, edits, ranges, source: "transcript" });
2685
+ if (!r2.ok) return this.fail(r2.error);
2686
+ this.error = null;
2687
+ this.select(null);
2688
+ return { ok: true, plan: r2.plan };
2689
+ }
2690
+ const r = this.controller.apply(edits, title);
2691
+ if (!r.ok) return this.fail(r.error);
2692
+ this.error = null;
2693
+ this.select(null);
2694
+ return { ok: true, applied: r };
2695
+ }
2696
+ /** Deletes the selected words, cutting their stretch out of the timeline (or proposing it with `planFirst`). */
2697
+ deleteSelection(options = {}) {
2698
+ const sel = this.state.selection;
2699
+ if (!sel) return this.fail("Select the words to delete first.");
2700
+ const { words } = this.state;
2701
+ const range = videoWordsRange(words, sel[0], sel[1]);
2702
+ const text = words.slice(sel[0], sel[1] + 1).map((w) => w.word).join(" ");
2703
+ return this.cut([{ ...range, text, reason: "deleted" }], sel[0] === sel[1] ? `Delete "${text}"` : `Delete ${sel[1] - sel[0] + 1} words`, options.plan ?? this.options.planFirst ?? false);
2704
+ }
2705
+ /** Cuts one disfluency out at once (its index in `disfluencies`), as one undo step. */
2706
+ removeDisfluency(index) {
2707
+ const d = this.state.disfluencies[index];
2708
+ if (!d) return this.fail(`There is no disfluency ${index}; there are ${this.state.disfluencies.length}.`);
2709
+ return this.cut([{ from: d.from, to: d.to, text: d.text, reason: d.kind }], d.kind === "pause" ? "Tighten pause" : `Remove "${d.text}"`, false);
2710
+ }
2711
+ /** Proposes one plan that cuts every disfluency of the given kinds (default all), for review. */
2712
+ planCleanup(kinds) {
2713
+ const found = this.state.disfluencies.filter((d) => !kinds || kinds.includes(d.kind));
2714
+ if (!found.length) return this.fail(kinds ? `No ${kinds.join(", ")} found.` : "No fillers, long pauses or repetitions found.");
2715
+ const counts = ["filler", "pause", "repetition"].map((k) => [k, found.filter((d) => d.kind === k).length]).filter(([, n]) => n);
2716
+ const title = `Clean up ${counts.map(([k, n]) => `${n} ${k}${n > 1 ? "s" : ""}`).join(", ")}`;
2717
+ return this.cut(
2718
+ found.map((d) => ({ from: d.from, to: d.to, text: d.text, reason: d.kind })),
2719
+ title,
2720
+ true
2721
+ );
2722
+ }
2723
+ };
2185
2724
 
2186
2725
  // src/video-editor/proxy.ts
2187
2726
  var VIDEO_PROXY_SCALES = [0.5, 0.25];
@@ -2773,7 +3312,7 @@ var VideoPreviewEngine = class {
2773
3312
  };
2774
3313
 
2775
3314
  // src/video-editor/controller.ts
2776
- var VideoEditorController = class {
3315
+ var VideoEditorController = class _VideoEditorController {
2777
3316
  history;
2778
3317
  player;
2779
3318
  /** Sound levels per asset, loaded on demand for waveforms and agents. */
@@ -2800,6 +3339,10 @@ var VideoEditorController = class {
2800
3339
  listeners = /* @__PURE__ */ new Set();
2801
3340
  unsubscribers = [];
2802
3341
  state;
3342
+ plans = [];
3343
+ /** The project each open plan was worked out against. */
3344
+ planBasis = /* @__PURE__ */ new Map();
3345
+ planCount = 0;
2803
3346
  constructor(options = {}) {
2804
3347
  this.history = options.history ?? new HistoryManager();
2805
3348
  this.audioPeaks = options.audioPeaks instanceof VideoAudioPeaksCache ? options.audioPeaks : new VideoAudioPeaksCache(options.audioPeaks);
@@ -2865,6 +3408,7 @@ var VideoEditorController = class {
2865
3408
  redoLabel: h.redoName,
2866
3409
  previewScale: this.previewScale,
2867
3410
  effectsProvider: this.effects.provider,
3411
+ plans: this.plans,
2868
3412
  revision: this.revision
2869
3413
  };
2870
3414
  }
@@ -2933,6 +3477,86 @@ var VideoEditorController = class {
2933
3477
  if (!options.dryRun) this.commit(label, result.project, options.merge);
2934
3478
  return result;
2935
3479
  }
3480
+ // -----------------------------------------------------------------------------------------
3481
+ // Edit plans: propose, review, apply or discard
3482
+ // -----------------------------------------------------------------------------------------
3483
+ /** Most plans kept open at once; proposing another drops the oldest. */
3484
+ static MAX_PLANS = 20;
3485
+ /**
3486
+ * Works out a batch of edits without applying it and keeps it for review (see `VideoEditPlan`):
3487
+ * the result says what it would do. Allowed while read-only (nothing changes); applying is not.
3488
+ * A plan with the id of an open one replaces it.
3489
+ */
3490
+ proposePlan(input) {
3491
+ const ids = new Set(this.plans.map((p) => p.id));
3492
+ let id = input.id;
3493
+ let count = this.planCount;
3494
+ if (id === void 0) {
3495
+ do
3496
+ id = `plan${++count}`;
3497
+ while (ids.has(id));
3498
+ }
3499
+ const result = planVideoEdits(this.project, { ...input, id });
3500
+ if (!result.ok) return result;
3501
+ this.planCount = count;
3502
+ const kept = this.plans.filter((p) => p.id !== id);
3503
+ while (kept.length >= _VideoEditorController.MAX_PLANS) this.planBasis.delete(kept.shift().id);
3504
+ this.plans = [...kept, result.plan];
3505
+ this.planBasis.set(id, this.project);
3506
+ this.notify();
3507
+ return { ok: true, plan: result.plan };
3508
+ }
3509
+ /** An open plan, or `undefined`. */
3510
+ getPlan(id) {
3511
+ return this.plans.find((p) => p.id === id);
3512
+ }
3513
+ /** Whether the project changed since a plan was made (its summary may then be out of date). */
3514
+ isPlanStale(id) {
3515
+ const basis = this.planBasis.get(id);
3516
+ return !!basis && basis !== this.project;
3517
+ }
3518
+ /** The project as an open plan would leave it, worked out against the current project; `null` when it no longer applies. */
3519
+ planPreview(id) {
3520
+ const plan = this.getPlan(id);
3521
+ if (!plan) return null;
3522
+ const result = applyVideoEdits(this.project, plan.edits);
3523
+ return result.ok ? result.project : null;
3524
+ }
3525
+ /**
3526
+ * Applies an open plan as one undo step labelled with its title and closes it. If the project
3527
+ * changed since it was made, its edits are checked again against the project as it is now and
3528
+ * refused (the plan stays open) when they no longer apply.
3529
+ */
3530
+ applyPlan(id) {
3531
+ const plan = this.getPlan(id);
3532
+ if (!plan) return this.refused(`There is no open plan "${id}"; the open plans are ${this.plans.map((p) => `"${p.id}"`).join(", ") || "none"}.`);
3533
+ const reason = this.readOnlyReason();
3534
+ if (reason) return this.refused(reason);
3535
+ const stale = this.isPlanStale(id);
3536
+ const result = applyVideoEdits(this.project, plan.edits);
3537
+ if (!result.ok) return this.refused(stale ? `The project changed since plan "${id}" was made and it no longer applies (${result.error}); discard it and make a new plan.` : result.error);
3538
+ this.dropPlan(id);
3539
+ this.commit(plan.title, result.project);
3540
+ return { ...result, plan, stale };
3541
+ }
3542
+ /** Closes an open plan without applying it. False when there is no such plan. */
3543
+ discardPlan(id) {
3544
+ if (!this.getPlan(id)) return false;
3545
+ this.dropPlan(id);
3546
+ this.notify();
3547
+ return true;
3548
+ }
3549
+ /** Closes every open plan. */
3550
+ discardPlans() {
3551
+ if (!this.plans.length) return;
3552
+ this.plans = [];
3553
+ this.planBasis.clear();
3554
+ this.notify();
3555
+ }
3556
+ dropPlan(id) {
3557
+ this.plans = this.plans.filter((p) => p.id !== id);
3558
+ this.planBasis.delete(id);
3559
+ }
2936
3560
  /** Opens a project (JSON or object). `clearHistory` drops the undo stack (opening a file); otherwise it is one undo step. */
2937
3561
  load(project, options = {}) {
2938
3562
  let parsed;
@@ -3345,6 +3969,7 @@ function videoClipTint(clip, asset) {
3345
3969
  if (clip.type === "sequence") return "#0d9488";
3346
3970
  if (clip.type === "color") return clip.color;
3347
3971
  if (clip.type === "effect") return "#db2777";
3972
+ if (clip.type === "adjustment") return "#64748b";
3348
3973
  if (!asset) return "#ef4444";
3349
3974
  return asset.kind === "audio" ? "#10b981" : asset.kind === "image" ? "#f59e0b" : "#3b82f6";
3350
3975
  }
@@ -3354,6 +3979,7 @@ function videoClipLabel(clip, asset, sequence) {
3354
3979
  if (clip.type === "color") return clip.color;
3355
3980
  if (clip.type === "sequence") return `Compound: ${sequence?.name ?? clip.sequence}`;
3356
3981
  if (clip.type === "effect") return `Effect: ${clip.effect}`;
3982
+ if (clip.type === "adjustment") return `Adjustment${clip.scope === "all" ? " (all tracks)" : clip.scope === "track" ? ` (${clip.targetTrack})` : ""}`;
3357
3983
  const base = asset?.name ?? asset?.src.replace(/^.*[\\/]/, "") ?? clip.asset;
3358
3984
  const speed = videoClipSpeed(clip);
3359
3985
  return speed !== 1 ? `${base} (${Math.round(speed * 100)}%)` : base;
@@ -3518,6 +4144,50 @@ function videoLutEdits(project, clips, lut) {
3518
4144
  }
3519
4145
  return edits;
3520
4146
  }
4147
+ var VIDEO_ADJUSTMENT_SCOPE_LABELS = {
4148
+ underneath: "Tracks underneath",
4149
+ all: "Whole frame",
4150
+ track: "One track"
4151
+ };
4152
+ var VIDEO_MASK_SHAPE_LABELS = {
4153
+ rectangle: "Rectangle",
4154
+ ellipse: "Ellipse",
4155
+ linear: "Split",
4156
+ polygon: "Polygon"
4157
+ };
4158
+ var videoClipHeading = (clip) => ({ media: "Media clip", text: "Title", sequence: "Compound clip", color: "Colour clip", effect: "Effect clip", adjustment: "Adjustment clip" })[clip.type];
4159
+ function videoAddAdjustmentEdits(project, time, options = {}) {
4160
+ const duration = options.duration ?? 3e3;
4161
+ const start = Math.max(0, time);
4162
+ const top = project.tracks[0];
4163
+ const free = top && top.kind === "video" && !top.locked && !top.clips.some((c) => c.start < start + duration && videoClipEnd(c) > start);
4164
+ const edits = [];
4165
+ let track = top?.id;
4166
+ if (!free) {
4167
+ const ids = new Set(project.tracks.map((t) => t.id));
4168
+ let n = 1;
4169
+ while (ids.has(n === 1 ? "adj" : `adj${n}`)) n++;
4170
+ track = n === 1 ? "adj" : `adj${n}`;
4171
+ edits.push({ op: "add_track", track: { id: track, kind: "video", name: "Adjustments" }, at: 0 });
4172
+ }
4173
+ edits.push({ op: "add_clip", track, clip: { type: "adjustment", ...options.id ? { id: options.id } : {}, start, duration, ...options.grade ? { grade: options.grade } : {} } });
4174
+ return edits;
4175
+ }
4176
+ function videoMaskEdit(clip, mask) {
4177
+ return mask ? { op: "update_clip", clip, set: { mask } } : { op: "update_clip", clip, remove: ["mask"] };
4178
+ }
4179
+ function videoSkinProtectionEdits(project, clips, amount) {
4180
+ const edits = [];
4181
+ for (const id of clips) {
4182
+ const clip = findVideoClip(project, id)?.clip;
4183
+ const lut = clip?.grade?.lut;
4184
+ if (!clip || !lut) continue;
4185
+ const { preserveSkinTones: _p, ...rest } = lut;
4186
+ const k = Math.min(1, Math.max(0, amount));
4187
+ edits.push({ op: "update_clip", clip: id, set: { grade: { ...clip.grade, lut: k > 0 ? { ...rest, preserveSkinTones: k } : rest } } });
4188
+ }
4189
+ return edits;
4190
+ }
3521
4191
 
3522
4192
  // src/video-editor/tools.ts
3523
4193
  var round = (ms) => Math.round(ms * 10) / 10;
@@ -3571,10 +4241,11 @@ var TRANSITION = object(
3571
4241
  );
3572
4242
  var LUT_SRC = { type: "string", minLength: 1, description: 'A .cube 3D LUT file the host can load and ffmpeg can read: a URL or path, often from the user (e.g. "luts/teal-orange.cube").' };
3573
4243
  var LUT_STRENGTH = { type: "number", minimum: 0, maximum: 1, description: "How much of the LUT's change to apply, 0 (none) to 1 (full, the default); 0.3-0.7 for a subtler look." };
4244
+ var SKIN = { type: "number", minimum: 0, maximum: 1, description: "How much of the LUT's change to hold back on skin tones, 0 (none, the default) to 1 (skin keeps its colour); 0.5-0.8 keeps faces natural under a heavy look. Applied in the preview and frame renders; ffmpeg's lut3d cannot, so the export notes it." };
3574
4245
  var GRADE = object(
3575
4246
  {
3576
4247
  ...Object.fromEntries(VIDEO_GRADE_CONTROLS.map((c) => [c.key, { type: "number", minimum: c.min, maximum: c.max, description: c.description }])),
3577
- lut: object({ src: LUT_SRC, strength: LUT_STRENGTH, name: { type: "string", minLength: 1, description: "A label for the look." } }, ["src"], "A 3D LUT applied after the other settings (set_video_lut checks the file first).")
4248
+ lut: object({ src: LUT_SRC, strength: LUT_STRENGTH, name: { type: "string", minLength: 1, description: "A label for the look." }, preserveSkinTones: SKIN }, ["src"], "A 3D LUT applied after the other settings (set_video_lut checks the file first).")
3578
4249
  },
3579
4250
  [],
3580
4251
  "Colour correction of the picture, applied in order: exposure, contrast, saturation, hue, white balance (temperature, tint), then a LUT. Leave a setting out for no change; the object replaces the clip's whole grade."
@@ -4053,12 +4724,12 @@ function createVideoEditorToolProvider(controller, options = {}) {
4053
4724
  const updateClip = {
4054
4725
  name: "update_video_clip",
4055
4726
  title: "Change a clip",
4056
- description: `Changes a clip's properties (one undo step): opacity, transform, fit, blend mode, colour grade, entrance and exit animations, fades, name; for media volume, mute, the sound's fade curves, speed (keeps the stretch of source, so the length changes) or asset; for compound clips in point, volume, mute and fade curves (no speed); for titles text and style; for colours the colour. Fields in "remove" go back to their defaults. Use move / trim for timing. Returns the clip.`,
4727
+ description: `Changes a clip's properties (one undo step): opacity, transform, fit, blend mode, colour grade, entrance and exit animations, fades, name; for media volume, mute, the sound's fade curves, speed (keeps the stretch of source, so the length changes) or asset; for compound clips in point, volume, mute and fade curves (no speed); for titles text and style; for colours the colour; for adjustment clips the scope and target track (masks: set_video_clip_mask). Fields in "remove" go back to their defaults. Use move / trim for timing. Returns the clip.`,
4057
4728
  inputSchema: object(
4058
4729
  {
4059
4730
  clip: CLIP_ID,
4060
- set: object({ ...CLIP_COMMON, ...MEDIA_FIELDS, asset: { ...ASSET_ID, description: "For media: play another asset (same in point)." }, ...TEXT_FIELDS, color: COLOR("Text colour, or a colour clip's fill") }, [], "Fields to replace (only those that fit the clip's type)."),
4061
- remove: { type: "array", items: { type: "string", enum: ["name", "opacity", "transform", "fit", "blend", "grade", "animateIn", "animateOut", "fadeIn", "fadeOut", "fadeInCurve", "fadeOutCurve", "in", "speed", "volume", "muted", "fontSize", "fontFamily", "fontWeight", "background"] }, description: "Fields to reset to their defaults." }
4731
+ set: object({ ...CLIP_COMMON, ...MEDIA_FIELDS, asset: { ...ASSET_ID, description: "For media: play another asset (same in point)." }, ...TEXT_FIELDS, color: COLOR("Text colour, or a colour clip's fill"), scope: { type: "string", enum: [...VIDEO_ADJUSTMENT_SCOPES], description: "For adjustment clips: which pictures it changes, underneath (default), all or track." }, targetTrack: { ...TRACK_ID, description: 'For adjustment clips with scope "track": the track whose pictures it changes.' } }, [], "Fields to replace (only those that fit the clip's type)."),
4732
+ remove: { type: "array", items: { type: "string", enum: ["name", "opacity", "transform", "fit", "blend", "grade", "animateIn", "animateOut", "fadeIn", "fadeOut", "fadeInCurve", "fadeOutCurve", "in", "speed", "volume", "muted", "fontSize", "fontFamily", "fontWeight", "background", "scope", "targetTrack"] }, description: 'Fields to reset to their defaults (an adjustment clip going from scope "track" to another scope must also remove targetTrack).' }
4062
4733
  },
4063
4734
  ["clip"]
4064
4735
  ),
@@ -4127,17 +4798,18 @@ function createVideoEditorToolProvider(controller, options = {}) {
4127
4798
  clips: { type: "array", items: CLIP_ID, minItems: 1, uniqueItems: true, description: "Clips on video tracks to grade." },
4128
4799
  src: LUT_SRC,
4129
4800
  strength: LUT_STRENGTH,
4130
- name: { type: "string", minLength: 1, description: "A label for the look (default the file's TITLE)." }
4801
+ name: { type: "string", minLength: 1, description: "A label for the look (default the file's TITLE)." },
4802
+ preserve_skin_tones: SKIN
4131
4803
  },
4132
4804
  ["clips", "src"]
4133
4805
  ),
4134
4806
  annotations: { title: "Apply a LUT", readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
4135
- handler: async ({ clips, src, strength, name }) => {
4807
+ handler: async ({ clips, src, strength, name, preserve_skin_tones }) => {
4136
4808
  if (strength === 0) throw new Error("A strength of 0 changes nothing; pass a strength above 0, or remove the LUT with remove_video_lut.");
4137
4809
  gradeTargets(clips);
4138
4810
  const lut = await controller.luts.load(src);
4139
4811
  const label = name ?? lut.title;
4140
- const setting = { src, ...strength !== void 0 && strength !== 1 ? { strength } : {}, ...label ? { name: label } : {} };
4812
+ const setting = { src, ...strength !== void 0 && strength !== 1 ? { strength } : {}, ...label ? { name: label } : {}, ...preserve_skin_tones ? { preserveSkinTones: preserve_skin_tones } : {} };
4141
4813
  return apply(videoLutEdits(project(), clips, setting), "Apply LUT", (r) => ({ lut: { src, ...lut.title ? { title: lut.title } : {}, size: lut.size }, clips: clips.map((id) => ({ id, grade: findVideoClip(r.project, id)?.clip.grade ?? null })) }));
4142
4814
  }
4143
4815
  };
@@ -4341,7 +5013,7 @@ function createVideoEditorToolProvider(controller, options = {}) {
4341
5013
  if (!at) throw new Error(`There is no clip "${id}"; get_video_project lists the clips.`);
4342
5014
  const { clip } = at;
4343
5015
  if (clip.type === "sequence") throw new Error(`Clip "${id}" is a compound clip, which plays its sequence at normal speed; change the speed of the clips inside the sequence instead.`);
4344
- if (clip.type !== "media") throw new Error(`Clip "${id}" is a ${clip.type === "text" ? "title" : clip.type === "effect" ? "effect clip" : "colour"}, so it has no source to change the speed of; use a video or audio clip.`);
5016
+ if (clip.type !== "media") throw new Error(`Clip "${id}" is a ${videoClipTypeLabel(clip)}, so it has no source to change the speed of; use a video or audio clip.`);
4345
5017
  if (project().assets.find((a) => a.id === clip.asset)?.kind === "image") throw new Error(`Clip "${id}" is a still, so it has no motion to change the speed of.`);
4346
5018
  return clip;
4347
5019
  };
@@ -4595,7 +5267,7 @@ function createVideoEditorToolProvider(controller, options = {}) {
4595
5267
  if (!(to > from)) throw new Error(`The stretch to read is empty (${from}\u2013${to} ms); "to" must be after "from"${args.clip !== void 0 ? " and both inside the clip" : asset.duration === void 0 ? ', and the asset has no duration, so pass "to"' : ""}.`);
4596
5268
  return { asset, from, to, toSource, toOut };
4597
5269
  };
4598
- const SOUND_TARGET = {
5270
+ const SOUND_TARGET2 = {
4599
5271
  clip: { ...CLIP_ID, description: "A media clip: read the stretch of source it plays, with times on the timeline. Pass this or asset." },
4600
5272
  asset: { ...ASSET_ID, description: "A video or audio asset: read its source, with times in the source. Pass this or clip." },
4601
5273
  from: MS("Start of the stretch (default: the clip's start, or 0 for an asset)"),
@@ -4606,7 +5278,7 @@ function createVideoEditorToolProvider(controller, options = {}) {
4606
5278
  name: "get_video_audio_levels",
4607
5279
  title: "Read sound levels",
4608
5280
  description: 'Measures how loud the source sound is over a clip or an asset, without changing anything: the peak level in dBFS (0 = full scale, -100 = silence) for each of "buckets" equal stretches, plus the loudest peak. Levels are the recording as it is, before clip volume and fades. Use it to find where speech or a beat starts, or to judge whether a clip is too loud. The first call for an asset decodes its file, which can take a moment.',
4609
- inputSchema: object({ ...SOUND_TARGET, buckets: { type: "integer", minimum: 1, maximum: 500, description: "How many equal stretches to measure (default 50)." } }),
5281
+ inputSchema: object({ ...SOUND_TARGET2, buckets: { type: "integer", minimum: 1, maximum: 500, description: "How many equal stretches to measure (default 50)." } }),
4610
5282
  annotations: { title: "Read sound levels", ...SOUND_ANNOTATIONS },
4611
5283
  handler: async (args) => {
4612
5284
  const r = soundRange(args);
@@ -4620,7 +5292,7 @@ function createVideoEditorToolProvider(controller, options = {}) {
4620
5292
  title: "Find silences",
4621
5293
  description: "Lists the stretches of a clip or an asset whose source sound stays below a level for at least a minimum length, as { start, end } ms (timeline times for a clip, so they can go straight to extract_video_range or split_video_at; source times for an asset). Use it to cut pauses, dead air or the gaps between takes. The first call for an asset decodes its file.",
4622
5294
  inputSchema: object({
4623
- ...SOUND_TARGET,
5295
+ ...SOUND_TARGET2,
4624
5296
  thresholdDb: { type: "number", minimum: -100, maximum: 0, description: "Quieter than this peak level counts as silence, in dBFS (default -40; -50 for a quiet room, -30 over background noise)." },
4625
5297
  minDuration: { type: "number", exclusiveMinimum: 0, description: "Shortest silence to report, in ms (default 300)." }
4626
5298
  }),
@@ -4671,8 +5343,167 @@ function createVideoEditorToolProvider(controller, options = {}) {
4671
5343
  return { time: t, timecode: formatVideoTimecode(t, p.fps), width: pixels.width, height: pixels.height, ...summarizeVideoScopes(pixels, { bins, columns }) };
4672
5344
  }
4673
5345
  };
4674
- const reads = [getProject, listSequences, getFrame, getTranscript, findText, findFillers, findPauses, findGaps, checkProject, renderFrame, getScopes, previewCache, planProxies, exportFfmpeg, exportLoudnessMeasure, exportEdl, audioLevels, findSilences, seek, setPreviewScale];
4675
- const writes = [setSettings, addAsset, updateAsset, removeAsset, setProxies, addTrack, updateTrack, removeTrack, moveTrack, addClip, moveClip, trimClip, splitClip, deleteClips, updateClip, setTransition, setSpeedRamp, addFreeze, removeRamp, setTranscript, removeRanges, applyGradePreset, copyGrade, setLut, removeLut, setKeyframes, removeKeyframes, slipClip, rollEdit, slideClip, liftRange, extractRange, splitAt, closeGaps, addMarker, removeMarker, editVideo, undo, redo];
5346
+ const MASK_FIELDS = {
5347
+ shape: { type: "string", enum: [...VIDEO_MASK_SHAPES], description: "rectangle (with corner_radius), ellipse, linear (a straight split: the side above the line at rotation 0 shows) or polygon (points)." },
5348
+ x: { type: "number", description: "Centre across the clip's picture, 0 (left edge) to 1 (right edge); default 0.5." },
5349
+ y: { type: "number", description: "Centre down the clip's picture, 0 (top) to 1 (bottom); default 0.5." },
5350
+ width: { type: "number", minimum: 0, description: "Width as a fraction of the picture's width (default 0.5). Unused by linear." },
5351
+ height: { type: "number", minimum: 0, description: "Height as a fraction of the picture's height (default 0.5). Unused by linear." },
5352
+ rotation: { type: "number", description: "Degrees clockwise (default 0)." },
5353
+ feather: { type: "number", minimum: 0, description: "Soft edge width in frame pixels (default 0 = hard edge)." },
5354
+ corner_radius: { type: "number", minimum: 0, maximum: 1, description: "For rectangle: corner rounding as a fraction of half the shorter side (default 0)." },
5355
+ inverted: { type: "boolean", description: "Show the outside of the shape instead of the inside (default false)." },
5356
+ points: { type: "array", minItems: 3, maxItems: 200, items: object({ x: { type: "number", description: "Across the picture, 0\u20131." }, y: { type: "number", description: "Down the picture, 0\u20131." } }, ["x", "y"], "A corner of the polygon."), description: "For polygon (required): its corners in order, as fractions of the clip's picture." }
5357
+ };
5358
+ const addAdjustment = {
5359
+ name: "add_video_adjustment_clip",
5360
+ title: "Add an adjustment clip",
5361
+ description: 'Adds an adjustment clip to a video track (one undo step): it has no picture, but while it plays its grade (and any effects added later with apply_effect, and a mask from set_video_clip_mask) change the composite of the pictures in its scope: "underneath" (every video track below its own, the default), "all" (the whole frame) or "track" (only target_track). Put it on a track above what it should change, usually a new top track. Give the look as "grade" and/or "preset" (a named look at "amount"). Returns the clip (id, start, duration, end, scope).',
5362
+ inputSchema: object(
5363
+ {
5364
+ track: { ...TRACK_ID, description: 'A video track to put it on; tracks below it are "underneath".' },
5365
+ start: MS("Where it starts on the timeline (default: the end of the track)"),
5366
+ duration: { type: "number", exclusiveMinimum: 0, description: "How long it lasts, in ms (default 3000)." },
5367
+ scope: { type: "string", enum: [...VIDEO_ADJUSTMENT_SCOPES], description: "Which pictures it changes: underneath (default), all or track." },
5368
+ target_track: { ...TRACK_ID, description: 'For scope "track" (required then): the track whose pictures it changes.' },
5369
+ grade: GRADE,
5370
+ preset: { type: "string", enum: [...VIDEO_GRADE_PRESET_NAMES], description: "A named look to start from (grade settings given override it)." },
5371
+ amount: { type: "number", minimum: 0, maximum: 1, description: "Strength of the preset, 0\u20131 (default 1)." },
5372
+ name: { type: "string", minLength: 1, description: 'A label for the clip (e.g. "Night look").' },
5373
+ id: { type: "string", minLength: 1, description: 'Your own id for the clip (default: a fresh one such as "c7").' },
5374
+ mode: MODE
5375
+ },
5376
+ ["track"]
5377
+ ),
5378
+ annotations: { title: "Add an adjustment clip", ...WRITE },
5379
+ handler: ({ track, start, duration, scope, target_track, grade, preset, amount, name, id, mode }) => {
5380
+ const t = project().tracks.find((x) => x.id === track);
5381
+ if (t && t.kind !== "video") throw new Error(`Track "${track}" is an audio track; adjustment clips change pictures, so put it on a video track.`);
5382
+ if (scope === "track" && !target_track) throw new Error('Scope "track" needs target_track: the id of the track whose pictures it changes.');
5383
+ if (target_track !== void 0 && scope !== "track") throw new Error('target_track is only for scope "track"; leave it out or set scope to "track".');
5384
+ const look = { ...preset ? videoGradePreset(preset, amount ?? 1) : {}, ...grade ?? {} };
5385
+ const clip = { type: "adjustment", ...id ? { id } : {}, ...name ? { name } : {}, ...start !== void 0 ? { start } : {}, duration: duration ?? 3e3, ...scope ? { scope } : {}, ...target_track ? { targetTrack: target_track } : {}, ...Object.keys(look).length ? { grade: look } : {} };
5386
+ return apply({ op: "add_clip", track, clip, mode }, "Add adjustment clip", (r) => ({ clip: clipOut(r.project, r.outcomes[0].clip), ...placed(r.outcomes[0]), ...Object.keys(look).length ? {} : { hint: "It changes nothing yet: give it a grade (update_video_clip), effects (apply_effect) or a mask." } }));
5387
+ }
5388
+ };
5389
+ const maskTarget = (id) => {
5390
+ const at = findVideoClip(project(), id);
5391
+ if (!at) throw new Error(`There is no clip "${id}"; get_video_project lists the clips.`);
5392
+ if (at.track.kind !== "video") throw new Error(`Clip "${id}" is on audio track "${at.track.id}"; masks cut pictures, so pass a clip on a video track.`);
5393
+ return at;
5394
+ };
5395
+ const setMask = {
5396
+ name: "set_video_clip_mask",
5397
+ title: "Mask a clip",
5398
+ description: `Cuts a clip's picture to a shape (one undo step): only the inside shows, or the outside when inverted, with a soft edge of "feather" pixels. Positions are fractions of the clip's placed picture, so the mask follows the clip's transform. On an adjustment clip it limits the adjustment to the shape (e.g. brighten a face). Replaces any mask the clip had. Returns the clip with its mask. ffmpeg exports need rendered frames for masks.`,
5399
+ inputSchema: object({ clip: CLIP_ID, ...MASK_FIELDS }, ["clip", "shape"]),
5400
+ annotations: { title: "Mask a clip", ...WRITE_IDEMPOTENT },
5401
+ handler: ({ clip, corner_radius, ...fields }) => {
5402
+ maskTarget(clip);
5403
+ if (fields.shape === "polygon" && !fields.points) throw new Error('A polygon mask needs "points": at least 3 { x, y } corners as fractions of the picture.');
5404
+ if (fields.shape !== "polygon" && fields.points) throw new Error('"points" is only for shape "polygon".');
5405
+ if (corner_radius !== void 0 && fields.shape !== "rectangle") throw new Error('"corner_radius" is only for shape "rectangle".');
5406
+ const mask = { ...fields, ...corner_radius !== void 0 ? { cornerRadius: corner_radius } : {} };
5407
+ return apply({ op: "update_clip", clip, set: { mask } }, "Mask clip", (r) => ({ clip: clipOut(r.project, clip) }));
5408
+ }
5409
+ };
5410
+ const removeMask = {
5411
+ name: "remove_video_clip_mask",
5412
+ title: "Remove a clip's mask",
5413
+ description: "Takes a clip's mask off, so its whole picture shows again (one undo step). Fails if it has none. Returns the clip.",
5414
+ inputSchema: object({ clip: CLIP_ID }, ["clip"]),
5415
+ annotations: { title: "Remove a clip's mask", ...DESTRUCTIVE },
5416
+ handler: ({ clip }) => {
5417
+ const at = maskTarget(clip);
5418
+ if (!at.clip.mask) throw new Error(`Clip "${clip}" has no mask.`);
5419
+ return apply({ op: "update_clip", clip, remove: ["mask"] }, "Remove mask", (r) => ({ clip: clipOut(r.project, clip) }));
5420
+ }
5421
+ };
5422
+ const setSkin = {
5423
+ name: "set_video_skin_protection",
5424
+ title: "Protect skin tones from a LUT",
5425
+ description: `Holds a LUT back on skin tones for clips that already have one (one undo step): at "amount" 1 skin keeps its colour while the rest of the picture takes the full look; 0 turns the protection off. Skin is found by colour, so warm orange or beige objects are protected too. Fails for clips without a LUT (add one with set_video_lut first). Returns each clip's LUT setting.`,
5426
+ inputSchema: object({ clips: { type: "array", items: CLIP_ID, minItems: 1, uniqueItems: true, description: "Clips with a LUT." }, amount: { ...SKIN, description: "How much of the LUT to hold back on skin, 0 (off) to 1 (all of it)." } }, ["clips", "amount"]),
5427
+ annotations: { title: "Protect skin tones from a LUT", ...WRITE_IDEMPOTENT },
5428
+ handler: ({ clips, amount }) => {
5429
+ gradeTargets(clips);
5430
+ const edits = [];
5431
+ for (const id of clips) {
5432
+ const clip = findVideoClip(project(), id).clip;
5433
+ const lut = clip.grade?.lut;
5434
+ if (!lut) throw new Error(`Clip "${id}" has no LUT to protect skin from; add one with set_video_lut first.`);
5435
+ const { preserveSkinTones: _p, ...rest } = lut;
5436
+ edits.push({ op: "update_clip", clip: id, set: { grade: { ...clip.grade, lut: amount > 0 ? { ...rest, preserveSkinTones: amount } : rest } } });
5437
+ }
5438
+ return apply(edits, amount > 0 ? "Protect skin tones" : "Stop protecting skin tones", (r) => ({ clips: clips.map((id) => ({ id, lut: findVideoClip(r.project, id)?.clip.grade?.lut ?? null })) }));
5439
+ }
5440
+ };
5441
+ const planOut = (plan) => ({
5442
+ id: plan.id,
5443
+ title: plan.title,
5444
+ ...plan.description ? { description: plan.description } : {},
5445
+ ...plan.source ? { source: plan.source } : {},
5446
+ summary: { ...plan.summary, newIssues: issueSummary(plan.summary.newIssues) },
5447
+ ...plan.ranges ? { ranges: plan.ranges.map((r) => ({ ...r, from: round(r.from), to: round(r.to) })) } : {},
5448
+ edits: plan.edits.length,
5449
+ stale: controller.isPlanStale(plan.id),
5450
+ text: describeVideoEditPlan(plan)
5451
+ });
5452
+ const PLAN_ID = { type: "string", minLength: 1, description: 'A plan id from plan_video_edits, a plan_* tool or list_video_edit_plans (e.g. "plan1").' };
5453
+ const planEdits = {
5454
+ name: "plan_video_edits",
5455
+ title: "Propose edits for review",
5456
+ description: "Works out a batch of edits without applying them and keeps it as a plan for review: the project does not change. The plan says what it would do (length before and after, clips added, removed and changed, problems it would add) and shows in the editor for the user to accept or discard. Use it for anything the user should see before it happens (a rough cut, a cleanup, a re-time). Fails, keeping nothing, if the edits do not apply. Apply it with apply_video_edit_plan. Returns the plan.",
5457
+ inputSchema: object(
5458
+ {
5459
+ title: { type: "string", minLength: 1, maxLength: 120, description: 'What the plan does, shown to the user and used as the undo label (e.g. "Tighten the intro").' },
5460
+ description: { type: "string", maxLength: 2e3, description: "Why, and anything the reviewer should check." },
5461
+ ops: { type: "array", items: EDIT_OP, minItems: 1, maxItems: 500, description: "The edits, in order, as for edit_video." },
5462
+ ranges: { type: "array", maxItems: 500, items: object({ from: MS("Start, on the timeline"), to: MS("End, on the timeline"), text: { type: "string", description: "What is said there." }, reason: { type: "string", description: 'Why it is in the plan (e.g. "filler").' } }, ["from", "to"], "A stretch the plan cuts or changes."), description: "The stretches it cuts or changes, for the review view (optional)." }
5463
+ },
5464
+ ["title", "ops"]
5465
+ ),
5466
+ annotations: { title: "Propose edits for review", readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
5467
+ handler: ({ title, description, ops, ranges }) => {
5468
+ if (ops.some((o) => o.op === "replace_project")) throw new Error("A plan cannot replace the whole project; use the individual ops.");
5469
+ const r = controller.proposePlan({ title, description, edits: ops, ranges, source: "agent" });
5470
+ if (!r.ok) throw new Error(r.error);
5471
+ return { plan: planOut(r.plan), hint: `Nothing changed yet. Ask the user to review it, then call apply_video_edit_plan with plan "${r.plan.id}" (or discard_video_edit_plan).` };
5472
+ }
5473
+ };
5474
+ const listPlans = {
5475
+ name: "list_video_edit_plans",
5476
+ title: "List proposed edit plans",
5477
+ description: "Lists the plans waiting for review, oldest first: id, title, summary (length change, clips added, removed and changed, new problems), the stretches they cut, and whether the project changed since each was made (stale: it is checked again when applied).",
5478
+ inputSchema: object({}),
5479
+ annotations: { title: "List proposed edit plans", ...READ },
5480
+ handler: () => ({ plans: controller.getState().plans.map(planOut) })
5481
+ };
5482
+ const applyPlan = {
5483
+ name: "apply_video_edit_plan",
5484
+ title: "Apply an edit plan",
5485
+ description: "Applies a proposed plan as one undo step (labelled with its title) and closes it. A plan made before the project changed is checked again first and refused, changing nothing, if its edits no longer apply. Returns what it did (each op's outcome), the new length and issues, and whether it was stale.",
5486
+ inputSchema: object({ plan: PLAN_ID }, ["plan"]),
5487
+ annotations: { title: "Apply an edit plan", ...DESTRUCTIVE },
5488
+ handler: ({ plan }) => {
5489
+ const r = controller.applyPlan(plan);
5490
+ if (!r.ok) throw new Error(r.error);
5491
+ return { plan: r.plan.id, title: r.plan.title, stale: r.stale, outcomes: r.outcomes, duration: videoProjectDuration(r.project), issues: issueSummary(r.issues) };
5492
+ }
5493
+ };
5494
+ const discardPlan = {
5495
+ name: "discard_video_edit_plan",
5496
+ title: "Discard an edit plan",
5497
+ description: "Closes a proposed plan without applying it; the project is unchanged. Returns the plans still open.",
5498
+ inputSchema: object({ plan: PLAN_ID }, ["plan"]),
5499
+ annotations: { title: "Discard an edit plan", readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
5500
+ handler: ({ plan }) => {
5501
+ if (!controller.discardPlan(plan)) throw new Error(`There is no open plan "${plan}"; the open plans are ${controller.getState().plans.map((p) => `"${p.id}"`).join(", ") || "none"}.`);
5502
+ return { discarded: plan, open: controller.getState().plans.map((p) => p.id) };
5503
+ }
5504
+ };
5505
+ const reads = [getProject, listPlans, listSequences, getFrame, getTranscript, findText, findFillers, findPauses, findGaps, checkProject, renderFrame, getScopes, previewCache, planProxies, exportFfmpeg, exportLoudnessMeasure, exportEdl, audioLevels, findSilences, seek, setPreviewScale];
5506
+ const writes = [setSettings, addAsset, updateAsset, removeAsset, setProxies, addTrack, updateTrack, removeTrack, moveTrack, addClip, moveClip, trimClip, splitClip, deleteClips, updateClip, setTransition, setSpeedRamp, addFreeze, removeRamp, setTranscript, removeRanges, applyGradePreset, copyGrade, setLut, removeLut, setSkin, addAdjustment, setMask, removeMask, planEdits, applyPlan, discardPlan, setKeyframes, removeKeyframes, slipClip, rollEdit, slideClip, liftRange, extractRange, splitAt, closeGaps, addMarker, removeMarker, editVideo, undo, redo];
4676
5507
  return withVideoPlayback({
4677
5508
  id: options.id ?? "video",
4678
5509
  namespace: options.namespace,
@@ -4868,6 +5699,456 @@ function createVideoEffectsToolProvider(controller, options = {}) {
4868
5699
  }), options.playbackSurface);
4869
5700
  }
4870
5701
 
5702
+ // src/video-editor/dialogue-tools.ts
5703
+ var round2 = (ms) => Math.round(ms * 10) / 10;
5704
+ var object2 = (properties, required = []) => ({ type: "object", properties, ...required.length ? { required } : {}, additionalProperties: false });
5705
+ var FIND_FIELDS = {
5706
+ track: { type: "string", minLength: 1, description: "Track whose words to read (default: the first audio track with a transcribed clip, else the first video track with one)." },
5707
+ kinds: { type: "array", minItems: 1, uniqueItems: true, items: { type: "string", enum: [...VIDEO_DISFLUENCY_KINDS] }, description: 'What to look for: filler (um, uh, you know\u2026), pause (long gaps between words), repetition (stutters such as "I I think"). Default all three.' },
5708
+ fillers: { type: "array", minItems: 1, items: { type: "string", minLength: 1 }, description: `Words or phrases counted as fillers instead of the defaults (${VIDEO_DEFAULT_FILLERS.join(", ")}).` },
5709
+ min_pause: { type: "number", exclusiveMinimum: 0, description: "Shortest gap between words that counts as a pause, in ms (default 700; 600 for brisk talking heads)." },
5710
+ keep: { type: "number", minimum: 0, maximum: 1e3, description: "Breath kept either side of a pause cut, in ms (default 150; 150\u2013250 sounds natural)." },
5711
+ max_phrase: { type: "integer", minimum: 1, maximum: 6, description: "Longest phrase checked for a repeat, in words (default 3)." }
5712
+ };
5713
+ function createVideoDialogueToolProvider(controller, options = {}) {
5714
+ const readOnlyReason = () => {
5715
+ const r = typeof options.readOnly === "function" ? options.readOnly() : options.readOnly;
5716
+ if (r) return typeof r === "string" ? r : "This video project is read-only.";
5717
+ return controller.readOnlyReason();
5718
+ };
5719
+ const find = (args) => {
5720
+ const project = controller.getProject();
5721
+ const words = videoTimelineTranscript(project, { track: args.track });
5722
+ if (!words.length) throw new Error(args.track ? `No clip on track "${args.track}" plays a transcribed asset; attach one with set_video_transcript.` : "No clip plays a transcribed asset; attach a transcript to the media with set_video_transcript first.");
5723
+ return detectVideoDisfluencies(words, {
5724
+ kinds: args.kinds,
5725
+ fillers: args.fillers,
5726
+ pauses: { fps: project.fps, ...args.min_pause !== void 0 ? { min: args.min_pause } : {}, ...args.keep !== void 0 ? { keep: args.keep } : {} },
5727
+ repetitions: args.max_phrase !== void 0 ? { maxPhrase: args.max_phrase } : void 0
5728
+ });
5729
+ };
5730
+ const out = (d) => ({ kind: d.kind, from: round2(d.from), to: round2(d.to), text: d.text, words: d.words });
5731
+ const findDisfluencies = {
5732
+ name: "find_video_disfluencies",
5733
+ title: "Find fillers, pauses and stutters",
5734
+ description: `Reads the timeline transcript and lists, in time order, every filler word, long pause and repeated word or phrase as { kind, from, to, text, words } (timeline ms; "words" are the first and last word indexes in get_video_transcript's list), with a count and total per kind. Changes nothing. Review the list (some repeats and pauses are meant), then call plan_video_dialogue_cleanup or remove_video_ranges with the ones to cut.`,
5735
+ inputSchema: object2(FIND_FIELDS),
5736
+ annotations: { title: "Find fillers, pauses and stutters", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
5737
+ handler: (args) => {
5738
+ const found = find(args);
5739
+ const totals = Object.fromEntries(VIDEO_DISFLUENCY_KINDS.map((k) => [k, { count: found.filter((d) => d.kind === k).length, time: round2(found.filter((d) => d.kind === k).reduce((n, d) => n + d.to - d.from, 0)) }]));
5740
+ const merged = mergeVideoRanges(found);
5741
+ return { disfluencies: found.map(out), totals, removable: round2(merged.reduce((n, r) => n + r.to - r.from, 0)) };
5742
+ }
5743
+ };
5744
+ const planCleanup = {
5745
+ name: "plan_video_dialogue_cleanup",
5746
+ title: "Propose a dialogue cleanup",
5747
+ description: 'Finds fillers, long pauses and stutters (as find_video_disfluencies) and proposes cutting them as one plan for review: nothing changes until apply_video_edit_plan. Pass "exclude" to keep finds the user wants (by their from time), and "margin" to keep a little breath around filler and stutter cuts. Every sync-locked track is cut with the dialogue. Returns the plan (id, title, length change, the stretches it cuts) for the user to review.',
5748
+ inputSchema: object2(
5749
+ {
5750
+ ...FIND_FIELDS,
5751
+ exclude: { type: "array", maxItems: 500, items: { type: "number", minimum: 0 }, description: 'The "from" times (ms) of finds to keep, from find_video_disfluencies.' },
5752
+ margin: { type: "number", minimum: 0, maximum: 200, description: "Ms left uncut at each end of a filler or stutter cut, so the words around it are not clipped (default 0)." },
5753
+ title: { type: "string", minLength: 1, maxLength: 120, description: `The plan's title (default: what it cleans up, e.g. "Clean up 12 fillers, 3 pauses").` }
5754
+ }
5755
+ ),
5756
+ annotations: { title: "Propose a dialogue cleanup", readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
5757
+ handler: (args) => {
5758
+ const skip = new Set((args.exclude ?? []).map((t) => Math.round(t)));
5759
+ const found = find(args).filter((d) => !skip.has(Math.round(d.from)));
5760
+ if (!found.length) throw new Error("Nothing to clean up: no fillers, long pauses or repetitions were found (or all were excluded).");
5761
+ const margin = args.margin ?? 0;
5762
+ const cuts = found.flatMap((d) => d.kind === "pause" || !margin ? [d] : videoCutsWithMargin([d], margin));
5763
+ const counts = VIDEO_DISFLUENCY_KINDS.map((k) => [k, found.filter((d) => d.kind === k).length]).filter(([, n]) => n);
5764
+ const title = args.title ?? `Clean up ${counts.map(([k, n]) => `${n} ${k}${n > 1 ? "s" : ""}`).join(", ")}`;
5765
+ const r = controller.proposePlan({ title, description: "Cuts fillers, long pauses and stutters found in the transcript, closing up every sync-locked track.", edits: videoRemoveRangesEdits(cuts), ranges: cuts.map((d) => ({ from: d.from, to: d.to, text: d.text, reason: d.kind })), source: "plan_video_dialogue_cleanup" });
5766
+ if (!r.ok) throw new Error(r.error);
5767
+ const p = r.plan;
5768
+ return { plan: { id: p.id, title: p.title, summary: p.summary, text: describeVideoEditPlan(p), cuts: cuts.length }, durationNow: videoProjectDuration(controller.getProject()), hint: `Nothing changed yet. Show the user the plan, then call apply_video_edit_plan with plan "${p.id}" (or discard_video_edit_plan).` };
5769
+ }
5770
+ };
5771
+ return withVideoPlayback(
5772
+ {
5773
+ id: options.id ?? "video-dialogue",
5774
+ namespace: options.namespace,
5775
+ title: "Video dialogue cleanup",
5776
+ description: "Talking-head cleanup by transcript: find fillers, long pauses and stutters, and propose cutting them as one plan for review.",
5777
+ skill: "pixerate-talking-head-edit",
5778
+ tools: () => readOnlyReason() ? [findDisfluencies] : [findDisfluencies, planCleanup],
5779
+ subscribe: (notify) => {
5780
+ let last = readOnlyReason();
5781
+ return controller.subscribe(() => {
5782
+ const now = readOnlyReason();
5783
+ if (now !== last) {
5784
+ last = now;
5785
+ notify();
5786
+ }
5787
+ });
5788
+ }
5789
+ },
5790
+ options.playbackSurface
5791
+ );
5792
+ }
5793
+
5794
+ // src/video-editor/music-tools.ts
5795
+ var round4 = (ms) => Math.round(ms * 10) / 10;
5796
+ var object3 = (properties, required = [], description) => ({ type: "object", ...description ? { description } : {}, properties, ...required.length ? { required } : {}, additionalProperties: false });
5797
+ var MS3 = (what) => ({ type: "number", minimum: 0, description: `${what}, in milliseconds.` });
5798
+ var CLIP_ID2 = { type: "string", minLength: 1, description: 'A clip id from get_video_project (e.g. "c1").' };
5799
+ var TRACK_ID2 = { type: "string", minLength: 1, description: 'A track id from get_video_project (e.g. "v1" or "a1").' };
5800
+ var SOUND_TARGET = {
5801
+ clip: { ...CLIP_ID2, description: "A media clip with sound: read the stretch of source it plays, times on the timeline. Pass this or asset." },
5802
+ asset: { type: "string", minLength: 1, description: "A video or audio asset: read its source, times in the source. Pass this or clip." },
5803
+ from: MS3("Start of the stretch (default: the clip's start, or 0 for an asset)"),
5804
+ to: MS3("End of the stretch (default: the clip's end, or the asset's duration)")
5805
+ };
5806
+ var SOUND = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true };
5807
+ function createVideoMusicToolProvider(controller, options = {}) {
5808
+ const readOnlyReason = () => {
5809
+ const r = typeof options.readOnly === "function" ? options.readOnly() : options.readOnly;
5810
+ if (r) return typeof r === "string" ? r : "This video project is read-only.";
5811
+ return controller.readOnlyReason();
5812
+ };
5813
+ const project = () => controller.getProject();
5814
+ const soundClip = (p, id) => {
5815
+ const at = findVideoClip(p, id);
5816
+ if (!at) throw new Error(`There is no clip "${id}"; get_video_project lists the clips.`);
5817
+ const c = at.clip;
5818
+ if (c.type !== "media") throw new Error(`Clip "${id}" is a ${c.type} clip and has no sound of its own; pass a video or audio clip.`);
5819
+ const asset = p.assets.find((a) => a.id === c.asset);
5820
+ if (!asset) throw new Error(`Clip "${id}" plays a missing asset "${c.asset}".`);
5821
+ if (asset.kind === "image" || asset.hasAudio === false) throw new Error(`Clip "${id}" has no sound (asset "${asset.id}").`);
5822
+ return { clip: c, asset, track: at.track.id };
5823
+ };
5824
+ const stretch = (args) => {
5825
+ const p = project();
5826
+ if (args.clip === void 0 === (args.asset === void 0)) throw new Error('Pass either "clip" (a media clip, times on the timeline) or "asset" (times in the source), not both.');
5827
+ if (args.clip !== void 0) {
5828
+ const { clip, asset: asset2 } = soundClip(p, args.clip);
5829
+ const speed = clip.speed ?? 1;
5830
+ const from2 = Math.max(clip.start, args.from ?? clip.start);
5831
+ const to2 = Math.min(videoClipEnd(clip), args.to ?? videoClipEnd(clip));
5832
+ if (!(to2 > from2)) throw new Error(`The stretch is empty (${from2}\u2013${to2} ms); "from" and "to" must be inside the clip (${clip.start}\u2013${videoClipEnd(clip)} ms) with "to" after "from".`);
5833
+ return { asset: asset2, from: (clip.in ?? 0) + (from2 - clip.start) * speed, to: (clip.in ?? 0) + (to2 - clip.start) * speed, out: (s) => clip.start + (s - (clip.in ?? 0)) / speed };
5834
+ }
5835
+ const asset = p.assets.find((a) => a.id === args.asset);
5836
+ if (!asset) throw new Error(`There is no asset "${args.asset}"; the assets are ${p.assets.map((a) => `"${a.id}"`).join(", ") || "none"}.`);
5837
+ if (asset.kind === "image" || asset.hasAudio === false) throw new Error(`Asset "${asset.id}" has no sound.`);
5838
+ const from = args.from ?? 0;
5839
+ const to = args.to ?? asset.duration ?? 0;
5840
+ if (!(to > from)) throw new Error(`The stretch is empty (${from}\u2013${to} ms)${asset.duration === void 0 ? '; the asset has no duration, so pass "to"' : ""}.`);
5841
+ return { asset, from, to, out: (s) => s };
5842
+ };
5843
+ const measureLoudness = {
5844
+ name: "measure_video_loudness",
5845
+ title: "Measure loudness",
5846
+ description: "Measures how loud the source sound of a clip or an asset is, as streaming services and broadcasters do (ITU-R BS.1770, gated): integrated loudness in LUFS, the sample peak in dBFS, and the gain that would bring it to -14 LUFS (streaming) without the peak passing -1 dBFS. Before clip volume and fades. Changes nothing. The first call for an asset decodes its file. Use normalize_video_loudness to apply the gain.",
5847
+ inputSchema: object3(SOUND_TARGET),
5848
+ annotations: { title: "Measure loudness", ...SOUND },
5849
+ handler: async (args) => {
5850
+ const r = stretch(args);
5851
+ const peaks = await controller.audioPeaks.load(r.asset);
5852
+ const lufs2 = videoAudioLoudness(peaks, r.from, r.to);
5853
+ const peakDb = Math.max(...videoAudioLevels(peaks, r.from, r.to, 50).map((l) => l.peakDb));
5854
+ return { asset: r.asset.id, lufs: lufs2, peakDb, ...lufs2 === null ? { note: "The stretch is silent (everything is below the -70 LUFS gate)." } : { toStreaming: videoLoudnessGain(lufs2, -14, { peakDb }) } };
5855
+ }
5856
+ };
5857
+ const normalizeLoudness = {
5858
+ name: "normalize_video_loudness",
5859
+ title: "Normalise loudness",
5860
+ description: "Sets each clip's volume so its sound plays at a target loudness (default -14 LUFS, streaming; -16 podcasts, -23 EBU R128 broadcast), keeping its peak under the ceiling and the gain at most 4\xD7 (one undo step). Measures each clip's own stretch of source first; silent clips are skipped. Refuses clips with volume keyframes (a constant gain would replace them) unless replace is true. Returns each clip's measured loudness, the gain set (linear and dB) and whether a cap held it short of the target.",
5861
+ inputSchema: object3(
5862
+ {
5863
+ clips: { type: "array", items: CLIP_ID2, minItems: 1, maxItems: 200, uniqueItems: true, description: "Media clips with sound." },
5864
+ target: { type: "number", minimum: -40, maximum: -5, description: "Loudness to reach, in LUFS (default -14)." },
5865
+ ceiling: { type: "number", minimum: -20, maximum: 0, description: "Highest sample peak allowed after the gain, in dBFS (default -1)." },
5866
+ replace: { type: "boolean", description: "Replace volume keyframes with the constant gain (default false: refuse)." }
5867
+ },
5868
+ ["clips"]
5869
+ ),
5870
+ annotations: { title: "Normalise loudness", readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
5871
+ handler: async ({ clips, target, ceiling, replace }) => {
5872
+ const p = project();
5873
+ const targets = clips.map((id) => soundClip(p, id));
5874
+ for (const t of targets) if (isVideoKeyframes(t.clip.volume) && !replace) throw new Error(`Clip "${t.clip.id}" has volume keyframes, which a constant gain would replace; pass replace: true, or remove them first.`);
5875
+ const results = [];
5876
+ const edits = [];
5877
+ for (const { clip, asset } of targets) {
5878
+ const peaks = await controller.audioPeaks.load(asset);
5879
+ const speed = clip.speed ?? 1;
5880
+ const from = clip.in ?? 0;
5881
+ const to = from + clip.duration * speed;
5882
+ const lufs2 = videoAudioLoudness(peaks, from, to);
5883
+ if (lufs2 === null) {
5884
+ results.push({ clip: clip.id, skipped: "silent" });
5885
+ continue;
5886
+ }
5887
+ const peakDb = Math.max(...videoAudioLevels(peaks, from, to, 50).map((l) => l.peakDb));
5888
+ const g = videoLoudnessGain(lufs2, target ?? -14, { peakDb, ceiling });
5889
+ edits.push({ op: "update_clip", clip: clip.id, set: { volume: g.gain } });
5890
+ results.push({ clip: clip.id, lufs: lufs2, gain: g.gain, gainDb: g.gainDb, ...g.limitedBy ? { limitedBy: g.limitedBy } : {} });
5891
+ }
5892
+ if (!edits.length) throw new Error("Every clip is silent, so there is nothing to normalise.");
5893
+ const r = controller.apply(edits, "Normalise loudness");
5894
+ if (!r.ok) throw new Error(r.error);
5895
+ return { target: target ?? -14, clips: results };
5896
+ }
5897
+ };
5898
+ const duckMusic = {
5899
+ name: "duck_video_music",
5900
+ title: "Duck music under speech",
5901
+ description: `Dips music clips under speech with volume keyframes (one undo step): before each stretch of speech the level eases down by duck_db over "attack" ms, holds, and eases back over "release" ms after it; gaps shorter than merge_gap stay ducked. Speech comes from the transcript of the dialogue track ("transcript", the default when it has one) or from where its sound is above -40 dBFS ("audio", which decodes it). Refuses music clips that already have volume keyframes unless replace is true. Returns each music clip's keys and the speech stretches used.`,
5902
+ inputSchema: object3(
5903
+ {
5904
+ music: { type: "array", items: CLIP_ID2, minItems: 1, maxItems: 100, uniqueItems: true, description: "The music clips to duck (media clips with sound)." },
5905
+ dialogue_track: { ...TRACK_ID2, description: 'Track the speech is on (default: the transcript track for "transcript"; required for "audio").' },
5906
+ speech: { type: "string", enum: ["transcript", "audio"], description: "Where speech is found: transcript words (default when transcribed) or the dialogue track's sound levels." },
5907
+ duck_db: { type: "number", minimum: -40, maximum: -1, description: "How far to dip, in dB (default -14; -12 to -18 is usual)." },
5908
+ attack: { type: "number", minimum: 0, maximum: 2e3, description: "Ms the dip takes to come in before speech (default 200)." },
5909
+ release: { type: "number", minimum: 0, maximum: 4e3, description: "Ms the music takes to come back after speech (default 400)." },
5910
+ merge_gap: { type: "number", minimum: 0, maximum: 1e4, description: "Speech gaps shorter than this stay ducked, in ms (default 600)." },
5911
+ replace: { type: "boolean", description: "Replace existing volume keyframes (default false: refuse)." }
5912
+ },
5913
+ ["music"]
5914
+ ),
5915
+ annotations: { title: "Duck music under speech", readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
5916
+ handler: async (args) => {
5917
+ const p = project();
5918
+ const music = args.music.map((id) => soundClip(p, id));
5919
+ for (const m of music) if (isVideoKeyframes(m.clip.volume) && !args.replace) throw new Error(`Music clip "${m.clip.id}" already has volume keyframes; pass replace: true to replace them, or remove them first.`);
5920
+ const transcriptTrack = videoTranscriptTrack(p, args.dialogue_track);
5921
+ const mode = args.speech ?? (transcriptTrack && videoTimelineTranscript(p, { track: transcriptTrack }).length ? "transcript" : "audio");
5922
+ let ranges = [];
5923
+ if (mode === "transcript") {
5924
+ const words = videoTimelineTranscript(p, { track: args.dialogue_track });
5925
+ if (!words.length) throw new Error(`No transcribed speech${args.dialogue_track ? ` on track "${args.dialogue_track}"` : ""}; attach a transcript with set_video_transcript, or pass speech: "audio" with dialogue_track.`);
5926
+ ranges = videoSpeechRanges(words, 250);
5927
+ } else {
5928
+ if (!args.dialogue_track) throw new Error('speech "audio" needs dialogue_track: the track whose sound is the speech.');
5929
+ const track = p.tracks.find((t) => t.id === args.dialogue_track);
5930
+ if (!track) throw new Error(`There is no track "${args.dialogue_track}".`);
5931
+ const musicIds = new Set(music.map((m) => m.clip.id));
5932
+ for (const c of sortedVideoClips(track)) {
5933
+ if (c.type !== "media" || musicIds.has(c.id)) continue;
5934
+ const asset = p.assets.find((a) => a.id === c.asset);
5935
+ if (!asset || asset.kind === "image" || asset.hasAudio === false) continue;
5936
+ const peaks = await controller.audioPeaks.load(asset);
5937
+ const speed = c.speed ?? 1;
5938
+ const src0 = c.in ?? 0;
5939
+ const silences = findVideoAudioSilences(peaks, src0, src0 + c.duration * speed, { thresholdDb: -40, minDuration: 250 });
5940
+ let at = c.start;
5941
+ for (const s of silences) {
5942
+ const a = c.start + (s.start - src0) / speed;
5943
+ if (a - at > VIDEO_TIME_EPSILON) ranges.push({ from: at, to: a });
5944
+ at = c.start + (s.end - src0) / speed;
5945
+ }
5946
+ if (videoClipEnd(c) - at > VIDEO_TIME_EPSILON) ranges.push({ from: at, to: videoClipEnd(c) });
5947
+ }
5948
+ if (!ranges.length) throw new Error(`Track "${args.dialogue_track}" has no sound above -40 dBFS, so there is no speech to duck under.`);
5949
+ }
5950
+ const edits = [];
5951
+ const out = [];
5952
+ for (const { clip } of music) {
5953
+ const base = typeof clip.volume === "number" ? clip.volume : 1;
5954
+ const keys = videoDuckingKeys(clip, ranges, { duckDb: args.duck_db, attack: args.attack, release: args.release, mergeGap: args.merge_gap, base });
5955
+ out.push({ clip: clip.id, keys: keys.length, ...keys.length ? { keyframes: keys } : { note: "No speech overlaps it." } });
5956
+ if (keys.length) edits.push({ op: "set_keyframes", clip: clip.id, property: "volume", keys });
5957
+ }
5958
+ if (!edits.length) throw new Error("No speech overlaps the music clips, so there is nothing to duck.");
5959
+ const r = controller.apply(edits, "Duck music");
5960
+ if (!r.ok) throw new Error(r.error);
5961
+ return { speech: mode, speechRanges: ranges.map((x) => ({ from: round4(x.from), to: round4(x.to) })), music: out };
5962
+ }
5963
+ };
5964
+ const BEAT_FIELDS = {
5965
+ sensitivity: { type: "number", minimum: 0.5, maximum: 4, description: "How far above the local average a hit must rise, in standard deviations (default 1.5; lower finds more)." },
5966
+ min_bpm: { type: "number", minimum: 30, maximum: 300, description: "Slowest tempo to consider (default 60)." },
5967
+ max_bpm: { type: "number", minimum: 30, maximum: 300, description: "Fastest tempo to consider (default 200)." }
5968
+ };
5969
+ const beatsOf = async (args) => {
5970
+ const r = stretch(args);
5971
+ const peaks = await controller.audioPeaks.load(r.asset);
5972
+ const found = findVideoAudioBeats(peaks, r.from, r.to, { sensitivity: args.sensitivity, minBpm: args.min_bpm, maxBpm: args.max_bpm });
5973
+ return { asset: r.asset.id, bpm: found.bpm, beats: found.beats.map((t) => round4(r.out(t))), onsets: found.onsets.map((t) => round4(r.out(t))) };
5974
+ };
5975
+ const findBeats = {
5976
+ name: "find_video_beats",
5977
+ title: "Find the beats",
5978
+ description: "Finds the beat of a music clip or asset: the tempo (BPM, or null when the hits do not repeat), a steady beat grid at that tempo, and the onsets (each hit) \u2014 timeline ms for a clip, source ms for an asset. Changes nothing. Use the beats to cut on the music (plan_video_beat_snap), place markers (add_video_marker) or time titles. Works best on percussive music. The first call for an asset decodes its file.",
5979
+ inputSchema: object3({ ...SOUND_TARGET, ...BEAT_FIELDS }),
5980
+ annotations: { title: "Find the beats", ...SOUND },
5981
+ handler: (args) => beatsOf(args)
5982
+ };
5983
+ const planBeatSnap = {
5984
+ name: "plan_video_beat_snap",
5985
+ title: "Propose cuts on the beat",
5986
+ description: 'Proposes, as a plan for review, moving each cut on a track to the nearest beat within "tolerance" ms with roll edits (the outgoing clip gets longer as the incoming one gets shorter, so nothing else moves). Beats come from a music clip (found as find_video_beats does) or are given. Cuts already on a beat, with none in reach, or without enough media to roll are left (listed in "skipped"). Nothing changes until apply_video_edit_plan. Returns the plan and what was skipped.',
5987
+ inputSchema: object3(
5988
+ {
5989
+ track: { ...TRACK_ID2, description: "The track whose cuts to move (default the first video track)." },
5990
+ music: { ...CLIP_ID2, description: "A music clip to take the beats from. Pass this or beats." },
5991
+ beats: { type: "array", minItems: 1, maxItems: 5e3, items: { type: "number", minimum: 0 }, description: "Beat times on the timeline, in ms. Pass this or music." },
5992
+ tolerance: { type: "number", exclusiveMinimum: 0, maximum: 2e3, description: "Furthest a cut may move, in ms (default 150)." },
5993
+ ...BEAT_FIELDS
5994
+ }
5995
+ ),
5996
+ annotations: { title: "Propose cuts on the beat", readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
5997
+ handler: async (args) => {
5998
+ const p = project();
5999
+ if (args.music === void 0 === (args.beats === void 0)) throw new Error('Pass either "music" (a music clip to find the beats in) or "beats" (times in ms), not both.');
6000
+ const track = args.track !== void 0 ? p.tracks.find((t) => t.id === args.track) : p.tracks.find((t) => t.kind === "video");
6001
+ if (!track) throw new Error(args.track !== void 0 ? `There is no track "${args.track}".` : "The project has no video track.");
6002
+ let beats;
6003
+ if (args.music !== void 0) {
6004
+ const found = await beatsOf({ clip: args.music, sensitivity: args.sensitivity, min_bpm: args.min_bpm, max_bpm: args.max_bpm });
6005
+ beats = found.beats.length ? found.beats : found.onsets;
6006
+ if (!beats.length) throw new Error(`No beats were found in "${args.music}"; try a lower sensitivity, or pass beats.`);
6007
+ } else beats = [...args.beats].sort((a, b) => a - b);
6008
+ const tolerance = args.tolerance ?? 150;
6009
+ const clips = sortedVideoClips(track);
6010
+ const edits = [];
6011
+ const ranges = [];
6012
+ const skipped = [];
6013
+ let working = p;
6014
+ for (let i = 0; i + 1 < clips.length; i++) {
6015
+ const left = clips[i];
6016
+ const right = clips[i + 1];
6017
+ const cut = videoClipEnd(left);
6018
+ if (Math.abs(right.start - cut) > VIDEO_TIME_EPSILON) continue;
6019
+ const beat = nearestVideoBeat(beats, cut, tolerance);
6020
+ if (beat === null) {
6021
+ skipped.push({ cut: round4(cut), reason: `no beat within ${tolerance} ms` });
6022
+ continue;
6023
+ }
6024
+ const delta = Math.round((beat - cut) * 10) / 10;
6025
+ if (Math.abs(delta) < 1) {
6026
+ skipped.push({ cut: round4(cut), reason: "already on the beat" });
6027
+ continue;
6028
+ }
6029
+ const edit = { op: "roll_edit", left: left.id, right: right.id, delta };
6030
+ const tried = applyVideoEdits(working, edit);
6031
+ if (!tried.ok) {
6032
+ skipped.push({ cut: round4(cut), reason: tried.error });
6033
+ continue;
6034
+ }
6035
+ working = tried.project;
6036
+ edits.push(edit);
6037
+ ranges.push({ from: Math.min(cut, beat), to: Math.max(cut, beat), reason: "beat" });
6038
+ }
6039
+ if (!edits.length) throw new Error(`No cut on track "${track.id}" can move to a beat${skipped.length ? `: ${skipped.slice(0, 5).map((s) => `${s.cut} ms (${s.reason})`).join("; ")}` : " (it has no cuts between touching clips)"}.`);
6040
+ const r = controller.proposePlan({ title: `Snap ${edits.length} cut${edits.length > 1 ? "s" : ""} to the beat`, description: `Rolls cuts on track "${track.id}" to the nearest beat within ${tolerance} ms.`, edits, ranges, source: "plan_video_beat_snap" });
6041
+ if (!r.ok) throw new Error(r.error);
6042
+ return { plan: { id: r.plan.id, title: r.plan.title, summary: r.plan.summary, text: describeVideoEditPlan(r.plan) }, moved: edits.length, skipped, hint: `Nothing changed yet. Call apply_video_edit_plan with plan "${r.plan.id}" once the user agrees.` };
6043
+ }
6044
+ };
6045
+ const reads = [measureLoudness, findBeats];
6046
+ const writes = [normalizeLoudness, duckMusic, planBeatSnap];
6047
+ return withVideoPlayback(
6048
+ {
6049
+ id: options.id ?? "video-music",
6050
+ namespace: options.namespace,
6051
+ title: "Video music and mix",
6052
+ description: "Music and the mix: beats and cuts on the beat, ducking music under speech, and loudness in LUFS.",
6053
+ skill: "pixerate-bgm-alignment",
6054
+ tools: () => readOnlyReason() ? reads : [...reads, ...writes],
6055
+ subscribe: (notify) => {
6056
+ let last = readOnlyReason();
6057
+ return controller.subscribe(() => {
6058
+ const now = readOnlyReason();
6059
+ if (now !== last) {
6060
+ last = now;
6061
+ notify();
6062
+ }
6063
+ });
6064
+ }
6065
+ },
6066
+ options.playbackSurface
6067
+ );
6068
+ }
6069
+
6070
+ // src/video-editor/effect-authoring.ts
6071
+ function videoEaseToAnimationEasing(ease) {
6072
+ if (ease === void 0 || ease === "linear") return "linear";
6073
+ if (Array.isArray(ease)) return { type: "cubic-bezier", x1: ease[0], y1: ease[1], x2: ease[2], y2: ease[3] };
6074
+ return ease;
6075
+ }
6076
+ function animationEasingToVideoEase(easing) {
6077
+ if (easing === void 0 || easing === "linear") return "linear";
6078
+ if (easing === "hold" || easing === "ease-in" || easing === "ease-out" || easing === "ease-in-out") return easing;
6079
+ if (typeof easing === "string") {
6080
+ const p = CUBIC_BEZIER_PRESETS[easing];
6081
+ return p ? [p[0], p[1], p[2], p[3]] : null;
6082
+ }
6083
+ if (easing.type === "cubic-bezier") return [easing.x1, easing.y1, easing.x2, easing.y2];
6084
+ return null;
6085
+ }
6086
+ var SAMPLES = 12;
6087
+ function videoClipEffectDocument(clip, instance, providerId) {
6088
+ const effect = (clip.effects ?? []).find((e) => e.id === instance);
6089
+ if (!effect) throw new Error(`Clip "${clip.id}" has no effect "${instance}"; its effects are ${(clip.effects ?? []).map((e) => `"${e.id}" (${e.name ?? e.effect})`).join(", ") || "none"}.`);
6090
+ const values = {};
6091
+ const tracks = {};
6092
+ for (const [control, v] of Object.entries(effect.values ?? {})) {
6093
+ if (isVideoKeyframes(v)) {
6094
+ values[control] = v.keys[0].v;
6095
+ tracks[control] = v.keys.map((k) => ({ time: k.t, value: k.v, ...k.ease && k.ease !== "linear" ? { easing: videoEaseToAnimationEasing(k.ease) } : {} }));
6096
+ } else values[control] = v;
6097
+ }
6098
+ return { version: 1, providerId, effectId: effect.effect, name: effect.name ?? effect.effect, values, tracks, presets: [], duration: clip.duration, loop: false };
6099
+ }
6100
+ function videoEffectValuesFromDocument(doc) {
6101
+ const values = { ...doc.values };
6102
+ const notes = [];
6103
+ for (const [control, track] of Object.entries(doc.tracks ?? {})) {
6104
+ const kfs = [...track].sort((a, b) => a.time - b.time);
6105
+ if (!kfs.length) continue;
6106
+ if (!kfs.every((k) => typeof k.value === "number")) {
6107
+ values[control] = kfs[0].value;
6108
+ notes.push(`"${control}" is keyframed with non-numeric values, which clip effects cannot animate; it keeps its first value.`);
6109
+ continue;
6110
+ }
6111
+ const keys = [];
6112
+ let sampled = false;
6113
+ kfs.forEach((k, i) => {
6114
+ const next = kfs[i + 1];
6115
+ const ease = animationEasingToVideoEase(k.easing);
6116
+ if (!next || ease) {
6117
+ keys.push({ t: k.time, v: k.value, ...next && ease && ease !== "linear" ? { ease } : {} });
6118
+ return;
6119
+ }
6120
+ sampled = true;
6121
+ const a = k.value;
6122
+ const b = next.value;
6123
+ const span = next.time - k.time;
6124
+ for (let s = 0; s < SAMPLES; s++) keys.push({ t: Math.round((k.time + span * s / SAMPLES) * 1e3) / 1e3, v: a + (b - a) * evaluateEasing(k.easing, s / SAMPLES, span) });
6125
+ });
6126
+ values[control] = { keys: keys.filter((k, i) => i === 0 || k.t > keys[i - 1].t) };
6127
+ if (sampled) notes.push(`"${control}" uses a spring or elastic easing, sampled into ${SAMPLES} linear steps per segment.`);
6128
+ }
6129
+ return { values, notes };
6130
+ }
6131
+ async function openVideoClipEffectAuthoring(controller, clip, instance, options = {}) {
6132
+ const provider = controller.effectsProvider;
6133
+ if (!provider) throw new Error("No effects provider is registered, so the effect cannot be opened for authoring; register one with setEffectsProvider.");
6134
+ const at = findVideoClip(controller.getProject(), clip);
6135
+ if (!at) throw new Error(`There is no clip "${clip}".`);
6136
+ const doc = videoClipEffectDocument(at.clip, instance, provider.id);
6137
+ const session = await createEffectAuthoringSession({ document: doc }, { ...options, provider });
6138
+ return {
6139
+ clip,
6140
+ instance,
6141
+ session,
6142
+ async commit() {
6143
+ const { values, notes } = videoEffectValuesFromDocument(session.exportDocument());
6144
+ const result = await controller.updateClipEffect(clip, instance, { values });
6145
+ return result.ok && notes.length ? { ...result, notes } : result;
6146
+ },
6147
+ dispose: () => session.dispose()
6148
+ };
6149
+ }
6150
+ var videoAuthorableEffects = (clip) => clip.effects ?? [];
6151
+
4871
6152
  // src/video-editor/editorDocument.ts
4872
6153
  function createVideoEditorDocument(controller) {
4873
6154
  return defineEditorDocument({
@@ -4894,6 +6175,9 @@ function createVideoEditorDocument(controller) {
4894
6175
  });
4895
6176
  }
4896
6177
  export {
6178
+ TranscriptVideoController,
6179
+ VIDEO_ADJUSTMENT_SCOPES,
6180
+ VIDEO_ADJUSTMENT_SCOPE_LABELS,
4897
6181
  VIDEO_BLEND_MODES,
4898
6182
  VIDEO_BLEND_MODE_LABELS,
4899
6183
  VIDEO_CLIP_ANIMATION_DURATION,
@@ -4903,6 +6187,7 @@ export {
4903
6187
  VIDEO_DEFAULT_FILLERS,
4904
6188
  VIDEO_DEFAULT_STILL_DURATION,
4905
6189
  VIDEO_DEFAULT_TITLE_DURATION,
6190
+ VIDEO_DISFLUENCY_KINDS,
4906
6191
  VIDEO_EASE_NAMES,
4907
6192
  VIDEO_EDIT_OPS,
4908
6193
  VIDEO_EFFECT_PLACES,
@@ -4915,7 +6200,11 @@ export {
4915
6200
  VIDEO_ISSUE_CODES,
4916
6201
  VIDEO_KEYFRAME_LIMITS,
4917
6202
  VIDEO_KEYFRAME_PROPERTIES,
6203
+ VIDEO_LOUDNESS_HOP,
4918
6204
  VIDEO_LUT_MAX_SIZE,
6205
+ VIDEO_MASK_DEFAULTS,
6206
+ VIDEO_MASK_SHAPES,
6207
+ VIDEO_MASK_SHAPE_LABELS,
4919
6208
  VIDEO_PEAK_BLOCK,
4920
6209
  VIDEO_PLACEMENT_MODES,
4921
6210
  VIDEO_PREVIEW_SCALE_OPTIONS,
@@ -4936,6 +6225,7 @@ export {
4936
6225
  VideoPreviewPixels,
4937
6226
  allVideoClipIds,
4938
6227
  allVideoTracks,
6228
+ animationEasingToVideoEase,
4939
6229
  applyVideoEdits,
4940
6230
  applyVideoGrade,
4941
6231
  applyVideoLut,
@@ -4945,20 +6235,27 @@ export {
4945
6235
  checkVideoEffectValues,
4946
6236
  checkVideoProject,
4947
6237
  checkVideoTimeRemap,
6238
+ createVideoDialogueToolProvider,
4948
6239
  createVideoEditorDocument,
4949
6240
  createVideoEditorToolProvider,
4950
6241
  createVideoEffectsToolProvider,
4951
6242
  createVideoElementDecoder,
6243
+ createVideoMusicToolProvider,
4952
6244
  createVideoProject,
4953
6245
  decodeVideoAudioPeaks,
6246
+ describeVideoEditPlan,
4954
6247
  describeVideoProject,
4955
6248
  describeVideoSequence,
6249
+ detectVideoDisfluencies,
6250
+ diffVideoProjects,
4956
6251
  drawVideoFrame,
4957
6252
  ffmpegFilterValue,
6253
+ findVideoAudioBeats,
4958
6254
  findVideoAudioSilences,
4959
6255
  findVideoClip,
4960
6256
  findVideoFillers,
4961
6257
  findVideoGaps,
6258
+ findVideoRepetitions,
4962
6259
  findVideoSequenceClip,
4963
6260
  findVideoSequenceCycle,
4964
6261
  findVideoTranscriptPauses,
@@ -4968,12 +6265,16 @@ export {
4968
6265
  formatVideoTimecodeFrames,
4969
6266
  isVideoDropFrameRate,
4970
6267
  isVideoKeyframes,
6268
+ measureVideoLoudness,
4971
6269
  mergeVideoRanges,
4972
6270
  mixEffectPixels,
6271
+ nearestVideoBeat,
4973
6272
  nextFreeVideoSlot,
6273
+ normalizeVideoClipMask,
4974
6274
  normalizeVideoGrade,
4975
6275
  normalizeVideoGradeLut,
4976
6276
  normalizeVideoWord,
6277
+ openVideoClipEffectAuthoring,
4977
6278
  overEffectPixels,
4978
6279
  parseVideoAnimatable,
4979
6280
  parseVideoAsset,
@@ -4981,6 +6282,7 @@ export {
4981
6282
  parseVideoClip,
4982
6283
  parseVideoClipAnimation,
4983
6284
  parseVideoClipEffects,
6285
+ parseVideoClipMask,
4984
6286
  parseVideoCubeLut,
4985
6287
  parseVideoEffectRef,
4986
6288
  parseVideoEffectValues,
@@ -5001,6 +6303,7 @@ export {
5001
6303
  parseVideoTransition,
5002
6304
  placeVideoRect,
5003
6305
  planVideoClipDrag,
6306
+ planVideoEdits,
5004
6307
  planVideoPrefetch,
5005
6308
  planVideoToolPlayback,
5006
6309
  probeVideoMedia,
@@ -5019,15 +6322,18 @@ export {
5019
6322
  toVideoEdl,
5020
6323
  toVideoFfmpeg,
5021
6324
  toVideoLoudnessMeasure,
6325
+ videoAddAdjustmentEdits,
5022
6326
  videoAssetDropEdit,
5023
6327
  videoAssetHasSound,
5024
6328
  videoAssetKindOf,
5025
6329
  videoAssetMap,
5026
6330
  videoAssetProxy,
5027
6331
  videoAudioLevels,
6332
+ videoAudioLoudness,
5028
6333
  videoAudioPeakRange,
5029
6334
  videoAudioPeakSpans,
5030
6335
  videoAudioPeaksDuration,
6336
+ videoAuthorableEffects,
5031
6337
  videoCacheEvictions,
5032
6338
  videoChroma,
5033
6339
  videoClipAfter,
@@ -5036,9 +6342,11 @@ export {
5036
6342
  videoClipAnimationSpans,
5037
6343
  videoClipAppliedEffects,
5038
6344
  videoClipBefore,
6345
+ videoClipEffectDocument,
5039
6346
  videoClipEffectUses,
5040
6347
  videoClipEnd,
5041
6348
  videoClipHandles,
6349
+ videoClipHeading,
5042
6350
  videoClipKeyframes,
5043
6351
  videoClipLabel,
5044
6352
  videoClipOverhang,
@@ -5049,21 +6357,27 @@ export {
5049
6357
  videoClipSpeed,
5050
6358
  videoClipSpeedAt,
5051
6359
  videoClipTint,
6360
+ videoClipTypeLabel,
5052
6361
  videoClipWaveform,
5053
6362
  videoClipWaveformPath,
5054
6363
  videoClipsAt,
5055
6364
  videoContactSheetSvg,
6365
+ videoCutsWithMargin,
5056
6366
  videoDragLabel,
5057
6367
  videoDropTracks,
6368
+ videoDuckingKeys,
5058
6369
  videoEaseBezier,
5059
6370
  videoEaseProgress,
6371
+ videoEaseToAnimationEasing,
5060
6372
  videoEffectFrameTime,
5061
6373
  videoEffectLayerKey,
5062
6374
  videoEffectValuesAt,
6375
+ videoEffectValuesFromDocument,
5063
6376
  videoExposureNotes,
5064
6377
  videoExposureStats,
5065
6378
  videoFadeCurveGain,
5066
6379
  videoFfmpegUnsupportedEffects,
6380
+ videoFfmpegUnsupportedFeatures,
5067
6381
  videoFrameAt,
5068
6382
  videoFrameCacheKey,
5069
6383
  videoFrameDuration,
@@ -5093,8 +6407,12 @@ export {
5093
6407
  videoKeyframeToggleEdit,
5094
6408
  videoKeyframeValueEdit,
5095
6409
  videoKeysOf,
6410
+ videoLayerMask,
5096
6411
  videoLayersUseEffects,
5097
6412
  videoLayersWithoutTransitionEffects,
6413
+ videoLoudnessEnergy,
6414
+ videoLoudnessGain,
6415
+ videoLoudnessOf,
5098
6416
  videoLuma,
5099
6417
  videoLumaWaveform,
5100
6418
  videoLutEdits,
@@ -5102,6 +6420,10 @@ export {
5102
6420
  videoLutSvgApproximation,
5103
6421
  videoLutSvgPrimitives,
5104
6422
  videoLutToCube,
6423
+ videoMaskContains,
6424
+ videoMaskEdit,
6425
+ videoMaskPolygon,
6426
+ videoMaskSvgPath,
5105
6427
  videoOverlap,
5106
6428
  videoPeakDb,
5107
6429
  videoPreviewSrc,
@@ -5119,10 +6441,13 @@ export {
5119
6441
  videoSequenceDuration,
5120
6442
  videoSequenceMap,
5121
6443
  videoShellQuote,
6444
+ videoSkinProtectionEdits,
6445
+ videoSkinToneWeight,
5122
6446
  videoSlowMotionRamp,
5123
6447
  videoSnapPoints,
5124
6448
  videoSourceFrame,
5125
6449
  videoSourceFrameTime,
6450
+ videoSpeechRanges,
5126
6451
  videoSpeedRampEdit,
5127
6452
  videoSpeedRampKeys,
5128
6453
  videoTextStyle,