fablecut 1.20.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 +140 -6
- package/README.md +9 -2
- package/app.js +564 -96
- package/clips.js +207 -0
- package/import-url.js +10 -3
- package/index.html +13 -5
- package/manifest.json +3 -1
- package/mcp-server.js +177 -20
- package/music.js +253 -0
- package/package.json +1 -1
- package/project-ops.js +12 -2
- package/server.js +3 -1
- package/style.css +52 -0
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
|
|
@@ -795,7 +796,7 @@ const runtime = {
|
|
|
795
796
|
const $ = (id) => document.getElementById(id);
|
|
796
797
|
const els = {
|
|
797
798
|
binList: $("binList"), binEmpty: $("binEmpty"), fileInput: $("fileInput"),
|
|
798
|
-
binTabs: $("binTabs"), libList: $("libList"), toast: $("toast"),
|
|
799
|
+
binTabs: $("binTabs"), binSubTabs: $("binSubTabs"), libList: $("libList"), toast: $("toast"),
|
|
799
800
|
binTools: $("binTools"), binSearch: $("binSearch"), binFilter: $("binFilter"), binSort: $("binSort"),
|
|
800
801
|
binSortDir: $("binSortDir"), binViewBtn: $("binViewBtn"), btnProxy: $("btnProxy"),
|
|
801
802
|
preview: $("preview"), tcCurrent: $("tcCurrent"), tcTotal: $("tcTotal"),
|
|
@@ -1482,6 +1483,8 @@ function syncExportFrameSel() {
|
|
|
1482
1483
|
els.exportFrameSel.innerHTML = html;
|
|
1483
1484
|
}
|
|
1484
1485
|
function applyProject(data, opts = {}) {
|
|
1486
|
+
// the Export dialog's music credits follow the timeline while it is open
|
|
1487
|
+
queueMicrotask(() => { if (!$("exportSetup")?.classList.contains("hidden")) syncExportCredits(); });
|
|
1485
1488
|
if (state.compCtx && !opts.ctx && SeqLib.activeId(data) !== SeqLib.activeId(state.compCtx.root)) {
|
|
1486
1489
|
// another sequence was opened (an agent, another tab): the comp was opened from the old one
|
|
1487
1490
|
state.compCtx = null;
|
|
@@ -1673,6 +1676,8 @@ function projectJSONHere() {
|
|
|
1673
1676
|
if (m.favorite === true) mo.favorite = true;
|
|
1674
1677
|
if (m.tags && m.tags.length) mo.tags = m.tags.slice();
|
|
1675
1678
|
if (derivedFrom) { mo.derivedFrom = derivedFrom; if (denoise) mo.denoise = denoise; }
|
|
1679
|
+
const lic = FableCutMusic.cleanLicense(m.license);
|
|
1680
|
+
if (lic) mo.license = lic;
|
|
1676
1681
|
return mo;
|
|
1677
1682
|
}),
|
|
1678
1683
|
clips: clips.map(serializeClip),
|
|
@@ -1757,7 +1762,7 @@ async function syncFromServer(force) {
|
|
|
1757
1762
|
if (state.gesture || state.exporting) { runtime.pendingSync = true; return false; }
|
|
1758
1763
|
runtime.pendingSync = false;
|
|
1759
1764
|
if (state.binTab === "templates") fetchSaved("templates").then(() => { if (state.binTab === "templates") renderTemplatesTab(); });
|
|
1760
|
-
else if (state.binTab !== "project" && state.binTab !== "shapes") fetchLibrary(state.binTab).then(renderLibrary);
|
|
1765
|
+
else if (state.binTab !== "project" && state.binTab !== "shapes" && state.binTab !== "music") fetchLibrary(state.binTab).then(renderLibrary);
|
|
1761
1766
|
fetchSaved("presets");
|
|
1762
1767
|
loadLibraryFonts();
|
|
1763
1768
|
fetchEncodeProfiles();
|
|
@@ -2622,12 +2627,16 @@ function showMediaInfo(m, x, y) {
|
|
|
2622
2627
|
})()],
|
|
2623
2628
|
["Folder", folder ? folder.name : ""], ["Tags", (m.tags || []).map((t) => "#" + t).join(" ")],
|
|
2624
2629
|
["Collections", cols.join(", ")], ["Favorite", m.favorite ? "★ yes" : ""],
|
|
2630
|
+
["Licence", m.license ? `${m.license.label} — ${FableCutMusic.licence(m.license.code).note}` : ""],
|
|
2631
|
+
["Credit", m.license ? FableCutMusic.creditLine(m.license) : ""],
|
|
2625
2632
|
].filter(([, v]) => v);
|
|
2626
2633
|
const pop = document.createElement("div");
|
|
2627
2634
|
pop.className = "ctx-menu bin-pop bin-info";
|
|
2628
2635
|
pop.innerHTML = `<div class="bin-pop-title"></div><table>${rows.map(([k, v]) => `<tr><th>${escapeHtml(k)}</th><td>${escapeHtml(v)}</td></tr>`).join("")}</table>` +
|
|
2636
|
+
(m.license ? `<button type="button" class="btn tiny bin-copy-credit">Copy credit</button>` : "") +
|
|
2629
2637
|
(m.size == null && state.connected ? `<div class="bin-pop-hint">Reading the file's details…</div>` : "");
|
|
2630
2638
|
pop.querySelector(".bin-pop-title").textContent = m.name;
|
|
2639
|
+
pop.querySelector(".bin-copy-credit")?.addEventListener("click", () => copyCredits([FableCutMusic.creditLine(m.license)]));
|
|
2631
2640
|
showPopover(pop, x, y);
|
|
2632
2641
|
if (m.size == null) refreshMediaInfo([m]);
|
|
2633
2642
|
}
|
|
@@ -2760,6 +2769,14 @@ async function setMediaSource(m, src, mode, name) {
|
|
|
2760
2769
|
if (mode === "replace") {
|
|
2761
2770
|
m.name = name || MediaLib.srcName(src);
|
|
2762
2771
|
delete m.duration; delete m.width; delete m.height;
|
|
2772
|
+
// another file: the old track's licence doesn't apply (a relink keeps it); the new file's
|
|
2773
|
+
// does, when another entry imported it with one (Music / SFX tab). The same file keeps its
|
|
2774
|
+
// licence. A replaced copy is no longer derived from its old original.
|
|
2775
|
+
if (src !== oldSrc) {
|
|
2776
|
+
const same = project.media.find((x) => x !== m && x.license && x.src === src);
|
|
2777
|
+
if (same) m.license = { ...same.license }; else delete m.license;
|
|
2778
|
+
delete m.derivedFrom; delete m.denoise;
|
|
2779
|
+
}
|
|
2763
2780
|
}
|
|
2764
2781
|
mediaOffline.delete(m.id);
|
|
2765
2782
|
reloadMediaSource(m, oldSrc);
|
|
@@ -3178,6 +3195,8 @@ function toggleSfxPreview(f, btn) {
|
|
|
3178
3195
|
return;
|
|
3179
3196
|
}
|
|
3180
3197
|
if (cur) { cur.pause(); }
|
|
3198
|
+
musicPreviewStop();
|
|
3199
|
+
els.libList.querySelectorAll(".music-play").forEach((b) => (b.textContent = "▶"));
|
|
3181
3200
|
els.libList.querySelectorAll(".lib-play").forEach((b) => (b.textContent = "▶"));
|
|
3182
3201
|
const a = new Audio(f.src);
|
|
3183
3202
|
a.dataset.src = f.src;
|
|
@@ -3188,10 +3207,19 @@ function toggleSfxPreview(f, btn) {
|
|
|
3188
3207
|
}
|
|
3189
3208
|
function renderLibrary() {
|
|
3190
3209
|
const dir = state.binTab;
|
|
3191
|
-
|
|
3210
|
+
// a library listing that arrives after the user moved to a tab drawn elsewhere must not replace it
|
|
3211
|
+
if (dir === "project" || dir === "music" || dir === "shapes" || dir === "templates") return;
|
|
3192
3212
|
const files = runtime.library[dir] || [];
|
|
3213
|
+
const focus = searchFocus();
|
|
3193
3214
|
els.libList.innerHTML = "";
|
|
3194
|
-
if (
|
|
3215
|
+
if (dir === "sfx") {
|
|
3216
|
+
// online sound effects (Openverse) first, then the library's own files
|
|
3217
|
+
appendOnlineSearch("sfx", focus);
|
|
3218
|
+
const head = document.createElement("div");
|
|
3219
|
+
head.className = "music-status lib-head";
|
|
3220
|
+
head.textContent = files.length ? `Your library — library/sfx (${files.length})` : "Your library — drop files into library/sfx/ to keep them here.";
|
|
3221
|
+
els.libList.appendChild(head);
|
|
3222
|
+
} else if (!files.length) {
|
|
3195
3223
|
els.libList.innerHTML = `<div class="bin-empty">
|
|
3196
3224
|
<div class="bin-empty-icon">${dir === "sfx" ? "🔊" : dir === "svg" ? "✨" : "🧩"}</div>
|
|
3197
3225
|
<p>No assets yet.</p>
|
|
@@ -3232,19 +3260,308 @@ function renderLibrary() {
|
|
|
3232
3260
|
els.libList.appendChild(item);
|
|
3233
3261
|
}
|
|
3234
3262
|
}
|
|
3263
|
+
/* The bin's tabs: Project, Audio (Music, SFX) and Graphics (Elements, SVG,
|
|
3264
|
+
Shapes, Templates); a group shows its own row of tabs and reopens the one
|
|
3265
|
+
last used in it. */
|
|
3266
|
+
const binGroupTab = { audio: "music", graphics: "elements" };
|
|
3235
3267
|
function setBinTab(tab) {
|
|
3268
|
+
if (tab !== state.binTab) musicPreviewStop();
|
|
3236
3269
|
state.binTab = tab;
|
|
3237
|
-
|
|
3238
|
-
|
|
3270
|
+
const sub = els.binSubTabs && els.binSubTabs.querySelector(`[data-tab="${tab}"]`);
|
|
3271
|
+
const group = sub ? sub.dataset.group : null;
|
|
3272
|
+
if (group) binGroupTab[group] = tab;
|
|
3273
|
+
for (const b of els.binTabs.querySelectorAll("[data-tab], [data-group]"))
|
|
3274
|
+
b.classList.toggle("on", b.dataset.tab ? b.dataset.tab === tab : b.dataset.group === group);
|
|
3275
|
+
if (els.binSubTabs) {
|
|
3276
|
+
els.binSubTabs.classList.toggle("hidden", !group);
|
|
3277
|
+
for (const b of els.binSubTabs.querySelectorAll("[data-tab]")) {
|
|
3278
|
+
b.classList.toggle("hidden", b.dataset.group !== group);
|
|
3279
|
+
b.classList.toggle("on", b.dataset.tab === tab);
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3239
3282
|
const isProj = tab === "project";
|
|
3240
3283
|
els.binList.classList.toggle("hidden", !isProj);
|
|
3241
3284
|
els.libList.classList.toggle("hidden", isProj);
|
|
3242
3285
|
if (els.binTools) els.binTools.classList.toggle("hidden", !isProj);
|
|
3243
3286
|
if (tab === "shapes") renderShapesTab();
|
|
3287
|
+
else if (tab === "music") renderMusicTab();
|
|
3244
3288
|
else if (tab === "templates") { renderTemplatesTab(); fetchSaved("templates").then(() => { if (state.binTab === "templates") renderTemplatesTab(); }); }
|
|
3245
3289
|
else if (!isProj) fetchLibrary(tab).then(renderLibrary);
|
|
3246
3290
|
}
|
|
3247
3291
|
|
|
3292
|
+
/* ═══════════════════════════ MUSIC (Openverse) ═══════════════════════════ */
|
|
3293
|
+
/* Online search in two bin tabs: Music (openly licensed music) and SFX (sound
|
|
3294
|
+
effects from Freesound, above the library/sfx files). Both come from
|
|
3295
|
+
Openverse (music.js builds the search and reads the licences). The browser
|
|
3296
|
+
asks Openverse directly; importing downloads the file through
|
|
3297
|
+
/api/import-url, and the media entry keeps the track's licence (m.license)
|
|
3298
|
+
for the credits. */
|
|
3299
|
+
const onlineSearch = {
|
|
3300
|
+
music: { query: "", length: "", commercial: false, tracks: [], page: 0, pages: 0, count: 0, busy: false, error: "", seq: 0 },
|
|
3301
|
+
sfx: { query: "", length: "", commercial: false, tracks: [], page: 0, pages: 0, count: 0, busy: false, error: "", seq: 0 },
|
|
3302
|
+
};
|
|
3303
|
+
const musicImporting = new Set();
|
|
3304
|
+
let musicPreview = null; // {id, audio}
|
|
3305
|
+
function musicPreviewStop() {
|
|
3306
|
+
if (musicPreview) { musicPreview.audio.pause(); musicPreview = null; }
|
|
3307
|
+
}
|
|
3308
|
+
/** Redraw whichever tab shows that search (the SFX tab also lists the library). */
|
|
3309
|
+
function renderOnlineTab(kind) {
|
|
3310
|
+
if (state.binTab !== kind) return;
|
|
3311
|
+
if (kind === "sfx") renderLibrary(); else renderMusicTab();
|
|
3312
|
+
}
|
|
3313
|
+
async function musicSearch(kind, more) {
|
|
3314
|
+
const s = onlineSearch[kind];
|
|
3315
|
+
const seq = ++s.seq;
|
|
3316
|
+
const page = more ? s.page + 1 : 1;
|
|
3317
|
+
s.busy = true; s.error = "";
|
|
3318
|
+
if (!more) { s.tracks = []; s.page = 0; musicPreviewStop(); }
|
|
3319
|
+
renderOnlineTab(kind);
|
|
3320
|
+
try {
|
|
3321
|
+
const res = await fetch(FableCutMusic.searchUrl({ query: s.query, kind, length: s.length, commercial: s.commercial, edits: s.commercial, page }),
|
|
3322
|
+
{ headers: { Accept: "application/json" } });
|
|
3323
|
+
const body = await res.json().catch(() => null);
|
|
3324
|
+
if (seq !== s.seq) return;
|
|
3325
|
+
if (res.status === 429) throw new Error("Openverse's limit for searches is used up for now — try again in a while");
|
|
3326
|
+
if (!res.ok) throw new Error("Openverse answered " + res.status + (body && body.detail ? ": " + body.detail : ""));
|
|
3327
|
+
const r = FableCutMusic.results(body, page);
|
|
3328
|
+
s.tracks = more ? s.tracks.concat(r.tracks) : r.tracks;
|
|
3329
|
+
s.page = page; s.pages = r.pages; s.count = r.count;
|
|
3330
|
+
} catch (e) {
|
|
3331
|
+
if (seq !== s.seq) return;
|
|
3332
|
+
s.error = e instanceof TypeError ? "Couldn't reach Openverse — are you online?" : e.message;
|
|
3333
|
+
}
|
|
3334
|
+
s.busy = false;
|
|
3335
|
+
renderOnlineTab(kind);
|
|
3336
|
+
}
|
|
3337
|
+
function musicTogglePreview(t, btn) {
|
|
3338
|
+
if (musicPreview && musicPreview.id === t.id) {
|
|
3339
|
+
musicPreviewStop(); btn.textContent = "▶"; return;
|
|
3340
|
+
}
|
|
3341
|
+
musicPreviewStop();
|
|
3342
|
+
if (runtime.sfxPreview) runtime.sfxPreview.pause();
|
|
3343
|
+
els.libList.querySelectorAll(".music-play, .lib-play").forEach((b) => (b.textContent = "▶"));
|
|
3344
|
+
const a = new Audio(t.url);
|
|
3345
|
+
// the list may have been redrawn since: reset whichever ▶ buttons are on screen now
|
|
3346
|
+
const done = () => {
|
|
3347
|
+
if (!musicPreview || musicPreview.audio !== a) return; // stopped or replaced meanwhile
|
|
3348
|
+
musicPreview = null;
|
|
3349
|
+
els.libList.querySelectorAll(".music-play").forEach((b) => (b.textContent = "▶"));
|
|
3350
|
+
};
|
|
3351
|
+
a.onended = done;
|
|
3352
|
+
a.play().catch((e) => {
|
|
3353
|
+
if (!musicPreview || musicPreview.audio !== a || (e && e.name === "AbortError")) return;
|
|
3354
|
+
done();
|
|
3355
|
+
toast("Couldn't play " + t.title);
|
|
3356
|
+
});
|
|
3357
|
+
btn.textContent = "⏸";
|
|
3358
|
+
musicPreview = { id: t.id, audio: a };
|
|
3359
|
+
}
|
|
3360
|
+
/** Download a track into media/ and register it with its licence; place = add at the playhead too. */
|
|
3361
|
+
/** Put an imported track at `at` (the timeline and playhead of the click) → "" when placed,
|
|
3362
|
+
* else why not. Never on another timeline, during an export, without a known length or on a locked track. */
|
|
3363
|
+
function placeImported(m, at) {
|
|
3364
|
+
if (!(m.duration > 0 && isFinite(m.duration))) return "its length couldn't be read, so it's in the Project bin but not on the timeline";
|
|
3365
|
+
if ((project.sequence || null) !== at.seq || compCtxId() !== at.comp) return "another timeline is open now, so it's in the Project bin but not placed";
|
|
3366
|
+
if (exportBusy()) return "an export is running, so it's in the Project bin but not placed";
|
|
3367
|
+
const lane = TRACKS.find((t) => t.kind === "audio"); // the top audio track there is (A1 may have been removed)
|
|
3368
|
+
if (!lane) return "there's no audio track, so it's in the Project bin but not placed";
|
|
3369
|
+
if (!addClipFromMedia(m, lane.id, at.t)) return "it's in the Project bin, but " + lane.id + " is locked, so it wasn't placed";
|
|
3370
|
+
return "";
|
|
3371
|
+
}
|
|
3372
|
+
async function musicImport(t, place, kind) {
|
|
3373
|
+
if (!state.connected) { toast("Importing needs the editor server"); return; }
|
|
3374
|
+
if (musicImporting.has(t.id)) return;
|
|
3375
|
+
// + places it where the user clicked: that timeline (sequence / comp) and playhead
|
|
3376
|
+
const at = { seq: project.sequence || null, comp: compCtxId(), t: state.time };
|
|
3377
|
+
const have = project.media.find((m) => m.license && m.license.openverse === t.id);
|
|
3378
|
+
if (have) {
|
|
3379
|
+
const why = place ? placeImported(have, at) : "";
|
|
3380
|
+
toast(`“${have.name}” is already in the project` + (why ? " — " + why : ""));
|
|
3381
|
+
return;
|
|
3382
|
+
}
|
|
3383
|
+
musicImporting.add(t.id);
|
|
3384
|
+
renderOnlineTab(kind);
|
|
3385
|
+
const gen = runtime.projectGen;
|
|
3386
|
+
try {
|
|
3387
|
+
const res = await fetch("/api/import-url", {
|
|
3388
|
+
method: "POST", headers: { "Content-Type": "application/json" },
|
|
3389
|
+
body: JSON.stringify({ url: t.url, name: FableCutMusic.fileName(t) }),
|
|
3390
|
+
});
|
|
3391
|
+
const body = await res.json().catch(() => ({}));
|
|
3392
|
+
if (!res.ok) throw new Error(body.error || "import failed (" + res.status + ")");
|
|
3393
|
+
const fileKind = libKind(body.name);
|
|
3394
|
+
if (fileKind !== "audio" && fileKind !== "video") throw new Error("the file isn't audio: " + (body.name || ""));
|
|
3395
|
+
// always an audio entry, even in a video container: a music track goes on an A track, with no linked stems
|
|
3396
|
+
const m = { id: "m_" + uid(), name: `${t.title} — ${t.creator}`, kind: "audio", src: body.src, folderId: null,
|
|
3397
|
+
license: FableCutMusic.mediaLicense(t) };
|
|
3398
|
+
try { await loadMediaMetadata(m); ensureWave(m); } catch { /* probeMissingMeta retries */ }
|
|
3399
|
+
if (gen !== runtime.projectGen) throw new Error("another project was opened — the file is in media/");
|
|
3400
|
+
project.media.push(m);
|
|
3401
|
+
renderBin(); scheduleSave();
|
|
3402
|
+
const what = `Imported “${t.title}” — ${t.license.label}: ${t.flags.join(", ")}`;
|
|
3403
|
+
const limit = FableCutMusic.warnings(t.license).find((w) => /derivatives|sampled/.test(w));
|
|
3404
|
+
const unplaced = place ? placeImported(m, at) : "";
|
|
3405
|
+
toast(what + (unplaced ? " — " + unplaced : "") + (limit ? " ⚠ " + limit : ""));
|
|
3406
|
+
} catch (e) {
|
|
3407
|
+
toast(e && e.message ? e.message : "Couldn't import it");
|
|
3408
|
+
} finally {
|
|
3409
|
+
musicImporting.delete(t.id);
|
|
3410
|
+
renderOnlineTab(kind);
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
function copyCredits(lines) {
|
|
3414
|
+
const refused = () => toast("Couldn't copy — select the credit text and copy it yourself");
|
|
3415
|
+
try {
|
|
3416
|
+
navigator.clipboard.writeText(lines.join("\n")).then(() => toast(lines.length === 1 ? "Copied the credit" : `Copied ${lines.length} credits`), refused);
|
|
3417
|
+
} catch { refused(); } // no clipboard access (an insecure page, an old browser)
|
|
3418
|
+
}
|
|
3419
|
+
/** The Export dialog's note: the licensed music the edit uses, its credits and any licence warnings. */
|
|
3420
|
+
function syncExportCredits() {
|
|
3421
|
+
const box = $("exportCredits");
|
|
3422
|
+
if (!box) return;
|
|
3423
|
+
// the edit being exported: the open sequence and the comps it places, not other sequences
|
|
3424
|
+
const list = FableCutMusic.credits(project, FableCutMusic.editUsage(project));
|
|
3425
|
+
box.classList.toggle("hidden", !list.length);
|
|
3426
|
+
box.innerHTML = "";
|
|
3427
|
+
if (!list.length) return;
|
|
3428
|
+
const head = document.createElement("div");
|
|
3429
|
+
head.className = "export-credits-head";
|
|
3430
|
+
head.innerHTML = `<b>Music credits</b> — put these in the video's description <button type="button" class="btn tiny">Copy</button>`;
|
|
3431
|
+
head.querySelector("button").addEventListener("click", () => copyCredits(list.map((c) => c.line)));
|
|
3432
|
+
box.appendChild(head);
|
|
3433
|
+
for (const c of list) {
|
|
3434
|
+
const p = document.createElement("div");
|
|
3435
|
+
p.className = "export-credit";
|
|
3436
|
+
p.textContent = c.line + (c.needsCredit ? "" : " (no credit required)");
|
|
3437
|
+
box.appendChild(p);
|
|
3438
|
+
for (const w of c.warnings) {
|
|
3439
|
+
const q = document.createElement("div");
|
|
3440
|
+
q.className = "export-credit warn";
|
|
3441
|
+
q.textContent = "⚠ " + w;
|
|
3442
|
+
box.appendChild(q);
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
/** The online search (box, filters, chips, results) for one kind, appended to the bin's list. */
|
|
3447
|
+
/** The online search box's focus and selection, read before the list is cleared. */
|
|
3448
|
+
function searchFocus() {
|
|
3449
|
+
const a = document.activeElement;
|
|
3450
|
+
return a && (a.id === "musicQuery" || a.id === "sfxQuery") ? { start: a.selectionStart, end: a.selectionEnd } : null;
|
|
3451
|
+
}
|
|
3452
|
+
function appendOnlineSearch(kind, focus) {
|
|
3453
|
+
const s = onlineSearch[kind], list = els.libList, sfx = kind === "sfx";
|
|
3454
|
+
const qid = sfx ? "sfxQuery" : "musicQuery";
|
|
3455
|
+
const form = document.createElement("form");
|
|
3456
|
+
form.className = "music-search";
|
|
3457
|
+
form.innerHTML = `
|
|
3458
|
+
<input type="search" id="${qid}" placeholder="${sfx ? "Search sound effects online — whoosh, impact…" : "Mood, genre, instrument…"}" aria-label="${sfx ? "Search sound effects" : "Search music"}" spellcheck="false" autocomplete="off">
|
|
3459
|
+
<div class="music-filters">
|
|
3460
|
+
${sfx ? "" : `<select data-f="length" aria-label="Length"><option value="">Any length</option>${Object.entries(FableCutMusic.LENGTHS).map(([k, v]) => `<option value="${k}">${escapeHtml(v)}</option>`).join("")}</select>`}
|
|
3461
|
+
<label class="music-commercial" title="Only licences that allow commercial use (ads, sponsored or monetized videos) and edits"><input type="checkbox" data-f="commercial"> OK to monetize</label>
|
|
3462
|
+
</div>`;
|
|
3463
|
+
const q = form.querySelector("input[type=search]");
|
|
3464
|
+
q.value = s.draft != null ? s.draft : s.query; // what the user is typing survives a redraw
|
|
3465
|
+
q.addEventListener("input", () => { s.draft = q.value; });
|
|
3466
|
+
const len = form.querySelector('[data-f="length"]');
|
|
3467
|
+
if (len) len.value = s.length;
|
|
3468
|
+
form.querySelector('[data-f="commercial"]').checked = s.commercial;
|
|
3469
|
+
form.addEventListener("submit", (e) => { e.preventDefault(); s.query = q.value.trim(); s.draft = null; musicSearch(kind, false); });
|
|
3470
|
+
form.addEventListener("change", (e) => {
|
|
3471
|
+
const f = e.target.dataset.f;
|
|
3472
|
+
if (f === "length") s.length = e.target.value;
|
|
3473
|
+
else if (f === "commercial") s.commercial = e.target.checked;
|
|
3474
|
+
else return;
|
|
3475
|
+
s.query = q.value.trim(); s.draft = null;
|
|
3476
|
+
musicSearch(kind, false);
|
|
3477
|
+
});
|
|
3478
|
+
list.appendChild(form);
|
|
3479
|
+
if (focus) { q.focus(); try { q.setSelectionRange(focus.start ?? q.value.length, focus.end ?? q.value.length); } catch { } }
|
|
3480
|
+
|
|
3481
|
+
if (!s.tracks.length && !s.busy) {
|
|
3482
|
+
const moods = document.createElement("div");
|
|
3483
|
+
moods.className = "music-moods";
|
|
3484
|
+
for (const w of sfx ? FableCutMusic.SFX_WORDS : FableCutMusic.MOODS) {
|
|
3485
|
+
const b = document.createElement("button");
|
|
3486
|
+
b.type = "button"; b.className = "bin-tag chip"; b.textContent = w;
|
|
3487
|
+
b.addEventListener("click", () => { s.query = w; s.draft = null; musicSearch(kind, false); });
|
|
3488
|
+
moods.appendChild(b);
|
|
3489
|
+
}
|
|
3490
|
+
list.appendChild(moods);
|
|
3491
|
+
}
|
|
3492
|
+
const status = (text, cls) => {
|
|
3493
|
+
const p = document.createElement("div");
|
|
3494
|
+
p.className = "music-status" + (cls ? " " + cls : "");
|
|
3495
|
+
p.textContent = text;
|
|
3496
|
+
list.appendChild(p);
|
|
3497
|
+
};
|
|
3498
|
+
if (s.error) status(s.error, "err");
|
|
3499
|
+
else if (!s.busy && s.page && !s.tracks.length) status("Nothing found — try other words" + (sfx ? "." : " or another length."));
|
|
3500
|
+
else if (s.page) status(`${s.count >= 240 ? "240+" : s.count} result${s.count === 1 ? "" : "s"}${s.query ? ` for “${s.query}”` : " — newest first"}`);
|
|
3501
|
+
else if (!s.busy && !sfx) status("Search openly licensed music, or pick a mood. Every track shows its licence.");
|
|
3502
|
+
|
|
3503
|
+
for (const t of s.tracks) {
|
|
3504
|
+
const item = document.createElement("div");
|
|
3505
|
+
item.className = "bin-item lib-item music-item";
|
|
3506
|
+
const busy = musicImporting.has(t.id);
|
|
3507
|
+
item.innerHTML = `
|
|
3508
|
+
<button type="button" class="btn tiny music-play" title="Preview">${musicPreview && musicPreview.id === t.id ? "⏸" : "▶"}</button>
|
|
3509
|
+
<div class="bin-meta">
|
|
3510
|
+
<div class="bin-name"></div>
|
|
3511
|
+
<div class="bin-sub"></div>
|
|
3512
|
+
<div class="music-lic"></div>
|
|
3513
|
+
</div>
|
|
3514
|
+
<button type="button" class="btn tiny music-get" title="Import into the Project bin"${busy ? " disabled" : ""}>${busy ? "…" : "⬇"}</button>
|
|
3515
|
+
<button type="button" class="btn tiny accent lib-add" title="Import and add at the playhead"${busy ? " disabled" : ""}>+</button>`;
|
|
3516
|
+
item.querySelector(".bin-name").textContent = t.title;
|
|
3517
|
+
item.querySelector(".bin-name").title = t.title + (t.tags.length ? "\n#" + t.tags.join(" #") : "");
|
|
3518
|
+
item.querySelector(".bin-sub").textContent = [t.creator, t.duration != null ? FableCutMusic.fmtLen(t.duration) : "", t.genres.join("/"), t.source].filter(Boolean).join(" · ");
|
|
3519
|
+
const lic = item.querySelector(".music-lic");
|
|
3520
|
+
const badge = document.createElement(t.license.url ? "a" : "span");
|
|
3521
|
+
badge.className = "music-badge" + (!t.license.edits ? " no" : !t.license.commercial ? " nc" : !t.license.credit ? " free" : "");
|
|
3522
|
+
badge.textContent = t.license.label;
|
|
3523
|
+
badge.title = t.license.note;
|
|
3524
|
+
if (t.license.url) { badge.href = t.license.url; badge.target = "_blank"; badge.rel = "noopener"; }
|
|
3525
|
+
lic.appendChild(badge);
|
|
3526
|
+
const fl = document.createElement("span");
|
|
3527
|
+
fl.className = "music-flags";
|
|
3528
|
+
fl.textContent = t.flags.join(" · ");
|
|
3529
|
+
fl.title = t.license.note;
|
|
3530
|
+
lic.appendChild(fl);
|
|
3531
|
+
if (t.page) {
|
|
3532
|
+
const a = document.createElement("a");
|
|
3533
|
+
a.className = "music-page"; a.href = t.page; a.target = "_blank"; a.rel = "noopener"; a.textContent = "page ↗";
|
|
3534
|
+
a.title = "Its page at " + (t.source || "its source");
|
|
3535
|
+
lic.appendChild(a);
|
|
3536
|
+
}
|
|
3537
|
+
const play = item.querySelector(".music-play");
|
|
3538
|
+
play.addEventListener("click", () => musicTogglePreview(t, play));
|
|
3539
|
+
item.querySelector(".music-get").addEventListener("click", () => musicImport(t, false, kind));
|
|
3540
|
+
item.querySelector(".lib-add").addEventListener("click", () => musicImport(t, true, kind));
|
|
3541
|
+
item.addEventListener("dblclick", (e) => { if (!e.target.closest("button, a")) musicImport(t, true, kind); });
|
|
3542
|
+
list.appendChild(item);
|
|
3543
|
+
}
|
|
3544
|
+
if (s.busy) status("Searching…");
|
|
3545
|
+
else if (s.page && s.page < s.pages) {
|
|
3546
|
+
const more = document.createElement("button");
|
|
3547
|
+
more.type = "button"; more.className = "btn tiny music-more"; more.textContent = "More results";
|
|
3548
|
+
more.addEventListener("click", () => musicSearch(kind, true));
|
|
3549
|
+
list.appendChild(more);
|
|
3550
|
+
}
|
|
3551
|
+
if (s.page || !sfx) {
|
|
3552
|
+
const about = document.createElement("p");
|
|
3553
|
+
about.className = "music-about";
|
|
3554
|
+
about.innerHTML = `Made with <a href="https://openverse.org" target="_blank" rel="noopener">Openverse</a>, not endorsed or certified by it. Licences are the artists' — check one before you publish, and credit where it says so (the Export dialog lists the credits).`;
|
|
3555
|
+
list.appendChild(about);
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
function renderMusicTab() {
|
|
3559
|
+
if (state.binTab !== "music") return;
|
|
3560
|
+
const focus = searchFocus();
|
|
3561
|
+
els.libList.innerHTML = "";
|
|
3562
|
+
appendOnlineSearch("music", focus);
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3248
3565
|
/* ═══════════════════════════ PROJECTS (dashboard) ═══════════════════════════ */
|
|
3249
3566
|
/* Several projects in one data folder (projects.js on the server). The open one
|
|
3250
3567
|
is always ./project.json, so everything else in the editor is unchanged; the
|
|
@@ -6892,6 +7209,7 @@ function renderInspector(lite) {
|
|
|
6892
7209
|
${row("Stroke col.", `<input type="color" data-k="strokeColor" value="${p.strokeColor}">`, "", "strokeColor")}
|
|
6893
7210
|
${row("Bg color", `<input type="color" data-k="bgColor" value="${p.bgColor}">`, "", "bgColor")}
|
|
6894
7211
|
${slider("bgOpacity", 0, 1, 0.05, p.bgOpacity)}
|
|
7212
|
+
${sel("Bg shape", "bgShape", ["lines", "box"], p.bgShape === "box" ? "box" : "lines")}
|
|
6895
7213
|
${slider("textShadow", 0, 40, 1, p.textShadow)}
|
|
6896
7214
|
${slider("glow", 0, 100, 1, p.glow)}
|
|
6897
7215
|
${row("Glow color", `<input type="color" data-k="glowColor" value="${p.glowColor || p.color}">
|
|
@@ -8249,6 +8567,12 @@ function loadFxWorklet(ctx) {
|
|
|
8249
8567
|
return p;
|
|
8250
8568
|
}
|
|
8251
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
|
+
}
|
|
8252
8576
|
function normFx(list) {
|
|
8253
8577
|
if (!Array.isArray(list) || !list.length) return undefined;
|
|
8254
8578
|
const out = typeof FableCutFx !== "undefined" ? FableCutFx.normalizeFx(list) : list;
|
|
@@ -8738,6 +9062,8 @@ async function denoiseClips(clips, level) {
|
|
|
8738
9062
|
toast(`Reducing noise (${level})…`);
|
|
8739
9063
|
for (const id of bases) {
|
|
8740
9064
|
const base = getMedia(id);
|
|
9065
|
+
// the licence of the file being cleaned, read now: the entry may point at another file by the time it's done
|
|
9066
|
+
const lic = base && base.license ? { ...base.license } : null; // base: gone if removed meanwhile (caught below)
|
|
8741
9067
|
try {
|
|
8742
9068
|
const r = await fetch("/api/denoise", { method: "POST", body: JSON.stringify({ src: base.src, amount: level }) })
|
|
8743
9069
|
.then(async (x) => { const j = await x.json(); if (!x.ok) throw new Error(j.error || x.status); return j; });
|
|
@@ -8745,9 +9071,10 @@ async function denoiseClips(clips, level) {
|
|
|
8745
9071
|
if (!m) {
|
|
8746
9072
|
m = { id: "m_" + uid(), name: r.name, kind: "audio", src: r.src, duration: r.duration, folderId: base.folderId || null,
|
|
8747
9073
|
derivedFrom: base.id, denoise: level };
|
|
9074
|
+
if (lic) m.license = lic; // the credit stays with the sound
|
|
8748
9075
|
if (r.channels) m.channels = r.channels;
|
|
8749
9076
|
project.media.push(m);
|
|
8750
|
-
}
|
|
9077
|
+
} else if (lic && !m.license) m.license = lic; // a copy made before the file had a licence
|
|
8751
9078
|
swap.set(id, m.id);
|
|
8752
9079
|
} catch (err) {
|
|
8753
9080
|
toast(`Noise reduction failed: ${err.message || err}`);
|
|
@@ -15653,18 +15980,38 @@ function drawText(c, p, local) {
|
|
|
15653
15980
|
}
|
|
15654
15981
|
const shadowBlur = (p.textShadow === 0 ? 0 : (+p.textShadow || 12)) * size / 100;
|
|
15655
15982
|
|
|
15656
|
-
// background
|
|
15983
|
+
// text background (static — anchors the animated words)
|
|
15657
15984
|
if (p.bgOpacity > 0) {
|
|
15658
15985
|
ctx2d.fillStyle = hexToRgba(p.bgColor || "#000", clamp(p.bgOpacity, 0, 1));
|
|
15659
15986
|
const padX = size * 0.4, padY = size * 0.18, r = size * 0.28;
|
|
15660
|
-
|
|
15661
|
-
|
|
15662
|
-
|
|
15663
|
-
|
|
15664
|
-
ctx2d.
|
|
15665
|
-
ctx2d.roundRect(
|
|
15666
|
-
|
|
15667
|
-
|
|
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();
|
|
15668
16015
|
}
|
|
15669
16016
|
|
|
15670
16017
|
const fillFor = (y) => {
|
|
@@ -16683,6 +17030,7 @@ async function openExportSetup() {
|
|
|
16683
17030
|
`${offUsed.length === 1 ? `“${offUsed[0].name}” is` : offUsed.length + " files are"} offline and will export as “Media offline” — relink first (right-click in the bin → Relink…).`;
|
|
16684
17031
|
warn.classList.remove("hidden");
|
|
16685
17032
|
}
|
|
17033
|
+
syncExportCredits();
|
|
16686
17034
|
fillExportRangeSelect();
|
|
16687
17035
|
syncExportRangeUi();
|
|
16688
17036
|
syncExportProfileVisibility();
|
|
@@ -16739,6 +17087,7 @@ async function openExportSetup() {
|
|
|
16739
17087
|
toast(exportRange(outFps).frames < 1 ? "The export range is empty — pick one"
|
|
16740
17088
|
: !choiceOk ? "The last export's preset isn't there any more — pick one" : "The last export's engine isn't available — pick one");
|
|
16741
17089
|
}
|
|
17090
|
+
syncExportCredits(); // the timeline may have changed while its settings loaded
|
|
16742
17091
|
els.exportSetup.classList.remove("hidden");
|
|
16743
17092
|
// aria-modal hides what is behind — focus has to come inside
|
|
16744
17093
|
if (!els.exportSetup.contains(document.activeElement)) $("exportRangeSel")?.focus();
|
|
@@ -16874,6 +17223,7 @@ function snapshotExportFrame() {
|
|
|
16874
17223
|
} catch (e) { throw canvasTaintError(e); }
|
|
16875
17224
|
}
|
|
16876
17225
|
const JPEG_WORKER_SRC = `"use strict";
|
|
17226
|
+
self.postMessage({ ready: true });
|
|
16877
17227
|
self.onmessage = async (e) => {
|
|
16878
17228
|
const { id, bmp, quality, type } = e.data;
|
|
16879
17229
|
try {
|
|
@@ -16890,46 +17240,63 @@ self.onmessage = async (e) => {
|
|
|
16890
17240
|
}
|
|
16891
17241
|
};
|
|
16892
17242
|
`;
|
|
16893
|
-
|
|
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 } = {}) {
|
|
16894
17252
|
if (typeof Worker !== "function" || typeof OffscreenCanvas !== "function") return null;
|
|
16895
17253
|
let url;
|
|
16896
17254
|
try { url = URL.createObjectURL(new Blob([JPEG_WORKER_SRC], { type: "text/javascript" })); }
|
|
16897
17255
|
catch { return null; }
|
|
16898
|
-
const
|
|
17256
|
+
const pool = [];
|
|
16899
17257
|
try {
|
|
16900
|
-
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() });
|
|
16901
17259
|
} catch {
|
|
16902
|
-
for (const
|
|
17260
|
+
for (const x of pool) try { x.w.terminate(); } catch { }
|
|
16903
17261
|
URL.revokeObjectURL(url);
|
|
16904
17262
|
return null;
|
|
16905
17263
|
}
|
|
16906
17264
|
URL.revokeObjectURL(url);
|
|
16907
|
-
const pending = new Map();
|
|
16908
17265
|
let nextId = 0, rr = 0;
|
|
16909
|
-
|
|
16910
|
-
|
|
16911
|
-
|
|
16912
|
-
|
|
16913
|
-
|
|
16914
|
-
|
|
16915
|
-
|
|
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);
|
|
16916
17283
|
};
|
|
16917
|
-
w.onerror = () =>
|
|
17284
|
+
x.w.onerror = (e) => drop(x, "a frame encoder stopped" + (e && e.message ? ": " + e.message : ""));
|
|
16918
17285
|
}
|
|
16919
17286
|
return {
|
|
16920
17287
|
encode(bmp, quality, type) {
|
|
16921
|
-
const
|
|
16922
|
-
|
|
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++;
|
|
16923
17291
|
return new Promise((resolve, reject) => {
|
|
16924
|
-
|
|
16925
|
-
|
|
16926
|
-
|
|
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); }
|
|
16927
17296
|
});
|
|
16928
17297
|
},
|
|
16929
17298
|
terminate() {
|
|
16930
|
-
for (const
|
|
16931
|
-
pending.clear();
|
|
16932
|
-
for (const w of workers) try { w.terminate(); } catch { }
|
|
17299
|
+
for (const x of pool) drop(x, "cancelled");
|
|
16933
17300
|
},
|
|
16934
17301
|
};
|
|
16935
17302
|
}
|
|
@@ -17036,11 +17403,43 @@ function postFrames(url, body, signal) {
|
|
|
17036
17403
|
xhr.send(body);
|
|
17037
17404
|
});
|
|
17038
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
|
+
}
|
|
17039
17437
|
/* Sequential /frame POSTs, batched. Concurrent bodies can still race on ffmpeg
|
|
17040
17438
|
stdin if they complete out of order, so the client starts each fetch only
|
|
17041
17439
|
after the previous one settles; rendering runs ahead under backpressure.
|
|
17042
|
-
JPEG Fast and WebCodecs Annex-B both concatenate on this path.
|
|
17043
|
-
|
|
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 }) {
|
|
17044
17443
|
let batch = [];
|
|
17045
17444
|
let packed = 0;
|
|
17046
17445
|
let sentFirst = false;
|
|
@@ -17064,6 +17463,7 @@ function createExportUploader(sessId, { batchItems, batchBytes, signal, getError
|
|
|
17064
17463
|
const err = getError();
|
|
17065
17464
|
if (err) throw err;
|
|
17066
17465
|
await postFrames("/api/export/frame?id=" + sessId, body, signal);
|
|
17466
|
+
if (onSent) onSent();
|
|
17067
17467
|
});
|
|
17068
17468
|
uploadTail = p.catch((err) => {
|
|
17069
17469
|
if (!getError()) setError(err);
|
|
@@ -17210,25 +17610,44 @@ function sameSourceFrame(el, mt, shown) {
|
|
|
17210
17610
|
return el.readyState >= 2 && !el.seeking && Math.abs(el.currentTime - mt) < 0.002 &&
|
|
17211
17611
|
mt >= shown - 1e-4 && mt < shown + dur - 1e-4;
|
|
17212
17612
|
}
|
|
17213
|
-
|
|
17613
|
+
/** A hidden tab renders nothing, so it presents no frames and runs no frame callbacks. */
|
|
17614
|
+
function tabHidden() { return typeof document !== "undefined" && document.hidden === true; }
|
|
17615
|
+
/** The running export's cancel signal, if any. */
|
|
17616
|
+
function exportSignal() { return typeof exportAbort !== "undefined" && exportAbort ? exportAbort.signal : null; }
|
|
17617
|
+
function hardSeekVideo(el, mt, attempt = 0, shown = el._fcPresentedTime, signal = exportSignal()) {
|
|
17214
17618
|
const hasRvfc = typeof el.requestVideoFrameCallback === "function";
|
|
17215
17619
|
const maxAttempts = 3;
|
|
17620
|
+
// an export's Cancel stops a seek that is still waiting (a hidden tab waits up to 10 s);
|
|
17621
|
+
// retries keep the signal of the export that started them, even once it is cleared
|
|
17622
|
+
if (signal && signal.aborted) return Promise.reject(new Error("cancelled"));
|
|
17216
17623
|
return new Promise((res, rej) => {
|
|
17217
17624
|
// a busy frame (grades, masks, blur) can present late: each retry waits longer
|
|
17218
|
-
const after = () =>
|
|
17219
|
-
.
|
|
17220
|
-
|
|
17221
|
-
|
|
17222
|
-
|
|
17223
|
-
|
|
17224
|
-
|
|
17225
|
-
|
|
17226
|
-
|
|
17227
|
-
|
|
17228
|
-
|
|
17229
|
-
|
|
17230
|
-
|
|
17231
|
-
|
|
17625
|
+
const after = () => {
|
|
17626
|
+
if (signal && signal.aborted) { rej(new Error("cancelled")); return; }
|
|
17627
|
+
// a hidden tab renders nothing, so no frame callback comes: a seek that finished on mt
|
|
17628
|
+
// is the signal. It is no presented frame, so it teaches nothing about frame durations.
|
|
17629
|
+
if (tabHidden() && el.readyState >= 2 && !el.seeking && Math.abs(el.currentTime - mt) < 0.002) {
|
|
17630
|
+
el._fcPresentedTime = el.currentTime;
|
|
17631
|
+
el._fcLastShown = null;
|
|
17632
|
+
res();
|
|
17633
|
+
return;
|
|
17634
|
+
}
|
|
17635
|
+
waitForPresentedFrame(el, [80, 250, 600][attempt] || 600)
|
|
17636
|
+
.then(res)
|
|
17637
|
+
.catch((err) => {
|
|
17638
|
+
// Slow motion lands several output frames on one source frame: seeking within the
|
|
17639
|
+
// frame already on screen presents nothing new, so no frame callback ever comes.
|
|
17640
|
+
// The seek finished on mt and the frame shown just before is within one source frame
|
|
17641
|
+
// of it (≥ 20 fps footage): that frame is the right picture.
|
|
17642
|
+
if (sameSourceFrame(el, mt, shown)) { notePresented(el, shown); res(); return; }
|
|
17643
|
+
if (signal && signal.aborted) { rej(new Error("cancelled")); return; }
|
|
17644
|
+
if (attempt + 1 < maxAttempts) { hardSeekVideo(el, mt, attempt + 1, shown, signal).then(res, rej); return; }
|
|
17645
|
+
// Last try: the seek finished on mt with the frame's data loaded, so the element holds
|
|
17646
|
+
// that frame even though no callback reported it. Better than failing the whole export.
|
|
17647
|
+
if (el.readyState >= 2 && !el.seeking && Math.abs(el.currentTime - mt) < 0.002) { notePresented(el, mt); res(); return; }
|
|
17648
|
+
rej(err);
|
|
17649
|
+
});
|
|
17650
|
+
};
|
|
17232
17651
|
if (presentedClose(el, mt, 0.002) && el.readyState >= 2) {
|
|
17233
17652
|
res();
|
|
17234
17653
|
return;
|
|
@@ -17244,10 +17663,14 @@ function hardSeekVideo(el, mt, attempt = 0, shown = el._fcPresentedTime) {
|
|
|
17244
17663
|
const done = () => {
|
|
17245
17664
|
clearTimeout(tm);
|
|
17246
17665
|
el.removeEventListener("seeked", done);
|
|
17666
|
+
if (signal) signal.removeEventListener("abort", done);
|
|
17247
17667
|
after();
|
|
17248
17668
|
};
|
|
17249
|
-
|
|
17669
|
+
// Chrome slows a hidden tab's decoding: re-seeking on a short timeout would restart a seek
|
|
17670
|
+
// that is still on its way, so wait longer for it there
|
|
17671
|
+
const tm = setTimeout(done, tabHidden() ? 10000 : 1500);
|
|
17250
17672
|
el.addEventListener("seeked", done);
|
|
17673
|
+
if (signal) signal.addEventListener("abort", done);
|
|
17251
17674
|
try {
|
|
17252
17675
|
if (!el.paused) el.pause();
|
|
17253
17676
|
// Same currentTime does not fire seeked — nudge so the decoder must present mt.
|
|
@@ -17260,8 +17683,10 @@ function hardSeekVideo(el, mt, attempt = 0, shown = el._fcPresentedTime) {
|
|
|
17260
17683
|
});
|
|
17261
17684
|
}
|
|
17262
17685
|
/** Play forward until a *presented* frame reaches mt. Pause afterwards unless
|
|
17263
|
-
keepPlaying — a free-running element overruns while JPEG encode/HTTP stalls.
|
|
17264
|
-
|
|
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()) {
|
|
17265
17690
|
return new Promise((res, rej) => {
|
|
17266
17691
|
let settled = false;
|
|
17267
17692
|
let rvfcId = null;
|
|
@@ -17269,6 +17694,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17269
17694
|
if (el._fcPrevMuted == null) el._fcPrevMuted = el.muted;
|
|
17270
17695
|
const wasPlaying = !el.paused;
|
|
17271
17696
|
const slop = Math.min(eps, 0.002);
|
|
17697
|
+
const ended = () => !!(signal && signal.aborted);
|
|
17272
17698
|
const cleanup = () => {
|
|
17273
17699
|
clearTimeout(tm);
|
|
17274
17700
|
if (poll) { clearInterval(poll); poll = null; }
|
|
@@ -17276,10 +17702,14 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17276
17702
|
try { el.cancelVideoFrameCallback(rvfcId); } catch { }
|
|
17277
17703
|
rvfcId = null;
|
|
17278
17704
|
}
|
|
17279
|
-
if (!keepPlaying) {
|
|
17705
|
+
if (!keepPlaying && !ended()) {
|
|
17280
17706
|
try { el.pause(); } catch { }
|
|
17281
17707
|
}
|
|
17282
17708
|
};
|
|
17709
|
+
const reseek = () => {
|
|
17710
|
+
if (ended()) rej(new Error("cancelled"));
|
|
17711
|
+
else hardSeekVideo(el, mt, 0, undefined, signal).then(res, rej);
|
|
17712
|
+
};
|
|
17283
17713
|
const finish = (presented) => {
|
|
17284
17714
|
if (settled) return;
|
|
17285
17715
|
if (!Number.isFinite(presented)) return;
|
|
@@ -17293,7 +17723,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17293
17723
|
const pictureOvershoot = presented > mt;
|
|
17294
17724
|
if (pictureOvershoot
|
|
17295
17725
|
|| (pictureShort && Math.abs(el.currentTime - mt) > Math.max(eps * 2, 0.008)))
|
|
17296
|
-
|
|
17726
|
+
reseek();
|
|
17297
17727
|
else res();
|
|
17298
17728
|
};
|
|
17299
17729
|
if (presentedClose(el, mt, slop) && el.readyState >= 2) {
|
|
@@ -17306,7 +17736,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17306
17736
|
if (settled) return;
|
|
17307
17737
|
settled = true;
|
|
17308
17738
|
cleanup();
|
|
17309
|
-
|
|
17739
|
+
reseek();
|
|
17310
17740
|
}, Math.min(3000, 400 + (remain * 1000) / Math.max(0.1, rate) * 2.5));
|
|
17311
17741
|
const check = (mediaTime) => {
|
|
17312
17742
|
// Presented frame only — currentTime finishes half a frame early and
|
|
@@ -17333,7 +17763,7 @@ function playAdvanceVideo(el, mt, eps, rate, { keepPlaying } = {}) {
|
|
|
17333
17763
|
if (settled) return;
|
|
17334
17764
|
settled = true;
|
|
17335
17765
|
cleanup();
|
|
17336
|
-
|
|
17766
|
+
reseek();
|
|
17337
17767
|
});
|
|
17338
17768
|
}
|
|
17339
17769
|
});
|
|
@@ -17477,13 +17907,19 @@ async function exportDecodeFrame(c, t) {
|
|
|
17477
17907
|
if (!m || !m.src) { d.sources.set(c.id, null); return false; }
|
|
17478
17908
|
if (!d.opening.has(c.id)) d.opening.set(c.id, ExportFrameSource.open(m.src));
|
|
17479
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; }
|
|
17480
17913
|
d.sources.set(c.id, src);
|
|
17481
17914
|
}
|
|
17482
17915
|
if (!src) return false;
|
|
17483
17916
|
try {
|
|
17484
|
-
|
|
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);
|
|
17485
17920
|
return true;
|
|
17486
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;
|
|
17487
17923
|
console.warn("[FableCut] export decode failed, using the video element:", e && e.message);
|
|
17488
17924
|
src.close(); d.sources.set(c.id, null); runtime.exportFrames.delete(c.id);
|
|
17489
17925
|
return false;
|
|
@@ -17502,6 +17938,9 @@ async function seekVideosTo(t, { queueBusy } = {}) {
|
|
|
17502
17938
|
const restoreGain = [];
|
|
17503
17939
|
const decoded = new Set();
|
|
17504
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;
|
|
17505
17944
|
if (dec) {
|
|
17506
17945
|
const jobs = [];
|
|
17507
17946
|
for (const c of mediaClips()) {
|
|
@@ -17515,6 +17954,7 @@ async function seekVideosTo(t, { queueBusy } = {}) {
|
|
|
17515
17954
|
jobs.push(exportDecodeFrame(c, t).then((ok) => { if (ok) decoded.add(c.id); }));
|
|
17516
17955
|
}
|
|
17517
17956
|
await Promise.all(jobs);
|
|
17957
|
+
if (exportWindow !== win) return;
|
|
17518
17958
|
}
|
|
17519
17959
|
for (const c of mediaClips()) {
|
|
17520
17960
|
if (c.kind !== "video") continue;
|
|
@@ -17568,6 +18008,7 @@ async function seekVideosTo(t, { queueBusy } = {}) {
|
|
|
17568
18008
|
}
|
|
17569
18009
|
}
|
|
17570
18010
|
await Promise.all(waits);
|
|
18011
|
+
if (exportWindow !== win) return;
|
|
17571
18012
|
for (const c of restoreGain) {
|
|
17572
18013
|
const chain = runtime.clipGain.get(c.id);
|
|
17573
18014
|
if (chain?.vol) driveClipChain(chain, c, evalProps(c, t), t);
|
|
@@ -17610,7 +18051,16 @@ async function renderAudioMix(t0, t1) {
|
|
|
17610
18051
|
if (dur <= 0) return null;
|
|
17611
18052
|
const sr = 48000;
|
|
17612
18053
|
const off = new OfflineAudioContext(2, Math.ceil(dur * sr) + 1, sr);
|
|
17613
|
-
|
|
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]);
|
|
17614
18064
|
const mix = buildMixBuses(off, audioTrackIds(), busIdsNow());
|
|
17615
18065
|
applyMixLevels(mix);
|
|
17616
18066
|
mix.masterOut.connect(off.destination);
|
|
@@ -17656,7 +18106,7 @@ async function renderAudioMix(t0, t1) {
|
|
|
17656
18106
|
}
|
|
17657
18107
|
scheduled = true;
|
|
17658
18108
|
}
|
|
17659
|
-
if (!scheduled) return null;
|
|
18109
|
+
if (!scheduled) { clearTimeout(timer); return null; }
|
|
17660
18110
|
// Effect automation: step the offline render and glide each keyed
|
|
17661
18111
|
// parameter, the same way preview drives it every frame.
|
|
17662
18112
|
const animated = [];
|
|
@@ -17675,7 +18125,8 @@ async function renderAudioMix(t0, t1) {
|
|
|
17675
18125
|
off.suspend(when).then(() => { for (const run of animated) run(t0 + when); off.resume(); });
|
|
17676
18126
|
}
|
|
17677
18127
|
}
|
|
17678
|
-
|
|
18128
|
+
const rendered = await Promise.race([off.startRendering(), stalled]).finally(() => clearTimeout(timer));
|
|
18129
|
+
return encodeWAV(rendered);
|
|
17679
18130
|
}
|
|
17680
18131
|
/* Frame-exact asset prep for the fast exporter: rasterize the SVG frame for
|
|
17681
18132
|
this exact time, and refresh AI person masks synchronously. */
|
|
@@ -17715,13 +18166,15 @@ async function fastExport(opts = {}) {
|
|
|
17715
18166
|
let sessId = null;
|
|
17716
18167
|
let uploadError = null;
|
|
17717
18168
|
const setError = (err) => { if (!uploadError) uploadError = err; };
|
|
18169
|
+
let watch = null;
|
|
17718
18170
|
try {
|
|
17719
18171
|
els.exportTitle.textContent = "Mixing audio…";
|
|
17720
|
-
const wav = await renderAudioMix(t0, t1);
|
|
18172
|
+
const wav = await renderAudioMix(t0, t1); // has its own watchdog
|
|
17721
18173
|
if (renderCancelled) throw new Error("cancelled");
|
|
18174
|
+
watch = exportWatchdog(frames / fps, setError);
|
|
17722
18175
|
const profileId = opts.profile || effectiveEncodeProfileId();
|
|
17723
18176
|
const cv = deliveryCanvas();
|
|
17724
|
-
const begin = await fetch("/api/export/begin", {
|
|
18177
|
+
const begin = await watch.guard(fetch("/api/export/begin", {
|
|
17725
18178
|
method: "POST",
|
|
17726
18179
|
body: JSON.stringify(delivery ? {
|
|
17727
18180
|
fps, duration: frames / fps,
|
|
@@ -17734,7 +18187,7 @@ async function fastExport(opts = {}) {
|
|
|
17734
18187
|
hasAudio: !!wav,
|
|
17735
18188
|
}),
|
|
17736
18189
|
signal,
|
|
17737
|
-
}).then((r) => r.json());
|
|
18190
|
+
}).then((r) => r.json()));
|
|
17738
18191
|
if (!begin.id) throw new Error(begin.error || "export begin failed");
|
|
17739
18192
|
sessId = begin.id;
|
|
17740
18193
|
const jpegQ = delivery ? begin.jpegQuality ?? 0.95 : exportProfileMeta(profileId).jpegQuality ?? 0.95;
|
|
@@ -17743,19 +18196,19 @@ async function fastExport(opts = {}) {
|
|
|
17743
18196
|
const frameType = begin.input === "png" ? "image/png" : "image/jpeg";
|
|
17744
18197
|
exportFullCanvas = !!delivery;
|
|
17745
18198
|
if (wav) {
|
|
17746
|
-
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 }));
|
|
17747
18200
|
if (!r.ok) throw new Error("audio upload failed");
|
|
17748
18201
|
}
|
|
17749
|
-
await loadProjectFonts();
|
|
18202
|
+
await watch.guard(loadProjectFonts());
|
|
17750
18203
|
resetExportCanvases();
|
|
17751
|
-
await armExportCors();
|
|
17752
|
-
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
|
|
17753
18206
|
exportDecodeBegin();
|
|
17754
18207
|
// JPEG off the compositor thread: snapshot is sync, encode/upload run ahead
|
|
17755
18208
|
// under backpressure. Awaiting toBlob every frame was slower than ffmpeg.
|
|
17756
18209
|
const up = createExportUploader(sessId, {
|
|
17757
18210
|
batchItems: 8, batchBytes: 512 * 1024, signal,
|
|
17758
|
-
getError: () => uploadError, setError,
|
|
18211
|
+
getError: () => uploadError, setError, onSent: watch.moved,
|
|
17759
18212
|
});
|
|
17760
18213
|
const workers = createJpegWorkers(Math.min(3, Math.max(1, (navigator.hardwareConcurrency || 2) - 1)));
|
|
17761
18214
|
let pixelChain = Promise.resolve();
|
|
@@ -17777,14 +18230,15 @@ async function fastExport(opts = {}) {
|
|
|
17777
18230
|
// enough that play-ahead would overrun during the wait (not on every blip).
|
|
17778
18231
|
const queueBusy = pixelsInflight > 6 || up.inFlight() > 4;
|
|
17779
18232
|
if (pixelsInflight > 4) pauseExportVideos();
|
|
17780
|
-
await waitPixels(6);
|
|
18233
|
+
await waitPixels(6); // the polling waits see the watchdog's error themselves
|
|
17781
18234
|
await up.waitBackpressure(4);
|
|
17782
18235
|
const t = t0 + f / fps;
|
|
17783
18236
|
state.time = t;
|
|
17784
|
-
await seekVideosTo(t, { queueBusy });
|
|
17785
|
-
await prepareFrameAssets(t);
|
|
18237
|
+
await watch.guard(seekVideosTo(t, { queueBusy }));
|
|
18238
|
+
await watch.guard(prepareFrameAssets(t));
|
|
17786
18239
|
drawFrame(t);
|
|
17787
18240
|
const snap = snapshotExportFrame();
|
|
18241
|
+
watch.moved();
|
|
17788
18242
|
pixelsInflight++;
|
|
17789
18243
|
let jpegP;
|
|
17790
18244
|
if (snap.kind === "bmp") {
|
|
@@ -17808,6 +18262,7 @@ async function fastExport(opts = {}) {
|
|
|
17808
18262
|
const buf = await jpegP;
|
|
17809
18263
|
if (!buf || !(buf.byteLength || buf.size || buf.length)) throw new Error("frame encode failed");
|
|
17810
18264
|
up.push(buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf);
|
|
18265
|
+
watch.moved();
|
|
17811
18266
|
}).catch((err) => { setError(err); throw err; }).finally(() => { pixelsInflight--; });
|
|
17812
18267
|
const pct = ((f + 1) / frames) * 100;
|
|
17813
18268
|
els.exportProgress.style.width = pct.toFixed(1) + "%";
|
|
@@ -17815,14 +18270,15 @@ async function fastExport(opts = {}) {
|
|
|
17815
18270
|
if (opts.onProgress) opts.onProgress(0.97 * (f + 1) / frames);
|
|
17816
18271
|
if (job) reportExportJob(job, { progress: 0.97 * (f + 1) / frames });
|
|
17817
18272
|
}
|
|
17818
|
-
await pixelChain;
|
|
18273
|
+
await watch.guard(pixelChain);
|
|
17819
18274
|
if (uploadError) throw uploadError;
|
|
17820
18275
|
els.exportTitle.textContent = "Encoding…";
|
|
17821
|
-
await up.done();
|
|
18276
|
+
await watch.guard(up.done());
|
|
17822
18277
|
if (uploadError) throw uploadError;
|
|
17823
18278
|
} finally {
|
|
17824
18279
|
try { workers?.terminate(); } catch { }
|
|
17825
18280
|
}
|
|
18281
|
+
watch.stop(); // finishing (the encoder's last frames, the checks) can take a while on its own
|
|
17826
18282
|
const end = await fetch("/api/export/end?id=" + sessId, { method: "POST", signal }).then((r) => r.json());
|
|
17827
18283
|
if (!end.src) throw new Error(end.error || "encode failed");
|
|
17828
18284
|
const outs = end.outputs || [{ file: decodeURIComponent(end.src.split("/").pop()), ok: true, src: end.src }];
|
|
@@ -17855,6 +18311,9 @@ async function fastExport(opts = {}) {
|
|
|
17855
18311
|
if (job) await reportExportJob(job, { status: "failed", error: msg }, true);
|
|
17856
18312
|
else if (msg !== "cancelled" && !opts.silent) alert("Export failed: " + msg);
|
|
17857
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 { }
|
|
17858
18317
|
exportAbort = null;
|
|
17859
18318
|
exportFullCanvas = false;
|
|
17860
18319
|
exportDecodeEnd();
|
|
@@ -18448,13 +18907,14 @@ async function webCodecsExport(name) {
|
|
|
18448
18907
|
let encoder = null;
|
|
18449
18908
|
let uploadError = null;
|
|
18450
18909
|
const setError = (err) => { if (!uploadError) uploadError = err; };
|
|
18451
|
-
let up = null;
|
|
18910
|
+
let up = null, watch = null;
|
|
18452
18911
|
try {
|
|
18453
18912
|
els.exportTitle.textContent = "Mixing audio…";
|
|
18454
|
-
const wav = await renderAudioMix(t0, t1);
|
|
18913
|
+
const wav = await renderAudioMix(t0, t1); // has its own watchdog
|
|
18455
18914
|
if (renderCancelled) throw new Error("cancelled");
|
|
18915
|
+
watch = exportWatchdog(frames / fps, setError);
|
|
18456
18916
|
|
|
18457
|
-
const begin = await fetch("/api/export/begin", {
|
|
18917
|
+
const begin = await watch.guard(fetch("/api/export/begin", {
|
|
18458
18918
|
method: "POST",
|
|
18459
18919
|
body: JSON.stringify({
|
|
18460
18920
|
fps,
|
|
@@ -18463,16 +18923,16 @@ async function webCodecsExport(name) {
|
|
|
18463
18923
|
hasAudio: !!wav,
|
|
18464
18924
|
}),
|
|
18465
18925
|
signal,
|
|
18466
|
-
}).then((r) => r.json());
|
|
18926
|
+
}).then((r) => r.json()));
|
|
18467
18927
|
if (!begin.id) throw new Error(begin.error || "export begin failed");
|
|
18468
18928
|
sessId = begin.id;
|
|
18469
18929
|
if (wav) {
|
|
18470
|
-
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 }));
|
|
18471
18931
|
if (!r.ok) throw new Error("audio upload failed");
|
|
18472
18932
|
}
|
|
18473
18933
|
up = createExportUploader(sessId, {
|
|
18474
18934
|
batchItems: 12, batchBytes: 128 * 1024, signal,
|
|
18475
|
-
getError: () => uploadError, setError,
|
|
18935
|
+
getError: () => uploadError, setError, onSent: watch.moved,
|
|
18476
18936
|
});
|
|
18477
18937
|
|
|
18478
18938
|
// Always encode at project/frame resolution (not display CSS size).
|
|
@@ -18499,10 +18959,10 @@ async function webCodecsExport(name) {
|
|
|
18499
18959
|
avc: { format: "annexb" },
|
|
18500
18960
|
latencyMode: "quality",
|
|
18501
18961
|
});
|
|
18502
|
-
await loadProjectFonts();
|
|
18962
|
+
await watch.guard(loadProjectFonts());
|
|
18503
18963
|
resetExportCanvases();
|
|
18504
|
-
await armExportCors();
|
|
18505
|
-
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
|
|
18506
18966
|
exportDecodeBegin();
|
|
18507
18967
|
|
|
18508
18968
|
for (let f = 0; f < frames; f++) {
|
|
@@ -18510,12 +18970,12 @@ async function webCodecsExport(name) {
|
|
|
18510
18970
|
if (uploadError) throw uploadError;
|
|
18511
18971
|
const queueBusy = up.inFlight() > 4 || encoder.encodeQueueSize > 4;
|
|
18512
18972
|
if (up.inFlight() > 3 || encoder.encodeQueueSize > 3) pauseExportVideos();
|
|
18513
|
-
await up.waitBackpressure(4);
|
|
18973
|
+
await up.waitBackpressure(4); // the polling waits see the watchdog's error themselves
|
|
18514
18974
|
await waitEncodeQueue(encoder, 4, { signal, getError: () => uploadError });
|
|
18515
18975
|
const t = t0 + f / fps;
|
|
18516
18976
|
state.time = t;
|
|
18517
|
-
await seekVideosTo(t, { queueBusy });
|
|
18518
|
-
await prepareFrameAssets(t);
|
|
18977
|
+
await watch.guard(seekVideosTo(t, { queueBusy }));
|
|
18978
|
+
await watch.guard(prepareFrameAssets(t));
|
|
18519
18979
|
drawFrame(t);
|
|
18520
18980
|
// Absolute µs timestamps; duration = delta so average rate stays exact
|
|
18521
18981
|
// (constant Math.round(1e6/fps) drifts, e.g. 33333µs → avg 1000000/33333).
|
|
@@ -18536,14 +18996,16 @@ async function webCodecsExport(name) {
|
|
|
18536
18996
|
} finally {
|
|
18537
18997
|
frame.close();
|
|
18538
18998
|
}
|
|
18999
|
+
watch.moved();
|
|
18539
19000
|
const pct = ((f + 1) / frames) * 100;
|
|
18540
19001
|
els.exportProgress.style.width = pct.toFixed(1) + "%";
|
|
18541
19002
|
els.exportTitle.textContent = `Encoding… ${pct.toFixed(0)}%`;
|
|
18542
19003
|
}
|
|
18543
19004
|
els.exportTitle.textContent = "Finishing…";
|
|
18544
|
-
await encoder.flush();
|
|
18545
|
-
await up.done();
|
|
19005
|
+
await watch.guard(encoder.flush());
|
|
19006
|
+
await watch.guard(up.done());
|
|
18546
19007
|
if (uploadError) throw uploadError;
|
|
19008
|
+
watch.stop();
|
|
18547
19009
|
encoder.close();
|
|
18548
19010
|
encoder = null;
|
|
18549
19011
|
const end = await fetch("/api/export/end?id=" + sessId, { method: "POST", signal }).then((r) => r.json());
|
|
@@ -18558,6 +19020,8 @@ async function webCodecsExport(name) {
|
|
|
18558
19020
|
const msg = e?.name === "AbortError" ? "cancelled" : String(e.message || e);
|
|
18559
19021
|
if (msg !== "cancelled") alert("Export failed: " + msg);
|
|
18560
19022
|
} finally {
|
|
19023
|
+
watch?.stop();
|
|
19024
|
+
try { exportAbort?.abort(); } catch { } // over: steps still waiting on this export stop too
|
|
18561
19025
|
exportAbort = null;
|
|
18562
19026
|
exportDecodeEnd();
|
|
18563
19027
|
restoreExportVideoState();
|
|
@@ -18897,16 +19361,16 @@ function cmdkCollect() {
|
|
|
18897
19361
|
};
|
|
18898
19362
|
// panels and tabs
|
|
18899
19363
|
// (the Color workspace and the Color side tab share a name: where each lives tells them apart)
|
|
18900
|
-
const panelWhere = { sideTabs: "Side panel", binTabs: "Bin", wsSwitch: "Workspace" };
|
|
18901
|
-
for (const b of document.querySelectorAll("#sideTabs [data-side], #binTabs [data-tab], #wsSwitch [data-ws]")) {
|
|
19364
|
+
const panelWhere = { sideTabs: "Side panel", binTabs: "Bin", binSubTabs: "Bin", wsSwitch: "Workspace" };
|
|
19365
|
+
for (const b of document.querySelectorAll("#sideTabs [data-side], #binTabs [data-tab], #binSubTabs [data-tab], #wsSwitch [data-ws]")) {
|
|
18902
19366
|
const where = panelWhere[b.parentElement.id] || "", title = (b.title || "").split(/ — |: /)[0] === cmdkName(b) ? "" : b.title;
|
|
18903
19367
|
add({ key: "Panel|" + b.parentElement.id + "|" + cmdkName(b), label: cmdkName(b), group: "Panel", hint: [where, title].filter(Boolean).join(" · "),
|
|
18904
|
-
keywords: ["tab", "show", "open", where], run: () => { if (b.closest("#binTabs")) cmdkShowBin(); b.click(); } });
|
|
19368
|
+
keywords: ["tab", "show", "open", where], run: () => { if (b.closest("#binTabs, #binSubTabs")) cmdkShowBin(); b.click(); } });
|
|
18905
19369
|
}
|
|
18906
19370
|
// toolbar actions: every named button outside dialogs, menus and the Inspector (and the timeline's edit tools)
|
|
18907
19371
|
const actions = [];
|
|
18908
19372
|
for (const b of document.querySelectorAll("button[id], button[data-edit-tool]")) {
|
|
18909
|
-
if (b.closest(".overlay, .ctx-menu, .style-menu, #inspector, #sideTabs, #binTabs, #wsSwitch") || b.id === "btnSearch") continue;
|
|
19373
|
+
if (b.closest(".overlay, .ctx-menu, .style-menu, #inspector, #sideTabs, #binTabs, #binSubTabs, #wsSwitch") || b.id === "btnSearch") continue;
|
|
18910
19374
|
if (!cmdkShown(b)) continue;
|
|
18911
19375
|
actions.push(b);
|
|
18912
19376
|
}
|
|
@@ -19150,6 +19614,10 @@ $("trackSizeGroup").addEventListener("click", (e) => {
|
|
|
19150
19614
|
if (b) setTrackSize(b.dataset.trackSize);
|
|
19151
19615
|
});
|
|
19152
19616
|
els.binTabs.addEventListener("click", (e) => {
|
|
19617
|
+
const b = e.target.closest("[data-tab], [data-group]");
|
|
19618
|
+
if (b) setBinTab(b.dataset.tab || binGroupTab[b.dataset.group]);
|
|
19619
|
+
});
|
|
19620
|
+
els.binSubTabs?.addEventListener("click", (e) => {
|
|
19153
19621
|
const b = e.target.closest("[data-tab]");
|
|
19154
19622
|
if (b) setBinTab(b.dataset.tab);
|
|
19155
19623
|
});
|