trace-avatar-render 0.1.5 → 0.1.7
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/CHANGELOG.md +18 -1
- package/README.md +39 -0
- package/dist/{chunk-OYFQTEVA.js → chunk-PPVNEPXF.js} +238 -11
- package/dist/chunk-PPVNEPXF.js.map +1 -0
- package/dist/cli.js +32 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +266 -162
- package/dist/index.js +23 -1
- package/package.json +4 -2
- package/schemas/catalogue-1.json +48 -0
- package/dist/chunk-OYFQTEVA.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.1.
|
|
3
|
+
## 0.1.7 (unreleased)
|
|
4
|
+
|
|
5
|
+
- **The clip catalogue, `trace-avatar-catalogue/1`** (`schemas/catalogue-1.json`, also at
|
|
6
|
+
https://traceavatar.com/schemas/catalogue-1.json): a public JSON file of a product's published videos, one entry per
|
|
7
|
+
file and shape, with each clip's own words (`says`), so a scheduler can post it and write about it truthfully.
|
|
8
|
+
- `trace-avatar-render catalogue check <file|url> [--fetch]` checks one: every field, unique ids, burned captions
|
|
9
|
+
with no captions file. With `--fetch` it checks the links too: they answer without cookies, with the right type;
|
|
10
|
+
the captions end within the video; the mp4 is H.264 (with AAC sound when narrated) and starts playing before it
|
|
11
|
+
has all loaded (`moov` first).
|
|
12
|
+
- `checkCatalogue()`, `catalogueId()`, `vttEnds()`, `mp4Head()` in the library.
|
|
13
|
+
|
|
14
|
+
## 0.1.6 (12 Nov 2026)
|
|
15
|
+
|
|
16
|
+
- **Cards between scenes** (`Capture.cards` in `finish()`; `withCards`, `cardFrames`): a card shown for its time at a
|
|
17
|
+
moment of the capture, in the title and end cards' look, fading in and out. A narrated card lasts as long as its
|
|
18
|
+
line. For pitch videos: the problem, the result and the ask on cards, between the app's scenes.
|
|
19
|
+
|
|
20
|
+
## 0.1.5 (12 Nov 2026)
|
|
4
21
|
|
|
5
22
|
- **Several shapes from one capture**: `--out file.mp4@1:1` (`OutSpec.canvas` in `render()` and `finish()`) gives
|
|
6
23
|
that output its own canvas, over `--canvas`. A 16:9, a 1:1 and a 4:5 cut of one run need one capture, not three
|
package/README.md
CHANGED
|
@@ -155,6 +155,39 @@ frames move with the holds. GIFs from the same render keep the original timing.
|
|
|
155
155
|
`<out>.narration.txt`. `suggest --task narration` drafts spoken lines from the steps (nothing typed is sent) for a
|
|
156
156
|
person to edit and pass with `--script`.
|
|
157
157
|
|
|
158
|
+
## A clip catalogue
|
|
159
|
+
|
|
160
|
+
Published videos are listed in a **clip catalogue**: a public JSON file (`trace-avatar-catalogue/1`, schema in
|
|
161
|
+
[`schemas/catalogue-1.json`](schemas/catalogue-1.json), also at https://traceavatar.com/schemas/catalogue-1.json).
|
|
162
|
+
It has one entry per file and shape, each with its link, length, captions, description (`alt`) and its own words in
|
|
163
|
+
order (`says`), so a scheduler can pick a clip and write a post that matches it.
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{ "spec": "trace-avatar-catalogue/1", "updated": "2026-11-12T22:54:29Z", "videos": [{
|
|
167
|
+
"id": "acme/ad-paid/product/1:1", "product": "acme", "video": "ad-paid", "kind": "ad", "preset": "product",
|
|
168
|
+
"shape": "1:1", "format": "mp4", "url": "https://cdn.acme.com/ad-paid-1x1-0123456789.mp4",
|
|
169
|
+
"poster": "https://cdn.acme.com/ad-paid-1x1-aaaaaaaaaa.png", "captions": "https://cdn.acme.com/ad-paid-1x1-bbbbbbbbbb.vtt",
|
|
170
|
+
"language": "en", "captionsBurned": false, "seconds": 12.5, "narrated": true, "title": null,
|
|
171
|
+
"alt": "Acme ad: an invoice marked paid the moment the transfer lands.",
|
|
172
|
+
"says": ["Get paid the day you send it.", "Marked paid when the transfer lands."],
|
|
173
|
+
"site": "https://acme.com", "endsWith": "For more info visit acme.com", "made": "2026-11-12T21:54:32Z" }] }
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
- `id` stays the same when a clip is re-rendered (`<product>/<video>/<preset>/<shape|gif>`); `url` changes. Name files
|
|
177
|
+
by their content and cache them forever; cache the catalogue itself briefly.
|
|
178
|
+
- `captions` is WebVTT, present only when the words aren't burned in (`captionsBurned`).
|
|
179
|
+
- `says` is what the viewer reads or hears: the captions (the spoken lines when narrated) and the cards' lines.
|
|
180
|
+
- Unknown fields are allowed.
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
trace-avatar-render catalogue check catalogue.json # every field, unique ids
|
|
184
|
+
trace-avatar-render catalogue check https://…/catalogue.json --fetch
|
|
185
|
+
# …and every link: answers without cookies with the right type; captions end within the video;
|
|
186
|
+
# the mp4 is H.264 (AAC when narrated) with its moov first (-movflags +faststart)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`checkCatalogue(doc, { fetch })` does the same from code (`{ ok, problems, warnings }`).
|
|
190
|
+
|
|
158
191
|
## From code
|
|
159
192
|
|
|
160
193
|
```js
|
|
@@ -176,6 +209,12 @@ r.offsetMs + outputAt(r.segments, t); // where a moment of the capture lan
|
|
|
176
209
|
|
|
177
210
|
`render` rejects with a `RenderError` (with `.screenshot`) when the guide stalls, errors, or can't start.
|
|
178
211
|
|
|
212
|
+
`finish(capture, outputs, options)` makes the video from a capture you made yourself (a Playwright script of your
|
|
213
|
+
own, say). A capture can carry **cards between scenes**: `capture.cards = [{ t, ms, card: { title, url, logo, color },
|
|
214
|
+
step }]` shows each card for `ms` at source time `t`, fading in from the app and out to it. With narration, a card
|
|
215
|
+
whose `step` has a line lasts as long as that line (and 0.7 s more); put that step's event at `t + 1`, so the line
|
|
216
|
+
is spoken over the card. A card says its own words, so it gets no burned-in caption.
|
|
217
|
+
|
|
179
218
|
## How it works
|
|
180
219
|
|
|
181
220
|
```
|
|
@@ -908,6 +908,42 @@ function withHolds(segs, holds) {
|
|
|
908
908
|
}
|
|
909
909
|
return out;
|
|
910
910
|
}
|
|
911
|
+
function withCards(segs, cards) {
|
|
912
|
+
const marks = cards.map((c, card) => ({ src: c.t, ms: Math.round(c.ms), card })).filter((m) => m.ms > 0).sort((a, b) => a.src - b.src);
|
|
913
|
+
if (!marks.length) return segs.map((s) => ({ ...s }));
|
|
914
|
+
const out = [];
|
|
915
|
+
let k = 0;
|
|
916
|
+
for (const s of segs) {
|
|
917
|
+
if (s.hold) {
|
|
918
|
+
out.push({ ...s });
|
|
919
|
+
continue;
|
|
920
|
+
}
|
|
921
|
+
let from = s.from;
|
|
922
|
+
while (k < marks.length && marks[k].src <= s.to) {
|
|
923
|
+
const m = marks[k++];
|
|
924
|
+
const at = Math.max(from, m.src);
|
|
925
|
+
if (at > from) out.push({ from, to: at });
|
|
926
|
+
out.push({ from: at, to: at, hold: m.ms, card: m.card });
|
|
927
|
+
from = at;
|
|
928
|
+
}
|
|
929
|
+
if (s.to > from) out.push({ from, to: s.to });
|
|
930
|
+
}
|
|
931
|
+
const last = segs.length ? segs[segs.length - 1].to : 0;
|
|
932
|
+
for (; k < marks.length; k += 1) out.push({ from: last, to: last, hold: marks[k].ms, card: marks[k].card });
|
|
933
|
+
return out;
|
|
934
|
+
}
|
|
935
|
+
function cardFrames(segs, fps) {
|
|
936
|
+
const n = Math.max(1, Math.round(durationOf(segs) / 1e3 * fps));
|
|
937
|
+
return Array.from({ length: n }, (_, k) => {
|
|
938
|
+
let left = k * 1e3 / fps;
|
|
939
|
+
for (const s of segs) {
|
|
940
|
+
const len = lenOf(s);
|
|
941
|
+
if (left < len) return s.card;
|
|
942
|
+
left -= len;
|
|
943
|
+
}
|
|
944
|
+
return void 0;
|
|
945
|
+
});
|
|
946
|
+
}
|
|
911
947
|
function frameTimes(segs, fps) {
|
|
912
948
|
const n = Math.max(1, Math.round(durationOf(segs) / 1e3 * fps));
|
|
913
949
|
return Array.from({ length: n }, (_, k) => sourceAt(segs, k * 1e3 / fps));
|
|
@@ -1380,6 +1416,8 @@ var LEAD_MS = 500;
|
|
|
1380
1416
|
var TITLE_MS = 1500;
|
|
1381
1417
|
var END_MS = 2e3;
|
|
1382
1418
|
var FADE_MS = 300;
|
|
1419
|
+
var CARD_PAD_MS = 700;
|
|
1420
|
+
var CLOSING_CARD_MS = 1500;
|
|
1383
1421
|
function cardOf(v, fallback) {
|
|
1384
1422
|
if (!v) return void 0;
|
|
1385
1423
|
if (v === true) return fallback;
|
|
@@ -1485,12 +1523,19 @@ repair: ${n ? `${n} fix${n > 1 ? "es" : ""} (${ok} verified${outcome.passed ? ",
|
|
|
1485
1523
|
var base = (file) => file.replace(/\.[^./]+$/, "");
|
|
1486
1524
|
async function finish(cap, outs, o = {}) {
|
|
1487
1525
|
const frames = cap.frames.slice().sort((a, b) => a.t - b.t);
|
|
1488
|
-
const
|
|
1489
|
-
const
|
|
1490
|
-
const
|
|
1491
|
-
const
|
|
1526
|
+
const capCards = cap.cards ?? [];
|
|
1527
|
+
const firstCard = capCards.length ? Math.min(...capCards.map((c) => c.t)) : Infinity;
|
|
1528
|
+
const lastCard = capCards.length ? Math.max(...capCards.map((c) => c.t)) : -Infinity;
|
|
1529
|
+
const start = Math.min(Math.max(frames[0].t, cap.playAt - LEAD_MS), firstCard);
|
|
1530
|
+
const end = lastCard >= cap.stopAt - CLOSING_CARD_MS ? Math.min(cap.stopAt, lastCard + 1) : cap.stopAt;
|
|
1492
1531
|
const warnings = [];
|
|
1493
1532
|
const narr = o.narration?.lines.size ? o.narration : null;
|
|
1533
|
+
const cards = capCards.map((c) => {
|
|
1534
|
+
const line = c.step !== void 0 ? narr?.lines.get(c.step) : void 0;
|
|
1535
|
+
return { ...c, ms: Math.max(c.ms, line ? msOf(line.audio) + CARD_PAD_MS : 0) };
|
|
1536
|
+
});
|
|
1537
|
+
const cut = withCards(editList(cap.events, { start, end, maxWaitMs: o.cuts?.maxWaitMs ?? DEFAULT_MAX_WAIT_MS }), cards);
|
|
1538
|
+
const stamps = frames.map((f) => f.t);
|
|
1494
1539
|
let said = null;
|
|
1495
1540
|
let held = cut;
|
|
1496
1541
|
if (narr) {
|
|
@@ -1538,7 +1583,8 @@ async function finish(cap, outs, o = {}) {
|
|
|
1538
1583
|
segs: sg,
|
|
1539
1584
|
contentMs: ms,
|
|
1540
1585
|
cam: o.camera ? cameraPath(actionsOf(cap.events, sg, scale), { width: srcW, height: srcH, ...typeof o.camera === "object" && o.camera.zoom ? { zoom: o.camera.zoom } : {} }) : null,
|
|
1541
|
-
|
|
1586
|
+
// A card says its own words: no caption over it or after it.
|
|
1587
|
+
cues: o.captions ? stepCues(cap.events.map((e) => e.stepType === "card" ? { ...e, say: void 0 } : e), sg, ms) : []
|
|
1542
1588
|
};
|
|
1543
1589
|
};
|
|
1544
1590
|
const main = variant(segs);
|
|
@@ -1548,7 +1594,7 @@ async function finish(cap, outs, o = {}) {
|
|
|
1548
1594
|
const titleMs = o.cards?.title ? TITLE_MS : 0;
|
|
1549
1595
|
const endMs = o.cards?.end ? END_MS : 0;
|
|
1550
1596
|
const full = { x: 0, y: 0, w: srcW, h: srcH };
|
|
1551
|
-
const needLayers = frameStyle !== "none" || canvases.some(Boolean) || !!mark || burn && (cues.length > 0 || plain.cues.length > 0) || !!o.cards?.title || !!o.cards?.end;
|
|
1597
|
+
const needLayers = frameStyle !== "none" || canvases.some(Boolean) || !!mark || burn && (cues.length > 0 || plain.cues.length > 0) || !!o.cards?.title || !!o.cards?.end || cards.length > 0;
|
|
1552
1598
|
const browser = needLayers ? await chromium2.launch() : null;
|
|
1553
1599
|
let layers = null;
|
|
1554
1600
|
const outputs = [];
|
|
@@ -1567,13 +1613,26 @@ async function finish(cap, outs, o = {}) {
|
|
|
1567
1613
|
const cues2 = v.cues;
|
|
1568
1614
|
const times = frameTimes(segs2, fps);
|
|
1569
1615
|
const picks = pickFrames(stamps, times);
|
|
1570
|
-
const art = await artFor(layers, layout, { frameStyle, background, cues: burn ? cues2 : [], urls: [...new Set(cap.events.map((e) => e.url).filter(Boolean))], titles: cap.titles ?? {}, cards: o.cards, mark });
|
|
1616
|
+
const art = await artFor(layers, layout, { frameStyle, background, cues: burn ? cues2 : [], urls: [...new Set(cap.events.map((e) => e.url).filter(Boolean))], titles: cap.titles ?? {}, cards: o.cards, mid: cards.map((c) => c.card), mark });
|
|
1617
|
+
const cardAt = cards.length ? cardFrames(segs2, fps) : [];
|
|
1571
1618
|
const nTitle = Math.round(titleMs * fps / 1e3);
|
|
1572
1619
|
const nEnd = Math.round(endMs * fps / 1e3);
|
|
1573
1620
|
const nFade = Math.max(1, Math.round(FADE_MS * fps / 1e3));
|
|
1574
1621
|
const total = nTitle + picks.length + nEnd;
|
|
1575
1622
|
let last = null;
|
|
1576
1623
|
const content = (k) => {
|
|
1624
|
+
const c = cardAt[k];
|
|
1625
|
+
if (c === void 0) return app(k);
|
|
1626
|
+
const img = art.mid[c];
|
|
1627
|
+
let s = k;
|
|
1628
|
+
while (s > 0 && cardAt[s - 1] === c) s -= 1;
|
|
1629
|
+
let e = k;
|
|
1630
|
+
while (e + 1 < cardAt.length && cardAt[e + 1] === c) e += 1;
|
|
1631
|
+
if (k - s < nFade && s > 0 && cardAt[s - 1] === void 0) return crossfade(app(s - 1), img, (k - s + 1) / nFade);
|
|
1632
|
+
if (e - k < nFade && e + 1 < picks.length && cardAt[e + 1] === void 0) return crossfade(img, app(e + 1), 1 - (e - k) / nFade);
|
|
1633
|
+
return img;
|
|
1634
|
+
};
|
|
1635
|
+
const app = (k) => {
|
|
1577
1636
|
const t = k * 1e3 / fps;
|
|
1578
1637
|
const i = picks[k];
|
|
1579
1638
|
const rect = cam ? cam(t) : full;
|
|
@@ -1700,7 +1759,7 @@ async function finish(cap, outs, o = {}) {
|
|
|
1700
1759
|
durationMs: Math.round(contentMs + titleMs + endMs),
|
|
1701
1760
|
offsetMs: titleMs,
|
|
1702
1761
|
rawMs: Math.round(end - start),
|
|
1703
|
-
segments: segs.map((s) => ({ from: rel(s.from), to: rel(s.to), ...s.hold ? { hold: s.hold } : {} })),
|
|
1762
|
+
segments: segs.map((s) => ({ from: rel(s.from), to: rel(s.to), ...s.hold ? { hold: s.hold } : {}, ...s.card !== void 0 ? { card: s.card } : {} })),
|
|
1704
1763
|
events: cap.events.map((e) => ({ ...e, t: rel(e.t) })),
|
|
1705
1764
|
outputs,
|
|
1706
1765
|
...poster ? { poster } : {},
|
|
@@ -1728,7 +1787,7 @@ function badgeAt(W, H, w, h, at = "bottom-right") {
|
|
|
1728
1787
|
return { x: at.endsWith("left") ? m : W - w - m, y: at.startsWith("top") ? m : H - h - m };
|
|
1729
1788
|
}
|
|
1730
1789
|
async function artFor(layers, layout, o) {
|
|
1731
|
-
const art = { base: null, captions: /* @__PURE__ */ new Map() };
|
|
1790
|
+
const art = { base: null, captions: /* @__PURE__ */ new Map(), mid: [] };
|
|
1732
1791
|
if (!layers) return art;
|
|
1733
1792
|
if (o.frameStyle !== "none" || layout.canvas) {
|
|
1734
1793
|
art.base = /* @__PURE__ */ new Map();
|
|
@@ -1741,6 +1800,7 @@ async function artFor(layers, layout, o) {
|
|
|
1741
1800
|
}
|
|
1742
1801
|
if (o.cards?.title) art.title = await layers.card(layout, { ...o.cards.title, background: o.background });
|
|
1743
1802
|
if (o.cards?.end) art.end = await layers.card(layout, { ...o.cards.end, background: o.background });
|
|
1803
|
+
for (const c of o.mid ?? []) art.mid.push(await layers.card(layout, { ...c, background: o.background }));
|
|
1744
1804
|
if (o.mark) {
|
|
1745
1805
|
const img = await layers.badge(o.mark.text, { fontPx: Math.max(11, Math.round(Math.min(layout.width, layout.height) * 0.024)), ...o.mark.logo ? { logo: o.mark.logo } : {} });
|
|
1746
1806
|
const { x, y } = badgeAt(layout.width, layout.height, img.width, img.height, o.mark.at);
|
|
@@ -1753,6 +1813,11 @@ async function artFor(layers, layout, o) {
|
|
|
1753
1813
|
art[k] = d;
|
|
1754
1814
|
}
|
|
1755
1815
|
}
|
|
1816
|
+
art.mid = art.mid.map((c) => {
|
|
1817
|
+
const d = copy(c);
|
|
1818
|
+
overlay(d, img, x, y, art.badge.alpha);
|
|
1819
|
+
return d;
|
|
1820
|
+
});
|
|
1756
1821
|
}
|
|
1757
1822
|
return art;
|
|
1758
1823
|
}
|
|
@@ -1884,6 +1949,157 @@ async function voiceOf(spec, env = process.env, o = {}) {
|
|
|
1884
1949
|
throw new Error(`--voice is gateway[:gemini[/<model>][:<voice>]], openai:<model>[:<voice>], say[:<voice>], or a .js file (got "${spec}")`);
|
|
1885
1950
|
}
|
|
1886
1951
|
|
|
1952
|
+
// src/catalogue.ts
|
|
1953
|
+
var CATALOGUE_SPEC = "trace-avatar-catalogue/1";
|
|
1954
|
+
var CATALOGUE_KINDS = ["intro", "demo", "guide", "onboarding", "pitch", "whats-new", "ad", "docs-gif", "qa", "support"];
|
|
1955
|
+
var CATALOGUE_SHAPES = ["16:9", "1:1", "4:5", "9:16"];
|
|
1956
|
+
var CATALOGUE_FORMATS = ["mp4", "gif"];
|
|
1957
|
+
var CATALOGUE_REQUIRED = ["id", "product", "video", "kind", "preset", "shape", "format", "url", "captionsBurned", "seconds", "narrated", "alt", "site", "made"];
|
|
1958
|
+
function catalogueId(e) {
|
|
1959
|
+
return `${e.product}/${e.video}/${e.preset}/${e.format === "gif" || !e.shape ? "gif" : e.shape}`;
|
|
1960
|
+
}
|
|
1961
|
+
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1962
|
+
var isTime = (v) => typeof v === "string" && /^\d{4}-\d{2}-\d{2}T/.test(v) && !Number.isNaN(Date.parse(v));
|
|
1963
|
+
var isHttps = (v) => {
|
|
1964
|
+
if (typeof v !== "string") return false;
|
|
1965
|
+
try {
|
|
1966
|
+
return new URL(v).protocol === "https:";
|
|
1967
|
+
} catch {
|
|
1968
|
+
return false;
|
|
1969
|
+
}
|
|
1970
|
+
};
|
|
1971
|
+
function checkShape(doc, problems, warnings, https) {
|
|
1972
|
+
if (!isObj(doc)) {
|
|
1973
|
+
problems.push("a catalogue is a JSON object { spec, updated, videos }");
|
|
1974
|
+
return [];
|
|
1975
|
+
}
|
|
1976
|
+
if (doc.spec !== CATALOGUE_SPEC) problems.push(doc.spec === void 0 ? `no spec: a catalogue says "spec": "${CATALOGUE_SPEC}"` : `spec is ${JSON.stringify(doc.spec)}; this checks ${CATALOGUE_SPEC}`);
|
|
1977
|
+
if (!isTime(doc.updated)) problems.push("updated is an ISO time");
|
|
1978
|
+
if (!Array.isArray(doc.videos)) {
|
|
1979
|
+
problems.push("videos is a list");
|
|
1980
|
+
return [];
|
|
1981
|
+
}
|
|
1982
|
+
const ids = /* @__PURE__ */ new Map();
|
|
1983
|
+
const tuples = /* @__PURE__ */ new Map();
|
|
1984
|
+
const good = [];
|
|
1985
|
+
doc.videos.forEach((v, i) => {
|
|
1986
|
+
const at = `videos[${i}]${isObj(v) && typeof v.id === "string" ? ` (${v.id})` : ""}`;
|
|
1987
|
+
if (!isObj(v)) {
|
|
1988
|
+
problems.push(`${at}: an entry is an object`);
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1991
|
+
const before = problems.length;
|
|
1992
|
+
const p = (m) => problems.push(`${at}: ${m}`);
|
|
1993
|
+
for (const k of CATALOGUE_REQUIRED) if (v[k] === void 0) p(`no ${k}`);
|
|
1994
|
+
for (const k of ["id", "product", "video", "preset"]) if (v[k] !== void 0 && !(typeof v[k] === "string" && /^\S+$/.test(v[k]))) p(`${k} is a word with no spaces`);
|
|
1995
|
+
if (v.kind !== void 0 && !CATALOGUE_KINDS.includes(v.kind)) p(`kind is one of ${CATALOGUE_KINDS.join(", ")}`);
|
|
1996
|
+
if (v.format !== void 0 && !CATALOGUE_FORMATS.includes(v.format)) p("format is mp4 or gif");
|
|
1997
|
+
if (v.format === "gif" && v.shape !== null && v.shape !== void 0) p("a GIF has no shape (null)");
|
|
1998
|
+
if (v.format === "mp4" && !CATALOGUE_SHAPES.includes(v.shape)) p(`an mp4's shape is one of ${CATALOGUE_SHAPES.join(", ")}`);
|
|
1999
|
+
for (const k of ["url", "site"]) if (v[k] !== void 0 && !https(v[k])) p(`${k} is an https link`);
|
|
2000
|
+
for (const k of ["poster", "captions"]) if (v[k] !== void 0 && !https(v[k])) p(`${k} is an https link`);
|
|
2001
|
+
if (v.captionsBurned !== void 0 && typeof v.captionsBurned !== "boolean") p("captionsBurned is true or false");
|
|
2002
|
+
if (v.narrated !== void 0 && typeof v.narrated !== "boolean") p("narrated is true or false");
|
|
2003
|
+
if (v.captions !== void 0 && v.captionsBurned === true) p("captions are burned in, so it has no captions file");
|
|
2004
|
+
if (v.seconds !== void 0 && !(typeof v.seconds === "number" && Number.isFinite(v.seconds) && v.seconds > 0)) p("seconds is its length, a number above 0");
|
|
2005
|
+
if (v.language !== void 0 && !(typeof v.language === "string" && /^[a-z]{2}$/.test(v.language))) p("language is two lowercase letters, e.g. en");
|
|
2006
|
+
if (v.title !== void 0 && v.title !== null && typeof v.title !== "string") p("title is text or null");
|
|
2007
|
+
if (v.alt !== void 0 && !(typeof v.alt === "string" && v.alt.trim())) p("alt says what it shows");
|
|
2008
|
+
if (v.says !== void 0 && !(Array.isArray(v.says) && v.says.length && v.says.every((s) => typeof s === "string" && s.trim()))) p("says is a list of the lines the video shows or speaks");
|
|
2009
|
+
if (v.endsWith !== void 0 && typeof v.endsWith !== "string") p("endsWith is text");
|
|
2010
|
+
if (v.made !== void 0 && !isTime(v.made)) p("made is an ISO time");
|
|
2011
|
+
if (problems.length > before) return;
|
|
2012
|
+
const e = v;
|
|
2013
|
+
const seen = ids.get(e.id);
|
|
2014
|
+
if (seen !== void 0) p(`id used twice (videos[${seen}])`);
|
|
2015
|
+
else ids.set(e.id, i);
|
|
2016
|
+
const tuple = `${e.product}/${e.video}/${e.preset}/${e.shape}/${e.format}`;
|
|
2017
|
+
const twin = tuples.get(tuple);
|
|
2018
|
+
if (twin !== void 0) p(`the same product, video, preset, shape and format as videos[${twin}]`);
|
|
2019
|
+
else tuples.set(tuple, i);
|
|
2020
|
+
if (e.id !== catalogueId(e)) warnings.push(`${at}: the id ${catalogueId(e)} is recommended (stable across re-renders)`);
|
|
2021
|
+
if (e.format === "mp4" && !e.captionsBurned && !e.captions && e.says?.length) warnings.push(`${at}: it has words but no captions file`);
|
|
2022
|
+
good.push(e);
|
|
2023
|
+
});
|
|
2024
|
+
return good;
|
|
2025
|
+
}
|
|
2026
|
+
function vttEnds(text) {
|
|
2027
|
+
if (!/^?WEBVTT(?:[ \t].*)?(?:\r?\n|$)/.test(text)) throw new Error("not WebVTT (it does not start with WEBVTT)");
|
|
2028
|
+
const ends = [];
|
|
2029
|
+
const re = /(?:(\d+):)?(\d{2}):(\d{2})\.(\d{3})\s+-->\s+(?:(\d+):)?(\d{2}):(\d{2})\.(\d{3})/g;
|
|
2030
|
+
for (let m = re.exec(text); m; m = re.exec(text)) ends.push(Number(m[5] ?? 0) * 3600 + Number(m[6]) * 60 + Number(m[7]) + Number(m[8]) / 1e3);
|
|
2031
|
+
return ends;
|
|
2032
|
+
}
|
|
2033
|
+
function mp4Head(bytes) {
|
|
2034
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
2035
|
+
const name = (at2) => String.fromCharCode(bytes[at2], bytes[at2 + 1], bytes[at2 + 2], bytes[at2 + 3]);
|
|
2036
|
+
let at = 0;
|
|
2037
|
+
while (at + 8 <= bytes.length) {
|
|
2038
|
+
let size = dv.getUint32(at);
|
|
2039
|
+
const type = name(at + 4);
|
|
2040
|
+
if (size === 1 && at + 16 <= bytes.length) size = Number(dv.getBigUint64(at + 8));
|
|
2041
|
+
if (type === "mdat") return { faststart: false, codecs: null };
|
|
2042
|
+
if (type === "moov") {
|
|
2043
|
+
if (size < 8 || at + size > bytes.length) return { faststart: true, codecs: null };
|
|
2044
|
+
const body = new TextDecoder("latin1").decode(bytes.subarray(at, at + size));
|
|
2045
|
+
return { faststart: true, codecs: ["avc1", "avc3", "hvc1", "hev1", "mp4a", "Opus"].filter((c) => body.includes(c)) };
|
|
2046
|
+
}
|
|
2047
|
+
if (size < 8) break;
|
|
2048
|
+
at += size;
|
|
2049
|
+
}
|
|
2050
|
+
return { faststart: null, codecs: null };
|
|
2051
|
+
}
|
|
2052
|
+
var TYPES = { mp4: /^video\/mp4\b/, gif: /^image\/gif\b/, poster: /^image\/(png|jpeg|webp)\b/, captions: /^text\/vtt\b/ };
|
|
2053
|
+
async function each(items, n, fn) {
|
|
2054
|
+
let i = 0;
|
|
2055
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => {
|
|
2056
|
+
while (i < items.length) await fn(items[i++]);
|
|
2057
|
+
}));
|
|
2058
|
+
}
|
|
2059
|
+
async function checkCatalogue(doc, o = {}) {
|
|
2060
|
+
const problems = [];
|
|
2061
|
+
const warnings = [];
|
|
2062
|
+
const https = o.allowHttp ? (v) => isHttps(v) || typeof v === "string" && /^http:\/\//.test(v) : isHttps;
|
|
2063
|
+
const entries = checkShape(doc, problems, warnings, https);
|
|
2064
|
+
let fetched = 0;
|
|
2065
|
+
if (o.fetch) {
|
|
2066
|
+
const f = o.fetcher ?? fetch;
|
|
2067
|
+
const jobs = [];
|
|
2068
|
+
for (const e of entries) {
|
|
2069
|
+
jobs.push({ e, what: e.format, url: e.url });
|
|
2070
|
+
if (e.poster) jobs.push({ e, what: "poster", url: e.poster });
|
|
2071
|
+
if (e.captions) jobs.push({ e, what: "captions", url: e.captions });
|
|
2072
|
+
}
|
|
2073
|
+
await each(jobs, o.concurrency ?? 6, async ({ e, what, url }) => {
|
|
2074
|
+
const at = `${e.id} ${what}`;
|
|
2075
|
+
try {
|
|
2076
|
+
const res = await f(url, { headers: what === "captions" ? {} : { range: "bytes=0-262143" }, redirect: "follow" });
|
|
2077
|
+
fetched += 1;
|
|
2078
|
+
if (!res.ok) {
|
|
2079
|
+
problems.push(`${at}: ${url} answered ${res.status}`);
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
const type = res.headers.get("content-type") ?? "";
|
|
2083
|
+
if (!TYPES[what].test(type)) problems.push(`${at}: served as ${type || "no type"}, not ${what === "captions" ? "text/vtt" : what === "poster" ? "an image" : what === "gif" ? "image/gif" : "video/mp4"}`);
|
|
2084
|
+
if (what === "captions") {
|
|
2085
|
+
const ends = vttEnds(await res.text());
|
|
2086
|
+
if (!ends.length) warnings.push(`${at}: the captions have no cues`);
|
|
2087
|
+
else if (Math.max(...ends) > e.seconds + 0.5) problems.push(`${at}: the captions run to ${Math.max(...ends).toFixed(1)} s; the video is ${e.seconds} s`);
|
|
2088
|
+
} else if (what === "mp4") {
|
|
2089
|
+
const head = mp4Head(new Uint8Array(await res.arrayBuffer()));
|
|
2090
|
+
if (head.faststart === false) problems.push(`${at}: its moov comes after its media, so it can't start before it has all loaded (encode with -movflags +faststart)`);
|
|
2091
|
+
else if (head.faststart === null) warnings.push(`${at}: could not read its first boxes`);
|
|
2092
|
+
if (head.codecs && !head.codecs.some((c) => c === "avc1" || c === "avc3")) problems.push(`${at}: not H.264 (${head.codecs.join(", ") || "no known codec"}); platforms want H.264/AAC`);
|
|
2093
|
+
if (head.codecs && e.narrated && !head.codecs.includes("mp4a")) problems.push(`${at}: narrated, but no AAC sound`);
|
|
2094
|
+
} else await res.body?.cancel();
|
|
2095
|
+
} catch (err) {
|
|
2096
|
+
problems.push(`${at}: ${err.message}`);
|
|
2097
|
+
}
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
return { ok: !problems.length, problems, warnings, videos: entries.length, fetched };
|
|
2101
|
+
}
|
|
2102
|
+
|
|
1887
2103
|
export {
|
|
1888
2104
|
ZOOM_KINDS,
|
|
1889
2105
|
cameraKeys,
|
|
@@ -1922,6 +2138,8 @@ export {
|
|
|
1922
2138
|
sourceAt,
|
|
1923
2139
|
outputAt,
|
|
1924
2140
|
withHolds,
|
|
2141
|
+
withCards,
|
|
2142
|
+
cardFrames,
|
|
1925
2143
|
frameTimes,
|
|
1926
2144
|
pickFrames,
|
|
1927
2145
|
actionsOf,
|
|
@@ -1959,6 +2177,15 @@ export {
|
|
|
1959
2177
|
openAiVoice,
|
|
1960
2178
|
sayVoice,
|
|
1961
2179
|
cached,
|
|
1962
|
-
voiceOf
|
|
2180
|
+
voiceOf,
|
|
2181
|
+
CATALOGUE_SPEC,
|
|
2182
|
+
CATALOGUE_KINDS,
|
|
2183
|
+
CATALOGUE_SHAPES,
|
|
2184
|
+
CATALOGUE_FORMATS,
|
|
2185
|
+
CATALOGUE_REQUIRED,
|
|
2186
|
+
catalogueId,
|
|
2187
|
+
vttEnds,
|
|
2188
|
+
mp4Head,
|
|
2189
|
+
checkCatalogue
|
|
1963
2190
|
};
|
|
1964
|
-
//# sourceMappingURL=chunk-
|
|
2191
|
+
//# sourceMappingURL=chunk-PPVNEPXF.js.map
|