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/index.js
CHANGED
|
@@ -265,7 +265,7 @@ var VERSION;
|
|
|
265
265
|
var init_version = __esm({
|
|
266
266
|
"src/version.ts"() {
|
|
267
267
|
"use strict";
|
|
268
|
-
VERSION = "4.6.
|
|
268
|
+
VERSION = "4.6.14";
|
|
269
269
|
}
|
|
270
270
|
});
|
|
271
271
|
|
|
@@ -15705,7 +15705,7 @@ import { existsSync, readdirSync } from "node:fs";
|
|
|
15705
15705
|
import { homedir } from "node:os";
|
|
15706
15706
|
import path from "node:path";
|
|
15707
15707
|
import { chromium } from "playwright-core";
|
|
15708
|
-
var BrowserUnavailableError, playwrightCaches, SYSTEM_BROWSERS, findChromium, OFFLINE, LAUNCH_ARGS, FRAME_ARGS, ARGS, MAX_RASTER_THREADS, chromiumArgs, closeOwnedBrowser, launchChromium;
|
|
15708
|
+
var BrowserUnavailableError, playwrightCaches, SYSTEM_BROWSERS, chromiumCandidates, findChromium, OFFLINE, LAUNCH_ARGS, FRAME_ARGS, ARGS, MAX_RASTER_THREADS, chromiumArgs, closeOwnedBrowser, launchChromium;
|
|
15709
15709
|
var init_browser = __esm({
|
|
15710
15710
|
"src/render/browser.ts"() {
|
|
15711
15711
|
"use strict";
|
|
@@ -15752,11 +15752,11 @@ var init_browser = __esm({
|
|
|
15752
15752
|
"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
|
|
15753
15753
|
"C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe"
|
|
15754
15754
|
];
|
|
15755
|
-
|
|
15755
|
+
chromiumCandidates = (env2) => {
|
|
15756
15756
|
const explicit = env2.POPOST_CHROME || env2.PLAYWRIGHT_CHROMIUM;
|
|
15757
|
-
|
|
15758
|
-
return [...SYSTEM_BROWSERS, ...playwrightCaches()].find((p) => existsSync(p)) ?? null;
|
|
15757
|
+
return [...new Set(explicit ? [explicit] : [...SYSTEM_BROWSERS, ...playwrightCaches()])].filter((p) => existsSync(p));
|
|
15759
15758
|
};
|
|
15759
|
+
findChromium = (env2) => chromiumCandidates(env2)[0] ?? null;
|
|
15760
15760
|
OFFLINE = "--host-resolver-rules=MAP * ~NOTFOUND";
|
|
15761
15761
|
LAUNCH_ARGS = ["--disable-gpu", "--font-render-hinting=none", OFFLINE];
|
|
15762
15762
|
FRAME_ARGS = [
|
|
@@ -15797,26 +15797,34 @@ var init_browser = __esm({
|
|
|
15797
15797
|
}
|
|
15798
15798
|
};
|
|
15799
15799
|
launchChromium = async (env2, profile = "pages", o = {}) => {
|
|
15800
|
-
const
|
|
15801
|
-
if (!
|
|
15800
|
+
const candidates3 = chromiumCandidates(env2);
|
|
15801
|
+
if (!candidates3.length)
|
|
15802
15802
|
throw new BrowserUnavailableError(
|
|
15803
15803
|
msg(
|
|
15804
15804
|
"No Chrome, Edge or Chromium found. Install Google Chrome, or set POPOST_CHROME to a Chromium executable.",
|
|
15805
15805
|
"\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"
|
|
15806
15806
|
)
|
|
15807
15807
|
);
|
|
15808
|
-
const
|
|
15809
|
-
|
|
15810
|
-
|
|
15811
|
-
|
|
15812
|
-
|
|
15813
|
-
|
|
15814
|
-
|
|
15815
|
-
|
|
15816
|
-
|
|
15817
|
-
|
|
15818
|
-
|
|
15808
|
+
const failures = [];
|
|
15809
|
+
for (const executablePath of candidates3) {
|
|
15810
|
+
try {
|
|
15811
|
+
const options = { executablePath, headless: true, args: chromiumArgs(profile, o) };
|
|
15812
|
+
if (profile !== "frames") return await chromium.launch(options);
|
|
15813
|
+
const server = await chromium.launchServer({ ...options, host: "127.0.0.1" });
|
|
15814
|
+
try {
|
|
15815
|
+
const browser = await chromium.connect(server.wsEndpoint(), { timeout: 3e4 });
|
|
15816
|
+
let closing;
|
|
15817
|
+
browser.close = () => closing ??= closeOwnedBrowser(server);
|
|
15818
|
+
return browser;
|
|
15819
|
+
} catch (e) {
|
|
15820
|
+
await server.kill().catch(() => void 0);
|
|
15821
|
+
throw e;
|
|
15822
|
+
}
|
|
15823
|
+
} catch (e) {
|
|
15824
|
+
failures.push(executablePath + ": " + (e instanceof Error ? e.message : String(e)).slice(0, 1500));
|
|
15825
|
+
}
|
|
15819
15826
|
}
|
|
15827
|
+
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"));
|
|
15820
15828
|
};
|
|
15821
15829
|
}
|
|
15822
15830
|
});
|
|
@@ -16059,7 +16067,7 @@ var init_page_bundle = __esm({
|
|
|
16059
16067
|
});
|
|
16060
16068
|
|
|
16061
16069
|
// src/video/render/chunks.ts
|
|
16062
|
-
var CHUNK_DIR, VERSION2, MAX_CHUNK_SECONDS, chunkRanges, SHARED_DIRS, SOUND, fileHash, filesBelow, sceneFile, sharedKey, keyContext, picturesOf, frameKey, chunkKey, chunkDir;
|
|
16070
|
+
var CHUNK_DIR, VERSION2, MAX_CHUNK_SECONDS, splitLong, chunkRanges, SHARED_DIRS, SOUND, fileHash, filesBelow, sceneFile, sharedKey, keyContext, picturesOf, FOOTAGE_FRAME, frameKey, chunkKey, chunkDir;
|
|
16063
16071
|
var init_chunks = __esm({
|
|
16064
16072
|
"src/video/render/chunks.ts"() {
|
|
16065
16073
|
"use strict";
|
|
@@ -16068,6 +16076,10 @@ var init_chunks = __esm({
|
|
|
16068
16076
|
CHUNK_DIR = ".cache/render-chunks";
|
|
16069
16077
|
VERSION2 = 1;
|
|
16070
16078
|
MAX_CHUNK_SECONDS = 4;
|
|
16079
|
+
splitLong = ([from, to], longest, shortest) => {
|
|
16080
|
+
const cuts = Array.from({ length: Math.max(0, Math.floor((to - from - shortest) / longest)) }, (_, k) => from + (k + 1) * longest);
|
|
16081
|
+
return [from, ...cuts].map((start, k) => [start, cuts[k] ?? to]);
|
|
16082
|
+
};
|
|
16071
16083
|
chunkRanges = (r) => {
|
|
16072
16084
|
const shortest = Math.max(1, Math.round(r.canvas.fps));
|
|
16073
16085
|
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);
|
|
@@ -16078,10 +16090,7 @@ var init_chunks = __esm({
|
|
|
16078
16090
|
const tail4 = joined[joined.length - 1], before = joined[joined.length - 2];
|
|
16079
16091
|
const ranges = tail4 && before && tail4[1] - tail4[0] < shortest ? [...joined.slice(0, -2), [before[0], tail4[1]]] : joined;
|
|
16080
16092
|
const longest = Math.max(shortest, Math.round(r.canvas.fps * MAX_CHUNK_SECONDS));
|
|
16081
|
-
return ranges.flatMap((
|
|
16082
|
-
const count5 = Math.ceil((to - from) / longest);
|
|
16083
|
-
return Array.from({ length: count5 }, (_, k) => [from + Math.round((to - from) * k / count5), from + Math.round((to - from) * (k + 1) / count5)]);
|
|
16084
|
-
});
|
|
16093
|
+
return ranges.flatMap((range2) => splitLong(range2, longest, shortest));
|
|
16085
16094
|
};
|
|
16086
16095
|
SHARED_DIRS = ["assets", "lib", "css", "fonts"];
|
|
16087
16096
|
SOUND = /\.(wav|mp3|m4a|aac|flac|ogg|opus)$|\.(sound|music|speech|voice|words)\.json$/i;
|
|
@@ -16117,13 +16126,17 @@ var init_chunks = __esm({
|
|
|
16117
16126
|
const found = [...markup.matchAll(/\bsrc="([^"]*)"/g), ...markup.matchAll(/url\((?:"|["'])?([^)"'&]+)/g)].map((m) => (m[1] ?? "").replace(/&/g, "&"));
|
|
16118
16127
|
return [...new Set(found.filter((u) => u && !u.startsWith("#") && !/^(data|blob|about):/.test(u)).map((u) => decodeURIComponent(u.replace(/^\/+/, "").split(/[?#]/)[0] ?? "")))].sort();
|
|
16119
16128
|
};
|
|
16129
|
+
FOOTAGE_FRAME = /\.cache\/video\/[0-9a-f]{16}\/\d+\.png/g;
|
|
16120
16130
|
frameKey = async (rt, c, state2) => {
|
|
16121
|
-
const
|
|
16131
|
+
const named = picturesOf(state2.markup);
|
|
16132
|
+
const hashes2 = new Map(await Promise.all(named.map(async (p) => [p, await fileHash(rt, c, p)])));
|
|
16133
|
+
const markup = state2.markup.replace(FOOTAGE_FRAME, (p) => "footage:" + (hashes2.get(p) ?? p));
|
|
16134
|
+
const pictures = named.filter((p) => p.replace(FOOTAGE_FRAME, "") !== "").map((p) => p + "=" + (hashes2.get(p) ?? ""));
|
|
16122
16135
|
const scenes = await Promise.all(state2.scenes.map(async (s) => {
|
|
16123
16136
|
const file = c.scenes[s.segment];
|
|
16124
16137
|
return (c.bases[s.segment] ?? "") + "@" + s.seconds.toFixed(6) + (file ? "=" + await fileHash(rt, c, file) : "");
|
|
16125
16138
|
}));
|
|
16126
|
-
return sha256([
|
|
16139
|
+
return sha256([markup, ...scenes, ...pictures, scenes.length ? c.shared : ""].join("\n"));
|
|
16127
16140
|
};
|
|
16128
16141
|
chunkKey = (c, frames) => sha256(c.settings + "\n" + frames.join("\n"));
|
|
16129
16142
|
chunkDir = (rt, c) => rt.path.join(c.root, CHUNK_DIR, c.settings.slice(0, 16));
|
|
@@ -18428,14 +18441,14 @@ var init_types = __esm({
|
|
|
18428
18441
|
});
|
|
18429
18442
|
|
|
18430
18443
|
// src/video/sound/modes.ts
|
|
18431
|
-
var CLIP_MUSIC_BASES, BASIS_MEANS, isSoundMode, isClipMusicBasis, modeContextOf, inferMode,
|
|
18444
|
+
var CLIP_MUSIC_BASES, BASIS_MEANS, isSoundMode, isClipMusicBasis, modeContextOf, inferMode, soundTail, musicBasisOf, speechProblems, modeProblems, RECEIPT, writeModeReceipt, readModeReceipt;
|
|
18432
18445
|
var init_modes = __esm({
|
|
18433
18446
|
"src/video/sound/modes.ts"() {
|
|
18434
18447
|
"use strict";
|
|
18435
18448
|
init_prompt_lang();
|
|
18436
18449
|
init_check_common();
|
|
18437
18450
|
init_types();
|
|
18438
|
-
CLIP_MUSIC_BASES = ["single-clip", "per-segment", "in-scene", "sung", "brand-sting", "own-footage", "user-wish"];
|
|
18451
|
+
CLIP_MUSIC_BASES = ["single-clip", "per-segment", "in-scene", "sung", "brand-sting", "own-footage", "user-wish", "model-native"];
|
|
18439
18452
|
BASIS_MEANS = {
|
|
18440
18453
|
"single-clip": "the video is one continuous clip with no cut: its own continuous soundtrack stays",
|
|
18441
18454
|
"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",
|
|
@@ -18443,7 +18456,8 @@ var init_modes = __esm({
|
|
|
18443
18456
|
sung: "a person sings, or lip-syncs a song",
|
|
18444
18457
|
"brand-sting": "a short brand sting of a second or two",
|
|
18445
18458
|
"own-footage": "the user's own filmed footage keeps the sound it was filmed with",
|
|
18446
|
-
"user-wish": "the user asked for it in so many words"
|
|
18459
|
+
"user-wish": "the user asked for it in so many words",
|
|
18460
|
+
"model-native": "the AI video model produces the clip soundtrack; cross-clip music continuity is best effort"
|
|
18447
18461
|
};
|
|
18448
18462
|
isSoundMode = (v) => SOUND_MODES.includes(v);
|
|
18449
18463
|
isClipMusicBasis = (v) => CLIP_MUSIC_BASES.includes(v);
|
|
@@ -18456,20 +18470,13 @@ var init_modes = __esm({
|
|
|
18456
18470
|
if (r.speech !== void 0 && r.speech !== null) return "speech";
|
|
18457
18471
|
return ctx.narrated && ctx.ambience !== "yes" ? "silent" : "ambience";
|
|
18458
18472
|
};
|
|
18459
|
-
NO_MUSIC_SENTENCE = "No background music and no score in this clip: the music of the video is a separate track.";
|
|
18460
18473
|
soundTail = (mode, o = {}) => {
|
|
18461
|
-
if (
|
|
18462
|
-
|
|
18463
|
-
|
|
18464
|
-
|
|
18465
|
-
|
|
18466
|
-
|
|
18467
|
-
}
|
|
18468
|
-
const music = o.music ? "" : " " + NO_MUSIC_SENTENCE;
|
|
18469
|
-
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;
|
|
18470
|
-
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;
|
|
18471
|
-
if (mode === "silent") return " The clip is used without its sound: nobody speaks to the camera, and mouths stay closed or turned away.";
|
|
18472
|
-
return "";
|
|
18474
|
+
if (mode === "exhibit") return "";
|
|
18475
|
+
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");
|
|
18476
|
+
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") : "";
|
|
18477
|
+
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");
|
|
18478
|
+
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");
|
|
18479
|
+
return lead + route2;
|
|
18473
18480
|
};
|
|
18474
18481
|
musicBasisOf = (r, recorded2) => {
|
|
18475
18482
|
if (isClipMusicBasis(r.clipMusic)) return r.clipMusic;
|
|
@@ -18493,7 +18500,7 @@ var init_modes = __esm({
|
|
|
18493
18500
|
if (!isClipMusicBasis(r.clipMusic))
|
|
18494
18501
|
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])];
|
|
18495
18502
|
if (r.sound === "silent") out2.push(error(at7 + ".clipMusic", "A silent clip carries no music.", 'Remove "clipMusic", or change "sound".'));
|
|
18496
|
-
if (!recorded2.some((c) => c.basis === r.clipMusic && (c.clip === r.file || c.clip === "all")))
|
|
18503
|
+
if (r.clipMusic !== "model-native" && !recorded2.some((c) => c.basis === r.clipMusic && (c.clip === r.file || c.clip === "all")))
|
|
18497
18504
|
out2.push(error(
|
|
18498
18505
|
at7 + ".clipMusic",
|
|
18499
18506
|
'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) + ".",
|
|
@@ -22384,6 +22391,49 @@ var init_wallet = __esm({
|
|
|
22384
22391
|
}
|
|
22385
22392
|
});
|
|
22386
22393
|
|
|
22394
|
+
// src/video/voice/cache.ts
|
|
22395
|
+
var FORMAT, VERSION3, keyOf2, baseOf, off, keptLine, keepLine;
|
|
22396
|
+
var init_cache = __esm({
|
|
22397
|
+
"src/video/voice/cache.ts"() {
|
|
22398
|
+
"use strict";
|
|
22399
|
+
init_util();
|
|
22400
|
+
FORMAT = "popost-voice-cache";
|
|
22401
|
+
VERSION3 = 1;
|
|
22402
|
+
keyOf2 = (voiceId, text13, speed) => sha256(JSON.stringify({ format: FORMAT, version: VERSION3, voiceId, text: text13, speed }));
|
|
22403
|
+
baseOf = (rt, key2) => rt.path.join(rt.path.resolve(rt.cwd), ".popost", "video-cache", "voice", key2);
|
|
22404
|
+
off = (rt) => rt.env.POPOST_VIDEO_CACHE === "off";
|
|
22405
|
+
keptLine = async (rt, voiceId, text13, speed) => {
|
|
22406
|
+
if (off(rt)) return void 0;
|
|
22407
|
+
const key2 = keyOf2(voiceId, text13, speed);
|
|
22408
|
+
const base = baseOf(rt, key2);
|
|
22409
|
+
try {
|
|
22410
|
+
const record2 = JSON.parse(await rt.fs.readText(base + ".json"));
|
|
22411
|
+
const audio = await rt.fs.readFile(base + ".wav");
|
|
22412
|
+
if (record2.format !== FORMAT || record2.key !== key2 || record2.audioSha256 !== sha256(audio) || typeof record2.operationKey !== "string") return void 0;
|
|
22413
|
+
return { audio, operationKey: record2.operationKey, ...Array.isArray(record2.words) ? { words: record2.words } : {} };
|
|
22414
|
+
} catch {
|
|
22415
|
+
return void 0;
|
|
22416
|
+
}
|
|
22417
|
+
};
|
|
22418
|
+
keepLine = async (rt, voiceId, text13, speed, line) => {
|
|
22419
|
+
if (off(rt)) return;
|
|
22420
|
+
const key2 = keyOf2(voiceId, text13, speed);
|
|
22421
|
+
const base = baseOf(rt, key2);
|
|
22422
|
+
const temporary = base + "." + rt.randomUUID() + ".tmp";
|
|
22423
|
+
try {
|
|
22424
|
+
await rt.fs.mkdir(rt.path.dirname(base));
|
|
22425
|
+
await rt.fs.writeFile(temporary, line.audio);
|
|
22426
|
+
await rt.fs.rename(temporary, base + ".wav");
|
|
22427
|
+
const record2 = { format: FORMAT, key: key2, voiceId, text: text13, speed, operationKey: line.operationKey, audioSha256: sha256(line.audio), ...line.words ? { words: line.words } : {} };
|
|
22428
|
+
await rt.fs.writeFile(temporary, JSON.stringify(record2));
|
|
22429
|
+
await rt.fs.rename(temporary, base + ".json");
|
|
22430
|
+
} catch {
|
|
22431
|
+
await rt.fs.rm(temporary).catch(() => void 0);
|
|
22432
|
+
}
|
|
22433
|
+
};
|
|
22434
|
+
}
|
|
22435
|
+
});
|
|
22436
|
+
|
|
22387
22437
|
// src/video/submit-retry.ts
|
|
22388
22438
|
var SUBMIT_TRIES, SUBMIT_PAUSE_MS, SAFE_AGAIN, textOf2, lastWord, sendIdempotent;
|
|
22389
22439
|
var init_submit_retry = __esm({
|
|
@@ -22615,49 +22665,6 @@ var init_paid_download = __esm({
|
|
|
22615
22665
|
}
|
|
22616
22666
|
});
|
|
22617
22667
|
|
|
22618
|
-
// src/video/voice/cache.ts
|
|
22619
|
-
var FORMAT, VERSION3, keyOf2, baseOf, off, keptLine, keepLine;
|
|
22620
|
-
var init_cache = __esm({
|
|
22621
|
-
"src/video/voice/cache.ts"() {
|
|
22622
|
-
"use strict";
|
|
22623
|
-
init_util();
|
|
22624
|
-
FORMAT = "popost-voice-cache";
|
|
22625
|
-
VERSION3 = 1;
|
|
22626
|
-
keyOf2 = (voiceId, text13, speed) => sha256(JSON.stringify({ format: FORMAT, version: VERSION3, voiceId, text: text13, speed }));
|
|
22627
|
-
baseOf = (rt, key2) => rt.path.join(rt.path.resolve(rt.cwd), ".popost", "video-cache", "voice", key2);
|
|
22628
|
-
off = (rt) => rt.env.POPOST_VIDEO_CACHE === "off";
|
|
22629
|
-
keptLine = async (rt, voiceId, text13, speed) => {
|
|
22630
|
-
if (off(rt)) return void 0;
|
|
22631
|
-
const key2 = keyOf2(voiceId, text13, speed);
|
|
22632
|
-
const base = baseOf(rt, key2);
|
|
22633
|
-
try {
|
|
22634
|
-
const record2 = JSON.parse(await rt.fs.readText(base + ".json"));
|
|
22635
|
-
const audio = await rt.fs.readFile(base + ".wav");
|
|
22636
|
-
if (record2.format !== FORMAT || record2.key !== key2 || record2.audioSha256 !== sha256(audio) || typeof record2.operationKey !== "string") return void 0;
|
|
22637
|
-
return { audio, operationKey: record2.operationKey, ...Array.isArray(record2.words) ? { words: record2.words } : {} };
|
|
22638
|
-
} catch {
|
|
22639
|
-
return void 0;
|
|
22640
|
-
}
|
|
22641
|
-
};
|
|
22642
|
-
keepLine = async (rt, voiceId, text13, speed, line) => {
|
|
22643
|
-
if (off(rt)) return;
|
|
22644
|
-
const key2 = keyOf2(voiceId, text13, speed);
|
|
22645
|
-
const base = baseOf(rt, key2);
|
|
22646
|
-
const temporary = base + "." + rt.randomUUID() + ".tmp";
|
|
22647
|
-
try {
|
|
22648
|
-
await rt.fs.mkdir(rt.path.dirname(base));
|
|
22649
|
-
await rt.fs.writeFile(temporary, line.audio);
|
|
22650
|
-
await rt.fs.rename(temporary, base + ".wav");
|
|
22651
|
-
const record2 = { format: FORMAT, key: key2, voiceId, text: text13, speed, operationKey: line.operationKey, audioSha256: sha256(line.audio), ...line.words ? { words: line.words } : {} };
|
|
22652
|
-
await rt.fs.writeFile(temporary, JSON.stringify(record2));
|
|
22653
|
-
await rt.fs.rename(temporary, base + ".json");
|
|
22654
|
-
} catch {
|
|
22655
|
-
await rt.fs.rm(temporary).catch(() => void 0);
|
|
22656
|
-
}
|
|
22657
|
-
};
|
|
22658
|
-
}
|
|
22659
|
-
});
|
|
22660
|
-
|
|
22661
22668
|
// src/video/voice/hosted.ts
|
|
22662
22669
|
var clip, client, hasHostedVoice, hostedVoicePage, selectHostedVoice, quoteHostedVoice, downloadVoiceAudio, hostedOperationKey, SPEECH_HINT, LINE_AGAIN, busy2, speak, VOICE_JOBS, writeLine, speakFresh, speaking, hostedSpeech, hostedSpeaker, speechPrice;
|
|
22663
22670
|
var init_hosted = __esm({
|
|
@@ -22791,7 +22798,7 @@ var init_hosted = __esm({
|
|
|
22791
22798
|
});
|
|
22792
22799
|
|
|
22793
22800
|
// src/video/voice/index.ts
|
|
22794
|
-
var VARIABLE, speaksHosted, commandSpeaker, audioSeconds, wordsBeside, TRIM, speakLines, mixPieces, mixLines;
|
|
22801
|
+
var VARIABLE, speaksHosted, commandSpeaker, speakOwn, audioSeconds, wordsBeside, TRIM, speakLines, mixPieces, mixLines;
|
|
22795
22802
|
var init_voice = __esm({
|
|
22796
22803
|
"src/video/voice/index.ts"() {
|
|
22797
22804
|
"use strict";
|
|
@@ -22799,6 +22806,8 @@ var init_voice = __esm({
|
|
|
22799
22806
|
init_tool();
|
|
22800
22807
|
init_wallet();
|
|
22801
22808
|
init_host();
|
|
22809
|
+
init_util();
|
|
22810
|
+
init_cache();
|
|
22802
22811
|
init_hosted();
|
|
22803
22812
|
VARIABLE = "POPOST_TTS_CMD";
|
|
22804
22813
|
speaksHosted = (rt, voice2) => hasHostedVoice(rt) && (!toolCommand(rt, VARIABLE) || Boolean(voice2?.startsWith("popost:")));
|
|
@@ -22809,13 +22818,26 @@ var init_voice = __esm({
|
|
|
22809
22818
|
return {
|
|
22810
22819
|
remote: (voice2) => !custom || Boolean(voice2?.startsWith("popost:")),
|
|
22811
22820
|
timed: (voice2) => !custom || Boolean(voice2?.startsWith("popost:")),
|
|
22812
|
-
speak: (text13, out2, opts = {}) => !custom || opts.voice?.startsWith("popost:") ? hosted.speak(text13, out2, opts) :
|
|
22813
|
-
const file = rt.path.join(dir, "text.txt");
|
|
22814
|
-
await rt.fs.writeFile(file, text13);
|
|
22815
|
-
await runTool(rt, VARIABLE, "The speaker", [file, out2, opts.voice ?? "", String(opts.speed ?? 1)]);
|
|
22816
|
-
})
|
|
22821
|
+
speak: (text13, out2, opts = {}) => !custom || opts.voice?.startsWith("popost:") ? hosted.speak(text13, out2, opts) : speakOwn(rt, custom, text13, out2, opts)
|
|
22817
22822
|
};
|
|
22818
22823
|
};
|
|
22824
|
+
speakOwn = async (rt, command2, text13, out2, opts) => {
|
|
22825
|
+
const voice2 = "command:" + sha256(command2.join(" ")) + ":" + (opts.voice ?? "");
|
|
22826
|
+
const speed = opts.speed ?? 1;
|
|
22827
|
+
const kept3 = await keptLine(rt, voice2, text13, speed);
|
|
22828
|
+
if (kept3) {
|
|
22829
|
+
await rt.fs.writeFile(out2, kept3.audio);
|
|
22830
|
+
if (kept3.words?.length) await rt.fs.writeFile(out2 + ".words.json", JSON.stringify({ words: kept3.words }) + "\n");
|
|
22831
|
+
return;
|
|
22832
|
+
}
|
|
22833
|
+
await withTempDir(rt, "popost-video-tts-", async (dir) => {
|
|
22834
|
+
const file = rt.path.join(dir, "text.txt");
|
|
22835
|
+
await rt.fs.writeFile(file, text13);
|
|
22836
|
+
await runTool(rt, VARIABLE, "The speaker", [file, out2, opts.voice ?? "", String(speed)]);
|
|
22837
|
+
});
|
|
22838
|
+
const words = await rt.fs.readText(out2 + ".words.json").then((t) => JSON.parse(t).words, () => void 0);
|
|
22839
|
+
await keepLine(rt, voice2, text13, speed, { audio: await rt.fs.readFile(out2), operationKey: "local", ...Array.isArray(words) ? { words } : {} });
|
|
22840
|
+
};
|
|
22819
22841
|
audioSeconds = async (rt, file) => {
|
|
22820
22842
|
const r = await runFfmpeg(rt, ["-i", file, "-vn", "-f", "null", "-"]);
|
|
22821
22843
|
const times = [...r.stderr.matchAll(/time=(\d+):(\d+):([\d.]+)/g)];
|
|
@@ -23116,8 +23138,8 @@ var init_speech = __esm({
|
|
|
23116
23138
|
isVisibleSpeech = (value) => isDialogue(value) || isPlain(value);
|
|
23117
23139
|
speakersOf = (speech2) => "lines" in speech2 ? [...new Set(speech2.lines.map((l) => l.speaker))] : [speech2.speaker];
|
|
23118
23140
|
speechAudio = (speech2) => speech2 && !("lines" in speech2) ? speech2.audio : void 0;
|
|
23119
|
-
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\
|
|
23120
|
-
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,
|
|
23141
|
+
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");
|
|
23142
|
+
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.";
|
|
23121
23143
|
finalizeSpeech = async (rt, clip11, speech2, dir, destination = clip11) => {
|
|
23122
23144
|
const said = "lines" in speech2 ? { text: speech2.lines.map((l) => l.text).join(" "), speaker: speakersOf(speech2).join(", ") } : { text: speech2.text, speaker: speech2.speaker };
|
|
23123
23145
|
if (!said.text?.trim() || !said.speaker?.trim()) throw new Error("Visible speech needs the final text and the visible speaker id.");
|
|
@@ -23139,7 +23161,11 @@ var init_speech = __esm({
|
|
|
23139
23161
|
} else if (speech2.mode !== "native") throw new Error("Visible speech mode must be native or lip-sync.");
|
|
23140
23162
|
const p = await probe2(rt, clip11);
|
|
23141
23163
|
const audioFile = clip11 + ".speech.wav";
|
|
23142
|
-
if (!p.hasAudio)
|
|
23164
|
+
if (!p.hasAudio) {
|
|
23165
|
+
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.";
|
|
23166
|
+
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));
|
|
23167
|
+
return limitation;
|
|
23168
|
+
}
|
|
23143
23169
|
await runFfmpegOk(rt, ["-y", "-loglevel", "error", "-i", clip11, "-map", "0:a:0", "-vn", "-ac", "1", "-ar", "48000", "-c:a", "pcm_s16le", audioFile]);
|
|
23144
23170
|
const receipt = {
|
|
23145
23171
|
version: 1,
|
|
@@ -23396,6 +23422,113 @@ var init_voice_spans = __esm({
|
|
|
23396
23422
|
}
|
|
23397
23423
|
});
|
|
23398
23424
|
|
|
23425
|
+
// src/video/compile/footage.ts
|
|
23426
|
+
var probeFootage, extractSize, cacheDir, keyOf3, extractFootage, releaseFootage;
|
|
23427
|
+
var init_footage3 = __esm({
|
|
23428
|
+
"src/video/compile/footage.ts"() {
|
|
23429
|
+
"use strict";
|
|
23430
|
+
init_util();
|
|
23431
|
+
init_host();
|
|
23432
|
+
init_check3();
|
|
23433
|
+
init_frame();
|
|
23434
|
+
init_footage();
|
|
23435
|
+
init_footage2();
|
|
23436
|
+
init_frames();
|
|
23437
|
+
init_frames();
|
|
23438
|
+
probeFootage = async (rt, project, projectDir) => {
|
|
23439
|
+
const root = rt.path.resolve(rt.cwd, projectDir);
|
|
23440
|
+
const strictSpeechRoot = await rt.fs.stat(rt.path.join(root, "replication.json")) ? root : void 0;
|
|
23441
|
+
const named = project.materials.filter((m) => m.kind === "video" && m.file && !isOutside(m.file));
|
|
23442
|
+
const videos = (await Promise.all(named.map(async (m) => await rt.fs.stat(rt.path.resolve(root, m.file ?? "")) === null ? [] : [m]))).flat();
|
|
23443
|
+
const read2 = await mapLimit2(videos, heavyJobs(rt), async (m) => {
|
|
23444
|
+
try {
|
|
23445
|
+
return { id: m.id, ...await readFootage(rt, rt.path.resolve(root, m.file ?? ""), { strictSpeechRoot }) };
|
|
23446
|
+
} catch (e) {
|
|
23447
|
+
return { id: m.id, error: (e instanceof Error ? e.message : String(e)).split("\n")[0] ?? "unreadable" };
|
|
23448
|
+
}
|
|
23449
|
+
});
|
|
23450
|
+
return {
|
|
23451
|
+
native: Object.fromEntries(read2.map((x2) => [x2.id, "native" in x2 && x2.native])),
|
|
23452
|
+
info: Object.fromEntries(read2.map((x2) => [x2.id, "facts" in x2 ? x2.facts : { error: x2.error ?? "unreadable" }])),
|
|
23453
|
+
colour: Object.fromEntries(read2.flatMap((x2) => "colour" in x2 ? [[x2.id, x2.colour]] : []))
|
|
23454
|
+
};
|
|
23455
|
+
};
|
|
23456
|
+
extractSize = (r, id2, src, scale = 1) => {
|
|
23457
|
+
const W = r.canvas.width * scale;
|
|
23458
|
+
const H = r.canvas.height * scale;
|
|
23459
|
+
const need2 = (w, h, fit) => fit === "cover" ? Math.max(w / src.width, h / src.height) : Math.min(w / src.width, h / src.height);
|
|
23460
|
+
const factors = [
|
|
23461
|
+
...r.segments.flatMap((s, k) => s.base.kind === "video" && s.base.play.material === id2 ? [need2(W, H, s.base.fit) * cameraPeak(r, k)] : []),
|
|
23462
|
+
...r.items.flatMap((it) => it.play?.material === id2 ? [need2(it.box[2] * W, it.box[3] * H, it.fit ?? "contain")] : [])
|
|
23463
|
+
];
|
|
23464
|
+
const f = Math.min(1, Math.max(0, ...factors));
|
|
23465
|
+
return { width: Math.max(2, Math.round(src.width * f)), height: Math.max(2, Math.round(src.height * f)) };
|
|
23466
|
+
};
|
|
23467
|
+
cacheDir = async (rt, projectDir, rel2) => {
|
|
23468
|
+
const realpath = rt.fs.realpath?.bind(rt.fs);
|
|
23469
|
+
const start = rt.path.resolve(rt.cwd, projectDir);
|
|
23470
|
+
const root = realpath ? await realpath(start) : start;
|
|
23471
|
+
let dir = start;
|
|
23472
|
+
for (const part of rel2.split("/")) {
|
|
23473
|
+
dir = rt.path.join(dir, part);
|
|
23474
|
+
await rt.fs.mkdir(dir);
|
|
23475
|
+
if (!realpath) continue;
|
|
23476
|
+
const real2 = await realpath(dir);
|
|
23477
|
+
const inside6 = rt.path.relative(root, real2);
|
|
23478
|
+
if (inside6 === "" || inside6.startsWith("..") || rt.path.isAbsolute(inside6))
|
|
23479
|
+
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.");
|
|
23480
|
+
}
|
|
23481
|
+
return dir;
|
|
23482
|
+
};
|
|
23483
|
+
keyOf3 = async (rt, projectDir, src, size) => {
|
|
23484
|
+
const file = rt.path.resolve(rt.cwd, projectDir, src);
|
|
23485
|
+
const info = await rt.fs.stat(file);
|
|
23486
|
+
if (!info) throw new Error("The video material " + src + " disappeared while the page was built. Build it again.");
|
|
23487
|
+
return {
|
|
23488
|
+
key: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs, size.width, size.height])).slice(0, 16),
|
|
23489
|
+
source: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs])).slice(0, 16)
|
|
23490
|
+
};
|
|
23491
|
+
};
|
|
23492
|
+
extractFootage = async (rt, r, projectDir, probed, opts = {}) => {
|
|
23493
|
+
const t0 = performance.now();
|
|
23494
|
+
const started = rt.now().getTime();
|
|
23495
|
+
const used = usedFrames(r);
|
|
23496
|
+
const stats = { extracted: 0, reused: 0 };
|
|
23497
|
+
const jobs2 = await Promise.all(Object.entries(r.footage ?? {}).map(async ([id2, f]) => {
|
|
23498
|
+
const facts = probed.info[id2];
|
|
23499
|
+
const colour2 = probed.colour[id2];
|
|
23500
|
+
if (!facts || "error" in facts || !colour2) throw new Error('extractFootage: video material "' + id2 + '" was not probed. Pass the result of probeFootage for this project.');
|
|
23501
|
+
const size = extractSize(r, id2, facts, opts.scale);
|
|
23502
|
+
return { id: id2, f, size, colour: colour2, ...await keyOf3(rt, projectDir, f.src, size) };
|
|
23503
|
+
}));
|
|
23504
|
+
const dirs = /* @__PURE__ */ new Map();
|
|
23505
|
+
for (const j of jobs2) dirs.set(j.key, await cacheDir(rt, projectDir, FOOTAGE_CACHE + "/" + j.key));
|
|
23506
|
+
await opts.hold?.keep(jobs2.map((j) => j.key));
|
|
23507
|
+
const footage2 = {};
|
|
23508
|
+
for (const j of jobs2) {
|
|
23509
|
+
const rel2 = FOOTAGE_CACHE + "/" + j.key;
|
|
23510
|
+
const dir = dirs.get(j.key);
|
|
23511
|
+
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 });
|
|
23512
|
+
await markUsed(rt, dir, j.source, rt.now().getTime());
|
|
23513
|
+
stats.extracted += res.extracted;
|
|
23514
|
+
stats.reused += res.reused;
|
|
23515
|
+
footage2[j.id] = { ...j.f, dir: rel2 };
|
|
23516
|
+
}
|
|
23517
|
+
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);
|
|
23518
|
+
const cache2 = swept ? { cacheBytes: swept.bytes, freedBytes: swept.freedBytes, ...swept.over ? { overCap: swept.over } : {} } : {};
|
|
23519
|
+
return { resolved: { ...r, footage: footage2 }, stats: { ...stats, ms: Math.round(performance.now() - t0), ...cache2 } };
|
|
23520
|
+
};
|
|
23521
|
+
releaseFootage = async (rt, r, projectDir, opts = {}) => {
|
|
23522
|
+
const started = rt.now().getTime();
|
|
23523
|
+
await opts.hold?.keep([]);
|
|
23524
|
+
const root = rt.path.resolve(rt.cwd, projectDir);
|
|
23525
|
+
if (!await rt.fs.stat(rt.path.join(root, FOOTAGE_CACHE))) return;
|
|
23526
|
+
const sources = await Promise.all(Object.values(r.footage ?? {}).map(async (f) => (await keyOf3(rt, projectDir, f.src, { width: 0, height: 0 })).source));
|
|
23527
|
+
await sweepFrames(rt, root, { sources, started });
|
|
23528
|
+
};
|
|
23529
|
+
}
|
|
23530
|
+
});
|
|
23531
|
+
|
|
23399
23532
|
// src/video/presets/fill.ts
|
|
23400
23533
|
var isGradient, fillColor;
|
|
23401
23534
|
var init_fill = __esm({
|
|
@@ -23766,6 +23899,7 @@ var init_retiming = __esm({
|
|
|
23766
23899
|
"use strict";
|
|
23767
23900
|
init_util();
|
|
23768
23901
|
init_check_common();
|
|
23902
|
+
init_footage3();
|
|
23769
23903
|
init_resolve();
|
|
23770
23904
|
init_io2();
|
|
23771
23905
|
init_revision();
|
|
@@ -23792,7 +23926,7 @@ var init_retiming = __esm({
|
|
|
23792
23926
|
}
|
|
23793
23927
|
const { contract } = await readReplication(rt, dir);
|
|
23794
23928
|
if (!contract) return;
|
|
23795
|
-
const r = resolve(project);
|
|
23929
|
+
const r = resolve(project, (await probeFootage(rt, project, dir)).info);
|
|
23796
23930
|
await rt.fs.writeFile(rt.path.join(dir, RETIMING_FILE), JSON.stringify({
|
|
23797
23931
|
format: "popost-video-retiming",
|
|
23798
23932
|
version: 1,
|
|
@@ -24731,18 +24865,18 @@ var init_clip_sound = __esm({
|
|
|
24731
24865
|
clipSoundOf = async (rt, dir, o) => {
|
|
24732
24866
|
const plan4 = await readMusicPlan(rt, dir);
|
|
24733
24867
|
const exceptions2 = plan4?.clipMusic ?? [];
|
|
24734
|
-
const basisOf2 = (r) => musicBasisOf(r, exceptions2);
|
|
24868
|
+
const basisOf2 = (r) => musicBasisOf(r, exceptions2) ?? (isVideo(r.file) && r.sound !== "silent" && (!plan4 || plan4.music === "none") ? "model-native" : void 0);
|
|
24735
24869
|
const why = (r, basis) => exceptions2.find((c) => c.basis === basis && (c.clip === r.file || c.clip === "all"))?.why ?? "";
|
|
24736
24870
|
const notes2 = [];
|
|
24737
|
-
if (o.clips
|
|
24871
|
+
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.");
|
|
24738
24872
|
if (o.clips && plan4?.unavailable) notes2.push(plan4.unavailable);
|
|
24739
24873
|
return {
|
|
24740
24874
|
exceptions: exceptions2,
|
|
24741
|
-
modeOf: (r) => !isVideo(r.file)
|
|
24875
|
+
modeOf: (r) => !isVideo(r.file) ? void 0 : inferMode(r),
|
|
24742
24876
|
basisOf: basisOf2,
|
|
24743
24877
|
tailOf: (r, mode) => {
|
|
24744
24878
|
const basis = basisOf2(r);
|
|
24745
|
-
return soundTail(mode, basis ? { music: basis } : {});
|
|
24879
|
+
return soundTail(mode, basis ? { music: basis } : { externalMusic: !!plan4 && plan4.music !== "none" });
|
|
24746
24880
|
},
|
|
24747
24881
|
uses: (requests) => requests.flatMap((r) => {
|
|
24748
24882
|
const basis = isVideo(r.file) && r.sound !== "silent" ? basisOf2(r) : void 0;
|
|
@@ -25557,7 +25691,10 @@ var init_generate = __esm({
|
|
|
25557
25691
|
if (made.credits !== void 0) entry2 = { ...entry2, credits: made.credits };
|
|
25558
25692
|
if (charged !== void 0) entry2 = { ...entry2, chargedCredits: charged };
|
|
25559
25693
|
if (!await exists4(partial)) throw new Error("The generator finished without writing the file.");
|
|
25560
|
-
if (sent)
|
|
25694
|
+
if (sent) {
|
|
25695
|
+
const limitation = await finalizeSpeech(rt, partial, sent, o.dir, target2);
|
|
25696
|
+
if (limitation) said.push(asked3.file + ": " + limitation);
|
|
25697
|
+
}
|
|
25561
25698
|
const stripped = mode === "silent" && await probe2(rt, partial).then((p) => p.hasAudio, () => false) ? await stripSound(rt, partial) : false;
|
|
25562
25699
|
const receipt = o.provider ? materialReceiptFile(asked3.file) : void 0;
|
|
25563
25700
|
const provenance = o.provider ? {
|
|
@@ -25575,7 +25712,9 @@ var init_generate = __esm({
|
|
|
25575
25712
|
}
|
|
25576
25713
|
if (made.task) entry2 = { ...entry2, task: made.task };
|
|
25577
25714
|
if (mode) await writeModeReceipt(rt, target2, { sound: mode, ...basis ? { clipMusic: basis } : {}, ...stripped ? { stripped: true } : {} });
|
|
25578
|
-
if (asked3.speech)
|
|
25715
|
+
if (asked3.speech) {
|
|
25716
|
+
for (const ext of [".speech.wav", ".speech.json"]) if (await exists4(partial + ext)) await rt.fs.rename(partial + ext, target2 + ext);
|
|
25717
|
+
}
|
|
25579
25718
|
if (cast || asked3.speech) await rt.fs.writeFile(target2 + ".generation.json", signature2);
|
|
25580
25719
|
if (shown3) await rt.fs.writeFile(receiptFile(target2), JSON.stringify(shown3.receipt, null, 2));
|
|
25581
25720
|
entry2 = { ...entry2, made: true, ...priceOnly ? { unanchored: true, waitsFor: priced } : {} };
|
|
@@ -27867,113 +28006,6 @@ var init_page = __esm({
|
|
|
27867
28006
|
}
|
|
27868
28007
|
});
|
|
27869
28008
|
|
|
27870
|
-
// src/video/compile/footage.ts
|
|
27871
|
-
var probeFootage, extractSize, cacheDir, keyOf3, extractFootage, releaseFootage;
|
|
27872
|
-
var init_footage3 = __esm({
|
|
27873
|
-
"src/video/compile/footage.ts"() {
|
|
27874
|
-
"use strict";
|
|
27875
|
-
init_util();
|
|
27876
|
-
init_host();
|
|
27877
|
-
init_check3();
|
|
27878
|
-
init_frame();
|
|
27879
|
-
init_footage();
|
|
27880
|
-
init_footage2();
|
|
27881
|
-
init_frames();
|
|
27882
|
-
init_frames();
|
|
27883
|
-
probeFootage = async (rt, project, projectDir) => {
|
|
27884
|
-
const root = rt.path.resolve(rt.cwd, projectDir);
|
|
27885
|
-
const strictSpeechRoot = await rt.fs.stat(rt.path.join(root, "replication.json")) ? root : void 0;
|
|
27886
|
-
const named = project.materials.filter((m) => m.kind === "video" && m.file && !isOutside(m.file));
|
|
27887
|
-
const videos = (await Promise.all(named.map(async (m) => await rt.fs.stat(rt.path.resolve(root, m.file ?? "")) === null ? [] : [m]))).flat();
|
|
27888
|
-
const read2 = await mapLimit2(videos, heavyJobs(rt), async (m) => {
|
|
27889
|
-
try {
|
|
27890
|
-
return { id: m.id, ...await readFootage(rt, rt.path.resolve(root, m.file ?? ""), { strictSpeechRoot }) };
|
|
27891
|
-
} catch (e) {
|
|
27892
|
-
return { id: m.id, error: (e instanceof Error ? e.message : String(e)).split("\n")[0] ?? "unreadable" };
|
|
27893
|
-
}
|
|
27894
|
-
});
|
|
27895
|
-
return {
|
|
27896
|
-
native: Object.fromEntries(read2.map((x2) => [x2.id, "native" in x2 && x2.native])),
|
|
27897
|
-
info: Object.fromEntries(read2.map((x2) => [x2.id, "facts" in x2 ? x2.facts : { error: x2.error ?? "unreadable" }])),
|
|
27898
|
-
colour: Object.fromEntries(read2.flatMap((x2) => "colour" in x2 ? [[x2.id, x2.colour]] : []))
|
|
27899
|
-
};
|
|
27900
|
-
};
|
|
27901
|
-
extractSize = (r, id2, src, scale = 1) => {
|
|
27902
|
-
const W = r.canvas.width * scale;
|
|
27903
|
-
const H = r.canvas.height * scale;
|
|
27904
|
-
const need2 = (w, h, fit) => fit === "cover" ? Math.max(w / src.width, h / src.height) : Math.min(w / src.width, h / src.height);
|
|
27905
|
-
const factors = [
|
|
27906
|
-
...r.segments.flatMap((s, k) => s.base.kind === "video" && s.base.play.material === id2 ? [need2(W, H, s.base.fit) * cameraPeak(r, k)] : []),
|
|
27907
|
-
...r.items.flatMap((it) => it.play?.material === id2 ? [need2(it.box[2] * W, it.box[3] * H, it.fit ?? "contain")] : [])
|
|
27908
|
-
];
|
|
27909
|
-
const f = Math.min(1, Math.max(0, ...factors));
|
|
27910
|
-
return { width: Math.max(2, Math.round(src.width * f)), height: Math.max(2, Math.round(src.height * f)) };
|
|
27911
|
-
};
|
|
27912
|
-
cacheDir = async (rt, projectDir, rel2) => {
|
|
27913
|
-
const realpath = rt.fs.realpath?.bind(rt.fs);
|
|
27914
|
-
const start = rt.path.resolve(rt.cwd, projectDir);
|
|
27915
|
-
const root = realpath ? await realpath(start) : start;
|
|
27916
|
-
let dir = start;
|
|
27917
|
-
for (const part of rel2.split("/")) {
|
|
27918
|
-
dir = rt.path.join(dir, part);
|
|
27919
|
-
await rt.fs.mkdir(dir);
|
|
27920
|
-
if (!realpath) continue;
|
|
27921
|
-
const real2 = await realpath(dir);
|
|
27922
|
-
const inside6 = rt.path.relative(root, real2);
|
|
27923
|
-
if (inside6 === "" || inside6.startsWith("..") || rt.path.isAbsolute(inside6))
|
|
27924
|
-
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.");
|
|
27925
|
-
}
|
|
27926
|
-
return dir;
|
|
27927
|
-
};
|
|
27928
|
-
keyOf3 = async (rt, projectDir, src, size) => {
|
|
27929
|
-
const file = rt.path.resolve(rt.cwd, projectDir, src);
|
|
27930
|
-
const info = await rt.fs.stat(file);
|
|
27931
|
-
if (!info) throw new Error("The video material " + src + " disappeared while the page was built. Build it again.");
|
|
27932
|
-
return {
|
|
27933
|
-
key: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs, size.width, size.height])).slice(0, 16),
|
|
27934
|
-
source: sha256(JSON.stringify([EXTRACT_VERSION, src, info.size, info.mtimeMs])).slice(0, 16)
|
|
27935
|
-
};
|
|
27936
|
-
};
|
|
27937
|
-
extractFootage = async (rt, r, projectDir, probed, opts = {}) => {
|
|
27938
|
-
const t0 = performance.now();
|
|
27939
|
-
const started = rt.now().getTime();
|
|
27940
|
-
const used = usedFrames(r);
|
|
27941
|
-
const stats = { extracted: 0, reused: 0 };
|
|
27942
|
-
const jobs2 = await Promise.all(Object.entries(r.footage ?? {}).map(async ([id2, f]) => {
|
|
27943
|
-
const facts = probed.info[id2];
|
|
27944
|
-
const colour2 = probed.colour[id2];
|
|
27945
|
-
if (!facts || "error" in facts || !colour2) throw new Error('extractFootage: video material "' + id2 + '" was not probed. Pass the result of probeFootage for this project.');
|
|
27946
|
-
const size = extractSize(r, id2, facts, opts.scale);
|
|
27947
|
-
return { id: id2, f, size, colour: colour2, ...await keyOf3(rt, projectDir, f.src, size) };
|
|
27948
|
-
}));
|
|
27949
|
-
const dirs = /* @__PURE__ */ new Map();
|
|
27950
|
-
for (const j of jobs2) dirs.set(j.key, await cacheDir(rt, projectDir, FOOTAGE_CACHE + "/" + j.key));
|
|
27951
|
-
await opts.hold?.keep(jobs2.map((j) => j.key));
|
|
27952
|
-
const footage2 = {};
|
|
27953
|
-
for (const j of jobs2) {
|
|
27954
|
-
const rel2 = FOOTAGE_CACHE + "/" + j.key;
|
|
27955
|
-
const dir = dirs.get(j.key);
|
|
27956
|
-
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 });
|
|
27957
|
-
await markUsed(rt, dir, j.source, rt.now().getTime());
|
|
27958
|
-
stats.extracted += res.extracted;
|
|
27959
|
-
stats.reused += res.reused;
|
|
27960
|
-
footage2[j.id] = { ...j.f, dir: rel2 };
|
|
27961
|
-
}
|
|
27962
|
-
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);
|
|
27963
|
-
const cache2 = swept ? { cacheBytes: swept.bytes, freedBytes: swept.freedBytes, ...swept.over ? { overCap: swept.over } : {} } : {};
|
|
27964
|
-
return { resolved: { ...r, footage: footage2 }, stats: { ...stats, ms: Math.round(performance.now() - t0), ...cache2 } };
|
|
27965
|
-
};
|
|
27966
|
-
releaseFootage = async (rt, r, projectDir, opts = {}) => {
|
|
27967
|
-
const started = rt.now().getTime();
|
|
27968
|
-
await opts.hold?.keep([]);
|
|
27969
|
-
const root = rt.path.resolve(rt.cwd, projectDir);
|
|
27970
|
-
if (!await rt.fs.stat(rt.path.join(root, FOOTAGE_CACHE))) return;
|
|
27971
|
-
const sources = await Promise.all(Object.values(r.footage ?? {}).map(async (f) => (await keyOf3(rt, projectDir, f.src, { width: 0, height: 0 })).source));
|
|
27972
|
-
await sweepFrames(rt, root, { sources, started });
|
|
27973
|
-
};
|
|
27974
|
-
}
|
|
27975
|
-
});
|
|
27976
|
-
|
|
27977
28009
|
// src/video/project/words.ts
|
|
27978
28010
|
import { z as z7 } from "zod";
|
|
27979
28011
|
var TokenSchema, WordsFileSchema, FORMAT3, VoiceWordsSchema, VOICE_FPS, voiceTokens, tokenError, parseWordsFile;
|
|
@@ -28076,6 +28108,7 @@ var init_speech_lock = __esm({
|
|
|
28076
28108
|
"src/video/generate/speech-lock.ts"() {
|
|
28077
28109
|
"use strict";
|
|
28078
28110
|
init_util();
|
|
28111
|
+
init_ffmpeg();
|
|
28079
28112
|
init_footage();
|
|
28080
28113
|
init_check_common();
|
|
28081
28114
|
checkSpeechLocks = async (rt, dir, r) => {
|
|
@@ -28095,6 +28128,10 @@ var init_speech_lock = __esm({
|
|
|
28095
28128
|
out2.push(error("materials." + id2, "This speaking clip changed after its audio was locked.", fix2));
|
|
28096
28129
|
continue;
|
|
28097
28130
|
}
|
|
28131
|
+
if (lock.hasAudio === false && !(await probe2(rt, file)).hasAudio) {
|
|
28132
|
+
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."));
|
|
28133
|
+
continue;
|
|
28134
|
+
}
|
|
28098
28135
|
for (const use2 of playsOf(r).filter((p) => p.play.material === id2)) {
|
|
28099
28136
|
const first = Math.max(0, use2.first, use2.play.start), last = Math.min(r.frames - 1, use2.last);
|
|
28100
28137
|
if (last < first) continue;
|
|
@@ -34807,16 +34844,16 @@ var init_speech_check = __esm({
|
|
|
34807
34844
|
SPEECH_PROBLEM = "speech-not-as-written";
|
|
34808
34845
|
speechMatchProblems = (file, m, key2) => {
|
|
34809
34846
|
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.")] : [];
|
|
34810
|
-
return [
|
|
34847
|
+
return [warning(
|
|
34811
34848
|
file,
|
|
34812
34849
|
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(" ") : "") + ".",
|
|
34813
|
-
"Listen to the
|
|
34850
|
+
"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 : "")
|
|
34814
34851
|
)];
|
|
34815
34852
|
};
|
|
34816
|
-
silentClipProblems = (file) => [
|
|
34853
|
+
silentClipProblems = (file) => [warning(
|
|
34817
34854
|
file,
|
|
34818
34855
|
SPEECH_PROBLEM + ": the clip has no sound (no audio stream), so it says none of its lines.",
|
|
34819
|
-
"
|
|
34856
|
+
"Disclose missing native speech as a model-output limitation. Keep the generated video; do not automatically regenerate or add replacement audio."
|
|
34820
34857
|
)];
|
|
34821
34858
|
receiptOf = (rt, clip11) => rt.fs.readText(clip11 + ".speech.json").then((t) => JSON.parse(t), () => void 0);
|
|
34822
34859
|
keptMeasurement = async (rt, dir, file) => {
|
|
@@ -37144,7 +37181,7 @@ var init_readback_frames = __esm({
|
|
|
37144
37181
|
});
|
|
37145
37182
|
|
|
37146
37183
|
// src/video/eval/readback-kept.ts
|
|
37147
|
-
var TEXT_CACHE, FORMAT4, readerOf, keptLines, keptReader;
|
|
37184
|
+
var TEXT_CACHE, FORMAT4, readerOf, keptLines, keepLines, keptReader;
|
|
37148
37185
|
var init_readback_kept = __esm({
|
|
37149
37186
|
"src/video/eval/readback-kept.ts"() {
|
|
37150
37187
|
"use strict";
|
|
@@ -37158,6 +37195,15 @@ var init_readback_kept = __esm({
|
|
|
37158
37195
|
const ok = kept3?.format === FORMAT4 && kept3.version === 1 && kept3.reader === reader && typeof kept3.frames === "object" && kept3.frames !== null;
|
|
37159
37196
|
return ok ? kept3.frames : {};
|
|
37160
37197
|
};
|
|
37198
|
+
keepLines = async (rt, file, kept3) => {
|
|
37199
|
+
const temporary = file + "." + rt.randomUUID() + ".tmp";
|
|
37200
|
+
try {
|
|
37201
|
+
await rt.fs.writeFile(temporary, JSON.stringify(kept3) + "\n");
|
|
37202
|
+
await rt.fs.rename(temporary, file);
|
|
37203
|
+
} catch {
|
|
37204
|
+
await rt.fs.rm(temporary).catch(() => void 0);
|
|
37205
|
+
}
|
|
37206
|
+
};
|
|
37161
37207
|
keptReader = (rt, file, reader, onKept) => ({
|
|
37162
37208
|
read: async (frames) => {
|
|
37163
37209
|
if (rt.env.POPOST_VIDEO_CACHE === "off") return reader.read(frames);
|
|
@@ -37171,8 +37217,7 @@ var init_readback_kept = __esm({
|
|
|
37171
37217
|
const lines2 = old[i] ?? read2.get(f.frame);
|
|
37172
37218
|
return lines2 ? [{ hash: hashes2[i], sample: { frame: f.frame, lines: lines2 } }] : [];
|
|
37173
37219
|
});
|
|
37174
|
-
|
|
37175
|
-
await rt.fs.writeFile(file, JSON.stringify(keep3) + "\n");
|
|
37220
|
+
await keepLines(rt, file, { format: FORMAT4, version: 1, reader: who, frames: Object.fromEntries(found.map((x2) => [x2.hash, x2.sample.lines])) });
|
|
37176
37221
|
return found.map((x2) => x2.sample).sort((a, b) => a.frame - b.frame);
|
|
37177
37222
|
}
|
|
37178
37223
|
});
|
|
@@ -37324,84 +37369,8 @@ var init_pictures = __esm({
|
|
|
37324
37369
|
}
|
|
37325
37370
|
});
|
|
37326
37371
|
|
|
37327
|
-
// src/video/look/index.ts
|
|
37328
|
-
var two11, r36, clamp4, shotMoments, secondMoments, GLYPHS, labelFilter, JPEG, pair3, sheet3, lookAt3;
|
|
37329
|
-
var init_look2 = __esm({
|
|
37330
|
-
"src/video/look/index.ts"() {
|
|
37331
|
-
"use strict";
|
|
37332
|
-
init_host();
|
|
37333
|
-
init_decode();
|
|
37334
|
-
init_ffmpeg();
|
|
37335
|
-
init_pictures();
|
|
37336
|
-
two11 = (n) => String(n).padStart(2, "0");
|
|
37337
|
-
r36 = (v) => Math.round(v * 1e3) / 1e3;
|
|
37338
|
-
clamp4 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
37339
|
-
shotMoments = (shots2) => shots2.flatMap((s, k) => lookTimes(s.start, s.end, 3).map((t, j) => {
|
|
37340
|
-
const part = ["a", "b", "c"][j] ?? "a";
|
|
37341
|
-
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 };
|
|
37342
|
-
}));
|
|
37343
|
-
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)) }));
|
|
37344
|
-
GLYPHS = {
|
|
37345
|
-
A: [".###.", "#...#", "#...#", "#####", "#...#", "#...#", "#...#"],
|
|
37346
|
-
B: ["####.", "#...#", "#...#", "####.", "#...#", "#...#", "####."]
|
|
37347
|
-
};
|
|
37348
|
-
labelFilter = (letter, height) => {
|
|
37349
|
-
const s = Math.max(2, Math.round(height / 60));
|
|
37350
|
-
const box2 = (x2, y, w, h, color2) => "drawbox=x=" + x2 + ":y=" + y + ":w=" + w + ":h=" + h + ":color=" + color2 + ":t=fill";
|
|
37351
|
-
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")));
|
|
37352
|
-
return [box2(s, s, 7 * s, 9 * s, "black@0.6"), ...cells].join(",");
|
|
37353
|
-
};
|
|
37354
|
-
JPEG = ["-q:v", "3"];
|
|
37355
|
-
pair3 = async (rt, a, b, height, out2) => {
|
|
37356
|
-
const side = (i, letter) => "[" + i + ":v]scale=-2:" + height + "," + labelFilter(letter, height) + "[" + letter + "]";
|
|
37357
|
-
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]);
|
|
37358
|
-
};
|
|
37359
|
-
sheet3 = async (rt, files, out2) => {
|
|
37360
|
-
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]);
|
|
37361
|
-
};
|
|
37362
|
-
lookAt3 = async (rt, o) => {
|
|
37363
|
-
const width = o.width ?? 480;
|
|
37364
|
-
const a = await probe2(rt, o.video);
|
|
37365
|
-
const b = o.against === void 0 ? void 0 : await probe2(rt, o.against);
|
|
37366
|
-
const { height } = thumbSize(a.width, a.height, width);
|
|
37367
|
-
const against = o.against;
|
|
37368
|
-
await rt.fs.mkdir(o.outDir);
|
|
37369
|
-
const pictures = [];
|
|
37370
|
-
await withTempDir(rt, "popost-video-look-", async (dir) => {
|
|
37371
|
-
const left = await extractFrames2(rt, o.video, o.moments.map((m) => m.frame), rt.path.join(dir, "a"), width);
|
|
37372
|
-
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))) : [];
|
|
37373
|
-
const right = b && against !== void 0 ? await extractFrames2(rt, against, others, rt.path.join(dir, "b"), width) : void 0;
|
|
37374
|
-
for (const [i, m] of o.moments.entries()) {
|
|
37375
|
-
const file = rt.path.join(o.outDir, m.name + ".jpg");
|
|
37376
|
-
const where3 = { ...m.shot === void 0 ? {} : { shot: m.shot }, ...m.part ? { part: m.part } : {} };
|
|
37377
|
-
if (!b || against === void 0) {
|
|
37378
|
-
const picture3 = left.get(m.frame);
|
|
37379
|
-
if (rt.fs.copyFile) await rt.fs.copyFile(picture3, file);
|
|
37380
|
-
else await rt.fs.writeFile(file, await rt.fs.readFile(picture3));
|
|
37381
|
-
pictures.push({ file, frame: m.frame, second: r36(m.frame / a.fps), ...where3 });
|
|
37382
|
-
continue;
|
|
37383
|
-
}
|
|
37384
|
-
const other = others[i];
|
|
37385
|
-
await pair3(rt, left.get(m.frame), right?.get(other), height, file);
|
|
37386
|
-
pictures.push({ file, frame: m.frame, second: r36(m.frame / a.fps), ...where3, against: { frame: other, second: r36(other / b.fps) } });
|
|
37387
|
-
}
|
|
37388
|
-
});
|
|
37389
|
-
const shots2 = [...new Set(pictures.flatMap((p) => p.shot === void 0 ? [] : [p.shot]))];
|
|
37390
|
-
const sheets = [];
|
|
37391
|
-
for (const shot of shots2) {
|
|
37392
|
-
const mine = pictures.filter((p) => p.shot === shot).map((p) => p.file);
|
|
37393
|
-
if (mine.length !== 3) continue;
|
|
37394
|
-
const file = rt.path.join(o.outDir, "shot-" + two11(shot) + ".jpg");
|
|
37395
|
-
await sheet3(rt, mine, file);
|
|
37396
|
-
sheets.push({ file, shot, pictures: mine });
|
|
37397
|
-
}
|
|
37398
|
-
return { pictures, sheets };
|
|
37399
|
-
};
|
|
37400
|
-
}
|
|
37401
|
-
});
|
|
37402
|
-
|
|
37403
37372
|
// src/video/look/sheets.ts
|
|
37404
|
-
var GAP2, BAND, MAX_WIDTH2, GROUND, INK2, MARK, MARK_INK,
|
|
37373
|
+
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;
|
|
37405
37374
|
var init_sheets = __esm({
|
|
37406
37375
|
"src/video/look/sheets.ts"() {
|
|
37407
37376
|
"use strict";
|
|
@@ -37416,7 +37385,7 @@ var init_sheets = __esm({
|
|
|
37416
37385
|
INK2 = [240, 240, 240];
|
|
37417
37386
|
MARK = [232, 160, 32];
|
|
37418
37387
|
MARK_INK = [16, 16, 16];
|
|
37419
|
-
|
|
37388
|
+
GLYPHS = {
|
|
37420
37389
|
"0": [".###.", "#...#", "#..##", "#.#.#", "##..#", "#...#", ".###."],
|
|
37421
37390
|
"1": ["..#..", ".##..", "..#..", "..#..", "..#..", "..#..", ".###."],
|
|
37422
37391
|
"2": [".###.", "#...#", "....#", "...#.", "..#..", ".#...", "#####"],
|
|
@@ -37448,7 +37417,7 @@ var init_sheets = __esm({
|
|
|
37448
37417
|
};
|
|
37449
37418
|
write = (c, text13, x2, y, s, rgb) => {
|
|
37450
37419
|
[...text13].forEach((ch, k) => {
|
|
37451
|
-
const rows3 =
|
|
37420
|
+
const rows3 = GLYPHS[ch];
|
|
37452
37421
|
if (!rows3) return;
|
|
37453
37422
|
rows3.forEach((row, r) => [...row].forEach((cell, q) => {
|
|
37454
37423
|
if (cell === "#") fill2(c, x2 + (k * 6 + q) * s, y + r * s, s, s, rgb);
|
|
@@ -37482,7 +37451,7 @@ var init_sheets = __esm({
|
|
|
37482
37451
|
}
|
|
37483
37452
|
};
|
|
37484
37453
|
place2 = (d, slot, rgb, tw, th, label2, marked2) => {
|
|
37485
|
-
const { width, height } = d.
|
|
37454
|
+
const { width, height } = d.drawn;
|
|
37486
37455
|
d.canvas ??= (() => {
|
|
37487
37456
|
const c = { width, height, data: new Uint8Array(width * height * 3) };
|
|
37488
37457
|
fill2(c, 0, 0, width, height, GROUND);
|
|
@@ -37494,9 +37463,16 @@ var init_sheets = __esm({
|
|
|
37494
37463
|
const s = 2, w = (label2.length * 6 - 1) * s;
|
|
37495
37464
|
write(d.canvas, label2, x2 + Math.max(0, Math.round((tw - w) / 2)), y + th + 2, s, marked2 ? MARK_INK : INK2);
|
|
37496
37465
|
};
|
|
37497
|
-
|
|
37466
|
+
LOOK_JPEG = ["-q:v", "5"];
|
|
37467
|
+
LOOK_MAX_PIXELS = 115e4;
|
|
37468
|
+
lookSize = (width, height) => {
|
|
37469
|
+
const k = Math.min(1, Math.sqrt(LOOK_MAX_PIXELS / Math.max(1, width * height)));
|
|
37470
|
+
return k === 1 ? { width, height } : { width: 2 * Math.floor(width * k / 2), height: 2 * Math.floor(height * k / 2) };
|
|
37471
|
+
};
|
|
37472
|
+
encodeJpeg = async (rt, c, file, out2) => {
|
|
37498
37473
|
await rt.fs.mkdir(rt.path.dirname(file));
|
|
37499
|
-
|
|
37474
|
+
const scale = out2.width === c.width && out2.height === c.height ? [] : ["-vf", "scale=" + out2.width + ":" + out2.height + ":flags=area"];
|
|
37475
|
+
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);
|
|
37500
37476
|
};
|
|
37501
37477
|
writeSheets2 = async (rt, video, specs2, o) => {
|
|
37502
37478
|
const p = o.probe ?? await probe2(rt, video);
|
|
@@ -37508,9 +37484,9 @@ var init_sheets = __esm({
|
|
|
37508
37484
|
const drawings = specs2.map((spec10) => {
|
|
37509
37485
|
const frames2 = spec10.frames.filter((f) => f >= 0 && f <= last);
|
|
37510
37486
|
const grid = gridOf(Math.max(1, frames2.length), size.width);
|
|
37511
|
-
const
|
|
37512
|
-
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 };
|
|
37513
|
-
return { spec: { ...spec10, frames: frames2 }, grid, left: frames2.length, result };
|
|
37487
|
+
const drawn = { width: GAP2 + grid.columns * (size.width + GAP2), height: GAP2 + grid.rows * (size.height + BAND + GAP2) };
|
|
37488
|
+
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) };
|
|
37489
|
+
return { spec: { ...spec10, frames: frames2 }, grid, drawn, left: frames2.length, result };
|
|
37514
37490
|
});
|
|
37515
37491
|
const wanted = /* @__PURE__ */ new Map();
|
|
37516
37492
|
for (const d of drawings) d.spec.frames.forEach((f, slot) => {
|
|
@@ -37525,7 +37501,7 @@ var init_sheets = __esm({
|
|
|
37525
37501
|
d.canvas = void 0;
|
|
37526
37502
|
if (!canvas) return;
|
|
37527
37503
|
d.written = true;
|
|
37528
|
-
written2 = written2.then(() => failed4 ? void 0 : encodeJpeg(rt, canvas, d.result.file)).catch((error2) => {
|
|
37504
|
+
written2 = written2.then(() => failed4 ? void 0 : encodeJpeg(rt, canvas, d.result.file, d.result)).catch((error2) => {
|
|
37529
37505
|
failed4 ??= { error: error2 };
|
|
37530
37506
|
});
|
|
37531
37507
|
};
|
|
@@ -37546,6 +37522,83 @@ var init_sheets = __esm({
|
|
|
37546
37522
|
}
|
|
37547
37523
|
});
|
|
37548
37524
|
|
|
37525
|
+
// src/video/look/index.ts
|
|
37526
|
+
var two11, r36, clamp4, shotMoments, secondMoments, GLYPHS2, labelFilter, JPEG, pair3, sheet3, lookAt3;
|
|
37527
|
+
var init_look2 = __esm({
|
|
37528
|
+
"src/video/look/index.ts"() {
|
|
37529
|
+
"use strict";
|
|
37530
|
+
init_host();
|
|
37531
|
+
init_decode();
|
|
37532
|
+
init_ffmpeg();
|
|
37533
|
+
init_pictures();
|
|
37534
|
+
init_sheets();
|
|
37535
|
+
two11 = (n) => String(n).padStart(2, "0");
|
|
37536
|
+
r36 = (v) => Math.round(v * 1e3) / 1e3;
|
|
37537
|
+
clamp4 = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
37538
|
+
shotMoments = (shots2) => shots2.flatMap((s, k) => lookTimes(s.start, s.end, 3).map((t, j) => {
|
|
37539
|
+
const part = ["a", "b", "c"][j] ?? "a";
|
|
37540
|
+
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 };
|
|
37541
|
+
}));
|
|
37542
|
+
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)) }));
|
|
37543
|
+
GLYPHS2 = {
|
|
37544
|
+
A: [".###.", "#...#", "#...#", "#####", "#...#", "#...#", "#...#"],
|
|
37545
|
+
B: ["####.", "#...#", "#...#", "####.", "#...#", "#...#", "####."]
|
|
37546
|
+
};
|
|
37547
|
+
labelFilter = (letter, height) => {
|
|
37548
|
+
const s = Math.max(2, Math.round(height / 60));
|
|
37549
|
+
const box2 = (x2, y, w, h, color2) => "drawbox=x=" + x2 + ":y=" + y + ":w=" + w + ":h=" + h + ":color=" + color2 + ":t=fill";
|
|
37550
|
+
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")));
|
|
37551
|
+
return [box2(s, s, 7 * s, 9 * s, "black@0.6"), ...cells].join(",");
|
|
37552
|
+
};
|
|
37553
|
+
JPEG = LOOK_JPEG;
|
|
37554
|
+
pair3 = async (rt, a, b, height, out2) => {
|
|
37555
|
+
const side = (i, letter) => "[" + i + ":v]scale=-2:" + height + "," + labelFilter(letter, height) + "[" + letter + "]";
|
|
37556
|
+
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]);
|
|
37557
|
+
};
|
|
37558
|
+
sheet3 = async (rt, files, out2) => {
|
|
37559
|
+
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]);
|
|
37560
|
+
};
|
|
37561
|
+
lookAt3 = async (rt, o) => {
|
|
37562
|
+
const width = o.width ?? 480;
|
|
37563
|
+
const a = await probe2(rt, o.video);
|
|
37564
|
+
const b = o.against === void 0 ? void 0 : await probe2(rt, o.against);
|
|
37565
|
+
const { height } = thumbSize(a.width, a.height, width);
|
|
37566
|
+
const against = o.against;
|
|
37567
|
+
await rt.fs.mkdir(o.outDir);
|
|
37568
|
+
const pictures = [];
|
|
37569
|
+
await withTempDir(rt, "popost-video-look-", async (dir) => {
|
|
37570
|
+
const left = await extractFrames2(rt, o.video, o.moments.map((m) => m.frame), rt.path.join(dir, "a"), width);
|
|
37571
|
+
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))) : [];
|
|
37572
|
+
const right = b && against !== void 0 ? await extractFrames2(rt, against, others, rt.path.join(dir, "b"), width) : void 0;
|
|
37573
|
+
for (const [i, m] of o.moments.entries()) {
|
|
37574
|
+
const file = rt.path.join(o.outDir, m.name + ".jpg");
|
|
37575
|
+
const where3 = { ...m.shot === void 0 ? {} : { shot: m.shot }, ...m.part ? { part: m.part } : {} };
|
|
37576
|
+
if (!b || against === void 0) {
|
|
37577
|
+
const picture3 = left.get(m.frame);
|
|
37578
|
+
if (rt.fs.copyFile) await rt.fs.copyFile(picture3, file);
|
|
37579
|
+
else await rt.fs.writeFile(file, await rt.fs.readFile(picture3));
|
|
37580
|
+
pictures.push({ file, frame: m.frame, second: r36(m.frame / a.fps), ...where3 });
|
|
37581
|
+
continue;
|
|
37582
|
+
}
|
|
37583
|
+
const other = others[i];
|
|
37584
|
+
await pair3(rt, left.get(m.frame), right?.get(other), height, file);
|
|
37585
|
+
pictures.push({ file, frame: m.frame, second: r36(m.frame / a.fps), ...where3, against: { frame: other, second: r36(other / b.fps) } });
|
|
37586
|
+
}
|
|
37587
|
+
});
|
|
37588
|
+
const shots2 = [...new Set(pictures.flatMap((p) => p.shot === void 0 ? [] : [p.shot]))];
|
|
37589
|
+
const sheets = [];
|
|
37590
|
+
for (const shot of shots2) {
|
|
37591
|
+
const mine = pictures.filter((p) => p.shot === shot).map((p) => p.file);
|
|
37592
|
+
if (mine.length !== 3) continue;
|
|
37593
|
+
const file = rt.path.join(o.outDir, "shot-" + two11(shot) + ".jpg");
|
|
37594
|
+
await sheet3(rt, mine, file);
|
|
37595
|
+
sheets.push({ file, shot, pictures: mine });
|
|
37596
|
+
}
|
|
37597
|
+
return { pictures, sheets };
|
|
37598
|
+
};
|
|
37599
|
+
}
|
|
37600
|
+
});
|
|
37601
|
+
|
|
37549
37602
|
// src/video/look/like.ts
|
|
37550
37603
|
var sheetsLike;
|
|
37551
37604
|
var init_like = __esm({
|
|
@@ -39208,7 +39261,7 @@ var init_shots = __esm({
|
|
|
39208
39261
|
});
|
|
39209
39262
|
|
|
39210
39263
|
// src/video/render/chunked.ts
|
|
39211
|
-
var keysOf3, draw, prune, chunkFile, join2, renderInChunks;
|
|
39264
|
+
var keysOf3, draw, prune, chunkFile, join2, shotsIn, renderInChunks;
|
|
39212
39265
|
var init_chunked = __esm({
|
|
39213
39266
|
"src/video/render/chunked.ts"() {
|
|
39214
39267
|
"use strict";
|
|
@@ -39256,6 +39309,7 @@ var init_chunked = __esm({
|
|
|
39256
39309
|
await rt.fs.rm(list7);
|
|
39257
39310
|
}
|
|
39258
39311
|
};
|
|
39312
|
+
shotsIn = (r, ranges) => r.segments.filter((s) => ranges.some(([from, to]) => s.start < to && s.end > from)).map((s) => s.id);
|
|
39259
39313
|
renderInChunks = async (rt, job) => {
|
|
39260
39314
|
const started = Date.now();
|
|
39261
39315
|
const first = job.sessions[0], r = first.resolved;
|
|
@@ -39264,13 +39318,17 @@ var init_chunked = __esm({
|
|
|
39264
39318
|
await rt.fs.mkdir(dir);
|
|
39265
39319
|
try {
|
|
39266
39320
|
const files = [];
|
|
39321
|
+
const drawn = [];
|
|
39267
39322
|
let reused = 0;
|
|
39268
39323
|
for (const [from, to] of chunkRanges(r)) {
|
|
39269
39324
|
const file = await chunkFile(rt, job, c, dir, from, to);
|
|
39270
39325
|
if (c && (await rt.fs.stat(file))?.isFile) {
|
|
39271
39326
|
reused++;
|
|
39272
39327
|
job.onProgress?.(to, r.frames);
|
|
39273
|
-
} else
|
|
39328
|
+
} else {
|
|
39329
|
+
await draw(rt, job, from, to, file);
|
|
39330
|
+
drawn.push([from, to]);
|
|
39331
|
+
}
|
|
39274
39332
|
files.push(file);
|
|
39275
39333
|
}
|
|
39276
39334
|
await join2(rt, job, files);
|
|
@@ -39278,7 +39336,7 @@ var init_chunked = __esm({
|
|
|
39278
39336
|
await prune(rt, dir, files, started);
|
|
39279
39337
|
await markSetUsed(rt, dir).catch(() => void 0);
|
|
39280
39338
|
}
|
|
39281
|
-
return { total: files.length, reused };
|
|
39339
|
+
return { total: files.length, reused, ...reused ? { drawnShots: shotsIn(r, drawn) } : {} };
|
|
39282
39340
|
} finally {
|
|
39283
39341
|
if (!c) await rt.fs.rm(dir);
|
|
39284
39342
|
}
|
|
@@ -39338,17 +39396,20 @@ var init_layout = __esm({
|
|
|
39338
39396
|
// src/video/render/index.ts
|
|
39339
39397
|
var render_exports2 = {};
|
|
39340
39398
|
__export(render_exports2, {
|
|
39399
|
+
LOOK_JPEG_QUALITY: () => LOOK_JPEG_QUALITY,
|
|
39341
39400
|
MAX_PAGES: () => MAX_PAGES2,
|
|
39342
39401
|
RenderRangeError: () => RenderRangeError,
|
|
39343
39402
|
checkLayout: () => checkLayout,
|
|
39344
39403
|
frameFileName: () => frameFileName,
|
|
39404
|
+
frameFormatOf: () => frameFormatOf,
|
|
39405
|
+
lookScale: () => lookScale,
|
|
39345
39406
|
openRenderer: () => openRenderer,
|
|
39346
39407
|
pagesFor: () => pagesFor,
|
|
39347
39408
|
renderFrame: () => renderFrame,
|
|
39348
39409
|
renderFrames: () => renderFrames,
|
|
39349
39410
|
renderVideo: () => renderVideo
|
|
39350
39411
|
});
|
|
39351
|
-
var RenderRangeError, range, MAX_PAGES2, WORK_PER_PAGE, pagesFor, cutSounds, inChunks, renderOnce, dropFrames, renderVideo, drawVideo, openRenderer, frameFileName, renderFrames, renderFrame;
|
|
39412
|
+
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;
|
|
39352
39413
|
var init_render2 = __esm({
|
|
39353
39414
|
"src/video/render/index.ts"() {
|
|
39354
39415
|
"use strict";
|
|
@@ -39362,6 +39423,7 @@ var init_render2 = __esm({
|
|
|
39362
39423
|
init_shots();
|
|
39363
39424
|
init_chunked();
|
|
39364
39425
|
init_frames();
|
|
39426
|
+
init_sheets();
|
|
39365
39427
|
init_layout();
|
|
39366
39428
|
RenderRangeError = class extends Error {
|
|
39367
39429
|
name = "RenderRangeError";
|
|
@@ -39443,11 +39505,19 @@ var init_render2 = __esm({
|
|
|
39443
39505
|
};
|
|
39444
39506
|
openRenderer = async (rt, projectDir, opts = {}) => {
|
|
39445
39507
|
const session = await openSession(rt, projectDir, { scale: opts.scale, reuse: opts.reuse === true, lazyScenes: opts.lazyScenes });
|
|
39446
|
-
return { width: session.width, height: session.height, frames: session.resolved.frames, frame: (n) => session.frame(n,
|
|
39508
|
+
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() };
|
|
39509
|
+
};
|
|
39510
|
+
LOOK_JPEG_QUALITY = 85;
|
|
39511
|
+
frameFormatOf = (file) => /\.jpe?g$/i.test(file) ? "jpeg" : "png";
|
|
39512
|
+
lookScale = async (rt, projectDir) => {
|
|
39513
|
+
const canvas = await rt.fs.readText(rt.path.resolve(rt.cwd, projectDir, "video.json")).then((t) => JSON.parse(t).canvas, () => void 0);
|
|
39514
|
+
const w = Number(canvas?.width), h = Number(canvas?.height);
|
|
39515
|
+
return w > 0 && h > 0 ? Math.min(1, Math.floor(Math.sqrt(LOOK_MAX_PIXELS / (w * h)) * 1e3) / 1e3) : 1;
|
|
39447
39516
|
};
|
|
39448
|
-
|
|
39517
|
+
scaleFor = async (rt, projectDir, format, scale) => scale ?? (format === "jpeg" ? await lookScale(rt, projectDir) : void 0);
|
|
39518
|
+
frameFileName = (n, format = "png") => "f" + String(n).padStart(6, "0") + (format === "jpeg" ? ".jpg" : ".png");
|
|
39449
39519
|
renderFrames = async (rt, opts) => {
|
|
39450
|
-
const renderer = await openRenderer(rt, opts.projectDir, { scale: opts.scale });
|
|
39520
|
+
const renderer = await openRenderer(rt, opts.projectDir, { scale: await scaleFor(rt, opts.projectDir, opts.format ?? "png", opts.scale) });
|
|
39451
39521
|
try {
|
|
39452
39522
|
const outside2 = opts.frames.find((n) => !Number.isInteger(n) || n < 0 || n >= renderer.frames);
|
|
39453
39523
|
if (outside2 !== void 0 || !opts.frames.length)
|
|
@@ -39455,8 +39525,8 @@ var init_render2 = __esm({
|
|
|
39455
39525
|
await rt.fs.mkdir(rt.path.resolve(rt.cwd, opts.outDir));
|
|
39456
39526
|
const files = [];
|
|
39457
39527
|
for (const n of [...new Set(opts.frames)].sort((a, b) => a - b)) {
|
|
39458
|
-
const out2 = rt.path.join(opts.outDir, frameFileName(n));
|
|
39459
|
-
await rt.fs.writeFile(rt.path.resolve(rt.cwd, out2), await renderer.frame(n));
|
|
39528
|
+
const out2 = rt.path.join(opts.outDir, frameFileName(n, opts.format));
|
|
39529
|
+
await rt.fs.writeFile(rt.path.resolve(rt.cwd, out2), await renderer.frame(n, opts.format));
|
|
39460
39530
|
files.push({ frame: n, out: out2 });
|
|
39461
39531
|
}
|
|
39462
39532
|
return { width: renderer.width, height: renderer.height, files };
|
|
@@ -39465,11 +39535,11 @@ var init_render2 = __esm({
|
|
|
39465
39535
|
}
|
|
39466
39536
|
};
|
|
39467
39537
|
renderFrame = async (rt, opts) => {
|
|
39468
|
-
const renderer = await openRenderer(rt, opts.projectDir, { scale: opts.scale });
|
|
39538
|
+
const renderer = await openRenderer(rt, opts.projectDir, { scale: await scaleFor(rt, opts.projectDir, frameFormatOf(opts.out), opts.scale) });
|
|
39469
39539
|
try {
|
|
39470
39540
|
if (!Number.isInteger(opts.frame) || opts.frame < 0 || opts.frame >= renderer.frames)
|
|
39471
39541
|
throw new RenderRangeError("renderFrame: frame " + opts.frame + " is outside the video, which has frames 0.." + (renderer.frames - 1) + ".");
|
|
39472
|
-
await rt.fs.writeFile(rt.path.resolve(rt.cwd, opts.out), await renderer.frame(opts.frame));
|
|
39542
|
+
await rt.fs.writeFile(rt.path.resolve(rt.cwd, opts.out), await renderer.frame(opts.frame, frameFormatOf(opts.out)));
|
|
39473
39543
|
return { width: renderer.width, height: renderer.height };
|
|
39474
39544
|
} finally {
|
|
39475
39545
|
await renderer.close();
|
|
@@ -46073,6 +46143,7 @@ var init_write2 = __esm({
|
|
|
46073
46143
|
"use strict";
|
|
46074
46144
|
init_check3();
|
|
46075
46145
|
init_schema();
|
|
46146
|
+
init_footage3();
|
|
46076
46147
|
init_compile();
|
|
46077
46148
|
init_resolve();
|
|
46078
46149
|
init_project3();
|
|
@@ -46087,7 +46158,7 @@ var init_write2 = __esm({
|
|
|
46087
46158
|
const { project, problems: named } = await withEffectFiles(rt, parsed.project);
|
|
46088
46159
|
const blocking = [...named, ...checkProject2(project)].filter((p) => p.level === "error");
|
|
46089
46160
|
if (blocking.length) return { scenes: [], problems: blocking };
|
|
46090
|
-
const r = resolve(project);
|
|
46161
|
+
const r = resolve(project, (await probeFootage(rt, project, dir)).info);
|
|
46091
46162
|
const fps = r.canvas.fps;
|
|
46092
46163
|
const offset = o.offset ?? 0;
|
|
46093
46164
|
const library = await exists3(rt, rt.path.join(dir, "lib", "gsap.min.js")) ? "gsap" : void 0;
|
|
@@ -46494,13 +46565,14 @@ var init_make = __esm({
|
|
|
46494
46565
|
return frames;
|
|
46495
46566
|
};
|
|
46496
46567
|
frame = command(
|
|
46497
|
-
"draw frames of the project
|
|
46568
|
+
"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",
|
|
46498
46569
|
{
|
|
46499
46570
|
positionals: [PROJECT3],
|
|
46500
46571
|
options: [
|
|
46501
46572
|
{ flag: "--frame", kind: "int", help: "the frame number, from 0" },
|
|
46502
46573
|
{ flag: "--frames", help: "frame numbers separated by commas; --out is then a directory" },
|
|
46503
|
-
{ flag: "--out", required: true, help: "the
|
|
46574
|
+
{ 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)" },
|
|
46575
|
+
{ flag: "--format", help: "with --frames: jpg (to look at) or png (exact pixels, the default)" },
|
|
46504
46576
|
SCALE
|
|
46505
46577
|
]
|
|
46506
46578
|
},
|
|
@@ -46509,9 +46581,12 @@ var init_make = __esm({
|
|
|
46509
46581
|
const scale = args.number("scale");
|
|
46510
46582
|
const many = args.string("frames");
|
|
46511
46583
|
const n = args.number("frame");
|
|
46512
|
-
if (many === void 0 === (n === void 0)) throw new VideoCommandError("Give either --frame N (one
|
|
46584
|
+
if (many === void 0 === (n === void 0)) throw new VideoCommandError("Give either --frame N (one picture) or --frames N,N,... (a directory of pictures).");
|
|
46585
|
+
const format = args.string("format");
|
|
46586
|
+
if (format !== void 0 && format !== "jpg" && format !== "png") throw new VideoCommandError("Choose --format jpg or --format png.");
|
|
46587
|
+
if (format !== void 0 && many === void 0) throw new VideoCommandError("--format goes with --frames; for one frame, name --out .jpg or .png.");
|
|
46513
46588
|
if (many !== void 0) {
|
|
46514
|
-
const r5 = await renderFrames(rt, { projectDir: args.req("project-dir"), frames: framesOf2(many), outDir: out2, ...scale === void 0 ? {} : { scale } });
|
|
46589
|
+
const r5 = await renderFrames(rt, { projectDir: args.req("project-dir"), frames: framesOf2(many), outDir: out2, ...scale === void 0 ? {} : { scale }, ...format === "jpg" ? { format: "jpeg" } : {} });
|
|
46515
46590
|
printJson(rt, { ok: true, dir: out2, frames: r5.files, width: r5.width, height: r5.height });
|
|
46516
46591
|
return;
|
|
46517
46592
|
}
|
|
@@ -46520,7 +46595,7 @@ var init_make = __esm({
|
|
|
46520
46595
|
})
|
|
46521
46596
|
);
|
|
46522
46597
|
render2 = command(
|
|
46523
|
-
"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",
|
|
46598
|
+
"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",
|
|
46524
46599
|
{
|
|
46525
46600
|
positionals: [PROJECT3],
|
|
46526
46601
|
options: [
|
|
@@ -47896,7 +47971,7 @@ var init_loop2 = __esm({
|
|
|
47896
47971
|
dir: out2,
|
|
47897
47972
|
scale: r.scale,
|
|
47898
47973
|
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 })),
|
|
47899
|
-
next: "
|
|
47974
|
+
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.",
|
|
47900
47975
|
...r.notes.length ? { notes: r.notes } : {}
|
|
47901
47976
|
});
|
|
47902
47977
|
};
|
|
@@ -48212,7 +48287,7 @@ var init_media = __esm({
|
|
|
48212
48287
|
};
|
|
48213
48288
|
HOSTED = "popost.ai";
|
|
48214
48289
|
HOSTED_NOTE = {
|
|
48215
|
-
speak: "popost: voices (popost:default-male, popost:default-female, popost:<id> from popost video voice list), with word times;
|
|
48290
|
+
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",
|
|
48216
48291
|
transcribe: "popost.ai transcribes the speech (a transcriber of your own in POPOST_ASR_CMD goes first when it is set)",
|
|
48217
48292
|
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",
|
|
48218
48293
|
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"
|
|
@@ -48237,7 +48312,7 @@ var init_media = __esm({
|
|
|
48237
48312
|
const cpus = budget ? { budget: budget.cpus, from: budget.source } : null;
|
|
48238
48313
|
const reading = named.readText !== null || named.transcribe !== null;
|
|
48239
48314
|
const cache2 = await projectCache(rt);
|
|
48240
|
-
printJson(rt, { ok: missing4.length === 0, ffmpeg: version, browser: browser === true, cpus, tools: tools2, ...cache2 ? { cache: cache2 } : {}, ...offers, ...reading ? { note: FIRST_RUN } : {}, ...missing4.length ? { missing: missing4 } : {} });
|
|
48315
|
+
printJson(rt, { ok: missing4.length === 0, ffmpeg: version, browser: browser === true, cpus, tools: tools2, ...cache2 ? { cache: cache2 } : {}, ...offers, ...reading ? { note: FIRST_RUN } : {}, ...missing4.length ? { missing: missing4, 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." } });
|
|
48241
48316
|
return missing4.length ? 2 : 0;
|
|
48242
48317
|
}
|
|
48243
48318
|
);
|
|
@@ -48278,7 +48353,7 @@ var init_plan = __esm({
|
|
|
48278
48353
|
return BASIS_LETTERS[t] ?? (isClipMusicBasis(t) ? t : void 0);
|
|
48279
48354
|
};
|
|
48280
48355
|
letterOf = (b) => String.fromCharCode(97 + CLIP_MUSIC_BASES.indexOf(b));
|
|
48281
|
-
noBedByException = (list7) => (list7 ?? []).find((c) => c.clip === WHOLE_VIDEO && (c.basis === "single-clip" || c.basis === "per-segment"));
|
|
48356
|
+
noBedByException = (list7) => (list7 ?? []).find((c) => c.clip === WHOLE_VIDEO && (c.basis === "single-clip" || c.basis === "per-segment" || c.basis === "model-native"));
|
|
48282
48357
|
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;
|
|
48283
48358
|
withException = (plan4, e) => {
|
|
48284
48359
|
const clipMusic = [...(plan4.clipMusic ?? []).filter((c) => c.clip !== e.clip), e];
|
|
@@ -48476,6 +48551,7 @@ var init_music_plan = __esm({
|
|
|
48476
48551
|
{
|
|
48477
48552
|
options: [
|
|
48478
48553
|
{ ...PROJECT_OPTION, required: true, help: "the video project the plan is for" },
|
|
48554
|
+
{ 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" },
|
|
48479
48555
|
{ flag: "--reading", metavar: "DIR", help: "what describe wrote (its sound.json) or the template; default the template the project was filled from" },
|
|
48480
48556
|
{ 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" },
|
|
48481
48557
|
{ flag: "--style", metavar: "TEXT", help: "with generated: the agreed style in plain words (genre, mood, tempo, instruments)" },
|
|
@@ -48491,6 +48567,13 @@ var init_music_plan = __esm({
|
|
|
48491
48567
|
async (args, rt) => {
|
|
48492
48568
|
const project = userPath(rt, args.req("project"));
|
|
48493
48569
|
const kept3 = await readMusicPlan(rt, project);
|
|
48570
|
+
if (args.flag("native-clips")) {
|
|
48571
|
+
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.");
|
|
48572
|
+
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." }] };
|
|
48573
|
+
await writeMusicPlan(rt, project, plan4);
|
|
48574
|
+
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." });
|
|
48575
|
+
return;
|
|
48576
|
+
}
|
|
48494
48577
|
const given2 = args.string("reading");
|
|
48495
48578
|
const reading = await readingFor(rt, project, given2 === void 0 ? void 0 : userPath(rt, given2));
|
|
48496
48579
|
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.");
|
|
@@ -49308,10 +49391,13 @@ var init_analysis = __esm({
|
|
|
49308
49391
|
});
|
|
49309
49392
|
|
|
49310
49393
|
// src/video/describe/parts.ts
|
|
49311
|
-
var samplesAndPictures, withShotFills, readReference4;
|
|
49394
|
+
var TEXT_KEPT, describeTextFile, withKeptLines, samplesAndPictures, withShotFills, readReference4;
|
|
49312
49395
|
var init_parts = __esm({
|
|
49313
49396
|
"src/video/describe/parts.ts"() {
|
|
49314
49397
|
"use strict";
|
|
49398
|
+
init_util();
|
|
49399
|
+
init_version();
|
|
49400
|
+
init_readback_kept();
|
|
49315
49401
|
init_host();
|
|
49316
49402
|
init_sheets();
|
|
49317
49403
|
init_decode();
|
|
@@ -49324,6 +49410,17 @@ var init_parts = __esm({
|
|
|
49324
49410
|
init_speech2();
|
|
49325
49411
|
init_tool();
|
|
49326
49412
|
init_text();
|
|
49413
|
+
init_reader_command();
|
|
49414
|
+
TEXT_KEPT = "popost-video-describe-text@1";
|
|
49415
|
+
describeTextFile = async (rt, video) => {
|
|
49416
|
+
const key2 = sha256(JSON.stringify({ format: TEXT_KEPT, version: VERSION, source: await sha256File(rt, video) }));
|
|
49417
|
+
return rt.path.join(rt.path.resolve(rt.cwd), ".popost", "video-cache", "text", key2 + ".json");
|
|
49418
|
+
};
|
|
49419
|
+
withKeptLines = async (rt, video, reader, onKept) => {
|
|
49420
|
+
if (rt.env.POPOST_VIDEO_CACHE === "off" || textReaderCommand(rt) === void 0) return reader;
|
|
49421
|
+
const file = await describeTextFile(rt, video).catch(() => void 0);
|
|
49422
|
+
return file === void 0 ? reader : keptReader(rt, file, reader, onKept);
|
|
49423
|
+
};
|
|
49327
49424
|
samplesAndPictures = async (rt, video, measure3, dir) => {
|
|
49328
49425
|
const p = await probe2(rt, video);
|
|
49329
49426
|
const { every, width } = insetPlan(p);
|
|
@@ -49361,8 +49458,13 @@ var init_parts = __esm({
|
|
|
49361
49458
|
}
|
|
49362
49459
|
};
|
|
49363
49460
|
const measureIt = () => part("measure", (onStage) => measureCached(rt, video, onStage ? { onStage } : {}));
|
|
49461
|
+
const reused = { frames: 0, of: 0 };
|
|
49364
49462
|
const readIt = () => reader ? part("text", async (onStage) => {
|
|
49365
|
-
const
|
|
49463
|
+
const kept3 = await withKeptLines(rt, video, reader, (frames, of) => {
|
|
49464
|
+
Object.assign(reused, { frames, of });
|
|
49465
|
+
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) : ""));
|
|
49466
|
+
});
|
|
49467
|
+
const track = cuesOf(await readSamples(rt, video, kept3, onStage ? { onStage } : {}));
|
|
49366
49468
|
onStage?.("measuring what is behind the caption letters");
|
|
49367
49469
|
return withCaptionLook(rt, video, track);
|
|
49368
49470
|
}) : Promise.resolve(void 0);
|
|
@@ -49405,7 +49507,8 @@ var init_parts = __esm({
|
|
|
49405
49507
|
...transcript2 ? { transcript: transcript2 } : {},
|
|
49406
49508
|
...inset ? { inset } : {},
|
|
49407
49509
|
...looked.pictures ? { pictures: looked.pictures } : {},
|
|
49408
|
-
...failure4.speech !== void 0 ? { speechFailed: failure4.speech } : {}
|
|
49510
|
+
...failure4.speech !== void 0 ? { speechFailed: failure4.speech } : {},
|
|
49511
|
+
...reused.frames ? { textReused: { ...reused } } : {}
|
|
49409
49512
|
};
|
|
49410
49513
|
} finally {
|
|
49411
49514
|
progress?.stop();
|
|
@@ -49959,6 +50062,7 @@ var init_read3 = __esm({
|
|
|
49959
50062
|
tokens: { "REFERENCE.md": d.tokens["REFERENCE.md"], "timeline.md": d.tokens["timeline.md"] },
|
|
49960
50063
|
sound: m.source.hasAudio,
|
|
49961
50064
|
text: cues !== void 0,
|
|
50065
|
+
...got.textReused ? { textReused: got.textReused } : {},
|
|
49962
50066
|
speech: spoken !== void 0,
|
|
49963
50067
|
chargedCredits: wallet?.spent ?? 0,
|
|
49964
50068
|
// What kind of speech it is decides whether the re-make has a voice-over (describe/speech-kind.ts).
|
|
@@ -51316,6 +51420,7 @@ var init_speech_check2 = __esm({
|
|
|
51316
51420
|
"src/video/commands/speech-check.ts"() {
|
|
51317
51421
|
"use strict";
|
|
51318
51422
|
init_util();
|
|
51423
|
+
init_ffmpeg();
|
|
51319
51424
|
init_hosted2();
|
|
51320
51425
|
init_speech2();
|
|
51321
51426
|
init_speech_check();
|
|
@@ -51358,7 +51463,8 @@ var init_speech_check2 = __esm({
|
|
|
51358
51463
|
}
|
|
51359
51464
|
const kept3 = /* @__PURE__ */ new Map();
|
|
51360
51465
|
for (const f of files) {
|
|
51361
|
-
|
|
51466
|
+
let m = await keptMeasurement(rt, dir, f).catch(() => void 0);
|
|
51467
|
+
if (!m && !(await probe2(rt, rt.path.resolve(dir, f))).hasAudio) m = await measureClipSpeech(rt, dir, f);
|
|
51362
51468
|
if (m) kept3.set(f, m);
|
|
51363
51469
|
}
|
|
51364
51470
|
const todo = files.filter((f) => !kept3.has(f));
|
|
@@ -51384,7 +51490,8 @@ var init_speech_check2 = __esm({
|
|
|
51384
51490
|
clips,
|
|
51385
51491
|
chargedCredits: wallet?.spent ?? 0,
|
|
51386
51492
|
problems: problems2,
|
|
51387
|
-
|
|
51493
|
+
speechQuality: problems2.length ? "limitations" : "asr-match",
|
|
51494
|
+
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."
|
|
51388
51495
|
});
|
|
51389
51496
|
return errors ? 2 : 0;
|
|
51390
51497
|
},
|