fablecut 1.21.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +44 -3
- package/README.md +8 -2
- package/app.js +189 -69
- package/clips.js +207 -0
- package/index.html +1 -0
- package/manifest.json +2 -1
- package/mcp-server.js +46 -1
- package/package.json +1 -1
- package/project-ops.js +2 -1
package/CLAUDE.md
CHANGED
|
@@ -54,6 +54,9 @@ Every Claude Code session then has these tools:
|
|
|
54
54
|
on that canvas whose shots follow the subject. See "Sequences" below.
|
|
55
55
|
- `fablecut_highlights` — the best moments of long footage cut into a short edit, in a new
|
|
56
56
|
sequence. See "Sequences" below.
|
|
57
|
+
- `fablecut_clips` — a long video (podcast, interview, talk, stream) into short clips in one
|
|
58
|
+
call: each part you pick becomes its own 9:16 sequence, framed on the subject, with a hook
|
|
59
|
+
title and captions, and can be exported. See "Sequences" below.
|
|
57
60
|
- `fablecut_music` — find openly licensed music and sound effects (Openverse), each with
|
|
58
61
|
its licence, import one into the project, and list the credits the edit needs. See
|
|
59
62
|
"Music" below.
|
|
@@ -449,7 +452,7 @@ These are quick looks. For real grading use `props.grade` (see "Color" below).
|
|
|
449
452
|
| `bold` / `weight` | true / 0 | `weight` (300–900) overrides `bold` when non-zero |
|
|
450
453
|
| `italic` `uppercase` | false | |
|
|
451
454
|
| `align` | "center" | left · center · right · **justify** (inserts spaces between words to fill the text box width, or ~85% of the canvas when no box) |
|
|
452
|
-
| `boxW` `boxH` | 0 | px text box; **0 = hug content**. When both > 0, corner handles resize the box (not `scale`). Default: fixed `fontSize`, word-wrap inside the box. |
|
|
455
|
+
| `boxW` `boxH` | 0 | px text box; **0 = hug content**. When both > 0, corner handles resize the box (not `scale`). Default: fixed `fontSize`, word-wrap inside the box. The background fills the box only with `bgShape:"box"`. |
|
|
453
456
|
| `boxFit` | false | when a box is set: `false` = wrap at fixed font size; `true` = scale font down (up to `fontSize`) so the whole text fits |
|
|
454
457
|
| `vAlign` | "middle" | top · middle · bottom — vertical alignment of the text block inside the box |
|
|
455
458
|
| `direction` | "auto" | auto · ltr · rtl — `auto` detects per line (Hebrew/Arabic → RTL); all `textAnim` modes honor reading direction (wipe, typewriter reveal, word/letter layout) |
|
|
@@ -459,7 +462,8 @@ These are quick looks. For real grading use `props.grade` (see "Color" below).
|
|
|
459
462
|
| `glow` | 0 | neon glow strength (0–100); replaces the drop shadow |
|
|
460
463
|
| `glowColor` | "" | glow color ("" = use the text color) |
|
|
461
464
|
| `strokeWidth` `strokeColor` | 0, "#000" | text outline |
|
|
462
|
-
| `bgColor` `bgOpacity` | "#000", 0 |
|
|
465
|
+
| `bgColor` `bgOpacity` | "#000", 0 | text background, drawn when `bgOpacity` > 0 (shape set by `bgShape`) |
|
|
466
|
+
| `bgShape` | "lines" | **lines** = a rounded pill hugging each line; wrapped lines that would overlap meet halfway instead, as one shape · **box** = one rounded box: the `boxW`×`boxH` text box when the clip has one (a brand box or lower-third taller than its text), else the whole text block plus padding. The background *is* the box only in `box`; in `lines` the pills follow the lines, which a text box still shapes (`boxFit` sets the font size, `vAlign` moves them, the box clips them) |
|
|
463
467
|
| `textAnim` | "none" | typewriter · word-pop · word-slide · karaoke · **highlight** (every word shown; the one being said in `highlightColor`) · **letter-pop** (per-character entrance; Arabic/Indic auto-fallback to per-word clusters so joined letters shape correctly) · **wave** (looping per-character ride; same shaping fallback) · **bounce** (looping per-word hop) · **shake** (looping jitter) · **clip-reveal** (wipe-mask sweep, per line) · **zoom-in** (scale + opacity settle) · **font-cut** (rhythmically swaps typeface, then settles — see `fontCutSet`) · **rise-mask** (line rises from behind its baseline, lower-third reveal) |
|
|
464
468
|
| `wordRate` | 0.15 | seconds per word (typewriter: /4, letter-pop: /3 per character); also staggers `clip-reveal`/`zoom-in`/`rise-mask` per line |
|
|
465
469
|
| `wordTimes` | — | `[[start, end], …]`, one pair per word (seconds from the clip's start): word-pop, word-slide, karaoke and highlight follow these instead of `wordRate` — a caption timed to speech. If the text is edited to another number of words they are spread over the clip. See "Captions" |
|
|
@@ -2161,7 +2165,44 @@ is kept first. In the editor: the sequence menu's **Highlights…** (15, 30, 60
|
|
|
2161
2165
|
reads the selected video clips, else every video clip on the timeline, with
|
|
2162
2166
|
progress and **Cancel**.
|
|
2163
2167
|
|
|
2164
|
-
|
|
2168
|
+
**Clips** — `fablecut_clips {clips:[{from, to, name?, title?}], aspect?, captions?, reframe?, title?, export?}`
|
|
2169
|
+
turns a long video into short clips in one call: the clipper's job. The agent
|
|
2170
|
+
picks the parts (read the talk with `fablecut_transcribe` first: a tip, an
|
|
2171
|
+
answer, a story, each usually 20–60 s, starting and ending on a full sentence)
|
|
2172
|
+
as timeline seconds of the open sequence, up to 10 at a time, each 3–180 s.
|
|
2173
|
+
For each one, in order:
|
|
2174
|
+
|
|
2175
|
+
1. a new sequence named after it, on the clip's canvas (`aspect`, default
|
|
2176
|
+
`9:16`; the project's shorter side is kept, so 1920×1080 → 1080×1920),
|
|
2177
|
+
holding only `from` → `to` of the open timeline: a copy of it with the rest
|
|
2178
|
+
extracted on every lane, so linked sound stays in step and the source
|
|
2179
|
+
sequence is left as it was;
|
|
2180
|
+
2. on another shape, each shot framed on the subject, as `fablecut_reframe {}`
|
|
2181
|
+
does (`reframe:false` only letterboxes);
|
|
2182
|
+
3. when the clip has a `title`, a hook title for its first 3 s: big outlined
|
|
2183
|
+
words in the top third that pop in word by word, on the top video lane
|
|
2184
|
+
when it is free (else left out, and the reply says so; `title:false`
|
|
2185
|
+
leaves every title out);
|
|
2186
|
+
4. captions timed to the words, as `fablecut_captions {style}` does (`captions`:
|
|
2187
|
+
`pop` by default, `highlight`, `karaoke`, `subtitle`, or `false`); the
|
|
2188
|
+
speech is transcribed the first time, once per file;
|
|
2189
|
+
5. with `export:"tiktok"` (or any delivery preset), rendered to `exports/`,
|
|
2190
|
+
named after the clip (`Tip 1` → `tip-1.mp4`).
|
|
2191
|
+
|
|
2192
|
+
A step that fails is reported on its clip, and the rest go on. Each export
|
|
2193
|
+
gets 3 minutes, or 6 s per second of the clip if longer: one still running
|
|
2194
|
+
then is stopped and reported as not exported. A timeline with locked clips or
|
|
2195
|
+
lanes refuses the call (each clip is cut out of a copy, and locked material
|
|
2196
|
+
can't be cut): unlock them only if the user agrees. The reply
|
|
2197
|
+
lists each clip (its sequence id, length, what was done, the file); the first
|
|
2198
|
+
clip is opened. A version is kept first. Check a clip with
|
|
2199
|
+
`openSequence` and `fablecut_frame {time}`; its title and captions are
|
|
2200
|
+
ordinary text clips, restyled with `updateClip` inside `inSequence`.
|
|
2201
|
+
|
|
2202
|
+
Recipes: **clips from a talk or podcast** — `fablecut_transcribe {}`, pick the
|
|
2203
|
+
3–5 parts that stand on their own, then `fablecut_clips {clips:[{from:43.2, to:88.0,
|
|
2204
|
+
name:"Tip 1 - comfort zone", title:"Start a little out of your comfort zone"}, …],
|
|
2205
|
+
export:"tiktok"}`; **vertical cut of a finished edit** — `fablecut_reframe {aspect:"9:16"}`,
|
|
2165
2206
|
then check the titles with `fablecut_frame`; by hand, `addSequence {name:"Reel 9:16",
|
|
2166
2207
|
from:"open", width:1080, height:1920}`, then `inSequence` ops to re-position
|
|
2167
2208
|
or re-scale the shots and `setProject {delivery:"instagram-reels"}` in it;
|
package/README.md
CHANGED
|
@@ -140,6 +140,10 @@ big operation (cutting silences, snapping to the beat, reframing), and every
|
|
|
140
140
|
clear picture) cut into a short edit in a new sequence, in story order and
|
|
141
141
|
never across a cut. From the sequence menu's **Highlights…**; agents use
|
|
142
142
|
`fablecut_highlights`.
|
|
143
|
+
- **Clips** — a long video (a podcast, an interview, a talk) into short
|
|
144
|
+
vertical clips in one ask: each part becomes its own 9:16 sequence, framed
|
|
145
|
+
on the speaker, with a hook title and word-timed captions, and can be
|
|
146
|
+
exported for TikTok, Shorts or Reels. Agents use `fablecut_clips`.
|
|
143
147
|
- **Silence removal** — the inspector's **Silence** section (or right-click →
|
|
144
148
|
**Find silences**) listens to a take and marks every pause on the timeline;
|
|
145
149
|
**Cut** extracts them all in one undo step, keeping a little quiet beside
|
|
@@ -313,7 +317,9 @@ big operation (cutting silences, snapping to the beat, reframing), and every
|
|
|
313
317
|
locks aspect). Inside a box, text wraps at the fixed font size by default;
|
|
314
318
|
enable **Scale to fit** to shrink the font so the whole block fits. **V-align**
|
|
315
319
|
(top / middle / bottom) places the text block vertically in the box. Set Box
|
|
316
|
-
W/H to `0` to return to hug-content sizing.
|
|
320
|
+
W/H to `0` to return to hug-content sizing. **Bg shape** (`bgShape`):
|
|
321
|
+
`lines` puts a pill behind each line (pills that would overlap join into one shape),
|
|
322
|
+
`box` one rounded box filling the text box, or the whole block without one.
|
|
317
323
|
|
|
318
324
|
**Animated SVG clips**
|
|
319
325
|
|
|
@@ -495,7 +501,7 @@ Three equivalent control surfaces:
|
|
|
495
501
|
`fablecut_get_project`, `fablecut_set_project`, `fablecut_patch_project`,
|
|
496
502
|
`fablecut_import_media`, `fablecut_files`, `fablecut_analyze_reference`, `fablecut_frame`,
|
|
497
503
|
`fablecut_encode_profiles`, `fablecut_normalize_audio`, `fablecut_auto_duck`,
|
|
498
|
-
`fablecut_denoise`, `fablecut_silence`, `fablecut_beats`, `fablecut_reframe`, `fablecut_highlights`, `fablecut_transcribe`, `fablecut_captions`, `fablecut_export`, `fablecut_scopes`, `fablecut_track`.
|
|
504
|
+
`fablecut_denoise`, `fablecut_silence`, `fablecut_beats`, `fablecut_reframe`, `fablecut_highlights`, `fablecut_clips`, `fablecut_transcribe`, `fablecut_captions`, `fablecut_export`, `fablecut_scopes`, `fablecut_track`.
|
|
499
505
|
|
|
500
506
|
FableCut is also published on the **official MCP registry** as
|
|
501
507
|
[`io.github.ronak-create/fablecut`](https://registry.modelcontextprotocol.io/v0/servers?search=fablecut)
|
package/app.js
CHANGED
|
@@ -75,6 +75,7 @@ const DEFAULT_PROPS = {
|
|
|
75
75
|
glow: 0, glowColor: "", // neon glow (glowColor defaults to fill)
|
|
76
76
|
textAnim: "none", wordRate: 0.15, direction: "auto", highlightColor: "#ffd166",
|
|
77
77
|
strokeWidth: 0, strokeColor: "#000000", bgColor: "#000000", bgOpacity: 0,
|
|
78
|
+
bgShape: "lines", // lines = a pill per line · box = one box (the text box, else the block)
|
|
78
79
|
boxW: 0, boxH: 0, // text box (px); 0 = hug content. Resize handles edit these.
|
|
79
80
|
boxFit: false, // false = wrap at fixed fontSize; true = scale font to fit box
|
|
80
81
|
vAlign: "middle", // top | middle | bottom — vertical align of the text block in the box
|
|
@@ -7208,6 +7209,7 @@ function renderInspector(lite) {
|
|
|
7208
7209
|
${row("Stroke col.", `<input type="color" data-k="strokeColor" value="${p.strokeColor}">`, "", "strokeColor")}
|
|
7209
7210
|
${row("Bg color", `<input type="color" data-k="bgColor" value="${p.bgColor}">`, "", "bgColor")}
|
|
7210
7211
|
${slider("bgOpacity", 0, 1, 0.05, p.bgOpacity)}
|
|
7212
|
+
${sel("Bg shape", "bgShape", ["lines", "box"], p.bgShape === "box" ? "box" : "lines")}
|
|
7211
7213
|
${slider("textShadow", 0, 40, 1, p.textShadow)}
|
|
7212
7214
|
${slider("glow", 0, 100, 1, p.glow)}
|
|
7213
7215
|
${row("Glow color", `<input type="color" data-k="glowColor" value="${p.glowColor || p.color}">
|
|
@@ -8565,6 +8567,12 @@ function loadFxWorklet(ctx) {
|
|
|
8565
8567
|
return p;
|
|
8566
8568
|
}
|
|
8567
8569
|
const FX_WORKLET_TYPES = { limiter: "fablecut-limiter", gate: "fablecut-gate", pitch: "fablecut-pitch" };
|
|
8570
|
+
/** Does the open sequence's mix use an effect from fx-worklet.js (on a clip, track, bus or the master)? */
|
|
8571
|
+
function mixUsesFxWorklet() {
|
|
8572
|
+
const uses = (list) => Array.isArray(list) && list.some((e) => e && e.on !== false && FX_WORKLET_TYPES[e.type]);
|
|
8573
|
+
return uses(project.master?.fx) || (project.tracks || []).some((t) => uses(t.fx)) || (project.buses || []).some((x) => uses(x.fx)) ||
|
|
8574
|
+
mediaClips().some((c) => uses(c.fx));
|
|
8575
|
+
}
|
|
8568
8576
|
function normFx(list) {
|
|
8569
8577
|
if (!Array.isArray(list) || !list.length) return undefined;
|
|
8570
8578
|
const out = typeof FableCutFx !== "undefined" ? FableCutFx.normalizeFx(list) : list;
|
|
@@ -15972,18 +15980,38 @@ function drawText(c, p, local) {
|
|
|
15972
15980
|
}
|
|
15973
15981
|
const shadowBlur = (p.textShadow === 0 ? 0 : (+p.textShadow || 12)) * size / 100;
|
|
15974
15982
|
|
|
15975
|
-
// background
|
|
15983
|
+
// text background (static — anchors the animated words)
|
|
15976
15984
|
if (p.bgOpacity > 0) {
|
|
15977
15985
|
ctx2d.fillStyle = hexToRgba(p.bgColor || "#000", clamp(p.bgOpacity, 0, 1));
|
|
15978
15986
|
const padX = size * 0.4, padY = size * 0.18, r = size * 0.28;
|
|
15979
|
-
|
|
15980
|
-
|
|
15981
|
-
|
|
15982
|
-
|
|
15983
|
-
ctx2d.
|
|
15984
|
-
ctx2d.roundRect(
|
|
15985
|
-
|
|
15986
|
-
|
|
15987
|
+
const half = (lh + padY * 2 - lh * 0.16) / 2; // a lone pill's half height
|
|
15988
|
+
ctx2d.beginPath();
|
|
15989
|
+
if (p.bgShape === "box") {
|
|
15990
|
+
// one box: the text box when there is one, else the whole block plus padding
|
|
15991
|
+
if (useBox) ctx2d.roundRect(-boxW / 2, -boxH / 2, boxW, boxH, Math.min(r, boxW / 2, boxH / 2));
|
|
15992
|
+
else ctx2d.roundRect(-blockW / 2 - padX, y0 - half, blockW + padX * 2, (nLines - 1) * lh + half * 2, r);
|
|
15993
|
+
} else {
|
|
15994
|
+
// a pill per line; where neighbours would overlap they meet halfway instead,
|
|
15995
|
+
// and the whole shape is filled once, so no strip is painted twice
|
|
15996
|
+
const pills = rawLines.map((ln, i) => {
|
|
15997
|
+
if (!ln.trim()) return null;
|
|
15998
|
+
const w = lineWidths[i];
|
|
15999
|
+
return { l: lineCx(i) - w / 2 - padX, r: lineCx(i) + w / 2 + padX, y: y0 + i * lh };
|
|
16000
|
+
});
|
|
16001
|
+
const meet = half * 2 >= lh;
|
|
16002
|
+
pills.forEach((q, i) => {
|
|
16003
|
+
if (!q) return;
|
|
16004
|
+
const up = meet ? pills[i - 1] : null, down = meet ? pills[i + 1] : null;
|
|
16005
|
+
const top = up ? q.y - lh / 2 : q.y - half;
|
|
16006
|
+
const bot = down ? q.y + lh / 2 : q.y + half;
|
|
16007
|
+
// a corner a neighbour covers is square, so stacked pills read as one shape
|
|
16008
|
+
const tl = up && up.l <= q.l + 1 ? 0 : r, tr = up && up.r >= q.r - 1 ? 0 : r;
|
|
16009
|
+
const bl = down && down.l <= q.l + 1 ? 0 : r, br = down && down.r >= q.r - 1 ? 0 : r;
|
|
16010
|
+
const rr = (v) => Math.min(v, (bot - top) / 2, (q.r - q.l) / 2);
|
|
16011
|
+
ctx2d.roundRect(q.l, top, q.r - q.l, bot - top, [rr(tl), rr(tr), rr(br), rr(bl)]);
|
|
16012
|
+
});
|
|
16013
|
+
}
|
|
16014
|
+
ctx2d.fill();
|
|
15987
16015
|
}
|
|
15988
16016
|
|
|
15989
16017
|
const fillFor = (y) => {
|
|
@@ -17195,6 +17223,7 @@ function snapshotExportFrame() {
|
|
|
17195
17223
|
} catch (e) { throw canvasTaintError(e); }
|
|
17196
17224
|
}
|
|
17197
17225
|
const JPEG_WORKER_SRC = `"use strict";
|
|
17226
|
+
self.postMessage({ ready: true });
|
|
17198
17227
|
self.onmessage = async (e) => {
|
|
17199
17228
|
const { id, bmp, quality, type } = e.data;
|
|
17200
17229
|
try {
|
|
@@ -17211,46 +17240,63 @@ self.onmessage = async (e) => {
|
|
|
17211
17240
|
}
|
|
17212
17241
|
};
|
|
17213
17242
|
`;
|
|
17214
|
-
|
|
17243
|
+
/* Frame encoders off the main thread. A worker gets frames only once it has
|
|
17244
|
+
said it is running: one that never starts (its script didn't load, or a
|
|
17245
|
+
debugger attached to the tab holds new workers at their first line) would
|
|
17246
|
+
keep every frame sent to it, and the export, which takes the frames back in
|
|
17247
|
+
order, would wait on it for good. Until a worker is ready, and when none is
|
|
17248
|
+
left, frames are encoded here. A worker that fails, or keeps a frame past
|
|
17249
|
+
answerMs, is dropped, and the frames it held fail the export with a reason. */
|
|
17250
|
+
const JPEG_ANSWER_MS = 60000;
|
|
17251
|
+
function createJpegWorkers(n, { answerMs = JPEG_ANSWER_MS } = {}) {
|
|
17215
17252
|
if (typeof Worker !== "function" || typeof OffscreenCanvas !== "function") return null;
|
|
17216
17253
|
let url;
|
|
17217
17254
|
try { url = URL.createObjectURL(new Blob([JPEG_WORKER_SRC], { type: "text/javascript" })); }
|
|
17218
17255
|
catch { return null; }
|
|
17219
|
-
const
|
|
17256
|
+
const pool = [];
|
|
17220
17257
|
try {
|
|
17221
|
-
for (let i = 0; i < n; i++)
|
|
17258
|
+
for (let i = 0; i < n; i++) pool.push({ w: new Worker(url), ready: false, dead: false, jobs: new Map() });
|
|
17222
17259
|
} catch {
|
|
17223
|
-
for (const
|
|
17260
|
+
for (const x of pool) try { x.w.terminate(); } catch { }
|
|
17224
17261
|
URL.revokeObjectURL(url);
|
|
17225
17262
|
return null;
|
|
17226
17263
|
}
|
|
17227
17264
|
URL.revokeObjectURL(url);
|
|
17228
|
-
const pending = new Map();
|
|
17229
17265
|
let nextId = 0, rr = 0;
|
|
17230
|
-
|
|
17231
|
-
|
|
17232
|
-
|
|
17233
|
-
|
|
17234
|
-
|
|
17235
|
-
|
|
17236
|
-
|
|
17266
|
+
const drop = (x, why) => {
|
|
17267
|
+
if (x.dead) return;
|
|
17268
|
+
x.dead = true;
|
|
17269
|
+
try { x.w.terminate(); } catch { }
|
|
17270
|
+
for (const job of x.jobs.values()) { clearTimeout(job.timer); job.reject(new Error(why)); }
|
|
17271
|
+
x.jobs.clear();
|
|
17272
|
+
};
|
|
17273
|
+
for (const x of pool) {
|
|
17274
|
+
x.w.onmessage = (e) => {
|
|
17275
|
+
const d = e.data || {};
|
|
17276
|
+
if (d.ready) { x.ready = true; return; }
|
|
17277
|
+
const job = x.jobs.get(d.id);
|
|
17278
|
+
if (!job) return;
|
|
17279
|
+
x.jobs.delete(d.id);
|
|
17280
|
+
clearTimeout(job.timer);
|
|
17281
|
+
if (d.error) job.reject(new Error(d.error));
|
|
17282
|
+
else job.resolve(d.buf);
|
|
17237
17283
|
};
|
|
17238
|
-
w.onerror = () =>
|
|
17284
|
+
x.w.onerror = (e) => drop(x, "a frame encoder stopped" + (e && e.message ? ": " + e.message : ""));
|
|
17239
17285
|
}
|
|
17240
17286
|
return {
|
|
17241
17287
|
encode(bmp, quality, type) {
|
|
17242
|
-
const
|
|
17243
|
-
|
|
17288
|
+
const live = pool.filter((x) => x.ready && !x.dead);
|
|
17289
|
+
if (!live.length) return jpegFromBitmap(bmp, quality, type);
|
|
17290
|
+
const x = live[rr++ % live.length], id = nextId++;
|
|
17244
17291
|
return new Promise((resolve, reject) => {
|
|
17245
|
-
|
|
17246
|
-
|
|
17247
|
-
|
|
17292
|
+
const timer = setTimeout(() => drop(x, `a frame encoder didn't answer in ${Math.round(answerMs / 1000)} s`), answerMs);
|
|
17293
|
+
x.jobs.set(id, { resolve, reject, timer });
|
|
17294
|
+
try { x.w.postMessage({ id, bmp, quality, type }, [bmp]); }
|
|
17295
|
+
catch (e) { x.jobs.delete(id); clearTimeout(timer); reject(e); }
|
|
17248
17296
|
});
|
|
17249
17297
|
},
|
|
17250
17298
|
terminate() {
|
|
17251
|
-
for (const
|
|
17252
|
-
pending.clear();
|
|
17253
|
-
for (const w of workers) try { w.terminate(); } catch { }
|
|
17299
|
+
for (const x of pool) drop(x, "cancelled");
|
|
17254
17300
|
},
|
|
17255
17301
|
};
|
|
17256
17302
|
}
|
|
@@ -17357,11 +17403,43 @@ function postFrames(url, body, signal) {
|
|
|
17357
17403
|
xhr.send(body);
|
|
17358
17404
|
});
|
|
17359
17405
|
}
|
|
17406
|
+
/* An export's stall watchdog. A step that never finishes (a decoder, a frame
|
|
17407
|
+
encoder, or the encoder behind the uploads that stopped answering) fails the
|
|
17408
|
+
export with a reason instead of holding it where it is for good. Each step
|
|
17409
|
+
that moves the export on calls moved(); guard(p) races p against the stall,
|
|
17410
|
+
and p finishing counts as moving on. The limit grows with the export's
|
|
17411
|
+
length, since a single step can scale with it: an in-browser encoder
|
|
17412
|
+
encodes the whole sound track at the first upload. In a hidden tab it is
|
|
17413
|
+
at least hiddenMs: after a few minutes there
|
|
17414
|
+
the browser runs the export's timers about once a minute, so a healthy
|
|
17415
|
+
export can go that long without moving. onStall(err) runs first, so
|
|
17416
|
+
polling waits see the error too. */
|
|
17417
|
+
function exportWatchdog(seconds, onStall, { minMs = 60000, msPerSecond = 100, hiddenMs = 300000 } = {}) {
|
|
17418
|
+
const limit = Math.max(minMs, seconds * msPerSecond);
|
|
17419
|
+
let movedAt = performance.now(), fail = null;
|
|
17420
|
+
const stalled = new Promise((_, rej) => { fail = rej; });
|
|
17421
|
+
stalled.catch(() => { });
|
|
17422
|
+
let timer = setInterval(() => {
|
|
17423
|
+
const lim = typeof document !== "undefined" && document.hidden ? Math.max(limit, hiddenMs) : limit;
|
|
17424
|
+
if (performance.now() - movedAt < lim) return;
|
|
17425
|
+
clearInterval(timer); timer = 0;
|
|
17426
|
+
const err = new Error(`the export stalled: nothing moved on for ${Math.round(lim / 1000)} s (a decoder or encoder stopped answering) — try it again`);
|
|
17427
|
+
if (onStall) onStall(err);
|
|
17428
|
+
fail(err);
|
|
17429
|
+
}, Math.min(1000, limit / 4));
|
|
17430
|
+
const moved = () => { movedAt = performance.now(); };
|
|
17431
|
+
return {
|
|
17432
|
+
moved,
|
|
17433
|
+
guard(p) { return Promise.race([Promise.resolve(p).then((v) => { moved(); return v; }), stalled]); },
|
|
17434
|
+
stop() { if (timer) clearInterval(timer); timer = 0; },
|
|
17435
|
+
};
|
|
17436
|
+
}
|
|
17360
17437
|
/* Sequential /frame POSTs, batched. Concurrent bodies can still race on ffmpeg
|
|
17361
17438
|
stdin if they complete out of order, so the client starts each fetch only
|
|
17362
17439
|
after the previous one settles; rendering runs ahead under backpressure.
|
|
17363
|
-
JPEG Fast and WebCodecs Annex-B both concatenate on this path.
|
|
17364
|
-
|
|
17440
|
+
JPEG Fast and WebCodecs Annex-B both concatenate on this path.
|
|
17441
|
+
onSent() runs after each POST the server took (the stall watchdog's moved). */
|
|
17442
|
+
function createExportUploader(sessId, { batchItems, batchBytes, signal, getError, setError, onSent }) {
|
|
17365
17443
|
let batch = [];
|
|
17366
17444
|
let packed = 0;
|
|
17367
17445
|
let sentFirst = false;
|
|
@@ -17385,6 +17463,7 @@ function createExportUploader(sessId, { batchItems, batchBytes, signal, getError
|
|
|
17385
17463
|
const err = getError();
|
|
17386
17464
|
if (err) throw err;
|
|
17387
17465
|
await postFrames("/api/export/frame?id=" + sessId, body, signal);
|
|
17466
|
+
if (onSent) onSent();
|
|
17388
17467
|
});
|
|
17389
17468
|
uploadTail = p.catch((err) => {
|
|
17390
17469
|
if (!getError()) setError(err);
|
|
@@ -17604,8 +17683,10 @@ function hardSeekVideo(el, mt, attempt = 0, shown = el._fcPresentedTime, signal
|
|
|
17604
17683
|
});
|
|
17605
17684
|
}
|
|
17606
17685
|
/** Play forward until a *presented* frame reaches mt. Pause afterwards unless
|
|
17607
|
-
keepPlaying — a free-running element overruns while JPEG encode/HTTP stalls.
|
|
17608
|
-
|
|
17686
|
+
keepPlaying — a free-running element overruns while JPEG encode/HTTP stalls.
|
|
17687
|
+
signal: the export's, kept for its callbacks: once that export has ended they
|
|
17688
|
+
neither pause nor seek the player, which may be the next export's by then. */
|
|
17689
|
+
function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}, signal = exportSignal()) {
|
|
17609
17690
|
return new Promise((res, rej) => {
|
|
17610
17691
|
let settled = false;
|
|
17611
17692
|
let rvfcId = null;
|
|
@@ -17613,6 +17694,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17613
17694
|
if (el._fcPrevMuted == null) el._fcPrevMuted = el.muted;
|
|
17614
17695
|
const wasPlaying = !el.paused;
|
|
17615
17696
|
const slop = Math.min(eps, 0.002);
|
|
17697
|
+
const ended = () => !!(signal && signal.aborted);
|
|
17616
17698
|
const cleanup = () => {
|
|
17617
17699
|
clearTimeout(tm);
|
|
17618
17700
|
if (poll) { clearInterval(poll); poll = null; }
|
|
@@ -17620,10 +17702,14 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17620
17702
|
try { el.cancelVideoFrameCallback(rvfcId); } catch { }
|
|
17621
17703
|
rvfcId = null;
|
|
17622
17704
|
}
|
|
17623
|
-
if (!keepPlaying) {
|
|
17705
|
+
if (!keepPlaying && !ended()) {
|
|
17624
17706
|
try { el.pause(); } catch { }
|
|
17625
17707
|
}
|
|
17626
17708
|
};
|
|
17709
|
+
const reseek = () => {
|
|
17710
|
+
if (ended()) rej(new Error("cancelled"));
|
|
17711
|
+
else hardSeekVideo(el, mt, 0, undefined, signal).then(res, rej);
|
|
17712
|
+
};
|
|
17627
17713
|
const finish = (presented) => {
|
|
17628
17714
|
if (settled) return;
|
|
17629
17715
|
if (!Number.isFinite(presented)) return;
|
|
@@ -17637,7 +17723,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17637
17723
|
const pictureOvershoot = presented > mt;
|
|
17638
17724
|
if (pictureOvershoot
|
|
17639
17725
|
|| (pictureShort && Math.abs(el.currentTime - mt) > Math.max(eps * 2, 0.008)))
|
|
17640
|
-
|
|
17726
|
+
reseek();
|
|
17641
17727
|
else res();
|
|
17642
17728
|
};
|
|
17643
17729
|
if (presentedClose(el, mt, slop) && el.readyState >= 2) {
|
|
@@ -17650,7 +17736,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17650
17736
|
if (settled) return;
|
|
17651
17737
|
settled = true;
|
|
17652
17738
|
cleanup();
|
|
17653
|
-
|
|
17739
|
+
reseek();
|
|
17654
17740
|
}, Math.min(3000, 400 + (remain * 1000) / Math.max(0.1, rate) * 2.5));
|
|
17655
17741
|
const check = (mediaTime) => {
|
|
17656
17742
|
// Presented frame only — currentTime finishes half a frame early and
|
|
@@ -17677,7 +17763,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17677
17763
|
if (settled) return;
|
|
17678
17764
|
settled = true;
|
|
17679
17765
|
cleanup();
|
|
17680
|
-
|
|
17766
|
+
reseek();
|
|
17681
17767
|
});
|
|
17682
17768
|
}
|
|
17683
17769
|
});
|
|
@@ -17821,13 +17907,19 @@ async function exportDecodeFrame(c, t) {
|
|
|
17821
17907
|
if (!m || !m.src) { d.sources.set(c.id, null); return false; }
|
|
17822
17908
|
if (!d.opening.has(c.id)) d.opening.set(c.id, ExportFrameSource.open(m.src));
|
|
17823
17909
|
src = await d.opening.get(c.id);
|
|
17910
|
+
// the export may have ended while this opened (its watchdog gave up, a cancel): the source is
|
|
17911
|
+
// nobody's then, and the frame map may be the next export's
|
|
17912
|
+
if (runtime.exportDecode !== d) { src?.close(); return false; }
|
|
17824
17913
|
d.sources.set(c.id, src);
|
|
17825
17914
|
}
|
|
17826
17915
|
if (!src) return false;
|
|
17827
17916
|
try {
|
|
17828
|
-
|
|
17917
|
+
const frame = await src.frameAt(mediaTimeAt(c, t));
|
|
17918
|
+
if (runtime.exportDecode !== d) return false; // ended meanwhile; its end closed this source
|
|
17919
|
+
runtime.exportFrames.set(c.id, frame);
|
|
17829
17920
|
return true;
|
|
17830
17921
|
} catch (e) { // a decode error: this clip falls back to its element for the rest of the export
|
|
17922
|
+
if (runtime.exportDecode !== d) return false;
|
|
17831
17923
|
console.warn("[FableCut] export decode failed, using the video element:", e && e.message);
|
|
17832
17924
|
src.close(); d.sources.set(c.id, null); runtime.exportFrames.delete(c.id);
|
|
17833
17925
|
return false;
|
|
@@ -17846,6 +17938,9 @@ async function seekVideosTo(t, { queueBusy } = {}) {
|
|
|
17846
17938
|
const restoreGain = [];
|
|
17847
17939
|
const decoded = new Set();
|
|
17848
17940
|
const dec = runtime.exportDecode;
|
|
17941
|
+
// the export this seek is for: it can end while the seek waits (its watchdog gave up), and the
|
|
17942
|
+
// players may be the next export's by then, so a stale seek stops instead of moving them
|
|
17943
|
+
const win = exportWindow;
|
|
17849
17944
|
if (dec) {
|
|
17850
17945
|
const jobs = [];
|
|
17851
17946
|
for (const c of mediaClips()) {
|
|
@@ -17859,6 +17954,7 @@ async function seekVideosTo(t, { queueBusy } = {}) {
|
|
|
17859
17954
|
jobs.push(exportDecodeFrame(c, t).then((ok) => { if (ok) decoded.add(c.id); }));
|
|
17860
17955
|
}
|
|
17861
17956
|
await Promise.all(jobs);
|
|
17957
|
+
if (exportWindow !== win) return;
|
|
17862
17958
|
}
|
|
17863
17959
|
for (const c of mediaClips()) {
|
|
17864
17960
|
if (c.kind !== "video") continue;
|
|
@@ -17912,6 +18008,7 @@ async function seekVideosTo(t, { queueBusy } = {}) {
|
|
|
17912
18008
|
}
|
|
17913
18009
|
}
|
|
17914
18010
|
await Promise.all(waits);
|
|
18011
|
+
if (exportWindow !== win) return;
|
|
17915
18012
|
for (const c of restoreGain) {
|
|
17916
18013
|
const chain = runtime.clipGain.get(c.id);
|
|
17917
18014
|
if (chain?.vol) driveClipChain(chain, c, evalProps(c, t), t);
|
|
@@ -17954,7 +18051,16 @@ async function renderAudioMix(t0, t1) {
|
|
|
17954
18051
|
if (dur <= 0) return null;
|
|
17955
18052
|
const sr = 48000;
|
|
17956
18053
|
const off = new OfflineAudioContext(2, Math.ceil(dur * sr) + 1, sr);
|
|
17957
|
-
|
|
18054
|
+
// A step that never finishes would hold the export at 0% for good (a debugger attached to the tab
|
|
18055
|
+
// can hold a worklet's thread at its start, for one): the effects' module and the render race a
|
|
18056
|
+
// deadline that fails the mix with a reason instead.
|
|
18057
|
+
let timer = null;
|
|
18058
|
+
const stalled = new Promise((_, rej) => {
|
|
18059
|
+
timer = setTimeout(() => rej(new Error("the audio mix didn't finish (the browser's audio renderer stalled) — try the export again")), Math.max(60, dur * 2) * 1000);
|
|
18060
|
+
});
|
|
18061
|
+
stalled.catch(() => { });
|
|
18062
|
+
// gate / limiter / pitch render in the export too; their worklet loads only when the mix uses one
|
|
18063
|
+
if (mixUsesFxWorklet()) await Promise.race([loadFxWorklet(off), stalled]);
|
|
17958
18064
|
const mix = buildMixBuses(off, audioTrackIds(), busIdsNow());
|
|
17959
18065
|
applyMixLevels(mix);
|
|
17960
18066
|
mix.masterOut.connect(off.destination);
|
|
@@ -18000,7 +18106,7 @@ async function renderAudioMix(t0, t1) {
|
|
|
18000
18106
|
}
|
|
18001
18107
|
scheduled = true;
|
|
18002
18108
|
}
|
|
18003
|
-
if (!scheduled) return null;
|
|
18109
|
+
if (!scheduled) { clearTimeout(timer); return null; }
|
|
18004
18110
|
// Effect automation: step the offline render and glide each keyed
|
|
18005
18111
|
// parameter, the same way preview drives it every frame.
|
|
18006
18112
|
const animated = [];
|
|
@@ -18019,7 +18125,8 @@ async function renderAudioMix(t0, t1) {
|
|
|
18019
18125
|
off.suspend(when).then(() => { for (const run of animated) run(t0 + when); off.resume(); });
|
|
18020
18126
|
}
|
|
18021
18127
|
}
|
|
18022
|
-
|
|
18128
|
+
const rendered = await Promise.race([off.startRendering(), stalled]).finally(() => clearTimeout(timer));
|
|
18129
|
+
return encodeWAV(rendered);
|
|
18023
18130
|
}
|
|
18024
18131
|
/* Frame-exact asset prep for the fast exporter: rasterize the SVG frame for
|
|
18025
18132
|
this exact time, and refresh AI person masks synchronously. */
|
|
@@ -18059,13 +18166,15 @@ async function fastExport(opts = {}) {
|
|
|
18059
18166
|
let sessId = null;
|
|
18060
18167
|
let uploadError = null;
|
|
18061
18168
|
const setError = (err) => { if (!uploadError) uploadError = err; };
|
|
18169
|
+
let watch = null;
|
|
18062
18170
|
try {
|
|
18063
18171
|
els.exportTitle.textContent = "Mixing audio…";
|
|
18064
|
-
const wav = await renderAudioMix(t0, t1);
|
|
18172
|
+
const wav = await renderAudioMix(t0, t1); // has its own watchdog
|
|
18065
18173
|
if (renderCancelled) throw new Error("cancelled");
|
|
18174
|
+
watch = exportWatchdog(frames / fps, setError);
|
|
18066
18175
|
const profileId = opts.profile || effectiveEncodeProfileId();
|
|
18067
18176
|
const cv = deliveryCanvas();
|
|
18068
|
-
const begin = await fetch("/api/export/begin", {
|
|
18177
|
+
const begin = await watch.guard(fetch("/api/export/begin", {
|
|
18069
18178
|
method: "POST",
|
|
18070
18179
|
body: JSON.stringify(delivery ? {
|
|
18071
18180
|
fps, duration: frames / fps,
|
|
@@ -18078,7 +18187,7 @@ async function fastExport(opts = {}) {
|
|
|
18078
18187
|
hasAudio: !!wav,
|
|
18079
18188
|
}),
|
|
18080
18189
|
signal,
|
|
18081
|
-
}).then((r) => r.json());
|
|
18190
|
+
}).then((r) => r.json()));
|
|
18082
18191
|
if (!begin.id) throw new Error(begin.error || "export begin failed");
|
|
18083
18192
|
sessId = begin.id;
|
|
18084
18193
|
const jpegQ = delivery ? begin.jpegQuality ?? 0.95 : exportProfileMeta(profileId).jpegQuality ?? 0.95;
|
|
@@ -18087,19 +18196,19 @@ async function fastExport(opts = {}) {
|
|
|
18087
18196
|
const frameType = begin.input === "png" ? "image/png" : "image/jpeg";
|
|
18088
18197
|
exportFullCanvas = !!delivery;
|
|
18089
18198
|
if (wav) {
|
|
18090
|
-
const r = await fetch("/api/export/audio?id=" + sessId, { method: "POST", body: wav, signal });
|
|
18199
|
+
const r = await watch.guard(fetch("/api/export/audio?id=" + sessId, { method: "POST", body: wav, signal }));
|
|
18091
18200
|
if (!r.ok) throw new Error("audio upload failed");
|
|
18092
18201
|
}
|
|
18093
|
-
await loadProjectFonts();
|
|
18202
|
+
await watch.guard(loadProjectFonts());
|
|
18094
18203
|
resetExportCanvases();
|
|
18095
|
-
await armExportCors();
|
|
18096
|
-
await useOriginalPlayers(); // proxies are for editing — export reads the originals
|
|
18204
|
+
await watch.guard(armExportCors());
|
|
18205
|
+
await watch.guard(useOriginalPlayers()); // proxies are for editing — export reads the originals
|
|
18097
18206
|
exportDecodeBegin();
|
|
18098
18207
|
// JPEG off the compositor thread: snapshot is sync, encode/upload run ahead
|
|
18099
18208
|
// under backpressure. Awaiting toBlob every frame was slower than ffmpeg.
|
|
18100
18209
|
const up = createExportUploader(sessId, {
|
|
18101
18210
|
batchItems: 8, batchBytes: 512 * 1024, signal,
|
|
18102
|
-
getError: () => uploadError, setError,
|
|
18211
|
+
getError: () => uploadError, setError, onSent: watch.moved,
|
|
18103
18212
|
});
|
|
18104
18213
|
const workers = createJpegWorkers(Math.min(3, Math.max(1, (navigator.hardwareConcurrency || 2) - 1)));
|
|
18105
18214
|
let pixelChain = Promise.resolve();
|
|
@@ -18121,14 +18230,15 @@ async function fastExport(opts = {}) {
|
|
|
18121
18230
|
// enough that play-ahead would overrun during the wait (not on every blip).
|
|
18122
18231
|
const queueBusy = pixelsInflight > 6 || up.inFlight() > 4;
|
|
18123
18232
|
if (pixelsInflight > 4) pauseExportVideos();
|
|
18124
|
-
await waitPixels(6);
|
|
18233
|
+
await waitPixels(6); // the polling waits see the watchdog's error themselves
|
|
18125
18234
|
await up.waitBackpressure(4);
|
|
18126
18235
|
const t = t0 + f / fps;
|
|
18127
18236
|
state.time = t;
|
|
18128
|
-
await seekVideosTo(t, { queueBusy });
|
|
18129
|
-
await prepareFrameAssets(t);
|
|
18237
|
+
await watch.guard(seekVideosTo(t, { queueBusy }));
|
|
18238
|
+
await watch.guard(prepareFrameAssets(t));
|
|
18130
18239
|
drawFrame(t);
|
|
18131
18240
|
const snap = snapshotExportFrame();
|
|
18241
|
+
watch.moved();
|
|
18132
18242
|
pixelsInflight++;
|
|
18133
18243
|
let jpegP;
|
|
18134
18244
|
if (snap.kind === "bmp") {
|
|
@@ -18152,6 +18262,7 @@ async function fastExport(opts = {}) {
|
|
|
18152
18262
|
const buf = await jpegP;
|
|
18153
18263
|
if (!buf || !(buf.byteLength || buf.size || buf.length)) throw new Error("frame encode failed");
|
|
18154
18264
|
up.push(buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf);
|
|
18265
|
+
watch.moved();
|
|
18155
18266
|
}).catch((err) => { setError(err); throw err; }).finally(() => { pixelsInflight--; });
|
|
18156
18267
|
const pct = ((f + 1) / frames) * 100;
|
|
18157
18268
|
els.exportProgress.style.width = pct.toFixed(1) + "%";
|
|
@@ -18159,14 +18270,15 @@ async function fastExport(opts = {}) {
|
|
|
18159
18270
|
if (opts.onProgress) opts.onProgress(0.97 * (f + 1) / frames);
|
|
18160
18271
|
if (job) reportExportJob(job, { progress: 0.97 * (f + 1) / frames });
|
|
18161
18272
|
}
|
|
18162
|
-
await pixelChain;
|
|
18273
|
+
await watch.guard(pixelChain);
|
|
18163
18274
|
if (uploadError) throw uploadError;
|
|
18164
18275
|
els.exportTitle.textContent = "Encoding…";
|
|
18165
|
-
await up.done();
|
|
18276
|
+
await watch.guard(up.done());
|
|
18166
18277
|
if (uploadError) throw uploadError;
|
|
18167
18278
|
} finally {
|
|
18168
18279
|
try { workers?.terminate(); } catch { }
|
|
18169
18280
|
}
|
|
18281
|
+
watch.stop(); // finishing (the encoder's last frames, the checks) can take a while on its own
|
|
18170
18282
|
const end = await fetch("/api/export/end?id=" + sessId, { method: "POST", signal }).then((r) => r.json());
|
|
18171
18283
|
if (!end.src) throw new Error(end.error || "encode failed");
|
|
18172
18284
|
const outs = end.outputs || [{ file: decodeURIComponent(end.src.split("/").pop()), ok: true, src: end.src }];
|
|
@@ -18199,6 +18311,9 @@ async function fastExport(opts = {}) {
|
|
|
18199
18311
|
if (job) await reportExportJob(job, { status: "failed", error: msg }, true);
|
|
18200
18312
|
else if (msg !== "cancelled" && !opts.silent) alert("Export failed: " + msg);
|
|
18201
18313
|
} finally {
|
|
18314
|
+
watch?.stop();
|
|
18315
|
+
// over, however it ended: steps still waiting on this export (a seek, an upload) stop too
|
|
18316
|
+
try { exportAbort?.abort(); } catch { }
|
|
18202
18317
|
exportAbort = null;
|
|
18203
18318
|
exportFullCanvas = false;
|
|
18204
18319
|
exportDecodeEnd();
|
|
@@ -18792,13 +18907,14 @@ async function webCodecsExport(name) {
|
|
|
18792
18907
|
let encoder = null;
|
|
18793
18908
|
let uploadError = null;
|
|
18794
18909
|
const setError = (err) => { if (!uploadError) uploadError = err; };
|
|
18795
|
-
let up = null;
|
|
18910
|
+
let up = null, watch = null;
|
|
18796
18911
|
try {
|
|
18797
18912
|
els.exportTitle.textContent = "Mixing audio…";
|
|
18798
|
-
const wav = await renderAudioMix(t0, t1);
|
|
18913
|
+
const wav = await renderAudioMix(t0, t1); // has its own watchdog
|
|
18799
18914
|
if (renderCancelled) throw new Error("cancelled");
|
|
18915
|
+
watch = exportWatchdog(frames / fps, setError);
|
|
18800
18916
|
|
|
18801
|
-
const begin = await fetch("/api/export/begin", {
|
|
18917
|
+
const begin = await watch.guard(fetch("/api/export/begin", {
|
|
18802
18918
|
method: "POST",
|
|
18803
18919
|
body: JSON.stringify({
|
|
18804
18920
|
fps,
|
|
@@ -18807,16 +18923,16 @@ async function webCodecsExport(name) {
|
|
|
18807
18923
|
hasAudio: !!wav,
|
|
18808
18924
|
}),
|
|
18809
18925
|
signal,
|
|
18810
|
-
}).then((r) => r.json());
|
|
18926
|
+
}).then((r) => r.json()));
|
|
18811
18927
|
if (!begin.id) throw new Error(begin.error || "export begin failed");
|
|
18812
18928
|
sessId = begin.id;
|
|
18813
18929
|
if (wav) {
|
|
18814
|
-
const r = await fetch("/api/export/audio?id=" + sessId, { method: "POST", body: wav, signal });
|
|
18930
|
+
const r = await watch.guard(fetch("/api/export/audio?id=" + sessId, { method: "POST", body: wav, signal }));
|
|
18815
18931
|
if (!r.ok) throw new Error("audio upload failed");
|
|
18816
18932
|
}
|
|
18817
18933
|
up = createExportUploader(sessId, {
|
|
18818
18934
|
batchItems: 12, batchBytes: 128 * 1024, signal,
|
|
18819
|
-
getError: () => uploadError, setError,
|
|
18935
|
+
getError: () => uploadError, setError, onSent: watch.moved,
|
|
18820
18936
|
});
|
|
18821
18937
|
|
|
18822
18938
|
// Always encode at project/frame resolution (not display CSS size).
|
|
@@ -18843,10 +18959,10 @@ async function webCodecsExport(name) {
|
|
|
18843
18959
|
avc: { format: "annexb" },
|
|
18844
18960
|
latencyMode: "quality",
|
|
18845
18961
|
});
|
|
18846
|
-
await loadProjectFonts();
|
|
18962
|
+
await watch.guard(loadProjectFonts());
|
|
18847
18963
|
resetExportCanvases();
|
|
18848
|
-
await armExportCors();
|
|
18849
|
-
await useOriginalPlayers(); // proxies are for editing — export reads the originals
|
|
18964
|
+
await watch.guard(armExportCors());
|
|
18965
|
+
await watch.guard(useOriginalPlayers()); // proxies are for editing — export reads the originals
|
|
18850
18966
|
exportDecodeBegin();
|
|
18851
18967
|
|
|
18852
18968
|
for (let f = 0; f < frames; f++) {
|
|
@@ -18854,12 +18970,12 @@ async function webCodecsExport(name) {
|
|
|
18854
18970
|
if (uploadError) throw uploadError;
|
|
18855
18971
|
const queueBusy = up.inFlight() > 4 || encoder.encodeQueueSize > 4;
|
|
18856
18972
|
if (up.inFlight() > 3 || encoder.encodeQueueSize > 3) pauseExportVideos();
|
|
18857
|
-
await up.waitBackpressure(4);
|
|
18973
|
+
await up.waitBackpressure(4); // the polling waits see the watchdog's error themselves
|
|
18858
18974
|
await waitEncodeQueue(encoder, 4, { signal, getError: () => uploadError });
|
|
18859
18975
|
const t = t0 + f / fps;
|
|
18860
18976
|
state.time = t;
|
|
18861
|
-
await seekVideosTo(t, { queueBusy });
|
|
18862
|
-
await prepareFrameAssets(t);
|
|
18977
|
+
await watch.guard(seekVideosTo(t, { queueBusy }));
|
|
18978
|
+
await watch.guard(prepareFrameAssets(t));
|
|
18863
18979
|
drawFrame(t);
|
|
18864
18980
|
// Absolute µs timestamps; duration = delta so average rate stays exact
|
|
18865
18981
|
// (constant Math.round(1e6/fps) drifts, e.g. 33333µs → avg 1000000/33333).
|
|
@@ -18880,14 +18996,16 @@ async function webCodecsExport(name) {
|
|
|
18880
18996
|
} finally {
|
|
18881
18997
|
frame.close();
|
|
18882
18998
|
}
|
|
18999
|
+
watch.moved();
|
|
18883
19000
|
const pct = ((f + 1) / frames) * 100;
|
|
18884
19001
|
els.exportProgress.style.width = pct.toFixed(1) + "%";
|
|
18885
19002
|
els.exportTitle.textContent = `Encoding… ${pct.toFixed(0)}%`;
|
|
18886
19003
|
}
|
|
18887
19004
|
els.exportTitle.textContent = "Finishing…";
|
|
18888
|
-
await encoder.flush();
|
|
18889
|
-
await up.done();
|
|
19005
|
+
await watch.guard(encoder.flush());
|
|
19006
|
+
await watch.guard(up.done());
|
|
18890
19007
|
if (uploadError) throw uploadError;
|
|
19008
|
+
watch.stop();
|
|
18891
19009
|
encoder.close();
|
|
18892
19010
|
encoder = null;
|
|
18893
19011
|
const end = await fetch("/api/export/end?id=" + sessId, { method: "POST", signal }).then((r) => r.json());
|
|
@@ -18902,6 +19020,8 @@ async function webCodecsExport(name) {
|
|
|
18902
19020
|
const msg = e?.name === "AbortError" ? "cancelled" : String(e.message || e);
|
|
18903
19021
|
if (msg !== "cancelled") alert("Export failed: " + msg);
|
|
18904
19022
|
} finally {
|
|
19023
|
+
watch?.stop();
|
|
19024
|
+
try { exportAbort?.abort(); } catch { } // over: steps still waiting on this export stop too
|
|
18905
19025
|
exportAbort = null;
|
|
18906
19026
|
exportDecodeEnd();
|
|
18907
19027
|
restoreExportVideoState();
|
package/clips.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/* FableCut clips — a long video into short clips, one call. The agent picks the
|
|
2
|
+
segments (from the transcript: a tip, an answer, a story); for each one this makes
|
|
3
|
+
a new sequence on the clip's canvas holding only that part of the open timeline,
|
|
4
|
+
then frames it (reframe), adds a hook title and captions, and can export it.
|
|
5
|
+
Zero dependencies; loaded by the editor as a plain script (global
|
|
6
|
+
`FableCutClips`) and required by the MCP server, so fablecut_clips and Studio
|
|
7
|
+
run the same steps. The steps themselves are the editor's own tools, passed in
|
|
8
|
+
as `env`: read() the project, patch(ops), reframe(args), captions(args),
|
|
9
|
+
exportClip(args) — each answering text, or throwing — and, optionally, progress(text)
|
|
10
|
+
as each clip and step starts. exportClip gets a `timeout` (seconds) for that clip and
|
|
11
|
+
answers once its export has ended (done, failed, or stopped when its time was up): the
|
|
12
|
+
next clip opens another sequence, and the editor renders the open one live. An answer
|
|
13
|
+
that says it is still running stops the batch there. */
|
|
14
|
+
(function (root, factory) {
|
|
15
|
+
const api = factory();
|
|
16
|
+
if (typeof module === "object" && module.exports) module.exports = api;
|
|
17
|
+
else root.FableCutClips = api;
|
|
18
|
+
})(typeof self !== "undefined" ? self : this, function () {
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
const ASPECTS = { "9:16": [9, 16], "1:1": [1, 1], "4:5": [4, 5], "16:9": [16, 9] };
|
|
22
|
+
const CAPTION_STYLES = ["pop", "highlight", "karaoke", "subtitle"];
|
|
23
|
+
const MAX_CLIPS = 10, MIN_LEN = 3, MAX_LEN = 180, TITLE_SECS = 3;
|
|
24
|
+
// each clip's export gets this long (3 min, or 6 s per second of the clip): one stuck past it is stopped
|
|
25
|
+
// and reported, so it can't hold up the clips after it
|
|
26
|
+
const EXPORT_MIN_S = 180, EXPORT_PER_S = 6;
|
|
27
|
+
|
|
28
|
+
/** The canvas for a shape, keeping the project's shorter side (1920×1080 → 1080×1920 for 9:16), even sizes. */
|
|
29
|
+
function canvasFor(aspect, W, H) {
|
|
30
|
+
const r = ASPECTS[aspect];
|
|
31
|
+
if (!r) throw new Error(`aspect must be one of ${Object.keys(ASPECTS).join(", ")}`);
|
|
32
|
+
const short = Math.min(W || 1920, H || 1080);
|
|
33
|
+
const even = (v) => Math.max(16, Math.round(v / 2) * 2);
|
|
34
|
+
return r[0] <= r[1] ? { width: even(short), height: even(short * r[1] / r[0]) } : { width: even(short * r[0] / r[1]), height: even(short) };
|
|
35
|
+
}
|
|
36
|
+
const end = (doc) => (doc.clips || []).reduce((m, c) => Math.max(m, (+c.start || 0) + (+c.duration || 0)), 0);
|
|
37
|
+
const clean = (s, n) => String(s == null ? "" : s).replace(/\s+/g, " ").trim().slice(0, n);
|
|
38
|
+
const fileName = (s) => clean(s, 60).replace(/[\\/:*?"<>|]+/g, "").replace(/\s+/g, "-").toLowerCase() || "clip";
|
|
39
|
+
|
|
40
|
+
/** Checked arguments: {clips:[{from, to, name, title}], aspect, captions, title, exportPreset}. Throws on anything wrong. */
|
|
41
|
+
function options(args, doc) {
|
|
42
|
+
args = args || {};
|
|
43
|
+
const list = args.clips;
|
|
44
|
+
if (!Array.isArray(list) || !list.length) throw new Error("clips must be a list of {from, to, name?, title?} — the parts of the timeline to make into clips (seconds)");
|
|
45
|
+
if (list.length > MAX_CLIPS) throw new Error(`up to ${MAX_CLIPS} clips at a time`);
|
|
46
|
+
const len = end(doc);
|
|
47
|
+
if (!(len > 0)) throw new Error("the open timeline is empty — put the long video on it first");
|
|
48
|
+
// each clip is cut out of a copy by extracting the rest, and an extract leaves locked material as it is:
|
|
49
|
+
// the copy would keep it whole and out of step with the rest, so the call is refused before anything changes
|
|
50
|
+
const lockedLanes = new Set(Array.isArray(doc.lockedTracks) ? doc.lockedTracks : []);
|
|
51
|
+
const locked = (doc.clips || []).filter((c) => c && (c.locked || lockedLanes.has(c.track)));
|
|
52
|
+
if (locked.length) throw new Error(`the timeline has locked material (${locked.slice(0, 4).map((c) => c.id + " on " + c.track).join(", ")}${locked.length > 4 ? ", …" : ""}): ` +
|
|
53
|
+
"clips are cut out of a copy by extracting the rest, and locked clips can't be cut — unlock them (updateClip set:{locked:null}, or the lane's lock) only if the user agrees, then call again");
|
|
54
|
+
const clips = list.map((c, i) => {
|
|
55
|
+
const from = +(c && c.from), to = +(c && c.to);
|
|
56
|
+
if (!Number.isFinite(from) || !Number.isFinite(to)) throw new Error(`clip ${i + 1}: from and to must be numbers (timeline seconds)`);
|
|
57
|
+
if (from < 0 || to > len + 0.05) throw new Error(`clip ${i + 1}: ${from}–${to} s is outside the timeline (0–${len.toFixed(2)} s)`);
|
|
58
|
+
if (to - from < MIN_LEN) throw new Error(`clip ${i + 1}: at least ${MIN_LEN} s`);
|
|
59
|
+
if (to - from > MAX_LEN) throw new Error(`clip ${i + 1}: at most ${MAX_LEN} s`);
|
|
60
|
+
return { from: Math.round(from * 1000) / 1000, to: Math.round(Math.min(to, len) * 1000) / 1000,
|
|
61
|
+
name: clean(c.name, 80) || `Clip ${i + 1}`, title: clean(c.title, 120) };
|
|
62
|
+
});
|
|
63
|
+
const aspect = args.aspect == null ? "9:16" : String(args.aspect);
|
|
64
|
+
if (!ASPECTS[aspect]) throw new Error(`aspect must be one of ${Object.keys(ASPECTS).join(", ")}`);
|
|
65
|
+
let captions = args.captions == null ? "pop" : args.captions;
|
|
66
|
+
if (captions !== false && !CAPTION_STYLES.includes(captions)) throw new Error(`captions must be one of ${CAPTION_STYLES.join(", ")}, or false`);
|
|
67
|
+
const exportPreset = args.export == null || args.export === false ? null : String(args.export);
|
|
68
|
+
return { clips, aspect, captions, title: args.title !== false, reframe: args.reframe !== false, exportPreset };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The hook title: big outlined words in the top third, popping in for the first seconds. */
|
|
72
|
+
function titleClip(id, text, track, W, H, len) {
|
|
73
|
+
const size = Math.round(Math.min(W, H) * 0.085);
|
|
74
|
+
return { id, kind: "text", mediaId: null, track, start: 0, in: 0, duration: Math.min(TITLE_SECS, len), name: "Hook title",
|
|
75
|
+
props: { text, font: "Anton", fontSize: size, uppercase: true, color: "#ffffff", strokeWidth: Math.max(3, Math.round(size * 0.07)),
|
|
76
|
+
strokeColor: "#000000", textShadow: 12, align: "center", boxW: Math.round(W * 0.86), boxH: Math.round(H * 0.22), boxFit: true,
|
|
77
|
+
y: -Math.round(H * 0.36), textAnim: "word-pop", wordRate: 0.12 },
|
|
78
|
+
transitionOut: { type: "fade", duration: 0.3 } };
|
|
79
|
+
}
|
|
80
|
+
/** The top video lane, when nothing is on it during the title; else null (the title is left out). */
|
|
81
|
+
function freeTopLane(doc, until) {
|
|
82
|
+
const lanes = (Array.isArray(doc.tracks) && doc.tracks.length ? doc.tracks : [{ id: "V3", kind: "video" }, { id: "V2", kind: "video" }, { id: "V1", kind: "video" }])
|
|
83
|
+
.filter((t) => t && t.kind === "video").map((t) => t.id).sort((a, b) => +b.slice(1) - +a.slice(1));
|
|
84
|
+
const top = lanes[0];
|
|
85
|
+
if (!top || (doc.lockedTracks || []).includes(top)) return null;
|
|
86
|
+
return (doc.clips || []).some((c) => c.track === top && c.start < until && c.start + c.duration > 0) ? null : top;
|
|
87
|
+
}
|
|
88
|
+
const first = (s) => String(s || "").split("\n")[0].slice(0, 200);
|
|
89
|
+
/** An export answer that says it hasn't ended ("Export x_1 running — 40% …"). */
|
|
90
|
+
const RUNNING = /\bExport (?:\S+ )?(?:pending|running|queued)\b/;
|
|
91
|
+
|
|
92
|
+
/** exportClip for a host whose exports run as jobs it can poll and cancel: start one, wait up to
|
|
93
|
+
* a.timeout for its end, cancel it past that, and answer once its status says it ended — else
|
|
94
|
+
* "Export <id> running: …", which stops the batch. io: start(a) → text naming the job (throws only
|
|
95
|
+
* when nothing was accepted), status(id, waitSecs) → text, cancel(id), sleep(ms). */
|
|
96
|
+
async function exportUntilEnded(io, a) {
|
|
97
|
+
const started = String(await io.start(a));
|
|
98
|
+
const id = (/\bExport (\S+) /.exec(started) || [])[1];
|
|
99
|
+
if (!id || !RUNNING.test(started)) return started;
|
|
100
|
+
let r;
|
|
101
|
+
try { r = String(await io.status(id, a.timeout)); }
|
|
102
|
+
catch (e) { r = `Export ${id} running (its status couldn't be read: ${first(e && e.message)})`; }
|
|
103
|
+
if (!RUNNING.test(r)) return r;
|
|
104
|
+
try { await io.cancel(id); } catch { }
|
|
105
|
+
await io.sleep(2000); // a running tab hears the cancel in the answer to its next progress report, once a second
|
|
106
|
+
let now = "";
|
|
107
|
+
try { now = String(await io.status(id, 0)); } catch { }
|
|
108
|
+
if (/\bExport \S+ done\b/.test(now)) return now;
|
|
109
|
+
if (/\bExport \S+ (?:cancelled|failed)\b/.test(now)) return `Export ${id} stopped: it didn't finish in ${a.timeout} s`;
|
|
110
|
+
return `Export ${id} running: it couldn't be confirmed stopped${now ? " (" + first(now) + ")" : ""}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Make the clips. Returns the reply text. */
|
|
114
|
+
async function run(args, env) {
|
|
115
|
+
const doc0 = await env.read();
|
|
116
|
+
const o = options(args, doc0);
|
|
117
|
+
const canvas = canvasFor(o.aspect, doc0.width, doc0.height);
|
|
118
|
+
const reshaped = canvas.width * (doc0.height || 1080) !== canvas.height * (doc0.width || 1920);
|
|
119
|
+
let source = doc0.sequence || null, opened = false, halted = null;
|
|
120
|
+
const taken = new Set((doc0.sequences || []).map((s) => s.id));
|
|
121
|
+
const made = [], lines = [];
|
|
122
|
+
const step = (i, what) => { if (typeof env.progress === "function") env.progress(`clip ${i + 1} of ${o.clips.length}, ${what}`, made.length); };
|
|
123
|
+
// measured on the source as it was (the open sequence may be the last clip by now); every lane named,
|
|
124
|
+
// since an extract given none skips the untargeted ones, and those must be cut too
|
|
125
|
+
const total = end(doc0);
|
|
126
|
+
const lanes = doc0.tracks && doc0.tracks.length ? doc0.tracks.map((t) => t.id) : [...new Set((doc0.clips || []).map((x) => x.track).filter(Boolean))];
|
|
127
|
+
for (let i = 0; i < o.clips.length; i++) {
|
|
128
|
+
const c = o.clips[i];
|
|
129
|
+
step(i, "cutting");
|
|
130
|
+
let id = "seq_clip" + (i + 1);
|
|
131
|
+
for (let n = 2; taken.has(id); n++) id = "seq_clip" + (i + 1) + "_" + n;
|
|
132
|
+
taken.add(id);
|
|
133
|
+
// the copy: the source timeline on the clip's canvas, cut down to from → to
|
|
134
|
+
const ops = [];
|
|
135
|
+
if (opened) ops.push({ op: "openSequence", id: source }); // the last clip's sequence is open
|
|
136
|
+
ops.push({ op: "addSequence", id, name: c.name, from: "open", width: canvas.width, height: canvas.height, open: true });
|
|
137
|
+
if (c.to < total - 0.001) ops.push({ op: "extract", from: c.to, to: total + 1, tracks: lanes });
|
|
138
|
+
if (c.from > 0.001) ops.push({ op: "extract", from: 0, to: c.from, tracks: lanes });
|
|
139
|
+
ops.push({ op: "setProject", set: { inPoint: null, outPoint: null } });
|
|
140
|
+
// a patch saves all of it or nothing: a clip that can't be cut is reported, and the next one goes on
|
|
141
|
+
try { await env.patch(ops); }
|
|
142
|
+
catch (e) { lines.push(` ${i + 1}. "${c.name}": not made (${first(e.message)})`); continue; }
|
|
143
|
+
opened = true;
|
|
144
|
+
if (!source) source = ((await env.read()).sequences || []).find((s) => s.id !== id)?.id || "main";
|
|
145
|
+
const len = Math.round((c.to - c.from) * 1000) / 1000, notes = [];
|
|
146
|
+
if (o.reframe && reshaped) {
|
|
147
|
+
step(i, "framing");
|
|
148
|
+
// the editor may save while the footage is read (just after opening, probing media): try once more
|
|
149
|
+
let err = null;
|
|
150
|
+
for (let k = 0; k < 2; k++) {
|
|
151
|
+
try { await env.reframe({}); err = null; break; }
|
|
152
|
+
catch (e) { err = e; if (!/changed/i.test(e.message)) break; }
|
|
153
|
+
}
|
|
154
|
+
notes.push(err ? "not reframed (" + first(err.message) + ")" : "framed on the subject");
|
|
155
|
+
}
|
|
156
|
+
if (o.title && c.title) {
|
|
157
|
+
const now = await env.read(), lane = freeTopLane(now, Math.min(TITLE_SECS, len));
|
|
158
|
+
if (lane) {
|
|
159
|
+
try { await env.patch([{ op: "addClip", clip: titleClip(id + "_title", c.title, lane, canvas.width, canvas.height, len) }]); notes.push(`hook title "${c.title}"`); }
|
|
160
|
+
catch (e) { notes.push("no title (" + first(e.message) + ")"); }
|
|
161
|
+
} else notes.push("no title (the top video lane is busy or locked — add a lane, then a title)");
|
|
162
|
+
}
|
|
163
|
+
if (o.captions) {
|
|
164
|
+
step(i, "captions");
|
|
165
|
+
try {
|
|
166
|
+
const r = String(await env.captions({ style: o.captions }));
|
|
167
|
+
// still transcribing (Studio answers before a long first transcription is done): say so, don't claim them
|
|
168
|
+
if (/call \S+ again|carries on/i.test(r)) notes.push("captions not added yet: the speech is still being transcribed — then openSequence and fablecut_captions {style:\"" + o.captions + "\"}");
|
|
169
|
+
else notes.push(o.captions + " captions");
|
|
170
|
+
}
|
|
171
|
+
catch (e) { notes.push("no captions (" + first(e.message) + ")"); }
|
|
172
|
+
}
|
|
173
|
+
let file = "", haltWhy = "";
|
|
174
|
+
if (o.exportPreset) {
|
|
175
|
+
step(i, "exporting");
|
|
176
|
+
try {
|
|
177
|
+
const r = String(await env.exportClip({ preset: o.exportPreset, name: fileName(c.name), timeout: Math.max(EXPORT_MIN_S, Math.ceil(len * EXPORT_PER_S)) }));
|
|
178
|
+
file = (r.match(/exports\/[^\s"'),]+/) || [""])[0];
|
|
179
|
+
// an export that hasn't ended still renders the open sequence: opening another one would change its frames
|
|
180
|
+
if (RUNNING.test(r)) { file = ""; haltWhy = "its export is still running"; notes.push("not exported (" + first(r) + ")"); }
|
|
181
|
+
// only a finished export counts: a stopped one is reported as it is
|
|
182
|
+
else if (file && !/ (failed|cancelled)\b|check again/i.test(r)) notes.push("exported → " + file);
|
|
183
|
+
else { file = ""; notes.push("not exported (" + first(r) + ")"); }
|
|
184
|
+
} catch (e) {
|
|
185
|
+
// the request failed: whether the export started isn't known, and one that did renders the open sequence
|
|
186
|
+
notes.push("not exported (" + first(e.message) + ")");
|
|
187
|
+
haltWhy = "its export request failed, so whether it started isn't known";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
made.push({ id, name: c.name, file });
|
|
191
|
+
lines.push(` ${i + 1}. "${c.name}" (${id}, ${len.toFixed(1)} s from ${c.from.toFixed(2)}–${c.to.toFixed(2)} s): ${notes.join(", ") || "made"}`);
|
|
192
|
+
if (haltWhy) {
|
|
193
|
+
halted = { clip: c.name, why: haltWhy };
|
|
194
|
+
if (i + 1 < o.clips.length) lines.push(` The clips after "${c.name}" weren't made: ${halted.why}, and opening another sequence would change what a running export renders. ` +
|
|
195
|
+
"Check fablecut_export (its job, or the export queue), then call again with those parts.");
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (!made.length) throw new Error("no clip was made:\n" + lines.join("\n"));
|
|
200
|
+
if (made.length > 1 && !halted) { try { await env.patch([{ op: "openSequence", id: made[0].id }]); } catch { } }
|
|
201
|
+
return `Made ${made.length} clip${made.length === 1 ? "" : "s"} on ${canvas.width}×${canvas.height} (${o.aspect}), each its own sequence; the source timeline is left as it was:\n` +
|
|
202
|
+
lines.join("\n") + (halted ? `\n"${halted.clip}" stays open (${halted.why}). ` : `\nOpened "${made[0].name}". `) + "Check each with fablecut_frame {time} after openSequence; " +
|
|
203
|
+
(o.exportPreset ? "the files are in exports/." : "export one with openSequence then fablecut_export {preset, name}, or call again with export:\"tiktok\".");
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return { ASPECTS, CAPTION_STYLES, MAX_CLIPS, MIN_LEN, MAX_LEN, canvasFor, options, titleClip, freeTopLane, exportUntilEnded, run };
|
|
207
|
+
});
|
package/index.html
CHANGED
|
@@ -719,6 +719,7 @@
|
|
|
719
719
|
<script src="mask.js"></script>
|
|
720
720
|
<script src="tracker.js"></script>
|
|
721
721
|
<script src="reframe.js"></script>
|
|
722
|
+
<script src="clips.js"></script>
|
|
722
723
|
<script src="highlights.js"></script>
|
|
723
724
|
<script src="motion.js"></script>
|
|
724
725
|
<script src="color.js"></script>
|
package/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifest_version": "0.2",
|
|
3
3
|
"name": "fablecut",
|
|
4
4
|
"display_name": "FableCut",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.22.0",
|
|
6
6
|
"description": "Zero-dependency browser video editor that AI agents can drive — JSON timeline, MCP tools, live-reloading UI.",
|
|
7
7
|
"long_description": "FableCut is a Premiere-style non-linear video editor that runs in the browser with zero npm dependencies. An AI agent edits video by patching a single project.json timeline (clips, keyframes, transitions, text animations, filters, speed ramps, adjustment layers) through MCP tools, with color grading, masks and tracking, an audio mixer with effects, motion graphics (shape layers, compositions, animation presets and templates), and media management with offline relink and proxies; the open editor UI live-reloads within ~150 ms and exports through ffmpeg with delivery presets (YouTube, Reels, TikTok, Broadcast ProRes, lossless archive…), batch outputs from one render, loudness normalization and a check of every file. Includes reference-video analysis (shot cuts, beats, BPM, energy, drop) so agents can remake an edit with new footage.",
|
|
8
8
|
"author": {
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
{ "name": "fablecut_beats", "description": "Find the music's beat (BPM, a steady beat grid, the drop), mark it, snap cuts to it, or re-cut a track's clips on it" },
|
|
44
44
|
{ "name": "fablecut_reframe", "description": "Reframe for another shape (9:16, 1:1, 4:5): a copy of the sequence on that canvas whose shots follow the subject" },
|
|
45
45
|
{ "name": "fablecut_highlights", "description": "The best moments of long footage (movement, sound, a clear picture) cut into a short edit in a new sequence" },
|
|
46
|
+
{ "name": "fablecut_clips", "description": "A long video into short clips in one call: each part a new 9:16 sequence, framed on the subject, with a hook title, captions and an optional export" },
|
|
46
47
|
{ "name": "fablecut_transcribe", "description": "Transcribe speech word by word in the browser, read it on the timeline, find a phrase and cut it out (text-based editing)" },
|
|
47
48
|
{ "name": "fablecut_captions", "description": "Make captions from the transcript (subtitle, karaoke, word highlight, word pop), timed word by word; export or import SRT / WebVTT" },
|
|
48
49
|
{ "name": "fablecut_proxy", "description": "Make, check or delete proxies: light copies of heavy footage the editor plays while editing (export always uses the originals)" },
|
package/mcp-server.js
CHANGED
|
@@ -355,6 +355,26 @@ const TOOLS = [
|
|
|
355
355
|
},
|
|
356
356
|
},
|
|
357
357
|
},
|
|
358
|
+
{
|
|
359
|
+
name: "fablecut_clips",
|
|
360
|
+
description: "A long video into short clips, in one call: the clipper's job (a podcast, an interview, a talk, a stream into Shorts / Reels / TikToks). First read what is said with fablecut_transcribe and pick the parts that stand on their own (a tip, an answer, a story, a strong opinion; usually 20–60 s each, starting and ending on a full sentence), then pass them here as timeline seconds. For each one it makes a new sequence on the clip's canvas (default 9:16) holding only that part of the open timeline — the source is left as it was — frames each shot on the subject (as fablecut_reframe), adds a hook title in the top third for the first 3 s (when you give `title`), makes captions timed to the words (as fablecut_captions, default style pop), and with export:\"tiktok\" (or any delivery preset) renders each one to exports/, named after the clip. The reply lists each clip and what was done; the first clip is opened. A version is saved first.",
|
|
361
|
+
inputSchema: {
|
|
362
|
+
type: "object",
|
|
363
|
+
required: ["clips"],
|
|
364
|
+
properties: {
|
|
365
|
+
clips: { type: "array", minItems: 1, maxItems: 10, description: "The clips to make, up to 10", items: { type: "object", required: ["from", "to"], properties: {
|
|
366
|
+
from: { type: "number", description: "Start, timeline seconds (start on a sentence)" },
|
|
367
|
+
to: { type: "number", description: "End, timeline seconds (3…180 s after from; end after a sentence)" },
|
|
368
|
+
name: { type: "string", description: "The clip's sequence (and file) name, e.g. \"Tip 1 - comfort zone\"" },
|
|
369
|
+
title: { type: "string", description: "The hook title shown for its first 3 s, a few punchy words (left out: no title)" } } } },
|
|
370
|
+
aspect: { type: "string", enum: ["9:16", "1:1", "4:5", "16:9"], description: "The clips' shape (default 9:16)" },
|
|
371
|
+
captions: { anyOf: [{ type: "string", enum: ["pop", "highlight", "karaoke", "subtitle"] }, { type: "boolean", enum: [false] }], description: "Caption style (default pop), or false for none" },
|
|
372
|
+
reframe: { type: "boolean", description: "Follow the subject on the new canvas (default true)" },
|
|
373
|
+
title: { type: "boolean", description: "false leaves the hook titles out even where clips give one" },
|
|
374
|
+
export: { type: "string", description: "Render each clip with this delivery preset (tiktok, youtube-shorts, instagram-reels, …; see fablecut_encode_profiles). Left out: no export" },
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
},
|
|
358
378
|
{
|
|
359
379
|
name: "fablecut_transcribe",
|
|
360
380
|
description: "What is said, word by word, with times — and text-based editing. Transcribes the clips' speech with Whisper in the editor (an open tab, else headless Chrome / Edge; the speech model downloads once, the audio never leaves the machine), keeps one transcript per file (analysis/transcripts/), and answers with the timeline's words as timed lines (timeline seconds), so you can read an interview, pick the good takes, or find where something is said. find:\"phrase\" (or a list) reports every place it is said — case, punctuation and spacing ignored, whole words only — with the exact span; cut:true then extracts each of them on the targeted tracks (or `tracks`), the words and the pause after them, last first, in one revision: later material moves up, linked stems stay in sync, locked clips stay put (lock the music bed first). A version is saved before a cut. Files already transcribed aren't done again unless again:true. Default clips: every video / audio clip with sound on the open timeline. mediaIds reads whole files instead (file seconds; no cut). The same as the editor's Transcript tab.",
|
|
@@ -964,6 +984,29 @@ async function highlightsTool(args) {
|
|
|
964
984
|
"\nCheck a moment with fablecut_frame {time}; with music under it, fablecut_beats {clipId, retime:{every:2}} cuts it on the beat." +
|
|
965
985
|
(verWarn || "\nThe project as it was is kept as a version (fablecut_versions; restore undoes it).");
|
|
966
986
|
}
|
|
987
|
+
/* fablecut_clips: clips.js runs the steps, each through the tool that does it here. */
|
|
988
|
+
async function clipsTool(args) {
|
|
989
|
+
const Clips = require("./clips.js");
|
|
990
|
+
Clips.options(args, readProject()); // refuse bad arguments before anything changes
|
|
991
|
+
let verWarn = "";
|
|
992
|
+
try { createHistory({ projects: createProjects({ dataDir: DATA_DIR, projectFile: PROJECT_FILE, libraryDir: LIBRARY_DIR }) }).beforeAgent("Before making clips"); }
|
|
993
|
+
catch (e) { verWarn = ` Warning: no version was saved first (${e.message}).`; }
|
|
994
|
+
const text = (r) => (typeof r === "string" ? r : (r?.content || []).map((c) => c.text || "").join("\n"));
|
|
995
|
+
const reply = await Clips.run(args, {
|
|
996
|
+
read: () => readProject(),
|
|
997
|
+
patch: async (ops) => text(await callTool("fablecut_patch_project", { ops }, 0)),
|
|
998
|
+
reframe: (a) => reframeTool(a),
|
|
999
|
+
captions: (a) => captionsTool(a),
|
|
1000
|
+
// answers once its export has ended, before the next clip opens another sequence (clips.js)
|
|
1001
|
+
exportClip: (a) => Clips.exportUntilEnded({
|
|
1002
|
+
start: async (x) => text(await exportTool({ ...x, wait: false })),
|
|
1003
|
+
status: async (id, secs) => text(await exportTool(secs ? { job: id, wait: true, timeout: secs } : { job: id })),
|
|
1004
|
+
cancel: (id) => exportTool({ cancel: id }),
|
|
1005
|
+
sleep,
|
|
1006
|
+
}, a),
|
|
1007
|
+
});
|
|
1008
|
+
return reply + (verWarn || "\nThe project as it was is kept as a version (fablecut_versions; restore undoes it).");
|
|
1009
|
+
}
|
|
967
1010
|
/** What words are placed by and cuts land on: where each clip sits and plays from, the track
|
|
968
1011
|
* switches and the frame rate. An editor saving probed media details while a transcription runs
|
|
969
1012
|
* doesn't change it; a moved, trimmed or cut clip does. */
|
|
@@ -1830,6 +1873,8 @@ async function callTool(name, args, attempt = 0) {
|
|
|
1830
1873
|
return reframeTool(args);
|
|
1831
1874
|
case "fablecut_highlights":
|
|
1832
1875
|
return highlightsTool(args);
|
|
1876
|
+
case "fablecut_clips":
|
|
1877
|
+
return clipsTool(args);
|
|
1833
1878
|
case "fablecut_transcribe":
|
|
1834
1879
|
return transcribeTool(args);
|
|
1835
1880
|
case "fablecut_captions":
|
|
@@ -2245,7 +2290,7 @@ async function handle(msg) {
|
|
|
2245
2290
|
result: {
|
|
2246
2291
|
protocolVersion: negotiateProtocolVersion(params?.protocolVersion),
|
|
2247
2292
|
capabilities: { tools: {} },
|
|
2248
|
-
serverInfo: { name: "fablecut", version: "1.
|
|
2293
|
+
serverInfo: { name: "fablecut", version: "1.22.0" },
|
|
2249
2294
|
},
|
|
2250
2295
|
});
|
|
2251
2296
|
}
|
package/package.json
CHANGED
package/project-ops.js
CHANGED
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
text: "Title", fontSize: 72, color: "#ffffff", color2: "", font: "Segoe UI",
|
|
54
54
|
bold: true, weight: 0, italic: false, uppercase: false, align: "center",
|
|
55
55
|
letterSpacing: 0, lineHeight: 1.2, textShadow: 12, glow: 0, glowColor: "",
|
|
56
|
-
strokeWidth: 0, strokeColor: "#000", bgColor: "#000", bgOpacity: 0,
|
|
56
|
+
strokeWidth: 0, strokeColor: "#000", bgColor: "#000", bgOpacity: 0, bgShape: "lines",
|
|
57
57
|
textAnim: "none", wordRate: 0.15, highlightColor: "#ffd166", direction: "auto", boxW: 0, boxH: 0, boxFit: false, vAlign: "middle",
|
|
58
58
|
anchorX: 0, anchorY: 0, trimStart: 0, trimEnd: 100, trimOffset: 0,
|
|
59
59
|
autoOrient: false, motionBlur: 0, motionBlurSamples: 8, pathOffset: 0, pathAlign: "start",
|
|
@@ -279,6 +279,7 @@
|
|
|
279
279
|
if (p.motionBlurSamples != null && !(Number.isInteger(p.motionBlurSamples) && p.motionBlurSamples >= 2 && p.motionBlurSamples <= 32)) throw new Error(`${label}: props.motionBlurSamples is a whole number 2…32`);
|
|
280
280
|
if (p.autoOrient != null && typeof p.autoOrient !== "boolean") throw new Error(`${label}: props.autoOrient is true or false`);
|
|
281
281
|
if (p.pathAlign != null && !["start", "center", "end"].includes(p.pathAlign)) throw new Error(`${label}: props.pathAlign is start | center | end`);
|
|
282
|
+
if (p.bgShape != null && !["lines", "box"].includes(p.bgShape)) throw new Error(`${label}: props.bgShape is lines | box`);
|
|
282
283
|
if (p.textPath != null) {
|
|
283
284
|
if (c.kind !== "text") throw new Error(`${label}: textPath goes on text clips`);
|
|
284
285
|
try { p.textPath = Motion.normalizeTextPath(p.textPath, true); } catch (err) { throw new Error(`${label}: props.${err.message}`); }
|