popost 4.6.13 → 4.6.14
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/SKILL.md +7 -1
- package/dist/cli.js +433 -327
- package/dist/index.js +434 -327
- package/dist/types/render/browser.d.ts +3 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/video/describe/parts.d.ts +13 -14
- package/dist/types/video/eval/readback-kept.d.ts +4 -3
- package/dist/types/video/generate/speech.d.ts +1 -1
- package/dist/types/video/look/sheets.d.ts +17 -0
- package/dist/types/video/render/chunked.d.ts +11 -2
- package/dist/types/video/render/chunks.d.ts +5 -2
- package/dist/types/video/render/index.d.ts +25 -5
- package/dist/types/video/sound/modes.d.ts +5 -7
- package/dist/types/video/sound/speech-check.d.ts +1 -1
- package/package.json +1 -1
- package/references/execution-contract.md +31 -0
- package/references/onboarding.md +2 -0
- package/references/video-continuity.md +2 -0
- package/references/video-native-observation.md +2 -0
- package/references/video-performers.md +2 -0
- package/references/video-project.md +2 -2
- package/references/video-scenes.md +2 -2
- package/references/video-sound.md +19 -27
- package/references/video-step-1-read.md +3 -0
- package/references/video-step-6-voice.md +6 -1
- package/references/video-step-7-deliver.md +6 -2
- package/references/video-tools.md +2 -0
- package/references/video.md +27 -2
package/dist/cli.js
CHANGED
|
@@ -280,7 +280,7 @@ var VERSION;
|
|
|
280
280
|
var init_version = __esm({
|
|
281
281
|
"src/version.ts"() {
|
|
282
282
|
"use strict";
|
|
283
|
-
VERSION = "4.6.
|
|
283
|
+
VERSION = "4.6.14";
|
|
284
284
|
}
|
|
285
285
|
});
|
|
286
286
|
|
|
@@ -15721,7 +15721,7 @@ import { existsSync, readdirSync } from "node:fs";
|
|
|
15721
15721
|
import { homedir } from "node:os";
|
|
15722
15722
|
import path from "node:path";
|
|
15723
15723
|
import { chromium } from "playwright-core";
|
|
15724
|
-
var BrowserUnavailableError, playwrightCaches, SYSTEM_BROWSERS,
|
|
15724
|
+
var BrowserUnavailableError, playwrightCaches, SYSTEM_BROWSERS, chromiumCandidates, OFFLINE, LAUNCH_ARGS, FRAME_ARGS, ARGS, MAX_RASTER_THREADS, chromiumArgs, closeOwnedBrowser, launchChromium;
|
|
15725
15725
|
var init_browser = __esm({
|
|
15726
15726
|
"src/render/browser.ts"() {
|
|
15727
15727
|
"use strict";
|
|
@@ -15768,10 +15768,9 @@ var init_browser = __esm({
|
|
|
15768
15768
|
"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
|
|
15769
15769
|
"C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe"
|
|
15770
15770
|
];
|
|
15771
|
-
|
|
15771
|
+
chromiumCandidates = (env2) => {
|
|
15772
15772
|
const explicit = env2.POPOST_CHROME || env2.PLAYWRIGHT_CHROMIUM;
|
|
15773
|
-
|
|
15774
|
-
return [...SYSTEM_BROWSERS, ...playwrightCaches()].find((p) => existsSync(p)) ?? null;
|
|
15773
|
+
return [...new Set(explicit ? [explicit] : [...SYSTEM_BROWSERS, ...playwrightCaches()])].filter((p) => existsSync(p));
|
|
15775
15774
|
};
|
|
15776
15775
|
OFFLINE = "--host-resolver-rules=MAP * ~NOTFOUND";
|
|
15777
15776
|
LAUNCH_ARGS = ["--disable-gpu", "--font-render-hinting=none", OFFLINE];
|
|
@@ -15813,26 +15812,34 @@ var init_browser = __esm({
|
|
|
15813
15812
|
}
|
|
15814
15813
|
};
|
|
15815
15814
|
launchChromium = async (env2, profile2 = "pages", o = {}) => {
|
|
15816
|
-
const
|
|
15817
|
-
if (!
|
|
15815
|
+
const candidates3 = chromiumCandidates(env2);
|
|
15816
|
+
if (!candidates3.length)
|
|
15818
15817
|
throw new BrowserUnavailableError(
|
|
15819
15818
|
msg(
|
|
15820
15819
|
"No Chrome, Edge or Chromium found. Install Google Chrome, or set POPOST_CHROME to a Chromium executable.",
|
|
15821
15820
|
"\u6CA1\u6709\u627E\u5230 Chrome\u3001Edge \u6216 Chromium\u3002\u8BF7\u5B89\u88C5 Google Chrome\uFF0C\u6216\u628A POPOST_CHROME \u8BBE\u4E3A\u67D0\u4E2A Chromium \u53EF\u6267\u884C\u6587\u4EF6\u3002"
|
|
15822
15821
|
)
|
|
15823
15822
|
);
|
|
15824
|
-
const
|
|
15825
|
-
|
|
15826
|
-
|
|
15827
|
-
|
|
15828
|
-
|
|
15829
|
-
|
|
15830
|
-
|
|
15831
|
-
|
|
15832
|
-
|
|
15833
|
-
|
|
15834
|
-
|
|
15823
|
+
const failures = [];
|
|
15824
|
+
for (const executablePath of candidates3) {
|
|
15825
|
+
try {
|
|
15826
|
+
const options = { executablePath, headless: true, args: chromiumArgs(profile2, o) };
|
|
15827
|
+
if (profile2 !== "frames") return await chromium.launch(options);
|
|
15828
|
+
const server = await chromium.launchServer({ ...options, host: "127.0.0.1" });
|
|
15829
|
+
try {
|
|
15830
|
+
const browser = await chromium.connect(server.wsEndpoint(), { timeout: 3e4 });
|
|
15831
|
+
let closing;
|
|
15832
|
+
browser.close = () => closing ??= closeOwnedBrowser(server);
|
|
15833
|
+
return browser;
|
|
15834
|
+
} catch (e) {
|
|
15835
|
+
await server.kill().catch(() => void 0);
|
|
15836
|
+
throw e;
|
|
15837
|
+
}
|
|
15838
|
+
} catch (e) {
|
|
15839
|
+
failures.push(executablePath + ": " + (e instanceof Error ? e.message : String(e)).slice(0, 1500));
|
|
15840
|
+
}
|
|
15835
15841
|
}
|
|
15842
|
+
throw new BrowserUnavailableError("Installed browsers could not start. This is a launch/runtime restriction, not proof that Chrome is missing. Install or select a compatible Chrome/Chromium using POPOST_CHROME and verify doctor plus a minimal render; keep the Popost production route. " + failures.join("\n"));
|
|
15836
15843
|
};
|
|
15837
15844
|
}
|
|
15838
15845
|
});
|
|
@@ -16075,7 +16082,7 @@ var init_page_bundle = __esm({
|
|
|
16075
16082
|
});
|
|
16076
16083
|
|
|
16077
16084
|
// src/video/render/chunks.ts
|
|
16078
|
-
var CHUNK_DIR, VERSION2, MAX_CHUNK_SECONDS, chunkRanges, SHARED_DIRS, SOUND, fileHash, filesBelow, sceneFile, sharedKey, keyContext, picturesOf, frameKey, chunkKey, chunkDir;
|
|
16085
|
+
var CHUNK_DIR, VERSION2, MAX_CHUNK_SECONDS, splitLong, chunkRanges, SHARED_DIRS, SOUND, fileHash, filesBelow, sceneFile, sharedKey, keyContext, picturesOf, FOOTAGE_FRAME, frameKey, chunkKey, chunkDir;
|
|
16079
16086
|
var init_chunks = __esm({
|
|
16080
16087
|
"src/video/render/chunks.ts"() {
|
|
16081
16088
|
"use strict";
|
|
@@ -16084,6 +16091,10 @@ var init_chunks = __esm({
|
|
|
16084
16091
|
CHUNK_DIR = ".cache/render-chunks";
|
|
16085
16092
|
VERSION2 = 1;
|
|
16086
16093
|
MAX_CHUNK_SECONDS = 4;
|
|
16094
|
+
splitLong = ([from, to], longest, shortest) => {
|
|
16095
|
+
const cuts = Array.from({ length: Math.max(0, Math.floor((to - from - shortest) / longest)) }, (_, k) => from + (k + 1) * longest);
|
|
16096
|
+
return [from, ...cuts].map((start, k) => [start, cuts[k] ?? to]);
|
|
16097
|
+
};
|
|
16087
16098
|
chunkRanges = (r) => {
|
|
16088
16099
|
const shortest = Math.max(1, Math.round(r.canvas.fps));
|
|
16089
16100
|
const bounds2 = [.../* @__PURE__ */ new Set([0, ...r.segments.map((s) => s.start).filter((f) => f > 0 && f < r.frames), r.frames])].sort((a, b) => a - b);
|
|
@@ -16094,10 +16105,7 @@ var init_chunks = __esm({
|
|
|
16094
16105
|
const tail4 = joined[joined.length - 1], before = joined[joined.length - 2];
|
|
16095
16106
|
const ranges = tail4 && before && tail4[1] - tail4[0] < shortest ? [...joined.slice(0, -2), [before[0], tail4[1]]] : joined;
|
|
16096
16107
|
const longest = Math.max(shortest, Math.round(r.canvas.fps * MAX_CHUNK_SECONDS));
|
|
16097
|
-
return ranges.flatMap((
|
|
16098
|
-
const count5 = Math.ceil((to - from) / longest);
|
|
16099
|
-
return Array.from({ length: count5 }, (_, k) => [from + Math.round((to - from) * k / count5), from + Math.round((to - from) * (k + 1) / count5)]);
|
|
16100
|
-
});
|
|
16108
|
+
return ranges.flatMap((range2) => splitLong(range2, longest, shortest));
|
|
16101
16109
|
};
|
|
16102
16110
|
SHARED_DIRS = ["assets", "lib", "css", "fonts"];
|
|
16103
16111
|
SOUND = /\.(wav|mp3|m4a|aac|flac|ogg|opus)$|\.(sound|music|speech|voice|words)\.json$/i;
|
|
@@ -16133,13 +16141,17 @@ var init_chunks = __esm({
|
|
|
16133
16141
|
const found = [...markup.matchAll(/\bsrc="([^"]*)"/g), ...markup.matchAll(/url\((?:"|["'])?([^)"'&]+)/g)].map((m) => (m[1] ?? "").replace(/&/g, "&"));
|
|
16134
16142
|
return [...new Set(found.filter((u) => u && !u.startsWith("#") && !/^(data|blob|about):/.test(u)).map((u) => decodeURIComponent(u.replace(/^\/+/, "").split(/[?#]/)[0] ?? "")))].sort();
|
|
16135
16143
|
};
|
|
16144
|
+
FOOTAGE_FRAME = /\.cache\/video\/[0-9a-f]{16}\/\d+\.png/g;
|
|
16136
16145
|
frameKey = async (rt, c, state2) => {
|
|
16137
|
-
const
|
|
16146
|
+
const named = picturesOf(state2.markup);
|
|
16147
|
+
const hashes2 = new Map(await Promise.all(named.map(async (p) => [p, await fileHash(rt, c, p)])));
|
|
16148
|
+
const markup = state2.markup.replace(FOOTAGE_FRAME, (p) => "footage:" + (hashes2.get(p) ?? p));
|
|
16149
|
+
const pictures = named.filter((p) => p.replace(FOOTAGE_FRAME, "") !== "").map((p) => p + "=" + (hashes2.get(p) ?? ""));
|
|
16138
16150
|
const scenes = await Promise.all(state2.scenes.map(async (s) => {
|
|
16139
16151
|
const file = c.scenes[s.segment];
|
|
16140
16152
|
return (c.bases[s.segment] ?? "") + "@" + s.seconds.toFixed(6) + (file ? "=" + await fileHash(rt, c, file) : "");
|
|
16141
16153
|
}));
|
|
16142
|
-
return sha256([
|
|
16154
|
+
return sha256([markup, ...scenes, ...pictures, scenes.length ? c.shared : ""].join("\n"));
|
|
16143
16155
|
};
|
|
16144
16156
|
chunkKey = (c, frames) => sha256(c.settings + "\n" + frames.join("\n"));
|
|
16145
16157
|
chunkDir = (rt, c) => rt.path.join(c.root, CHUNK_DIR, c.settings.slice(0, 16));
|
|
@@ -18496,14 +18508,14 @@ var init_types = __esm({
|
|
|
18496
18508
|
});
|
|
18497
18509
|
|
|
18498
18510
|
// src/video/sound/modes.ts
|
|
18499
|
-
var CLIP_MUSIC_BASES, BASIS_MEANS, isSoundMode, isClipMusicBasis, modeContextOf, inferMode,
|
|
18511
|
+
var CLIP_MUSIC_BASES, BASIS_MEANS, isSoundMode, isClipMusicBasis, modeContextOf, inferMode, soundTail, musicBasisOf, speechProblems, modeProblems, RECEIPT, writeModeReceipt, readModeReceipt;
|
|
18500
18512
|
var init_modes = __esm({
|
|
18501
18513
|
"src/video/sound/modes.ts"() {
|
|
18502
18514
|
"use strict";
|
|
18503
18515
|
init_prompt_lang();
|
|
18504
18516
|
init_check_common();
|
|
18505
18517
|
init_types();
|
|
18506
|
-
CLIP_MUSIC_BASES = ["single-clip", "per-segment", "in-scene", "sung", "brand-sting", "own-footage", "user-wish"];
|
|
18518
|
+
CLIP_MUSIC_BASES = ["single-clip", "per-segment", "in-scene", "sung", "brand-sting", "own-footage", "user-wish", "model-native"];
|
|
18507
18519
|
BASIS_MEANS = {
|
|
18508
18520
|
"single-clip": "the video is one continuous clip with no cut: its own continuous soundtrack stays",
|
|
18509
18521
|
"per-segment": "the reference changes its music from segment to segment on purpose (a compilation, chapters; segments of several seconds): each clip brings its own, and the video has no bed",
|
|
@@ -18511,7 +18523,8 @@ var init_modes = __esm({
|
|
|
18511
18523
|
sung: "a person sings, or lip-syncs a song",
|
|
18512
18524
|
"brand-sting": "a short brand sting of a second or two",
|
|
18513
18525
|
"own-footage": "the user's own filmed footage keeps the sound it was filmed with",
|
|
18514
|
-
"user-wish": "the user asked for it in so many words"
|
|
18526
|
+
"user-wish": "the user asked for it in so many words",
|
|
18527
|
+
"model-native": "the AI video model produces the clip soundtrack; cross-clip music continuity is best effort"
|
|
18515
18528
|
};
|
|
18516
18529
|
isSoundMode = (v) => SOUND_MODES.includes(v);
|
|
18517
18530
|
isClipMusicBasis = (v) => CLIP_MUSIC_BASES.includes(v);
|
|
@@ -18524,20 +18537,13 @@ var init_modes = __esm({
|
|
|
18524
18537
|
if (r.speech !== void 0 && r.speech !== null) return "speech";
|
|
18525
18538
|
return ctx.narrated && ctx.ambience !== "yes" ? "silent" : "ambience";
|
|
18526
18539
|
};
|
|
18527
|
-
NO_MUSIC_SENTENCE = "No background music and no score in this clip: the music of the video is a separate track.";
|
|
18528
18540
|
soundTail = (mode, o = {}) => {
|
|
18529
|
-
if (
|
|
18530
|
-
|
|
18531
|
-
|
|
18532
|
-
|
|
18533
|
-
|
|
18534
|
-
|
|
18535
|
-
}
|
|
18536
|
-
const music = o.music ? "" : " " + NO_MUSIC_SENTENCE;
|
|
18537
|
-
if (mode === "speech") return " Sound: the speaker's voice is the lead of this clip, clear and close, over the quiet ambient sound of the scene." + music;
|
|
18538
|
-
if (mode === "ambience") return " Sound: only the ambient sound of the scene and the sounds of what happens in it. Nobody speaks: no dialogue, no narrator, no voice." + music;
|
|
18539
|
-
if (mode === "silent") return " The clip is used without its sound: nobody speaks to the camera, and mouths stay closed or turned away.";
|
|
18540
|
-
return "";
|
|
18541
|
+
if (mode === "exhibit") return "";
|
|
18542
|
+
if (mode === "silent") return pl(" This explicitly silent clip is used without its soundtrack.", " \u672C\u7247\u6BB5\u6309\u660E\u786E\u7684\u9759\u97F3\u65B9\u6848\u4F7F\u7528\uFF0C\u4E0D\u4F7F\u7528\u81EA\u5E26\u97F3\u8F68\u3002");
|
|
18543
|
+
const lead = mode === "speech" ? pl(" Keep the requested speaker clear and consistent across clips.", " \u4FDD\u6301\u6307\u5B9A\u8BF4\u8BDD\u4EBA\u6E05\u6670\uFF0C\u8DE8\u7247\u6BB5\u4FDD\u6301\u540C\u4E00\u97F3\u8272\u548C\u8BED\u6C14\u3002") : "";
|
|
18544
|
+
if (o.externalMusic) return lead + pl(" Background music is supplied separately in this explicit audio plan; do not generate another music bed.", " \u5F53\u524D\u660E\u786E\u7684\u97F3\u9891\u65B9\u6848\u53E6\u6709\u80CC\u666F\u97F3\u4E50\uFF0C\u4E0D\u751F\u6210\u91CD\u590D\u914D\u4E50\u3002");
|
|
18545
|
+
const route2 = o.music && o.music !== "model-native" ? "" : pl(" Generate the speech, narration, music, ambience and effects required by the prompt together with the video. Preserve native picture/audio synchronization.", " \u6839\u636E\u63D0\u793A\u8BCD\u968F\u89C6\u9891\u4E00\u4F53\u751F\u6210\u6240\u9700\u7684\u53E3\u64AD\u3001\u65C1\u767D\u3001\u97F3\u4E50\u3001\u73AF\u5883\u58F0\u4E0E\u97F3\u6548\uFF0C\u4FDD\u6301\u539F\u751F\u97F3\u753B\u540C\u6B65\u3002");
|
|
18546
|
+
return lead + route2;
|
|
18541
18547
|
};
|
|
18542
18548
|
musicBasisOf = (r, recorded2) => {
|
|
18543
18549
|
if (isClipMusicBasis(r.clipMusic)) return r.clipMusic;
|
|
@@ -18561,7 +18567,7 @@ var init_modes = __esm({
|
|
|
18561
18567
|
if (!isClipMusicBasis(r.clipMusic))
|
|
18562
18568
|
return [...out2, error(at7 + ".clipMusic", '"clipMusic" names why this clip carries music of its own; it is ' + JSON.stringify(r.clipMusic) + ".", "Write one of the stated exceptions, or remove it: by default a clip has no music and the video has one music track.", [...CLIP_MUSIC_BASES])];
|
|
18563
18569
|
if (r.sound === "silent") out2.push(error(at7 + ".clipMusic", "A silent clip carries no music.", 'Remove "clipMusic", or change "sound".'));
|
|
18564
|
-
if (!recorded2.some((c) => c.basis === r.clipMusic && (c.clip === r.file || c.clip === "all")))
|
|
18570
|
+
if (r.clipMusic !== "model-native" && !recorded2.some((c) => c.basis === r.clipMusic && (c.clip === r.file || c.clip === "all")))
|
|
18565
18571
|
out2.push(error(
|
|
18566
18572
|
at7 + ".clipMusic",
|
|
18567
18573
|
'Music inside a clip is an exception that needs its basis on record, and the project records no "' + r.clipMusic + '" (' + BASIS_MEANS[r.clipMusic] + ") for " + String(r.file) + ".",
|
|
@@ -22452,6 +22458,49 @@ var init_wallet = __esm({
|
|
|
22452
22458
|
}
|
|
22453
22459
|
});
|
|
22454
22460
|
|
|
22461
|
+
// src/video/voice/cache.ts
|
|
22462
|
+
var FORMAT, VERSION3, keyOf2, baseOf, off, keptLine, keepLine;
|
|
22463
|
+
var init_cache = __esm({
|
|
22464
|
+
"src/video/voice/cache.ts"() {
|
|
22465
|
+
"use strict";
|
|
22466
|
+
init_util();
|
|
22467
|
+
FORMAT = "popost-voice-cache";
|
|
22468
|
+
VERSION3 = 1;
|
|
22469
|
+
keyOf2 = (voiceId, text13, speed) => sha256(JSON.stringify({ format: FORMAT, version: VERSION3, voiceId, text: text13, speed }));
|
|
22470
|
+
baseOf = (rt, key2) => rt.path.join(rt.path.resolve(rt.cwd), ".popost", "video-cache", "voice", key2);
|
|
22471
|
+
off = (rt) => rt.env.POPOST_VIDEO_CACHE === "off";
|
|
22472
|
+
keptLine = async (rt, voiceId, text13, speed) => {
|
|
22473
|
+
if (off(rt)) return void 0;
|
|
22474
|
+
const key2 = keyOf2(voiceId, text13, speed);
|
|
22475
|
+
const base = baseOf(rt, key2);
|
|
22476
|
+
try {
|
|
22477
|
+
const record2 = JSON.parse(await rt.fs.readText(base + ".json"));
|
|
22478
|
+
const audio = await rt.fs.readFile(base + ".wav");
|
|
22479
|
+
if (record2.format !== FORMAT || record2.key !== key2 || record2.audioSha256 !== sha256(audio) || typeof record2.operationKey !== "string") return void 0;
|
|
22480
|
+
return { audio, operationKey: record2.operationKey, ...Array.isArray(record2.words) ? { words: record2.words } : {} };
|
|
22481
|
+
} catch {
|
|
22482
|
+
return void 0;
|
|
22483
|
+
}
|
|
22484
|
+
};
|
|
22485
|
+
keepLine = async (rt, voiceId, text13, speed, line) => {
|
|
22486
|
+
if (off(rt)) return;
|
|
22487
|
+
const key2 = keyOf2(voiceId, text13, speed);
|
|
22488
|
+
const base = baseOf(rt, key2);
|
|
22489
|
+
const temporary = base + "." + rt.randomUUID() + ".tmp";
|
|
22490
|
+
try {
|
|
22491
|
+
await rt.fs.mkdir(rt.path.dirname(base));
|
|
22492
|
+
await rt.fs.writeFile(temporary, line.audio);
|
|
22493
|
+
await rt.fs.rename(temporary, base + ".wav");
|
|
22494
|
+
const record2 = { format: FORMAT, key: key2, voiceId, text: text13, speed, operationKey: line.operationKey, audioSha256: sha256(line.audio), ...line.words ? { words: line.words } : {} };
|
|
22495
|
+
await rt.fs.writeFile(temporary, JSON.stringify(record2));
|
|
22496
|
+
await rt.fs.rename(temporary, base + ".json");
|
|
22497
|
+
} catch {
|
|
22498
|
+
await rt.fs.rm(temporary).catch(() => void 0);
|
|
22499
|
+
}
|
|
22500
|
+
};
|
|
22501
|
+
}
|
|
22502
|
+
});
|
|
22503
|
+
|
|
22455
22504
|
// src/video/submit-retry.ts
|
|
22456
22505
|
var SUBMIT_TRIES, SUBMIT_PAUSE_MS, SAFE_AGAIN, textOf2, lastWord, sendIdempotent;
|
|
22457
22506
|
var init_submit_retry = __esm({
|
|
@@ -22683,49 +22732,6 @@ var init_paid_download = __esm({
|
|
|
22683
22732
|
}
|
|
22684
22733
|
});
|
|
22685
22734
|
|
|
22686
|
-
// src/video/voice/cache.ts
|
|
22687
|
-
var FORMAT, VERSION3, keyOf2, baseOf, off, keptLine, keepLine;
|
|
22688
|
-
var init_cache = __esm({
|
|
22689
|
-
"src/video/voice/cache.ts"() {
|
|
22690
|
-
"use strict";
|
|
22691
|
-
init_util();
|
|
22692
|
-
FORMAT = "popost-voice-cache";
|
|
22693
|
-
VERSION3 = 1;
|
|
22694
|
-
keyOf2 = (voiceId, text13, speed) => sha256(JSON.stringify({ format: FORMAT, version: VERSION3, voiceId, text: text13, speed }));
|
|
22695
|
-
baseOf = (rt, key2) => rt.path.join(rt.path.resolve(rt.cwd), ".popost", "video-cache", "voice", key2);
|
|
22696
|
-
off = (rt) => rt.env.POPOST_VIDEO_CACHE === "off";
|
|
22697
|
-
keptLine = async (rt, voiceId, text13, speed) => {
|
|
22698
|
-
if (off(rt)) return void 0;
|
|
22699
|
-
const key2 = keyOf2(voiceId, text13, speed);
|
|
22700
|
-
const base = baseOf(rt, key2);
|
|
22701
|
-
try {
|
|
22702
|
-
const record2 = JSON.parse(await rt.fs.readText(base + ".json"));
|
|
22703
|
-
const audio = await rt.fs.readFile(base + ".wav");
|
|
22704
|
-
if (record2.format !== FORMAT || record2.key !== key2 || record2.audioSha256 !== sha256(audio) || typeof record2.operationKey !== "string") return void 0;
|
|
22705
|
-
return { audio, operationKey: record2.operationKey, ...Array.isArray(record2.words) ? { words: record2.words } : {} };
|
|
22706
|
-
} catch {
|
|
22707
|
-
return void 0;
|
|
22708
|
-
}
|
|
22709
|
-
};
|
|
22710
|
-
keepLine = async (rt, voiceId, text13, speed, line) => {
|
|
22711
|
-
if (off(rt)) return;
|
|
22712
|
-
const key2 = keyOf2(voiceId, text13, speed);
|
|
22713
|
-
const base = baseOf(rt, key2);
|
|
22714
|
-
const temporary = base + "." + rt.randomUUID() + ".tmp";
|
|
22715
|
-
try {
|
|
22716
|
-
await rt.fs.mkdir(rt.path.dirname(base));
|
|
22717
|
-
await rt.fs.writeFile(temporary, line.audio);
|
|
22718
|
-
await rt.fs.rename(temporary, base + ".wav");
|
|
22719
|
-
const record2 = { format: FORMAT, key: key2, voiceId, text: text13, speed, operationKey: line.operationKey, audioSha256: sha256(line.audio), ...line.words ? { words: line.words } : {} };
|
|
22720
|
-
await rt.fs.writeFile(temporary, JSON.stringify(record2));
|
|
22721
|
-
await rt.fs.rename(temporary, base + ".json");
|
|
22722
|
-
} catch {
|
|
22723
|
-
await rt.fs.rm(temporary).catch(() => void 0);
|
|
22724
|
-
}
|
|
22725
|
-
};
|
|
22726
|
-
}
|
|
22727
|
-
});
|
|
22728
|
-
|
|
22729
22735
|
// src/video/voice/hosted.ts
|
|
22730
22736
|
var clip, client, hasHostedVoice, hostedVoicePage, selectHostedVoice, quoteHostedVoice, downloadVoiceAudio, hostedOperationKey, SPEECH_HINT, LINE_AGAIN, busy2, speak, VOICE_JOBS, writeLine, speakFresh, speaking, hostedSpeech, hostedSpeaker, speechPrice;
|
|
22731
22737
|
var init_hosted = __esm({
|
|
@@ -22859,7 +22865,7 @@ var init_hosted = __esm({
|
|
|
22859
22865
|
});
|
|
22860
22866
|
|
|
22861
22867
|
// src/video/voice/index.ts
|
|
22862
|
-
var VARIABLE, speaksHosted, commandSpeaker, audioSeconds, wordsBeside, TRIM, speakLines, mixPieces, mixLines;
|
|
22868
|
+
var VARIABLE, speaksHosted, commandSpeaker, speakOwn, audioSeconds, wordsBeside, TRIM, speakLines, mixPieces, mixLines;
|
|
22863
22869
|
var init_voice = __esm({
|
|
22864
22870
|
"src/video/voice/index.ts"() {
|
|
22865
22871
|
"use strict";
|
|
@@ -22867,6 +22873,8 @@ var init_voice = __esm({
|
|
|
22867
22873
|
init_tool();
|
|
22868
22874
|
init_wallet();
|
|
22869
22875
|
init_host();
|
|
22876
|
+
init_util();
|
|
22877
|
+
init_cache();
|
|
22870
22878
|
init_hosted();
|
|
22871
22879
|
VARIABLE = "POPOST_TTS_CMD";
|
|
22872
22880
|
speaksHosted = (rt, voice2) => hasHostedVoice(rt) && (!toolCommand(rt, VARIABLE) || Boolean(voice2?.startsWith("popost:")));
|
|
@@ -22877,13 +22885,26 @@ var init_voice = __esm({
|
|
|
22877
22885
|
return {
|
|
22878
22886
|
remote: (voice2) => !custom || Boolean(voice2?.startsWith("popost:")),
|
|
22879
22887
|
timed: (voice2) => !custom || Boolean(voice2?.startsWith("popost:")),
|
|
22880
|
-
speak: (text13, out2, opts = {}) => !custom || opts.voice?.startsWith("popost:") ? hosted.speak(text13, out2, opts) :
|
|
22881
|
-
const file = rt.path.join(dir, "text.txt");
|
|
22882
|
-
await rt.fs.writeFile(file, text13);
|
|
22883
|
-
await runTool(rt, VARIABLE, "The speaker", [file, out2, opts.voice ?? "", String(opts.speed ?? 1)]);
|
|
22884
|
-
})
|
|
22888
|
+
speak: (text13, out2, opts = {}) => !custom || opts.voice?.startsWith("popost:") ? hosted.speak(text13, out2, opts) : speakOwn(rt, custom, text13, out2, opts)
|
|
22885
22889
|
};
|
|
22886
22890
|
};
|
|
22891
|
+
speakOwn = async (rt, command2, text13, out2, opts) => {
|
|
22892
|
+
const voice2 = "command:" + sha256(command2.join(" ")) + ":" + (opts.voice ?? "");
|
|
22893
|
+
const speed = opts.speed ?? 1;
|
|
22894
|
+
const kept3 = await keptLine(rt, voice2, text13, speed);
|
|
22895
|
+
if (kept3) {
|
|
22896
|
+
await rt.fs.writeFile(out2, kept3.audio);
|
|
22897
|
+
if (kept3.words?.length) await rt.fs.writeFile(out2 + ".words.json", JSON.stringify({ words: kept3.words }) + "\n");
|
|
22898
|
+
return;
|
|
22899
|
+
}
|
|
22900
|
+
await withTempDir(rt, "popost-video-tts-", async (dir) => {
|
|
22901
|
+
const file = rt.path.join(dir, "text.txt");
|
|
22902
|
+
await rt.fs.writeFile(file, text13);
|
|
22903
|
+
await runTool(rt, VARIABLE, "The speaker", [file, out2, opts.voice ?? "", String(speed)]);
|
|
22904
|
+
});
|
|
22905
|
+
const words = await rt.fs.readText(out2 + ".words.json").then((t) => JSON.parse(t).words, () => void 0);
|
|
22906
|
+
await keepLine(rt, voice2, text13, speed, { audio: await rt.fs.readFile(out2), operationKey: "local", ...Array.isArray(words) ? { words } : {} });
|
|
22907
|
+
};
|
|
22887
22908
|
audioSeconds = async (rt, file) => {
|
|
22888
22909
|
const r = await runFfmpeg(rt, ["-i", file, "-vn", "-f", "null", "-"]);
|
|
22889
22910
|
const times = [...r.stderr.matchAll(/time=(\d+):(\d+):([\d.]+)/g)];
|
|
@@ -23184,8 +23205,8 @@ var init_speech = __esm({
|
|
|
23184
23205
|
isVisibleSpeech = (value) => isDialogue(value) || isPlain(value);
|
|
23185
23206
|
speakersOf = (speech2) => "lines" in speech2 ? [...new Set(speech2.lines.map((l) => l.speaker))] : [speech2.speaker];
|
|
23186
23207
|
speechAudio = (speech2) => speech2 && !("lines" in speech2) ? speech2.audio : void 0;
|
|
23187
|
-
speechPrompt = (speech2) => "lines" in speech2 ? dialoguePrompt(speech2) : pl(plainSpeechPrompt(speech2), speech2.mode === "native" ? " \u51FA\u955C\u8BF4\u8BDD\u4EBA " + speech2.speaker + " \u4E00\u5B57\u4E0D\u5DEE\u5730\u8BF4\uFF1A" + JSON.stringify(speech2.text) + "\u3002\u540C\u6B65\u751F\u6210\u53EF\u89C1\u7684\u53E3\u578B\u548C\u539F\u751F\u8BED\u97F3\uFF0C\u505C\u987F\u81EA\u7136\uFF1B\u6CA1\u6709\u5176\u4ED6\u5BF9\u767D\u3001\
|
|
23188
|
-
plainSpeechPrompt = (speech2) => speech2.mode === "native" ? " Visible speaker " + speech2.speaker + " says exactly: " + JSON.stringify(speech2.text) + ". Generate synchronized visible articulation and native speech audio together, with natural pauses; no other dialogue,
|
|
23208
|
+
speechPrompt = (speech2) => "lines" in speech2 ? dialoguePrompt(speech2) : pl(plainSpeechPrompt(speech2), speech2.mode === "native" ? " \u51FA\u955C\u8BF4\u8BDD\u4EBA " + speech2.speaker + " \u4E00\u5B57\u4E0D\u5DEE\u5730\u8BF4\uFF1A" + JSON.stringify(speech2.text) + "\u3002\u540C\u6B65\u751F\u6210\u53EF\u89C1\u7684\u53E3\u578B\u548C\u539F\u751F\u8BED\u97F3\uFF0C\u505C\u987F\u81EA\u7136\uFF1B\u6CA1\u6709\u5176\u4ED6\u5BF9\u767D\u3001\u5B57\u5E55\u3001\u7FFB\u8BD1\u914D\u97F3\uFF0C\u4E5F\u6CA1\u6709\u65E0\u58F0\u7684\u5634\u90E8\u52A8\u4F5C\u3002\u751F\u6210\u7684\u8BED\u97F3\u5C31\u662F\u6700\u7EC8\u97F3\u9891\uFF0C\u4E4B\u540E\u4E0D\u4F1A\u88AB\u66FF\u6362\u3002" : " \u51FA\u955C\u8BF4\u8BDD\u4EBA " + speech2.speaker + " \u8868\u6F14\u7ED9\u5B9A\u7684\u5BF9\u767D\u3002\u6700\u7EC8\u7684\u58F0\u97F3\u53E6\u884C\u786E\u5B9A\uFF0C\u6210\u7247\u4F1A\u6309\u90A3\u6BB5\u97F3\u9891\u505A\u53E3\u578B\u540C\u6B65\u3002");
|
|
23209
|
+
plainSpeechPrompt = (speech2) => speech2.mode === "native" ? " Visible speaker " + speech2.speaker + " says exactly: " + JSON.stringify(speech2.text) + ". Generate synchronized visible articulation and native speech audio together, with natural pauses; no other dialogue, captions, translated dubbing or silent mouth motion. The generated speech audio is authoritative and will not be replaced afterwards." : " Visible speaker " + speech2.speaker + " performs the supplied dialogue. The final voice is fixed separately and the result will pass through lip synchronization to that exact audio.";
|
|
23189
23210
|
finalizeSpeech = async (rt, clip11, speech2, dir, destination = clip11) => {
|
|
23190
23211
|
const said = "lines" in speech2 ? { text: speech2.lines.map((l) => l.text).join(" "), speaker: speakersOf(speech2).join(", ") } : { text: speech2.text, speaker: speech2.speaker };
|
|
23191
23212
|
if (!said.text?.trim() || !said.speaker?.trim()) throw new Error("Visible speech needs the final text and the visible speaker id.");
|
|
@@ -23207,7 +23228,11 @@ var init_speech = __esm({
|
|
|
23207
23228
|
} else if (speech2.mode !== "native") throw new Error("Visible speech mode must be native or lip-sync.");
|
|
23208
23229
|
const p = await probe2(rt, clip11);
|
|
23209
23230
|
const audioFile = clip11 + ".speech.wav";
|
|
23210
|
-
if (!p.hasAudio)
|
|
23231
|
+
if (!p.hasAudio) {
|
|
23232
|
+
const limitation = "The video model returned this clip without sound. The generated video is retained; disclose the missing speech as a model-output limitation. No automatic retry or replacement dubbing.";
|
|
23233
|
+
await rt.fs.writeFile(clip11 + ".speech.json", JSON.stringify({ version: 1, mode: speech2.mode, speaker: said.speaker, text: said.text, videoSha256: sha256(await rt.fs.readFile(clip11)), sourceFrames: p.frames, sourceFps: p.fps, modelLimitation: limitation, hasAudio: false }, null, 2));
|
|
23234
|
+
return limitation;
|
|
23235
|
+
}
|
|
23211
23236
|
await runFfmpegOk(rt, ["-y", "-loglevel", "error", "-i", clip11, "-map", "0:a:0", "-vn", "-ac", "1", "-ar", "48000", "-c:a", "pcm_s16le", audioFile]);
|
|
23212
23237
|
const receipt = {
|
|
23213
23238
|
version: 1,
|
|
@@ -23464,6 +23489,113 @@ var init_voice_spans = __esm({
|
|
|
23464
23489
|
}
|
|
23465
23490
|
});
|
|
23466
23491
|
|
|
23492
|
+
// src/video/compile/footage.ts
|
|
23493
|
+
var probeFootage, extractSize, cacheDir, keyOf3, extractFootage, releaseFootage;
|
|
23494
|
+
var init_footage3 = __esm({
|
|
23495
|
+
"src/video/compile/footage.ts"() {
|
|
23496
|
+
"use strict";
|
|
23497
|
+
init_util();
|
|
23498
|
+
init_host();
|
|
23499
|
+
init_check3();
|
|
23500
|
+
init_frame();
|
|
23501
|
+
init_footage();
|
|
23502
|
+
init_footage2();
|
|
23503
|
+
init_frames();
|
|
23504
|
+
init_frames();
|
|
23505
|
+
probeFootage = async (rt, project, projectDir) => {
|
|
23506
|
+
const root = rt.path.resolve(rt.cwd, projectDir);
|
|
23507
|
+
const strictSpeechRoot = await rt.fs.stat(rt.path.join(root, "replication.json")) ? root : void 0;
|
|
23508
|
+
const named = project.materials.filter((m) => m.kind === "video" && m.file && !isOutside(m.file));
|
|
23509
|
+
const videos = (await Promise.all(named.map(async (m) => await rt.fs.stat(rt.path.resolve(root, m.file ?? "")) === null ? [] : [m]))).flat();
|
|
23510
|
+
const read2 = await mapLimit2(videos, heavyJobs(rt), async (m) => {
|
|
23511
|
+
try {
|
|
23512
|
+
return { id: m.id, ...await readFootage(rt, rt.path.resolve(root, m.file ?? ""), { strictSpeechRoot }) };
|
|
23513
|
+
} catch (e) {
|
|
23514
|
+
return { id: m.id, error: (e instanceof Error ? e.message : String(e)).split("\n")[0] ?? "unreadable" };
|
|
23515
|
+
}
|
|
23516
|
+
});
|
|
23517
|
+
return {
|
|
23518
|
+
native: Object.fromEntries(read2.map((x2) => [x2.id, "native" in x2 && x2.native])),
|
|
23519
|
+
info: Object.fromEntries(read2.map((x2) => [x2.id, "facts" in x2 ? x2.facts : { error: x2.error ?? "unreadable" }])),
|
|
23520
|
+
colour: Object.fromEntries(read2.flatMap((x2) => "colour" in x2 ? [[x2.id, x2.colour]] : []))
|
|
23521
|
+
};
|
|
23522
|
+
};
|
|
23523
|
+
extractSize = (r, id2, src, scale = 1) => {
|
|
23524
|
+
const W = r.canvas.width * scale;
|
|
23525
|
+
const H = r.canvas.height * scale;
|
|
23526
|
+
const need2 = (w, h, fit) => fit === "cover" ? Math.max(w / src.width, h / src.height) : Math.min(w / src.width, h / src.height);
|
|
23527
|
+
const factors = [
|
|
23528
|
+
...r.segments.flatMap((s, k) => s.base.kind === "video" && s.base.play.material === id2 ? [need2(W, H, s.base.fit) * cameraPeak(r, k)] : []),
|
|
23529
|
+
...r.items.flatMap((it) => it.play?.material === id2 ? [need2(it.box[2] * W, it.box[3] * H, it.fit ?? "contain")] : [])
|
|
23530
|
+
];
|
|
23531
|
+
const f = Math.min(1, Math.max(0, ...factors));
|
|
23532
|
+
return { width: Math.max(2, Math.round(src.width * f)), height: Math.max(2, Math.round(src.height * f)) };
|
|
23533
|
+
};
|
|
23534
|
+
cacheDir = async (rt, projectDir, rel2) => {
|
|
23535
|
+
const realpath2 = rt.fs.realpath?.bind(rt.fs);
|
|
23536
|
+
const start = rt.path.resolve(rt.cwd, projectDir);
|
|
23537
|
+
const root = realpath2 ? await realpath2(start) : start;
|
|
23538
|
+
let dir = start;
|
|
23539
|
+
for (const part of rel2.split("/")) {
|
|
23540
|
+
dir = rt.path.join(dir, part);
|
|
23541
|
+
await rt.fs.mkdir(dir);
|
|
23542
|
+
if (!realpath2) continue;
|
|
23543
|
+
const real2 = await realpath2(dir);
|
|
23544
|
+
const inside6 = rt.path.relative(root, real2);
|
|
23545
|
+
if (inside6 === "" || inside6.startsWith("..") || rt.path.isAbsolute(inside6))
|
|
23546
|
+
throw new Error("The frame cache " + dir + " resolves to " + real2 + ", outside the project directory. Remove the link so that the cache stays inside the project.");
|
|
23547
|
+
}
|
|
23548
|
+
return dir;
|
|
23549
|
+
};
|
|
23550
|
+
keyOf3 = async (rt, projectDir, src, size) => {
|
|
23551
|
+
const file = rt.path.resolve(rt.cwd, projectDir, src);
|
|
23552
|
+
const info = await rt.fs.stat(file);
|
|
23553
|
+
if (!info) throw new Error("The video material " + src + " disappeared while the page was built. Build it again.");
|
|
23554
|
+
return {
|
|
23555
|
+
key: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs, size.width, size.height])).slice(0, 16),
|
|
23556
|
+
source: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs])).slice(0, 16)
|
|
23557
|
+
};
|
|
23558
|
+
};
|
|
23559
|
+
extractFootage = async (rt, r, projectDir, probed, opts = {}) => {
|
|
23560
|
+
const t0 = performance.now();
|
|
23561
|
+
const started = rt.now().getTime();
|
|
23562
|
+
const used = usedFrames(r);
|
|
23563
|
+
const stats = { extracted: 0, reused: 0 };
|
|
23564
|
+
const jobs2 = await Promise.all(Object.entries(r.footage ?? {}).map(async ([id2, f]) => {
|
|
23565
|
+
const facts = probed.info[id2];
|
|
23566
|
+
const colour2 = probed.colour[id2];
|
|
23567
|
+
if (!facts || "error" in facts || !colour2) throw new Error('extractFootage: video material "' + id2 + '" was not probed. Pass the result of probeFootage for this project.');
|
|
23568
|
+
const size = extractSize(r, id2, facts, opts.scale);
|
|
23569
|
+
return { id: id2, f, size, colour: colour2, ...await keyOf3(rt, projectDir, f.src, size) };
|
|
23570
|
+
}));
|
|
23571
|
+
const dirs = /* @__PURE__ */ new Map();
|
|
23572
|
+
for (const j of jobs2) dirs.set(j.key, await cacheDir(rt, projectDir, FOOTAGE_CACHE + "/" + j.key));
|
|
23573
|
+
await opts.hold?.keep(jobs2.map((j) => j.key));
|
|
23574
|
+
const footage2 = {};
|
|
23575
|
+
for (const j of jobs2) {
|
|
23576
|
+
const rel2 = FOOTAGE_CACHE + "/" + j.key;
|
|
23577
|
+
const dir = dirs.get(j.key);
|
|
23578
|
+
const res = await extractFrames(rt, { file: rt.path.resolve(rt.cwd, projectDir, j.f.src), dir, frames: used.get(j.id) ?? [], ...j.size, colour: j.colour });
|
|
23579
|
+
await markUsed(rt, dir, j.source, rt.now().getTime());
|
|
23580
|
+
stats.extracted += res.extracted;
|
|
23581
|
+
stats.reused += res.reused;
|
|
23582
|
+
footage2[j.id] = { ...j.f, dir: rel2 };
|
|
23583
|
+
}
|
|
23584
|
+
const swept = await sweepFrames(rt, rt.path.resolve(rt.cwd, projectDir), { needed: jobs2.map((j) => j.key), sources: jobs2.map((j) => j.source), started, ...opts.hold ? { ownHold: opts.hold.id } : {} }).catch(() => void 0);
|
|
23585
|
+
const cache2 = swept ? { cacheBytes: swept.bytes, freedBytes: swept.freedBytes, ...swept.over ? { overCap: swept.over } : {} } : {};
|
|
23586
|
+
return { resolved: { ...r, footage: footage2 }, stats: { ...stats, ms: Math.round(performance.now() - t0), ...cache2 } };
|
|
23587
|
+
};
|
|
23588
|
+
releaseFootage = async (rt, r, projectDir, opts = {}) => {
|
|
23589
|
+
const started = rt.now().getTime();
|
|
23590
|
+
await opts.hold?.keep([]);
|
|
23591
|
+
const root = rt.path.resolve(rt.cwd, projectDir);
|
|
23592
|
+
if (!await rt.fs.stat(rt.path.join(root, FOOTAGE_CACHE))) return;
|
|
23593
|
+
const sources = await Promise.all(Object.values(r.footage ?? {}).map(async (f) => (await keyOf3(rt, projectDir, f.src, { width: 0, height: 0 })).source));
|
|
23594
|
+
await sweepFrames(rt, root, { sources, started });
|
|
23595
|
+
};
|
|
23596
|
+
}
|
|
23597
|
+
});
|
|
23598
|
+
|
|
23467
23599
|
// src/video/presets/fill.ts
|
|
23468
23600
|
var isGradient, fillColor;
|
|
23469
23601
|
var init_fill = __esm({
|
|
@@ -23834,6 +23966,7 @@ var init_retiming = __esm({
|
|
|
23834
23966
|
"use strict";
|
|
23835
23967
|
init_util();
|
|
23836
23968
|
init_check_common();
|
|
23969
|
+
init_footage3();
|
|
23837
23970
|
init_resolve();
|
|
23838
23971
|
init_io2();
|
|
23839
23972
|
init_revision();
|
|
@@ -23860,7 +23993,7 @@ var init_retiming = __esm({
|
|
|
23860
23993
|
}
|
|
23861
23994
|
const { contract } = await readReplication(rt, dir);
|
|
23862
23995
|
if (!contract) return;
|
|
23863
|
-
const r = resolve(project);
|
|
23996
|
+
const r = resolve(project, (await probeFootage(rt, project, dir)).info);
|
|
23864
23997
|
await rt.fs.writeFile(rt.path.join(dir, RETIMING_FILE), JSON.stringify({
|
|
23865
23998
|
format: "popost-video-retiming",
|
|
23866
23999
|
version: 1,
|
|
@@ -24799,18 +24932,18 @@ var init_clip_sound = __esm({
|
|
|
24799
24932
|
clipSoundOf = async (rt, dir, o) => {
|
|
24800
24933
|
const plan4 = await readMusicPlan(rt, dir);
|
|
24801
24934
|
const exceptions2 = plan4?.clipMusic ?? [];
|
|
24802
|
-
const basisOf2 = (r) => musicBasisOf(r, exceptions2);
|
|
24935
|
+
const basisOf2 = (r) => musicBasisOf(r, exceptions2) ?? (isVideo(r.file) && r.sound !== "silent" && (!plan4 || plan4.music === "none") ? "model-native" : void 0);
|
|
24803
24936
|
const why = (r, basis) => exceptions2.find((c) => c.basis === basis && (c.clip === r.file || c.clip === "all"))?.why ?? "";
|
|
24804
24937
|
const notes2 = [];
|
|
24805
|
-
if (o.clips
|
|
24938
|
+
if (o.clips) notes2.push("AI video clips generate their own speech and soundtrack. No separate voice/music selection is needed. Keep one speaker across clips; music continuity is best effort. Disclose model-output limitations without automatically regenerating or replacing audio.");
|
|
24806
24939
|
if (o.clips && plan4?.unavailable) notes2.push(plan4.unavailable);
|
|
24807
24940
|
return {
|
|
24808
24941
|
exceptions: exceptions2,
|
|
24809
|
-
modeOf: (r) => !isVideo(r.file)
|
|
24942
|
+
modeOf: (r) => !isVideo(r.file) ? void 0 : inferMode(r),
|
|
24810
24943
|
basisOf: basisOf2,
|
|
24811
24944
|
tailOf: (r, mode) => {
|
|
24812
24945
|
const basis = basisOf2(r);
|
|
24813
|
-
return soundTail(mode, basis ? { music: basis } : {});
|
|
24946
|
+
return soundTail(mode, basis ? { music: basis } : { externalMusic: !!plan4 && plan4.music !== "none" });
|
|
24814
24947
|
},
|
|
24815
24948
|
uses: (requests) => requests.flatMap((r) => {
|
|
24816
24949
|
const basis = isVideo(r.file) && r.sound !== "silent" ? basisOf2(r) : void 0;
|
|
@@ -25625,7 +25758,10 @@ var init_generate = __esm({
|
|
|
25625
25758
|
if (made.credits !== void 0) entry2 = { ...entry2, credits: made.credits };
|
|
25626
25759
|
if (charged !== void 0) entry2 = { ...entry2, chargedCredits: charged };
|
|
25627
25760
|
if (!await exists4(partial)) throw new Error("The generator finished without writing the file.");
|
|
25628
|
-
if (sent)
|
|
25761
|
+
if (sent) {
|
|
25762
|
+
const limitation = await finalizeSpeech(rt, partial, sent, o.dir, target2);
|
|
25763
|
+
if (limitation) said.push(asked3.file + ": " + limitation);
|
|
25764
|
+
}
|
|
25629
25765
|
const stripped = mode === "silent" && await probe2(rt, partial).then((p) => p.hasAudio, () => false) ? await stripSound(rt, partial) : false;
|
|
25630
25766
|
const receipt = o.provider ? materialReceiptFile(asked3.file) : void 0;
|
|
25631
25767
|
const provenance = o.provider ? {
|
|
@@ -25643,7 +25779,9 @@ var init_generate = __esm({
|
|
|
25643
25779
|
}
|
|
25644
25780
|
if (made.task) entry2 = { ...entry2, task: made.task };
|
|
25645
25781
|
if (mode) await writeModeReceipt(rt, target2, { sound: mode, ...basis ? { clipMusic: basis } : {}, ...stripped ? { stripped: true } : {} });
|
|
25646
|
-
if (asked3.speech)
|
|
25782
|
+
if (asked3.speech) {
|
|
25783
|
+
for (const ext of [".speech.wav", ".speech.json"]) if (await exists4(partial + ext)) await rt.fs.rename(partial + ext, target2 + ext);
|
|
25784
|
+
}
|
|
25647
25785
|
if (cast || asked3.speech) await rt.fs.writeFile(target2 + ".generation.json", signature2);
|
|
25648
25786
|
if (shown3) await rt.fs.writeFile(receiptFile(target2), JSON.stringify(shown3.receipt, null, 2));
|
|
25649
25787
|
entry2 = { ...entry2, made: true, ...priceOnly ? { unanchored: true, waitsFor: priced } : {} };
|
|
@@ -27935,113 +28073,6 @@ var init_page = __esm({
|
|
|
27935
28073
|
}
|
|
27936
28074
|
});
|
|
27937
28075
|
|
|
27938
|
-
// src/video/compile/footage.ts
|
|
27939
|
-
var probeFootage, extractSize, cacheDir, keyOf3, extractFootage, releaseFootage;
|
|
27940
|
-
var init_footage3 = __esm({
|
|
27941
|
-
"src/video/compile/footage.ts"() {
|
|
27942
|
-
"use strict";
|
|
27943
|
-
init_util();
|
|
27944
|
-
init_host();
|
|
27945
|
-
init_check3();
|
|
27946
|
-
init_frame();
|
|
27947
|
-
init_footage();
|
|
27948
|
-
init_footage2();
|
|
27949
|
-
init_frames();
|
|
27950
|
-
init_frames();
|
|
27951
|
-
probeFootage = async (rt, project, projectDir) => {
|
|
27952
|
-
const root = rt.path.resolve(rt.cwd, projectDir);
|
|
27953
|
-
const strictSpeechRoot = await rt.fs.stat(rt.path.join(root, "replication.json")) ? root : void 0;
|
|
27954
|
-
const named = project.materials.filter((m) => m.kind === "video" && m.file && !isOutside(m.file));
|
|
27955
|
-
const videos = (await Promise.all(named.map(async (m) => await rt.fs.stat(rt.path.resolve(root, m.file ?? "")) === null ? [] : [m]))).flat();
|
|
27956
|
-
const read2 = await mapLimit2(videos, heavyJobs(rt), async (m) => {
|
|
27957
|
-
try {
|
|
27958
|
-
return { id: m.id, ...await readFootage(rt, rt.path.resolve(root, m.file ?? ""), { strictSpeechRoot }) };
|
|
27959
|
-
} catch (e) {
|
|
27960
|
-
return { id: m.id, error: (e instanceof Error ? e.message : String(e)).split("\n")[0] ?? "unreadable" };
|
|
27961
|
-
}
|
|
27962
|
-
});
|
|
27963
|
-
return {
|
|
27964
|
-
native: Object.fromEntries(read2.map((x2) => [x2.id, "native" in x2 && x2.native])),
|
|
27965
|
-
info: Object.fromEntries(read2.map((x2) => [x2.id, "facts" in x2 ? x2.facts : { error: x2.error ?? "unreadable" }])),
|
|
27966
|
-
colour: Object.fromEntries(read2.flatMap((x2) => "colour" in x2 ? [[x2.id, x2.colour]] : []))
|
|
27967
|
-
};
|
|
27968
|
-
};
|
|
27969
|
-
extractSize = (r, id2, src, scale = 1) => {
|
|
27970
|
-
const W = r.canvas.width * scale;
|
|
27971
|
-
const H = r.canvas.height * scale;
|
|
27972
|
-
const need2 = (w, h, fit) => fit === "cover" ? Math.max(w / src.width, h / src.height) : Math.min(w / src.width, h / src.height);
|
|
27973
|
-
const factors = [
|
|
27974
|
-
...r.segments.flatMap((s, k) => s.base.kind === "video" && s.base.play.material === id2 ? [need2(W, H, s.base.fit) * cameraPeak(r, k)] : []),
|
|
27975
|
-
...r.items.flatMap((it) => it.play?.material === id2 ? [need2(it.box[2] * W, it.box[3] * H, it.fit ?? "contain")] : [])
|
|
27976
|
-
];
|
|
27977
|
-
const f = Math.min(1, Math.max(0, ...factors));
|
|
27978
|
-
return { width: Math.max(2, Math.round(src.width * f)), height: Math.max(2, Math.round(src.height * f)) };
|
|
27979
|
-
};
|
|
27980
|
-
cacheDir = async (rt, projectDir, rel2) => {
|
|
27981
|
-
const realpath2 = rt.fs.realpath?.bind(rt.fs);
|
|
27982
|
-
const start = rt.path.resolve(rt.cwd, projectDir);
|
|
27983
|
-
const root = realpath2 ? await realpath2(start) : start;
|
|
27984
|
-
let dir = start;
|
|
27985
|
-
for (const part of rel2.split("/")) {
|
|
27986
|
-
dir = rt.path.join(dir, part);
|
|
27987
|
-
await rt.fs.mkdir(dir);
|
|
27988
|
-
if (!realpath2) continue;
|
|
27989
|
-
const real2 = await realpath2(dir);
|
|
27990
|
-
const inside6 = rt.path.relative(root, real2);
|
|
27991
|
-
if (inside6 === "" || inside6.startsWith("..") || rt.path.isAbsolute(inside6))
|
|
27992
|
-
throw new Error("The frame cache " + dir + " resolves to " + real2 + ", outside the project directory. Remove the link so that the cache stays inside the project.");
|
|
27993
|
-
}
|
|
27994
|
-
return dir;
|
|
27995
|
-
};
|
|
27996
|
-
keyOf3 = async (rt, projectDir, src, size) => {
|
|
27997
|
-
const file = rt.path.resolve(rt.cwd, projectDir, src);
|
|
27998
|
-
const info = await rt.fs.stat(file);
|
|
27999
|
-
if (!info) throw new Error("The video material " + src + " disappeared while the page was built. Build it again.");
|
|
28000
|
-
return {
|
|
28001
|
-
key: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs, size.width, size.height])).slice(0, 16),
|
|
28002
|
-
source: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs])).slice(0, 16)
|
|
28003
|
-
};
|
|
28004
|
-
};
|
|
28005
|
-
extractFootage = async (rt, r, projectDir, probed, opts = {}) => {
|
|
28006
|
-
const t0 = performance.now();
|
|
28007
|
-
const started = rt.now().getTime();
|
|
28008
|
-
const used = usedFrames(r);
|
|
28009
|
-
const stats = { extracted: 0, reused: 0 };
|
|
28010
|
-
const jobs2 = await Promise.all(Object.entries(r.footage ?? {}).map(async ([id2, f]) => {
|
|
28011
|
-
const facts = probed.info[id2];
|
|
28012
|
-
const colour2 = probed.colour[id2];
|
|
28013
|
-
if (!facts || "error" in facts || !colour2) throw new Error('extractFootage: video material "' + id2 + '" was not probed. Pass the result of probeFootage for this project.');
|
|
28014
|
-
const size = extractSize(r, id2, facts, opts.scale);
|
|
28015
|
-
return { id: id2, f, size, colour: colour2, ...await keyOf3(rt, projectDir, f.src, size) };
|
|
28016
|
-
}));
|
|
28017
|
-
const dirs = /* @__PURE__ */ new Map();
|
|
28018
|
-
for (const j of jobs2) dirs.set(j.key, await cacheDir(rt, projectDir, FOOTAGE_CACHE + "/" + j.key));
|
|
28019
|
-
await opts.hold?.keep(jobs2.map((j) => j.key));
|
|
28020
|
-
const footage2 = {};
|
|
28021
|
-
for (const j of jobs2) {
|
|
28022
|
-
const rel2 = FOOTAGE_CACHE + "/" + j.key;
|
|
28023
|
-
const dir = dirs.get(j.key);
|
|
28024
|
-
const res = await extractFrames(rt, { file: rt.path.resolve(rt.cwd, projectDir, j.f.src), dir, frames: used.get(j.id) ?? [], ...j.size, colour: j.colour });
|
|
28025
|
-
await markUsed(rt, dir, j.source, rt.now().getTime());
|
|
28026
|
-
stats.extracted += res.extracted;
|
|
28027
|
-
stats.reused += res.reused;
|
|
28028
|
-
footage2[j.id] = { ...j.f, dir: rel2 };
|
|
28029
|
-
}
|
|
28030
|
-
const swept = await sweepFrames(rt, rt.path.resolve(rt.cwd, projectDir), { needed: jobs2.map((j) => j.key), sources: jobs2.map((j) => j.source), started, ...opts.hold ? { ownHold: opts.hold.id } : {} }).catch(() => void 0);
|
|
28031
|
-
const cache2 = swept ? { cacheBytes: swept.bytes, freedBytes: swept.freedBytes, ...swept.over ? { overCap: swept.over } : {} } : {};
|
|
28032
|
-
return { resolved: { ...r, footage: footage2 }, stats: { ...stats, ms: Math.round(performance.now() - t0), ...cache2 } };
|
|
28033
|
-
};
|
|
28034
|
-
releaseFootage = async (rt, r, projectDir, opts = {}) => {
|
|
28035
|
-
const started = rt.now().getTime();
|
|
28036
|
-
await opts.hold?.keep([]);
|
|
28037
|
-
const root = rt.path.resolve(rt.cwd, projectDir);
|
|
28038
|
-
if (!await rt.fs.stat(rt.path.join(root, FOOTAGE_CACHE))) return;
|
|
28039
|
-
const sources = await Promise.all(Object.values(r.footage ?? {}).map(async (f) => (await keyOf3(rt, projectDir, f.src, { width: 0, height: 0 })).source));
|
|
28040
|
-
await sweepFrames(rt, root, { sources, started });
|
|
28041
|
-
};
|
|
28042
|
-
}
|
|
28043
|
-
});
|
|
28044
|
-
|
|
28045
28076
|
// src/video/project/words.ts
|
|
28046
28077
|
import { z as z7 } from "zod";
|
|
28047
28078
|
var TokenSchema, WordsFileSchema, FORMAT3, VoiceWordsSchema, VOICE_FPS, voiceTokens, tokenError, parseWordsFile;
|
|
@@ -28144,6 +28175,7 @@ var init_speech_lock = __esm({
|
|
|
28144
28175
|
"src/video/generate/speech-lock.ts"() {
|
|
28145
28176
|
"use strict";
|
|
28146
28177
|
init_util();
|
|
28178
|
+
init_ffmpeg();
|
|
28147
28179
|
init_footage();
|
|
28148
28180
|
init_check_common();
|
|
28149
28181
|
checkSpeechLocks = async (rt, dir, r) => {
|
|
@@ -28163,6 +28195,10 @@ var init_speech_lock = __esm({
|
|
|
28163
28195
|
out2.push(error("materials." + id2, "This speaking clip changed after its audio was locked.", fix2));
|
|
28164
28196
|
continue;
|
|
28165
28197
|
}
|
|
28198
|
+
if (lock.hasAudio === false && !(await probe2(rt, file)).hasAudio) {
|
|
28199
|
+
out2.push(warning("materials." + id2, lock.modelLimitation ?? "The model returned no native audio.", "Disclose this model-output limitation; preserve the paid clip without automatically replacing or regenerating its sound."));
|
|
28200
|
+
continue;
|
|
28201
|
+
}
|
|
28166
28202
|
for (const use2 of playsOf(r).filter((p) => p.play.material === id2)) {
|
|
28167
28203
|
const first = Math.max(0, use2.first, use2.play.start), last = Math.min(r.frames - 1, use2.last);
|
|
28168
28204
|
if (last < first) continue;
|
|
@@ -34875,16 +34911,16 @@ var init_speech_check = __esm({
|
|
|
34875
34911
|
SPEECH_PROBLEM = "speech-not-as-written";
|
|
34876
34912
|
speechMatchProblems = (file, m, key2) => {
|
|
34877
34913
|
if (m.share >= MATCH_FLOOR) return m.missing.length || m.extra.length ? [warning(file, "The clip says " + m.matched + " of the " + m.script + " words of its script" + (m.missing.length ? "; not heard: " + m.missing.join(" ") : "") + (m.extra.length ? "; heard besides: " + m.extra.join(" ") : "") + ".", "Listen to it; a recogniser mishears a word now and then. The captions and the mix follow the measured times.")] : [];
|
|
34878
|
-
return [
|
|
34914
|
+
return [warning(
|
|
34879
34915
|
file,
|
|
34880
34916
|
SPEECH_PROBLEM + ": the clip says " + m.matched + " of the " + m.script + " words of its script (" + Math.round(m.share * 100) + "%, under " + Math.round(MATCH_FLOOR * 100) + "%)" + (m.missing.length ? "; not heard: " + m.missing.join(" ") : "") + (m.extra.length ? "; heard besides: " + m.extra.join(" ") : "") + ".",
|
|
34881
|
-
"Listen to the
|
|
34917
|
+
"Listen to confirm the actual words. Disclose this model-output limitation and preserve the generated clip; no automatic regeneration or replacement dubbing." + (key2 ? " Request key: " + key2 : "")
|
|
34882
34918
|
)];
|
|
34883
34919
|
};
|
|
34884
|
-
silentClipProblems = (file) => [
|
|
34920
|
+
silentClipProblems = (file) => [warning(
|
|
34885
34921
|
file,
|
|
34886
34922
|
SPEECH_PROBLEM + ": the clip has no sound (no audio stream), so it says none of its lines.",
|
|
34887
|
-
"
|
|
34923
|
+
"Disclose missing native speech as a model-output limitation. Keep the generated video; do not automatically regenerate or add replacement audio."
|
|
34888
34924
|
)];
|
|
34889
34925
|
receiptOf = (rt, clip11) => rt.fs.readText(clip11 + ".speech.json").then((t) => JSON.parse(t), () => void 0);
|
|
34890
34926
|
keptMeasurement = async (rt, dir, file) => {
|
|
@@ -37212,7 +37248,7 @@ var init_readback_frames = __esm({
|
|
|
37212
37248
|
});
|
|
37213
37249
|
|
|
37214
37250
|
// src/video/eval/readback-kept.ts
|
|
37215
|
-
var TEXT_CACHE, FORMAT4, readerOf, keptLines, keptReader;
|
|
37251
|
+
var TEXT_CACHE, FORMAT4, readerOf, keptLines, keepLines, keptReader;
|
|
37216
37252
|
var init_readback_kept = __esm({
|
|
37217
37253
|
"src/video/eval/readback-kept.ts"() {
|
|
37218
37254
|
"use strict";
|
|
@@ -37226,6 +37262,15 @@ var init_readback_kept = __esm({
|
|
|
37226
37262
|
const ok = kept3?.format === FORMAT4 && kept3.version === 1 && kept3.reader === reader && typeof kept3.frames === "object" && kept3.frames !== null;
|
|
37227
37263
|
return ok ? kept3.frames : {};
|
|
37228
37264
|
};
|
|
37265
|
+
keepLines = async (rt, file, kept3) => {
|
|
37266
|
+
const temporary = file + "." + rt.randomUUID() + ".tmp";
|
|
37267
|
+
try {
|
|
37268
|
+
await rt.fs.writeFile(temporary, JSON.stringify(kept3) + "\n");
|
|
37269
|
+
await rt.fs.rename(temporary, file);
|
|
37270
|
+
} catch {
|
|
37271
|
+
await rt.fs.rm(temporary).catch(() => void 0);
|
|
37272
|
+
}
|
|
37273
|
+
};
|
|
37229
37274
|
keptReader = (rt, file, reader, onKept) => ({
|
|
37230
37275
|
read: async (frames) => {
|
|
37231
37276
|
if (rt.env.POPOST_VIDEO_CACHE === "off") return reader.read(frames);
|
|
@@ -37239,8 +37284,7 @@ var init_readback_kept = __esm({
|
|
|
37239
37284
|
const lines2 = old[i] ?? read2.get(f.frame);
|
|
37240
37285
|
return lines2 ? [{ hash: hashes2[i], sample: { frame: f.frame, lines: lines2 } }] : [];
|
|
37241
37286
|
});
|
|
37242
|
-
|
|
37243
|
-
await rt.fs.writeFile(file, JSON.stringify(keep3) + "\n");
|
|
37287
|
+
await keepLines(rt, file, { format: FORMAT4, version: 1, reader: who, frames: Object.fromEntries(found.map((x2) => [x2.hash, x2.sample.lines])) });
|
|
37244
37288
|
return found.map((x2) => x2.sample).sort((a, b) => a.frame - b.frame);
|
|
37245
37289
|
}
|
|
37246
37290
|
});
|
|
@@ -37392,84 +37436,8 @@ var init_pictures = __esm({
|
|
|
37392
37436
|
}
|
|
37393
37437
|
});
|
|
37394
37438
|
|
|
37395
|
-
// src/video/look/index.ts
|
|
37396
|
-
var two11, r36, clamp4, shotMoments, secondMoments, GLYPHS, labelFilter, JPEG, pair3, sheet3, lookAt3;
|
|
37397
|
-
var init_look2 = __esm({
|
|
37398
|
-
"src/video/look/index.ts"() {
|
|
37399
|
-
"use strict";
|
|
37400
|
-
init_host();
|
|
37401
|
-
init_decode();
|
|
37402
|
-
init_ffmpeg();
|
|
37403
|
-
init_pictures();
|
|
37404
|
-
two11 = (n) => String(n).padStart(2, "0");
|
|
37405
|
-
r36 = (v) => Math.round(v * 1e3) / 1e3;
|
|
37406
|
-
clamp4 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
37407
|
-
shotMoments = (shots2) => shots2.flatMap((s, k) => lookTimes(s.start, s.end, 3).map((t, j) => {
|
|
37408
|
-
const part = ["a", "b", "c"][j] ?? "a";
|
|
37409
|
-
return { name: "shot-" + two11(k + 1) + "-" + part, frame: clamp4(Math.round(t), s.start, Math.max(s.start, s.end - 1)), shot: k + 1, part };
|
|
37410
|
-
}));
|
|
37411
|
-
secondMoments = (seconds8, fps, frames) => seconds8.map((s, i) => ({ name: "at-" + two11(i + 1), frame: clamp4(Math.round(s * fps), 0, Math.max(0, frames - 1)) }));
|
|
37412
|
-
GLYPHS = {
|
|
37413
|
-
A: [".###.", "#...#", "#...#", "#####", "#...#", "#...#", "#...#"],
|
|
37414
|
-
B: ["####.", "#...#", "#...#", "####.", "#...#", "#...#", "####."]
|
|
37415
|
-
};
|
|
37416
|
-
labelFilter = (letter, height) => {
|
|
37417
|
-
const s = Math.max(2, Math.round(height / 60));
|
|
37418
|
-
const box2 = (x2, y, w, h, color2) => "drawbox=x=" + x2 + ":y=" + y + ":w=" + w + ":h=" + h + ":color=" + color2 + ":t=fill";
|
|
37419
|
-
const cells = GLYPHS[letter].flatMap((row, y) => [...row.matchAll(/#+/g)].map((m) => box2(2 * s + (m.index ?? 0) * s, 2 * s + y * s, m[0].length * s, s, "white")));
|
|
37420
|
-
return [box2(s, s, 7 * s, 9 * s, "black@0.6"), ...cells].join(",");
|
|
37421
|
-
};
|
|
37422
|
-
JPEG = ["-q:v", "3"];
|
|
37423
|
-
pair3 = async (rt, a, b, height, out2) => {
|
|
37424
|
-
const side = (i, letter) => "[" + i + ":v]scale=-2:" + height + "," + labelFilter(letter, height) + "[" + letter + "]";
|
|
37425
|
-
await runFfmpegOk(rt, ["-y", "-loglevel", "error", "-i", a, "-i", b, "-filter_complex", side(0, "A") + ";" + side(1, "B") + ";[A][B]hstack=inputs=2", "-frames:v", "1", ...JPEG, out2]);
|
|
37426
|
-
};
|
|
37427
|
-
sheet3 = async (rt, files, out2) => {
|
|
37428
|
-
await runFfmpegOk(rt, ["-y", "-loglevel", "error", ...files.flatMap((f) => ["-i", f]), "-filter_complex", files.map((_f, i) => "[" + i + ":v]").join("") + "hstack=inputs=" + files.length, "-frames:v", "1", ...JPEG, out2]);
|
|
37429
|
-
};
|
|
37430
|
-
lookAt3 = async (rt, o) => {
|
|
37431
|
-
const width = o.width ?? 480;
|
|
37432
|
-
const a = await probe2(rt, o.video);
|
|
37433
|
-
const b = o.against === void 0 ? void 0 : await probe2(rt, o.against);
|
|
37434
|
-
const { height } = thumbSize(a.width, a.height, width);
|
|
37435
|
-
const against = o.against;
|
|
37436
|
-
await rt.fs.mkdir(o.outDir);
|
|
37437
|
-
const pictures = [];
|
|
37438
|
-
await withTempDir(rt, "popost-video-look-", async (dir) => {
|
|
37439
|
-
const left = await extractFrames2(rt, o.video, o.moments.map((m) => m.frame), rt.path.join(dir, "a"), width);
|
|
37440
|
-
const others = b ? o.moments.map((m) => clamp4(m.against ?? Math.round(m.frame / Math.max(1, a.frames) * b.frames), 0, Math.max(0, b.frames - 1))) : [];
|
|
37441
|
-
const right = b && against !== void 0 ? await extractFrames2(rt, against, others, rt.path.join(dir, "b"), width) : void 0;
|
|
37442
|
-
for (const [i, m] of o.moments.entries()) {
|
|
37443
|
-
const file = rt.path.join(o.outDir, m.name + ".jpg");
|
|
37444
|
-
const where3 = { ...m.shot === void 0 ? {} : { shot: m.shot }, ...m.part ? { part: m.part } : {} };
|
|
37445
|
-
if (!b || against === void 0) {
|
|
37446
|
-
const picture3 = left.get(m.frame);
|
|
37447
|
-
if (rt.fs.copyFile) await rt.fs.copyFile(picture3, file);
|
|
37448
|
-
else await rt.fs.writeFile(file, await rt.fs.readFile(picture3));
|
|
37449
|
-
pictures.push({ file, frame: m.frame, second: r36(m.frame / a.fps), ...where3 });
|
|
37450
|
-
continue;
|
|
37451
|
-
}
|
|
37452
|
-
const other = others[i];
|
|
37453
|
-
await pair3(rt, left.get(m.frame), right?.get(other), height, file);
|
|
37454
|
-
pictures.push({ file, frame: m.frame, second: r36(m.frame / a.fps), ...where3, against: { frame: other, second: r36(other / b.fps) } });
|
|
37455
|
-
}
|
|
37456
|
-
});
|
|
37457
|
-
const shots2 = [...new Set(pictures.flatMap((p) => p.shot === void 0 ? [] : [p.shot]))];
|
|
37458
|
-
const sheets = [];
|
|
37459
|
-
for (const shot of shots2) {
|
|
37460
|
-
const mine = pictures.filter((p) => p.shot === shot).map((p) => p.file);
|
|
37461
|
-
if (mine.length !== 3) continue;
|
|
37462
|
-
const file = rt.path.join(o.outDir, "shot-" + two11(shot) + ".jpg");
|
|
37463
|
-
await sheet3(rt, mine, file);
|
|
37464
|
-
sheets.push({ file, shot, pictures: mine });
|
|
37465
|
-
}
|
|
37466
|
-
return { pictures, sheets };
|
|
37467
|
-
};
|
|
37468
|
-
}
|
|
37469
|
-
});
|
|
37470
|
-
|
|
37471
37439
|
// src/video/look/sheets.ts
|
|
37472
|
-
var GAP2, BAND, MAX_WIDTH2, GROUND, INK2, MARK, MARK_INK,
|
|
37440
|
+
var GAP2, BAND, MAX_WIDTH2, GROUND, INK2, MARK, MARK_INK, GLYPHS, gridOf, timeLabel, fill2, write, blit, decodePicked, place2, LOOK_JPEG, LOOK_MAX_PIXELS, lookSize, encodeJpeg, writeSheets2;
|
|
37473
37441
|
var init_sheets = __esm({
|
|
37474
37442
|
"src/video/look/sheets.ts"() {
|
|
37475
37443
|
"use strict";
|
|
@@ -37484,7 +37452,7 @@ var init_sheets = __esm({
|
|
|
37484
37452
|
INK2 = [240, 240, 240];
|
|
37485
37453
|
MARK = [232, 160, 32];
|
|
37486
37454
|
MARK_INK = [16, 16, 16];
|
|
37487
|
-
|
|
37455
|
+
GLYPHS = {
|
|
37488
37456
|
"0": [".###.", "#...#", "#..##", "#.#.#", "##..#", "#...#", ".###."],
|
|
37489
37457
|
"1": ["..#..", ".##..", "..#..", "..#..", "..#..", "..#..", ".###."],
|
|
37490
37458
|
"2": [".###.", "#...#", "....#", "...#.", "..#..", ".#...", "#####"],
|
|
@@ -37516,7 +37484,7 @@ var init_sheets = __esm({
|
|
|
37516
37484
|
};
|
|
37517
37485
|
write = (c, text13, x2, y, s, rgb) => {
|
|
37518
37486
|
[...text13].forEach((ch, k) => {
|
|
37519
|
-
const rows3 =
|
|
37487
|
+
const rows3 = GLYPHS[ch];
|
|
37520
37488
|
if (!rows3) return;
|
|
37521
37489
|
rows3.forEach((row, r) => [...row].forEach((cell, q) => {
|
|
37522
37490
|
if (cell === "#") fill2(c, x2 + (k * 6 + q) * s, y + r * s, s, s, rgb);
|
|
@@ -37550,7 +37518,7 @@ var init_sheets = __esm({
|
|
|
37550
37518
|
}
|
|
37551
37519
|
};
|
|
37552
37520
|
place2 = (d, slot, rgb, tw, th, label2, marked2) => {
|
|
37553
|
-
const { width, height } = d.
|
|
37521
|
+
const { width, height } = d.drawn;
|
|
37554
37522
|
d.canvas ??= (() => {
|
|
37555
37523
|
const c = { width, height, data: new Uint8Array(width * height * 3) };
|
|
37556
37524
|
fill2(c, 0, 0, width, height, GROUND);
|
|
@@ -37562,9 +37530,16 @@ var init_sheets = __esm({
|
|
|
37562
37530
|
const s = 2, w = (label2.length * 6 - 1) * s;
|
|
37563
37531
|
write(d.canvas, label2, x2 + Math.max(0, Math.round((tw - w) / 2)), y + th + 2, s, marked2 ? MARK_INK : INK2);
|
|
37564
37532
|
};
|
|
37565
|
-
|
|
37533
|
+
LOOK_JPEG = ["-q:v", "5"];
|
|
37534
|
+
LOOK_MAX_PIXELS = 115e4;
|
|
37535
|
+
lookSize = (width, height) => {
|
|
37536
|
+
const k = Math.min(1, Math.sqrt(LOOK_MAX_PIXELS / Math.max(1, width * height)));
|
|
37537
|
+
return k === 1 ? { width, height } : { width: 2 * Math.floor(width * k / 2), height: 2 * Math.floor(height * k / 2) };
|
|
37538
|
+
};
|
|
37539
|
+
encodeJpeg = async (rt, c, file, out2) => {
|
|
37566
37540
|
await rt.fs.mkdir(rt.path.dirname(file));
|
|
37567
|
-
|
|
37541
|
+
const scale = out2.width === c.width && out2.height === c.height ? [] : ["-vf", "scale=" + out2.width + ":" + out2.height + ":flags=area"];
|
|
37542
|
+
await runFfmpegOk(rt, ["-y", "-loglevel", "error", "-f", "rawvideo", "-pix_fmt", "rgb24", "-s", c.width + "x" + c.height, "-i", "pipe:0", "-frames:v", "1", ...scale, ...LOOK_JPEG, file], c.data);
|
|
37568
37543
|
};
|
|
37569
37544
|
writeSheets2 = async (rt, video, specs2, o) => {
|
|
37570
37545
|
const p = o.probe ?? await probe2(rt, video);
|
|
@@ -37576,9 +37551,9 @@ var init_sheets = __esm({
|
|
|
37576
37551
|
const drawings = specs2.map((spec10) => {
|
|
37577
37552
|
const frames2 = spec10.frames.filter((f) => f >= 0 && f <= last);
|
|
37578
37553
|
const grid = gridOf(Math.max(1, frames2.length), size.width);
|
|
37579
|
-
const
|
|
37580
|
-
const result = { file: rt.path.join(o.outDir, spec10.file), frames: frames2, seconds: frames2.map((f) => Math.round(secondsOf4(f) * 1e3) / 1e3), ...grid, width, height };
|
|
37581
|
-
return { spec: { ...spec10, frames: frames2 }, grid, left: frames2.length, result };
|
|
37554
|
+
const drawn = { width: GAP2 + grid.columns * (size.width + GAP2), height: GAP2 + grid.rows * (size.height + BAND + GAP2) };
|
|
37555
|
+
const result = { file: rt.path.join(o.outDir, spec10.file), frames: frames2, seconds: frames2.map((f) => Math.round(secondsOf4(f) * 1e3) / 1e3), ...grid, ...lookSize(drawn.width, drawn.height) };
|
|
37556
|
+
return { spec: { ...spec10, frames: frames2 }, grid, drawn, left: frames2.length, result };
|
|
37582
37557
|
});
|
|
37583
37558
|
const wanted = /* @__PURE__ */ new Map();
|
|
37584
37559
|
for (const d of drawings) d.spec.frames.forEach((f, slot) => {
|
|
@@ -37593,7 +37568,7 @@ var init_sheets = __esm({
|
|
|
37593
37568
|
d.canvas = void 0;
|
|
37594
37569
|
if (!canvas) return;
|
|
37595
37570
|
d.written = true;
|
|
37596
|
-
written2 = written2.then(() => failed4 ? void 0 : encodeJpeg(rt, canvas, d.result.file)).catch((error2) => {
|
|
37571
|
+
written2 = written2.then(() => failed4 ? void 0 : encodeJpeg(rt, canvas, d.result.file, d.result)).catch((error2) => {
|
|
37597
37572
|
failed4 ??= { error: error2 };
|
|
37598
37573
|
});
|
|
37599
37574
|
};
|
|
@@ -37614,6 +37589,83 @@ var init_sheets = __esm({
|
|
|
37614
37589
|
}
|
|
37615
37590
|
});
|
|
37616
37591
|
|
|
37592
|
+
// src/video/look/index.ts
|
|
37593
|
+
var two11, r36, clamp4, shotMoments, secondMoments, GLYPHS2, labelFilter, JPEG, pair3, sheet3, lookAt3;
|
|
37594
|
+
var init_look2 = __esm({
|
|
37595
|
+
"src/video/look/index.ts"() {
|
|
37596
|
+
"use strict";
|
|
37597
|
+
init_host();
|
|
37598
|
+
init_decode();
|
|
37599
|
+
init_ffmpeg();
|
|
37600
|
+
init_pictures();
|
|
37601
|
+
init_sheets();
|
|
37602
|
+
two11 = (n) => String(n).padStart(2, "0");
|
|
37603
|
+
r36 = (v) => Math.round(v * 1e3) / 1e3;
|
|
37604
|
+
clamp4 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
37605
|
+
shotMoments = (shots2) => shots2.flatMap((s, k) => lookTimes(s.start, s.end, 3).map((t, j) => {
|
|
37606
|
+
const part = ["a", "b", "c"][j] ?? "a";
|
|
37607
|
+
return { name: "shot-" + two11(k + 1) + "-" + part, frame: clamp4(Math.round(t), s.start, Math.max(s.start, s.end - 1)), shot: k + 1, part };
|
|
37608
|
+
}));
|
|
37609
|
+
secondMoments = (seconds8, fps, frames) => seconds8.map((s, i) => ({ name: "at-" + two11(i + 1), frame: clamp4(Math.round(s * fps), 0, Math.max(0, frames - 1)) }));
|
|
37610
|
+
GLYPHS2 = {
|
|
37611
|
+
A: [".###.", "#...#", "#...#", "#####", "#...#", "#...#", "#...#"],
|
|
37612
|
+
B: ["####.", "#...#", "#...#", "####.", "#...#", "#...#", "####."]
|
|
37613
|
+
};
|
|
37614
|
+
labelFilter = (letter, height) => {
|
|
37615
|
+
const s = Math.max(2, Math.round(height / 60));
|
|
37616
|
+
const box2 = (x2, y, w, h, color2) => "drawbox=x=" + x2 + ":y=" + y + ":w=" + w + ":h=" + h + ":color=" + color2 + ":t=fill";
|
|
37617
|
+
const cells = GLYPHS2[letter].flatMap((row, y) => [...row.matchAll(/#+/g)].map((m) => box2(2 * s + (m.index ?? 0) * s, 2 * s + y * s, m[0].length * s, s, "white")));
|
|
37618
|
+
return [box2(s, s, 7 * s, 9 * s, "black@0.6"), ...cells].join(",");
|
|
37619
|
+
};
|
|
37620
|
+
JPEG = LOOK_JPEG;
|
|
37621
|
+
pair3 = async (rt, a, b, height, out2) => {
|
|
37622
|
+
const side = (i, letter) => "[" + i + ":v]scale=-2:" + height + "," + labelFilter(letter, height) + "[" + letter + "]";
|
|
37623
|
+
await runFfmpegOk(rt, ["-y", "-loglevel", "error", "-i", a, "-i", b, "-filter_complex", side(0, "A") + ";" + side(1, "B") + ";[A][B]hstack=inputs=2", "-frames:v", "1", ...JPEG, out2]);
|
|
37624
|
+
};
|
|
37625
|
+
sheet3 = async (rt, files, out2) => {
|
|
37626
|
+
await runFfmpegOk(rt, ["-y", "-loglevel", "error", ...files.flatMap((f) => ["-i", f]), "-filter_complex", files.map((_f, i) => "[" + i + ":v]").join("") + "hstack=inputs=" + files.length, "-frames:v", "1", ...JPEG, out2]);
|
|
37627
|
+
};
|
|
37628
|
+
lookAt3 = async (rt, o) => {
|
|
37629
|
+
const width = o.width ?? 480;
|
|
37630
|
+
const a = await probe2(rt, o.video);
|
|
37631
|
+
const b = o.against === void 0 ? void 0 : await probe2(rt, o.against);
|
|
37632
|
+
const { height } = thumbSize(a.width, a.height, width);
|
|
37633
|
+
const against = o.against;
|
|
37634
|
+
await rt.fs.mkdir(o.outDir);
|
|
37635
|
+
const pictures = [];
|
|
37636
|
+
await withTempDir(rt, "popost-video-look-", async (dir) => {
|
|
37637
|
+
const left = await extractFrames2(rt, o.video, o.moments.map((m) => m.frame), rt.path.join(dir, "a"), width);
|
|
37638
|
+
const others = b ? o.moments.map((m) => clamp4(m.against ?? Math.round(m.frame / Math.max(1, a.frames) * b.frames), 0, Math.max(0, b.frames - 1))) : [];
|
|
37639
|
+
const right = b && against !== void 0 ? await extractFrames2(rt, against, others, rt.path.join(dir, "b"), width) : void 0;
|
|
37640
|
+
for (const [i, m] of o.moments.entries()) {
|
|
37641
|
+
const file = rt.path.join(o.outDir, m.name + ".jpg");
|
|
37642
|
+
const where3 = { ...m.shot === void 0 ? {} : { shot: m.shot }, ...m.part ? { part: m.part } : {} };
|
|
37643
|
+
if (!b || against === void 0) {
|
|
37644
|
+
const picture3 = left.get(m.frame);
|
|
37645
|
+
if (rt.fs.copyFile) await rt.fs.copyFile(picture3, file);
|
|
37646
|
+
else await rt.fs.writeFile(file, await rt.fs.readFile(picture3));
|
|
37647
|
+
pictures.push({ file, frame: m.frame, second: r36(m.frame / a.fps), ...where3 });
|
|
37648
|
+
continue;
|
|
37649
|
+
}
|
|
37650
|
+
const other = others[i];
|
|
37651
|
+
await pair3(rt, left.get(m.frame), right?.get(other), height, file);
|
|
37652
|
+
pictures.push({ file, frame: m.frame, second: r36(m.frame / a.fps), ...where3, against: { frame: other, second: r36(other / b.fps) } });
|
|
37653
|
+
}
|
|
37654
|
+
});
|
|
37655
|
+
const shots2 = [...new Set(pictures.flatMap((p) => p.shot === void 0 ? [] : [p.shot]))];
|
|
37656
|
+
const sheets = [];
|
|
37657
|
+
for (const shot of shots2) {
|
|
37658
|
+
const mine = pictures.filter((p) => p.shot === shot).map((p) => p.file);
|
|
37659
|
+
if (mine.length !== 3) continue;
|
|
37660
|
+
const file = rt.path.join(o.outDir, "shot-" + two11(shot) + ".jpg");
|
|
37661
|
+
await sheet3(rt, mine, file);
|
|
37662
|
+
sheets.push({ file, shot, pictures: mine });
|
|
37663
|
+
}
|
|
37664
|
+
return { pictures, sheets };
|
|
37665
|
+
};
|
|
37666
|
+
}
|
|
37667
|
+
});
|
|
37668
|
+
|
|
37617
37669
|
// src/video/look/like.ts
|
|
37618
37670
|
var sheetsLike;
|
|
37619
37671
|
var init_like = __esm({
|
|
@@ -39276,7 +39328,7 @@ var init_shots = __esm({
|
|
|
39276
39328
|
});
|
|
39277
39329
|
|
|
39278
39330
|
// src/video/render/chunked.ts
|
|
39279
|
-
var keysOf3, draw, prune, chunkFile, join2, renderInChunks;
|
|
39331
|
+
var keysOf3, draw, prune, chunkFile, join2, shotsIn, renderInChunks;
|
|
39280
39332
|
var init_chunked = __esm({
|
|
39281
39333
|
"src/video/render/chunked.ts"() {
|
|
39282
39334
|
"use strict";
|
|
@@ -39324,6 +39376,7 @@ var init_chunked = __esm({
|
|
|
39324
39376
|
await rt.fs.rm(list7);
|
|
39325
39377
|
}
|
|
39326
39378
|
};
|
|
39379
|
+
shotsIn = (r, ranges) => r.segments.filter((s) => ranges.some(([from, to]) => s.start < to && s.end > from)).map((s) => s.id);
|
|
39327
39380
|
renderInChunks = async (rt, job) => {
|
|
39328
39381
|
const started = Date.now();
|
|
39329
39382
|
const first = job.sessions[0], r = first.resolved;
|
|
@@ -39332,13 +39385,17 @@ var init_chunked = __esm({
|
|
|
39332
39385
|
await rt.fs.mkdir(dir);
|
|
39333
39386
|
try {
|
|
39334
39387
|
const files = [];
|
|
39388
|
+
const drawn = [];
|
|
39335
39389
|
let reused = 0;
|
|
39336
39390
|
for (const [from, to] of chunkRanges(r)) {
|
|
39337
39391
|
const file = await chunkFile(rt, job, c, dir, from, to);
|
|
39338
39392
|
if (c && (await rt.fs.stat(file))?.isFile) {
|
|
39339
39393
|
reused++;
|
|
39340
39394
|
job.onProgress?.(to, r.frames);
|
|
39341
|
-
} else
|
|
39395
|
+
} else {
|
|
39396
|
+
await draw(rt, job, from, to, file);
|
|
39397
|
+
drawn.push([from, to]);
|
|
39398
|
+
}
|
|
39342
39399
|
files.push(file);
|
|
39343
39400
|
}
|
|
39344
39401
|
await join2(rt, job, files);
|
|
@@ -39346,7 +39403,7 @@ var init_chunked = __esm({
|
|
|
39346
39403
|
await prune(rt, dir, files, started);
|
|
39347
39404
|
await markSetUsed(rt, dir).catch(() => void 0);
|
|
39348
39405
|
}
|
|
39349
|
-
return { total: files.length, reused };
|
|
39406
|
+
return { total: files.length, reused, ...reused ? { drawnShots: shotsIn(r, drawn) } : {} };
|
|
39350
39407
|
} finally {
|
|
39351
39408
|
if (!c) await rt.fs.rm(dir);
|
|
39352
39409
|
}
|
|
@@ -39406,17 +39463,20 @@ var init_layout = __esm({
|
|
|
39406
39463
|
// src/video/render/index.ts
|
|
39407
39464
|
var render_exports2 = {};
|
|
39408
39465
|
__export(render_exports2, {
|
|
39466
|
+
LOOK_JPEG_QUALITY: () => LOOK_JPEG_QUALITY,
|
|
39409
39467
|
MAX_PAGES: () => MAX_PAGES2,
|
|
39410
39468
|
RenderRangeError: () => RenderRangeError,
|
|
39411
39469
|
checkLayout: () => checkLayout,
|
|
39412
39470
|
frameFileName: () => frameFileName,
|
|
39471
|
+
frameFormatOf: () => frameFormatOf,
|
|
39472
|
+
lookScale: () => lookScale,
|
|
39413
39473
|
openRenderer: () => openRenderer,
|
|
39414
39474
|
pagesFor: () => pagesFor,
|
|
39415
39475
|
renderFrame: () => renderFrame,
|
|
39416
39476
|
renderFrames: () => renderFrames,
|
|
39417
39477
|
renderVideo: () => renderVideo
|
|
39418
39478
|
});
|
|
39419
|
-
var RenderRangeError, range, MAX_PAGES2, WORK_PER_PAGE, pagesFor, cutSounds, inChunks, renderOnce, dropFrames, renderVideo, drawVideo, openRenderer, frameFileName, renderFrames, renderFrame;
|
|
39479
|
+
var RenderRangeError, range, MAX_PAGES2, WORK_PER_PAGE, pagesFor, cutSounds, inChunks, renderOnce, dropFrames, renderVideo, drawVideo, openRenderer, LOOK_JPEG_QUALITY, frameFormatOf, lookScale, scaleFor, frameFileName, renderFrames, renderFrame;
|
|
39420
39480
|
var init_render2 = __esm({
|
|
39421
39481
|
"src/video/render/index.ts"() {
|
|
39422
39482
|
"use strict";
|
|
@@ -39430,6 +39490,7 @@ var init_render2 = __esm({
|
|
|
39430
39490
|
init_shots();
|
|
39431
39491
|
init_chunked();
|
|
39432
39492
|
init_frames();
|
|
39493
|
+
init_sheets();
|
|
39433
39494
|
init_layout();
|
|
39434
39495
|
RenderRangeError = class extends Error {
|
|
39435
39496
|
name = "RenderRangeError";
|
|
@@ -39511,11 +39572,19 @@ var init_render2 = __esm({
|
|
|
39511
39572
|
};
|
|
39512
39573
|
openRenderer = async (rt, projectDir, opts = {}) => {
|
|
39513
39574
|
const session = await openSession(rt, projectDir, { scale: opts.scale, reuse: opts.reuse === true, lazyScenes: opts.lazyScenes });
|
|
39514
|
-
return { width: session.width, height: session.height, frames: session.resolved.frames, frame: (n) => session.frame(n,
|
|
39575
|
+
return { width: session.width, height: session.height, frames: session.resolved.frames, frame: (n, format = "png") => session.frame(n, format, LOOK_JPEG_QUALITY), close: () => session.close() };
|
|
39576
|
+
};
|
|
39577
|
+
LOOK_JPEG_QUALITY = 85;
|
|
39578
|
+
frameFormatOf = (file) => /\.jpe?g$/i.test(file) ? "jpeg" : "png";
|
|
39579
|
+
lookScale = async (rt, projectDir) => {
|
|
39580
|
+
const canvas = await rt.fs.readText(rt.path.resolve(rt.cwd, projectDir, "video.json")).then((t) => JSON.parse(t).canvas, () => void 0);
|
|
39581
|
+
const w = Number(canvas?.width), h = Number(canvas?.height);
|
|
39582
|
+
return w > 0 && h > 0 ? Math.min(1, Math.floor(Math.sqrt(LOOK_MAX_PIXELS / (w * h)) * 1e3) / 1e3) : 1;
|
|
39515
39583
|
};
|
|
39516
|
-
|
|
39584
|
+
scaleFor = async (rt, projectDir, format, scale) => scale ?? (format === "jpeg" ? await lookScale(rt, projectDir) : void 0);
|
|
39585
|
+
frameFileName = (n, format = "png") => "f" + String(n).padStart(6, "0") + (format === "jpeg" ? ".jpg" : ".png");
|
|
39517
39586
|
renderFrames = async (rt, opts) => {
|
|
39518
|
-
const renderer = await openRenderer(rt, opts.projectDir, { scale: opts.scale });
|
|
39587
|
+
const renderer = await openRenderer(rt, opts.projectDir, { scale: await scaleFor(rt, opts.projectDir, opts.format ?? "png", opts.scale) });
|
|
39519
39588
|
try {
|
|
39520
39589
|
const outside2 = opts.frames.find((n) => !Number.isInteger(n) || n < 0 || n >= renderer.frames);
|
|
39521
39590
|
if (outside2 !== void 0 || !opts.frames.length)
|
|
@@ -39523,8 +39592,8 @@ var init_render2 = __esm({
|
|
|
39523
39592
|
await rt.fs.mkdir(rt.path.resolve(rt.cwd, opts.outDir));
|
|
39524
39593
|
const files = [];
|
|
39525
39594
|
for (const n of [...new Set(opts.frames)].sort((a, b) => a - b)) {
|
|
39526
|
-
const out2 = rt.path.join(opts.outDir, frameFileName(n));
|
|
39527
|
-
await rt.fs.writeFile(rt.path.resolve(rt.cwd, out2), await renderer.frame(n));
|
|
39595
|
+
const out2 = rt.path.join(opts.outDir, frameFileName(n, opts.format));
|
|
39596
|
+
await rt.fs.writeFile(rt.path.resolve(rt.cwd, out2), await renderer.frame(n, opts.format));
|
|
39528
39597
|
files.push({ frame: n, out: out2 });
|
|
39529
39598
|
}
|
|
39530
39599
|
return { width: renderer.width, height: renderer.height, files };
|
|
@@ -39533,11 +39602,11 @@ var init_render2 = __esm({
|
|
|
39533
39602
|
}
|
|
39534
39603
|
};
|
|
39535
39604
|
renderFrame = async (rt, opts) => {
|
|
39536
|
-
const renderer = await openRenderer(rt, opts.projectDir, { scale: opts.scale });
|
|
39605
|
+
const renderer = await openRenderer(rt, opts.projectDir, { scale: await scaleFor(rt, opts.projectDir, frameFormatOf(opts.out), opts.scale) });
|
|
39537
39606
|
try {
|
|
39538
39607
|
if (!Number.isInteger(opts.frame) || opts.frame < 0 || opts.frame >= renderer.frames)
|
|
39539
39608
|
throw new RenderRangeError("renderFrame: frame " + opts.frame + " is outside the video, which has frames 0.." + (renderer.frames - 1) + ".");
|
|
39540
|
-
await rt.fs.writeFile(rt.path.resolve(rt.cwd, opts.out), await renderer.frame(opts.frame));
|
|
39609
|
+
await rt.fs.writeFile(rt.path.resolve(rt.cwd, opts.out), await renderer.frame(opts.frame, frameFormatOf(opts.out)));
|
|
39541
39610
|
return { width: renderer.width, height: renderer.height };
|
|
39542
39611
|
} finally {
|
|
39543
39612
|
await renderer.close();
|
|
@@ -46141,6 +46210,7 @@ var init_write2 = __esm({
|
|
|
46141
46210
|
"use strict";
|
|
46142
46211
|
init_check3();
|
|
46143
46212
|
init_schema();
|
|
46213
|
+
init_footage3();
|
|
46144
46214
|
init_compile();
|
|
46145
46215
|
init_resolve();
|
|
46146
46216
|
init_project3();
|
|
@@ -46155,7 +46225,7 @@ var init_write2 = __esm({
|
|
|
46155
46225
|
const { project, problems: named } = await withEffectFiles(rt, parsed.project);
|
|
46156
46226
|
const blocking = [...named, ...checkProject2(project)].filter((p) => p.level === "error");
|
|
46157
46227
|
if (blocking.length) return { scenes: [], problems: blocking };
|
|
46158
|
-
const r = resolve(project);
|
|
46228
|
+
const r = resolve(project, (await probeFootage(rt, project, dir)).info);
|
|
46159
46229
|
const fps = r.canvas.fps;
|
|
46160
46230
|
const offset = o.offset ?? 0;
|
|
46161
46231
|
const library = await exists3(rt, rt.path.join(dir, "lib", "gsap.min.js")) ? "gsap" : void 0;
|
|
@@ -46562,13 +46632,14 @@ var init_make = __esm({
|
|
|
46562
46632
|
return frames;
|
|
46563
46633
|
};
|
|
46564
46634
|
frame = command(
|
|
46565
|
-
"draw frames of the project
|
|
46635
|
+
"draw frames of the project: one with --frame N --out f.jpg, or many in one browser session with --frames 0,45,90 --out dir --format jpg (dir/f000045.jpg ...), which is much faster than one command a frame. A .jpg is for looking at (every picture an agent opens is sent to its model, and a JPEG is a fifth to a tenth of the PNG): without --scale it is drawn at most at about 1.15 megapixels, the size a model looks at; a .png keeps exact pixels at the canvas size",
|
|
46566
46636
|
{
|
|
46567
46637
|
positionals: [PROJECT3],
|
|
46568
46638
|
options: [
|
|
46569
46639
|
{ flag: "--frame", kind: "int", help: "the frame number, from 0" },
|
|
46570
46640
|
{ flag: "--frames", help: "frame numbers separated by commas; --out is then a directory" },
|
|
46571
|
-
{ flag: "--out", required: true, help: "the
|
|
46641
|
+
{ flag: "--out", required: true, help: "the picture to write: name it .jpg to look at it (a fifth to a tenth of the bytes of a PNG; every picture an agent opens is sent to its model), .png for exact pixels (a directory with --frames)" },
|
|
46642
|
+
{ flag: "--format", help: "with --frames: jpg (to look at) or png (exact pixels, the default)" },
|
|
46572
46643
|
SCALE
|
|
46573
46644
|
]
|
|
46574
46645
|
},
|
|
@@ -46577,9 +46648,12 @@ var init_make = __esm({
|
|
|
46577
46648
|
const scale = args2.number("scale");
|
|
46578
46649
|
const many = args2.string("frames");
|
|
46579
46650
|
const n = args2.number("frame");
|
|
46580
|
-
if (many === void 0 === (n === void 0)) throw new VideoCommandError("Give either --frame N (one
|
|
46651
|
+
if (many === void 0 === (n === void 0)) throw new VideoCommandError("Give either --frame N (one picture) or --frames N,N,... (a directory of pictures).");
|
|
46652
|
+
const format = args2.string("format");
|
|
46653
|
+
if (format !== void 0 && format !== "jpg" && format !== "png") throw new VideoCommandError("Choose --format jpg or --format png.");
|
|
46654
|
+
if (format !== void 0 && many === void 0) throw new VideoCommandError("--format goes with --frames; for one frame, name --out .jpg or .png.");
|
|
46581
46655
|
if (many !== void 0) {
|
|
46582
|
-
const r5 = await renderFrames(rt, { projectDir: args2.req("project-dir"), frames: framesOf2(many), outDir: out2, ...scale === void 0 ? {} : { scale } });
|
|
46656
|
+
const r5 = await renderFrames(rt, { projectDir: args2.req("project-dir"), frames: framesOf2(many), outDir: out2, ...scale === void 0 ? {} : { scale }, ...format === "jpg" ? { format: "jpeg" } : {} });
|
|
46583
46657
|
printJson(rt, { ok: true, dir: out2, frames: r5.files, width: r5.width, height: r5.height });
|
|
46584
46658
|
return;
|
|
46585
46659
|
}
|
|
@@ -46588,7 +46662,7 @@ var init_make = __esm({
|
|
|
46588
46662
|
})
|
|
46589
46663
|
);
|
|
46590
46664
|
render2 = command(
|
|
46591
|
-
"render the project to an MP4: frames drawn in Chrome, encoded with ffmpeg with the sound mixed in; next names the compare to run, a warning says when the render before it was never compared, and problems says when the music ends before the video does. Each shot is kept in the project (.cache/render-chunks), so a render after a local fix draws only the shots it changed: chunks says how many there are and how many were copied. The frames extracted from video materials (.cache/video) are removed once the MP4 is written, except what an open Studio shows (framesFreedBytes); the next command that needs them extracts them again",
|
|
46665
|
+
"render the project to an MP4: frames drawn in Chrome, encoded with ffmpeg with the sound mixed in; next names the compare to run, a warning says when the render before it was never compared, and problems says when the music ends before the video does. Each shot is kept in the project (.cache/render-chunks), so a render after a local fix draws only the shots it changed: chunks says how many there are and how many were copied, and drawnShots which shots the drawn ones show (the ones to look at again after a fix). The frames extracted from video materials (.cache/video) are removed once the MP4 is written, except what an open Studio shows (framesFreedBytes); the next command that needs them extracts them again",
|
|
46592
46666
|
{
|
|
46593
46667
|
positionals: [PROJECT3],
|
|
46594
46668
|
options: [
|
|
@@ -47964,7 +48038,7 @@ var init_loop2 = __esm({
|
|
|
47964
48038
|
dir: out2,
|
|
47965
48039
|
scale: r.scale,
|
|
47966
48040
|
pictures: r.sheets.map((s) => ({ file: s.file, frames: s.frames.length, from: s.seconds[0] ?? 0, to: s.seconds[s.seconds.length - 1] ?? 0 })),
|
|
47967
|
-
next: "
|
|
48041
|
+
next: "Hold each against the reference's picture of the same name in " + like + " (shots/NN-frames.jpg, transitions/NN.jpg, opening.jpg): the same frames, the same effects? Open a reference picture again only for a detail your notes lack, and after a fix only the pictures of the shots the render drew again (chunks.drawnShots) and of worst: every picture opened is sent to the model.",
|
|
47968
48042
|
...r.notes.length ? { notes: r.notes } : {}
|
|
47969
48043
|
});
|
|
47970
48044
|
};
|
|
@@ -48280,7 +48354,7 @@ var init_media = __esm({
|
|
|
48280
48354
|
};
|
|
48281
48355
|
HOSTED = "popost.ai";
|
|
48282
48356
|
HOSTED_NOTE = {
|
|
48283
|
-
speak: "popost: voices (popost:default-male, popost:default-female, popost:<id> from popost video voice list), with word times;
|
|
48357
|
+
speak: "popost: voices (popost:default-male, popost:default-female, popost:<id> from popost video voice list), with word times; for non-AI-video or explicit external audio work, never required for model-native clip audio",
|
|
48284
48358
|
transcribe: "popost.ai transcribes the speech (a transcriber of your own in POPOST_ASR_CMD goes first when it is set)",
|
|
48285
48359
|
music: "popost video music make: background music generated from a description, priced by its length (popost video music quote); planned from the reading of the reference (popost video music plan) and made only as the user agreed. When the generator is not available the quote says so and the plan has no generated bed",
|
|
48286
48360
|
paid: "read live prices before paid work; each paid command prints its price without --confirm (exit code 3) and charges only with --confirm --max-credits N under valid scope/account/cost authorization"
|
|
@@ -48305,7 +48379,7 @@ var init_media = __esm({
|
|
|
48305
48379
|
const cpus = budget2 ? { budget: budget2.cpus, from: budget2.source } : null;
|
|
48306
48380
|
const reading = named.readText !== null || named.transcribe !== null;
|
|
48307
48381
|
const cache2 = await projectCache(rt);
|
|
48308
|
-
printJson(rt, { ok: missing5.length === 0, ffmpeg: version, browser: browser === true, cpus, tools: tools2, ...cache2 ? { cache: cache2 } : {}, ...offers, ...reading ? { note: FIRST_RUN } : {}, ...missing5.length ? { missing: missing5 } : {} });
|
|
48382
|
+
printJson(rt, { ok: missing5.length === 0, ffmpeg: version, browser: browser === true, cpus, tools: tools2, ...cache2 ? { cache: cache2 } : {}, ...offers, ...reading ? { note: FIRST_RUN } : {}, ...missing5.length ? { missing: missing5, next: "Keep the Popost route and selected providers. Install missing ordinary FFmpeg/Chrome dependencies from official distributions within task preparation, set POPOST_FFMPEG/POPOST_CHROME if needed, rerun doctor and a minimal render. If browser startup is sandbox-blocked, use an allowed host runtime or report that restriction; do not substitute an Agent-written production pipeline." } : { next: "Verify a minimal Popost render in this runtime before paid production. AI video models own native speech and soundtrack by default; no separate audio-provider interview is needed." } });
|
|
48309
48383
|
return missing5.length ? 2 : 0;
|
|
48310
48384
|
}
|
|
48311
48385
|
);
|
|
@@ -48346,7 +48420,7 @@ var init_plan = __esm({
|
|
|
48346
48420
|
return BASIS_LETTERS[t] ?? (isClipMusicBasis(t) ? t : void 0);
|
|
48347
48421
|
};
|
|
48348
48422
|
letterOf = (b) => String.fromCharCode(97 + CLIP_MUSIC_BASES.indexOf(b));
|
|
48349
|
-
noBedByException = (list7) => (list7 ?? []).find((c) => c.clip === WHOLE_VIDEO && (c.basis === "single-clip" || c.basis === "per-segment"));
|
|
48423
|
+
noBedByException = (list7) => (list7 ?? []).find((c) => c.clip === WHOLE_VIDEO && (c.basis === "single-clip" || c.basis === "per-segment" || c.basis === "model-native"));
|
|
48350
48424
|
exceptionProblem = (basis, clip11) => WHOLE_ONLY.includes(basis) && clip11 !== WHOLE_VIDEO ? "(" + letterOf(basis) + ") " + basis + " holds for the whole video: write --clip-music " + WHOLE_VIDEO + "." : void 0;
|
|
48351
48425
|
withException = (plan4, e) => {
|
|
48352
48426
|
const clipMusic = [...(plan4.clipMusic ?? []).filter((c) => c.clip !== e.clip), e];
|
|
@@ -48544,6 +48618,7 @@ var init_music_plan = __esm({
|
|
|
48544
48618
|
{
|
|
48545
48619
|
options: [
|
|
48546
48620
|
{ ...PROJECT_OPTION, required: true, help: "the video project the plan is for" },
|
|
48621
|
+
{ flag: "--native-clips", kind: "flag", help: "AI video clips produce all their own audio; record the model-native route without quoting or asking for separate voice/music services" },
|
|
48547
48622
|
{ flag: "--reading", metavar: "DIR", help: "what describe wrote (its sound.json) or the template; default the template the project was filled from" },
|
|
48548
48623
|
{ flag: "--music", choices: ["generated", "own", "reference", "none"], help: "generated: one track made for the whole video (popost video music make); own: the user's file (popost video music own); reference: the reference's own soundtrack, kept as it is when nobody speaks over it (popost video replication sound); none: no music" },
|
|
48549
48624
|
{ flag: "--style", metavar: "TEXT", help: "with generated: the agreed style in plain words (genre, mood, tempo, instruments)" },
|
|
@@ -48559,6 +48634,13 @@ var init_music_plan = __esm({
|
|
|
48559
48634
|
async (args2, rt) => {
|
|
48560
48635
|
const project = userPath(rt, args2.req("project"));
|
|
48561
48636
|
const kept3 = await readMusicPlan(rt, project);
|
|
48637
|
+
if (args2.flag("native-clips")) {
|
|
48638
|
+
if (kept3 && kept3.music !== "none") throw new VideoCommandError("A separate soundtrack is already recorded. Preserve the existing explicit audio selection; do not replace it implicitly.");
|
|
48639
|
+
const plan4 = { version: 1, music: "none", clipMusic: [{ clip: "all", basis: "model-native", why: "AI video models produce speech, narration and soundtrack together; other soundtrack continuity is best effort." }] };
|
|
48640
|
+
await writeMusicPlan(rt, project, plan4);
|
|
48641
|
+
printJson(rt, { ok: true, project, plan: plan4, show: ["The video model produces all clip audio. No separate voice/music selection is needed."], next: "Continue Popost materials, render and actual-output review. Disclose model-output limitations; do not automatically regenerate or replace native audio." });
|
|
48642
|
+
return;
|
|
48643
|
+
}
|
|
48562
48644
|
const given2 = args2.string("reading");
|
|
48563
48645
|
const reading = await readingFor(rt, project, given2 === void 0 ? void 0 : userPath(rt, given2));
|
|
48564
48646
|
if (given2 !== void 0 && !reading) throw new VideoCommandError("No reading of the sound is in " + given2 + ": give what describe wrote (with its sound.json) or a template saved after describe read the sound.");
|
|
@@ -49376,10 +49458,13 @@ var init_analysis = __esm({
|
|
|
49376
49458
|
});
|
|
49377
49459
|
|
|
49378
49460
|
// src/video/describe/parts.ts
|
|
49379
|
-
var samplesAndPictures, withShotFills, readReference4;
|
|
49461
|
+
var TEXT_KEPT, describeTextFile, withKeptLines, samplesAndPictures, withShotFills, readReference4;
|
|
49380
49462
|
var init_parts = __esm({
|
|
49381
49463
|
"src/video/describe/parts.ts"() {
|
|
49382
49464
|
"use strict";
|
|
49465
|
+
init_util();
|
|
49466
|
+
init_version();
|
|
49467
|
+
init_readback_kept();
|
|
49383
49468
|
init_host();
|
|
49384
49469
|
init_sheets();
|
|
49385
49470
|
init_decode();
|
|
@@ -49392,6 +49477,17 @@ var init_parts = __esm({
|
|
|
49392
49477
|
init_speech2();
|
|
49393
49478
|
init_tool();
|
|
49394
49479
|
init_text();
|
|
49480
|
+
init_reader_command();
|
|
49481
|
+
TEXT_KEPT = "popost-video-describe-text@1";
|
|
49482
|
+
describeTextFile = async (rt, video) => {
|
|
49483
|
+
const key2 = sha256(JSON.stringify({ format: TEXT_KEPT, version: VERSION, source: await sha256File(rt, video) }));
|
|
49484
|
+
return rt.path.join(rt.path.resolve(rt.cwd), ".popost", "video-cache", "text", key2 + ".json");
|
|
49485
|
+
};
|
|
49486
|
+
withKeptLines = async (rt, video, reader, onKept) => {
|
|
49487
|
+
if (rt.env.POPOST_VIDEO_CACHE === "off" || textReaderCommand(rt) === void 0) return reader;
|
|
49488
|
+
const file = await describeTextFile(rt, video).catch(() => void 0);
|
|
49489
|
+
return file === void 0 ? reader : keptReader(rt, file, reader, onKept);
|
|
49490
|
+
};
|
|
49395
49491
|
samplesAndPictures = async (rt, video, measure3, dir) => {
|
|
49396
49492
|
const p = await probe2(rt, video);
|
|
49397
49493
|
const { every, width } = insetPlan(p);
|
|
@@ -49429,8 +49525,13 @@ var init_parts = __esm({
|
|
|
49429
49525
|
}
|
|
49430
49526
|
};
|
|
49431
49527
|
const measureIt = () => part("measure", (onStage) => measureCached(rt, video, onStage ? { onStage } : {}));
|
|
49528
|
+
const reused = { frames: 0, of: 0 };
|
|
49432
49529
|
const readIt = () => reader ? part("text", async (onStage) => {
|
|
49433
|
-
const
|
|
49530
|
+
const kept3 = await withKeptLines(rt, video, reader, (frames, of) => {
|
|
49531
|
+
Object.assign(reused, { frames, of });
|
|
49532
|
+
if (frames) onStage?.("the text of " + frames + " of " + of + " frames is taken from the last describe of this video" + (frames < of ? "; the reader reads " + (of - frames) : ""));
|
|
49533
|
+
});
|
|
49534
|
+
const track = cuesOf(await readSamples(rt, video, kept3, onStage ? { onStage } : {}));
|
|
49434
49535
|
onStage?.("measuring what is behind the caption letters");
|
|
49435
49536
|
return withCaptionLook(rt, video, track);
|
|
49436
49537
|
}) : Promise.resolve(void 0);
|
|
@@ -49473,7 +49574,8 @@ var init_parts = __esm({
|
|
|
49473
49574
|
...transcript2 ? { transcript: transcript2 } : {},
|
|
49474
49575
|
...inset ? { inset } : {},
|
|
49475
49576
|
...looked.pictures ? { pictures: looked.pictures } : {},
|
|
49476
|
-
...failure4.speech !== void 0 ? { speechFailed: failure4.speech } : {}
|
|
49577
|
+
...failure4.speech !== void 0 ? { speechFailed: failure4.speech } : {},
|
|
49578
|
+
...reused.frames ? { textReused: { ...reused } } : {}
|
|
49477
49579
|
};
|
|
49478
49580
|
} finally {
|
|
49479
49581
|
progress?.stop();
|
|
@@ -50027,6 +50129,7 @@ var init_read3 = __esm({
|
|
|
50027
50129
|
tokens: { "REFERENCE.md": d.tokens["REFERENCE.md"], "timeline.md": d.tokens["timeline.md"] },
|
|
50028
50130
|
sound: m.source.hasAudio,
|
|
50029
50131
|
text: cues !== void 0,
|
|
50132
|
+
...got.textReused ? { textReused: got.textReused } : {},
|
|
50030
50133
|
speech: spoken !== void 0,
|
|
50031
50134
|
chargedCredits: wallet?.spent ?? 0,
|
|
50032
50135
|
// What kind of speech it is decides whether the re-make has a voice-over (describe/speech-kind.ts).
|
|
@@ -51384,6 +51487,7 @@ var init_speech_check2 = __esm({
|
|
|
51384
51487
|
"src/video/commands/speech-check.ts"() {
|
|
51385
51488
|
"use strict";
|
|
51386
51489
|
init_util();
|
|
51490
|
+
init_ffmpeg();
|
|
51387
51491
|
init_hosted2();
|
|
51388
51492
|
init_speech2();
|
|
51389
51493
|
init_speech_check();
|
|
@@ -51426,7 +51530,8 @@ var init_speech_check2 = __esm({
|
|
|
51426
51530
|
}
|
|
51427
51531
|
const kept3 = /* @__PURE__ */ new Map();
|
|
51428
51532
|
for (const f of files) {
|
|
51429
|
-
|
|
51533
|
+
let m = await keptMeasurement(rt, dir, f).catch(() => void 0);
|
|
51534
|
+
if (!m && !(await probe2(rt, rt.path.resolve(dir, f))).hasAudio) m = await measureClipSpeech(rt, dir, f);
|
|
51430
51535
|
if (m) kept3.set(f, m);
|
|
51431
51536
|
}
|
|
51432
51537
|
const todo = files.filter((f) => !kept3.has(f));
|
|
@@ -51452,7 +51557,8 @@ var init_speech_check2 = __esm({
|
|
|
51452
51557
|
clips,
|
|
51453
51558
|
chargedCredits: wallet?.spent ?? 0,
|
|
51454
51559
|
problems: problems2,
|
|
51455
|
-
|
|
51560
|
+
speechQuality: problems2.length ? "limitations" : "asr-match",
|
|
51561
|
+
next: problems2.length ? "Disclose the observed model-output limitations and keep the generated clips. Do not automatically regenerate or replace native audio. Build or fill using actual observed timing." : "The mix and the captions now follow what the clips really say: build or fill again."
|
|
51456
51562
|
});
|
|
51457
51563
|
return errors ? 2 : 0;
|
|
51458
51564
|
},
|