@softure-ai/marketing-kit 0.21.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/NOTICE +11 -0
- package/README.md +35 -4
- package/dist/config/actions-schema.d.ts +35 -35
- package/dist/config/brand.d.ts.map +1 -1
- package/dist/config/brand.js +22 -1
- package/dist/config/brand.js.map +1 -1
- package/dist/config/colors.d.ts +12 -2
- package/dist/config/colors.d.ts.map +1 -1
- package/dist/config/colors.js +32 -0
- package/dist/config/colors.js.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +2 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/schema.d.ts +181 -172
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +16 -4
- package/dist/config/schema.js.map +1 -1
- package/dist/config/shot-steps.d.ts +40 -40
- package/dist/footage/caption-highlight.d.ts +44 -0
- package/dist/footage/caption-highlight.d.ts.map +1 -0
- package/dist/footage/caption-highlight.js +29 -0
- package/dist/footage/caption-highlight.js.map +1 -0
- package/dist/footage/compose.d.ts +3 -0
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +33 -6
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/draft-color.d.ts +6 -0
- package/dist/footage/draft-color.d.ts.map +1 -0
- package/dist/footage/draft-color.js +14 -0
- package/dist/footage/draft-color.js.map +1 -0
- package/dist/footage/draft-overlays.d.ts +12 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -0
- package/dist/footage/draft-overlays.js +83 -0
- package/dist/footage/draft-overlays.js.map +1 -0
- package/dist/footage/draft.d.ts +27 -9
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +99 -37
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/edl.d.ts +41 -0
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +10 -0
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/film.d.ts +14 -0
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.js +2 -0
- package/dist/footage/film.js.map +1 -1
- package/dist/footage/isolate-ranges.js +1 -1
- package/dist/footage/isolate-ranges.js.map +1 -1
- package/dist/footage/overlay-html.d.ts +29 -0
- package/dist/footage/overlay-html.d.ts.map +1 -0
- package/dist/footage/overlay-html.js +112 -0
- package/dist/footage/overlay-html.js.map +1 -0
- package/dist/footage/overlay-schema.d.ts +97 -0
- package/dist/footage/overlay-schema.d.ts.map +1 -0
- package/dist/footage/overlay-schema.js +104 -0
- package/dist/footage/overlay-schema.js.map +1 -0
- package/dist/footage/overlays.d.ts +112 -0
- package/dist/footage/overlays.d.ts.map +1 -0
- package/dist/footage/overlays.js +222 -0
- package/dist/footage/overlays.js.map +1 -0
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +10 -1
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/footage/speech-ranges.d.ts +8 -3
- package/dist/footage/speech-ranges.d.ts.map +1 -1
- package/dist/footage/speech-ranges.js +7 -4
- package/dist/footage/speech-ranges.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/og/index.d.ts +1 -1
- package/dist/og/index.d.ts.map +1 -1
- package/dist/og/index.js +1 -1
- package/dist/og/index.js.map +1 -1
- package/dist/og/photo-cover.d.ts +18 -1
- package/dist/og/photo-cover.d.ts.map +1 -1
- package/dist/og/photo-cover.js +56 -28
- package/dist/og/photo-cover.js.map +1 -1
- package/dist/render/hyperframes.d.ts +1 -1
- package/dist/render/hyperframes.d.ts.map +1 -1
- package/dist/render/hyperframes.js +1 -1
- package/dist/render/hyperframes.js.map +1 -1
- package/package.json +3 -2
- package/schema/edl.schema.json +130 -0
- package/schema/marketing.schema.json +33 -0
- package/src/config/brand.ts +20 -1
- package/src/config/colors.ts +39 -2
- package/src/config/config.ts +2 -0
- package/src/config/schema.ts +19 -7
- package/src/footage/caption-highlight.ts +52 -0
- package/src/footage/compose.ts +40 -6
- package/src/footage/draft-color.ts +12 -0
- package/src/footage/draft-overlays.ts +91 -0
- package/src/footage/draft.ts +117 -39
- package/src/footage/edl.ts +17 -0
- package/src/footage/film.ts +16 -0
- package/src/footage/isolate-ranges.ts +1 -1
- package/src/footage/overlay-html.ts +127 -0
- package/src/footage/overlay-schema.ts +146 -0
- package/src/footage/overlays.ts +272 -0
- package/src/footage/pipeline.ts +8 -1
- package/src/footage/speech-ranges.ts +8 -5
- package/src/index.ts +56 -1
- package/src/og/index.ts +2 -0
- package/src/og/photo-cover.ts +83 -33
- package/src/render/hyperframes.ts +1 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { BrandColors } from "../config/colors.js";
|
|
2
|
+
import { escapeHtml } from "../compose/html.js";
|
|
3
|
+
import { OVERLAY_LINE_HEIGHT, OVERLAY_LIST_LINE_HEIGHT, OVERLAY_PADDING_EM, type ResolvedOverlay } from "./overlays.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The render's overlays (issue #1200): HTML, CSS and GSAP tweens for the HyperFrames composition, every look in the
|
|
7
|
+
* brand's colours and fonts and every element a local clip (no network at render time).
|
|
8
|
+
*
|
|
9
|
+
* The motion is adapted from HyperFrames registry blocks (Apache-2.0, https://github.com/heygen-com/hyperframes):
|
|
10
|
+
* `lt-soft-pill` (the lower third's scale-pop pill, dot and settling text), `marker-highlight` (the stroke drawn over
|
|
11
|
+
* its target), `hw-arrow` (the drawn-on arrow whose head arrives last) and `push-in` (the eased camera push, in
|
|
12
|
+
* `composeFootage`). They are rewritten for the kit's frame, timeline and brand tokens: see the package's NOTICE.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** The seconds an overlay takes to leave, ending with its clip. */
|
|
16
|
+
const EXIT_SECONDS = 0.3;
|
|
17
|
+
/** An arrow's or a highlight's stroke, in px of a 1080 px wide frame. */
|
|
18
|
+
const STROKE_WIDTH = 10;
|
|
19
|
+
/** The arrow head's length, in px of a 1080 px wide frame. */
|
|
20
|
+
const ARROW_HEAD = 46;
|
|
21
|
+
|
|
22
|
+
const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
|
|
23
|
+
|
|
24
|
+
export interface OverlayMarkup {
|
|
25
|
+
html: string[];
|
|
26
|
+
css: string[];
|
|
27
|
+
tweens: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The brand's colours an overlay paints with: its card, its text, its accent (the dot, the arrow, the marker). */
|
|
31
|
+
export type OverlayColors = Pick<BrandColors, "background" | "foreground" | "accent">;
|
|
32
|
+
|
|
33
|
+
/** The CSS every overlay kind shares, written once when the film has any drawn overlay. */
|
|
34
|
+
function getOverlayCss(colors: OverlayColors, headingFont: string): string[] {
|
|
35
|
+
return [
|
|
36
|
+
`.ov{position:absolute;display:flex;pointer-events:none}`,
|
|
37
|
+
`.ov.right{justify-content:flex-end}`,
|
|
38
|
+
`.ov-card{display:flex;align-items:center;gap:.45em;padding:${OVERLAY_PADDING_EM.y}em ${OVERLAY_PADDING_EM.x}em;border-radius:.42em;background:${colors.background};color:${colors.foreground};box-shadow:0 14px 44px rgba(0,0,0,.35);line-height:${OVERLAY_LINE_HEIGHT};font-weight:700;letter-spacing:-.015em;max-width:100%;overflow-wrap:anywhere;transform-origin:0% 100%}`,
|
|
39
|
+
`.ov.right .ov-card{transform-origin:100% 100%}`,
|
|
40
|
+
`.ov-keyword .ov-card{font-family:${headingFont};border-bottom:.12em solid ${colors.accent}}`,
|
|
41
|
+
`.ov-dot{flex:none;width:.36em;height:.36em;border-radius:50%;background:${colors.accent}}`,
|
|
42
|
+
`.ov-list .ov-card{flex-direction:column;align-items:flex-start;gap:0;line-height:${OVERLAY_LIST_LINE_HEIGHT};font-weight:650}`,
|
|
43
|
+
`.ov-list li{display:flex;align-items:center;gap:.45em;list-style:none}`,
|
|
44
|
+
`.ov-svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}`,
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The SVG path of an arrow from `from` to `to`: a gentle curve bowed to one side, and its head's two strokes. */
|
|
49
|
+
export function getArrowPaths(overlay: Extract<ResolvedOverlay, { kind: "arrow" }>, scale: number): { curve: string; head: string } {
|
|
50
|
+
const { from, to } = overlay;
|
|
51
|
+
const [dx, dy] = [to.x - from.x, to.y - from.y];
|
|
52
|
+
const length = Math.hypot(dx, dy) || 1;
|
|
53
|
+
// The control point sits off the middle by a fifth of the length, on the left of the travel (a hand-drawn bow).
|
|
54
|
+
const bow = 0.2 * length;
|
|
55
|
+
const control = { x: from.x + dx / 2 + (dy / length) * bow, y: from.y + dy / 2 - (dx / length) * bow };
|
|
56
|
+
const angle = Math.atan2(to.y - control.y, to.x - control.x);
|
|
57
|
+
const head = ARROW_HEAD * scale;
|
|
58
|
+
const wing = (turn: number) => ({ x: to.x - head * Math.cos(angle + turn), y: to.y - head * Math.sin(angle + turn) });
|
|
59
|
+
const [left, right] = [wing(Math.PI / 6), wing(-Math.PI / 6)];
|
|
60
|
+
const f = (value: number) => String(r3(value));
|
|
61
|
+
return {
|
|
62
|
+
curve: `M${f(from.x)} ${f(from.y)} Q${f(control.x)} ${f(control.y)} ${f(to.x)} ${f(to.y)}`,
|
|
63
|
+
head: `M${f(left.x)} ${f(left.y)} L${f(to.x)} ${f(to.y)} L${f(right.x)} ${f(right.y)}`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The drawn overlays' markup, CSS and tweens (a `punch_in` draws nothing: `composeFootage` zooms the picture). Each
|
|
69
|
+
* overlay is a clip shown for its own span, entering at its start and leaving over its last 0.3 s.
|
|
70
|
+
*/
|
|
71
|
+
export function getOverlayMarkup(overlays: readonly ResolvedOverlay[], input: { colors: OverlayColors; headingFont: string; frame: { width: number; height: number } }): OverlayMarkup {
|
|
72
|
+
const drawn = overlays.filter((overlay) => overlay.kind !== "punch_in");
|
|
73
|
+
if (drawn.length === 0) return { html: [], css: [], tweens: [] };
|
|
74
|
+
const { colors, frame } = input;
|
|
75
|
+
const scale = frame.width / 1080;
|
|
76
|
+
const stroke = r3(STROKE_WIDTH * scale);
|
|
77
|
+
const html: string[] = [];
|
|
78
|
+
const tweens: string[] = [];
|
|
79
|
+
for (const overlay of drawn) {
|
|
80
|
+
const id = `ov${overlay.index}`;
|
|
81
|
+
const duration = r3(overlay.end - overlay.start);
|
|
82
|
+
const exitAt = r3(overlay.end - EXIT_SECONDS);
|
|
83
|
+
const clip = (classes: string, style: string, body: string) =>
|
|
84
|
+
`<div id="${id}" class="clip ${classes}" data-start="${overlay.start}" data-duration="${duration}" style="${style}">${body}</div>`;
|
|
85
|
+
if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") {
|
|
86
|
+
const { box, fontSize, side } = overlay;
|
|
87
|
+
const style = `left:${box.left}px;top:${box.top}px;width:${box.width}px;height:${box.height}px;font-size:${fontSize}px;align-items:${overlay.kind === "lower_third" ? "flex-end" : "flex-start"}`;
|
|
88
|
+
const body =
|
|
89
|
+
overlay.kind === "list"
|
|
90
|
+
? `<ul class="ov-card">${overlay.items.map((item, i) => `<li id="${id}i${i}"><i class="ov-dot"></i>${escapeHtml(item)}</li>`).join("")}</ul>`
|
|
91
|
+
: `<div class="ov-card">${overlay.kind === "lower_third" ? `<i class="ov-dot" id="${id}d"></i>` : ""}<span id="${id}t">${escapeHtml(overlay.text)}</span></div>`;
|
|
92
|
+
html.push(clip(`ov ov-${overlay.kind.replace("_", "-")}${side === "right" ? " right" : ""}`, style, body));
|
|
93
|
+
// The soft pill's entrance: the card pops up from its foot, then its dot and its text settle in.
|
|
94
|
+
tweens.push(`tl.fromTo("#${id} .ov-card", { scale: 0.88, y: 18, opacity: 0 }, { scale: 1, y: 0, opacity: 1, duration: 0.45, ease: "back.out(1.7)", immediateRender: false }, ${overlay.start});`);
|
|
95
|
+
if (overlay.kind === "lower_third") {
|
|
96
|
+
tweens.push(`tl.fromTo("#${id}d", { scale: 0 }, { scale: 1, duration: 0.35, ease: "back.out(3)", immediateRender: false }, ${r3(overlay.start + 0.25)});`);
|
|
97
|
+
tweens.push(`tl.fromTo("#${id}t", { opacity: 0, x: -10 }, { opacity: 1, x: 0, duration: 0.4, ease: "power3.out", immediateRender: false }, ${r3(overlay.start + 0.3)});`);
|
|
98
|
+
}
|
|
99
|
+
if (overlay.kind === "list") {
|
|
100
|
+
overlay.items.forEach((_item, i) => {
|
|
101
|
+
tweens.push(`tl.fromTo("#${id}i${i}", { opacity: 0, y: 14 }, { opacity: 1, y: 0, duration: 0.35, ease: "power3.out", immediateRender: false }, ${r3(overlay.start + 0.2 + 0.12 * i)});`);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
tweens.push(`tl.to("#${id} .ov-card", { scale: 0.94, y: 14, opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${exitAt});`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const view = `viewBox="0 0 ${frame.width} ${frame.height}"`;
|
|
108
|
+
if (overlay.kind === "arrow") {
|
|
109
|
+
const paths = getArrowPaths(overlay, scale);
|
|
110
|
+
const body = `<svg class="ov-svg" ${view}><path id="${id}c" d="${paths.curve}" fill="none" stroke="${colors.accent}" stroke-width="${stroke}" stroke-linecap="round" pathLength="1" stroke-dasharray="1" stroke-dashoffset="1"/><path id="${id}h" d="${paths.head}" fill="none" stroke="${colors.accent}" stroke-width="${stroke}" stroke-linecap="round" stroke-linejoin="round" opacity="0"/></svg>`;
|
|
111
|
+
html.push(clip("ov ov-arrow", "inset:0", body));
|
|
112
|
+
// Drawn on from the tail; the head arrives as the stroke reaches the point.
|
|
113
|
+
tweens.push(`tl.fromTo("#${id}c", { attr: { "stroke-dashoffset": 1 } }, { attr: { "stroke-dashoffset": 0 }, duration: 0.45, ease: "power2.out", immediateRender: false }, ${overlay.start});`);
|
|
114
|
+
tweens.push(`tl.fromTo("#${id}h", { opacity: 0 }, { opacity: 1, duration: 0.12, ease: "none", immediateRender: false }, ${r3(overlay.start + 0.38)});`);
|
|
115
|
+
} else if (overlay.kind === "highlight") {
|
|
116
|
+
const { rect } = overlay;
|
|
117
|
+
const radius = r3(18 * scale);
|
|
118
|
+
const body = `<svg class="ov-svg" ${view}><rect x="${rect.left}" y="${rect.top}" width="${rect.width}" height="${rect.height}" rx="${radius}" fill="${colors.accent}" fill-opacity="0.18" stroke="none" id="${id}f" opacity="0"/><rect id="${id}s" x="${rect.left}" y="${rect.top}" width="${rect.width}" height="${rect.height}" rx="${radius}" fill="none" stroke="${colors.accent}" stroke-width="${stroke}" pathLength="1" stroke-dasharray="1" stroke-dashoffset="1"/></svg>`;
|
|
119
|
+
html.push(clip("ov ov-highlight", "inset:0", body));
|
|
120
|
+
// The marker's stroke drawn round its target, the tint settling in behind it.
|
|
121
|
+
tweens.push(`tl.fromTo("#${id}s", { attr: { "stroke-dashoffset": 1 } }, { attr: { "stroke-dashoffset": 0 }, duration: 0.5, ease: "power2.inOut", immediateRender: false }, ${overlay.start});`);
|
|
122
|
+
tweens.push(`tl.fromTo("#${id}f", { opacity: 0 }, { opacity: 1, duration: 0.3, ease: "none", immediateRender: false }, ${r3(overlay.start + 0.3)});`);
|
|
123
|
+
}
|
|
124
|
+
tweens.push(`tl.to("#${id} .ov-svg", { opacity: 0, duration: ${EXIT_SECONDS}, ease: "power2.in" }, ${exitAt});`);
|
|
125
|
+
}
|
|
126
|
+
return { html, css: getOverlayCss(colors, input.headingFont), tweens };
|
|
127
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An EDL's overlays (issue #1200): small graphics and an emphasis zoom placed on a word of the transcript or at a film
|
|
5
|
+
* second, drawn by the render and the draft alike from a fixed catalogue. Their shape lives here so the EDL schema can
|
|
6
|
+
* read them; `overlays.ts` resolves them to film time and places them.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `punch_in`: an emphasis zoom of the picture on a word, eased in and back out. `keyword`: one word or number beside
|
|
11
|
+
* the subject. `lower_third`: a place or a name above the captions. `list`: 2 to 4 short points. `arrow`: points at
|
|
12
|
+
* `anchor` in the frame. `highlight`: marks the `anchor` rectangle of the frame.
|
|
13
|
+
*/
|
|
14
|
+
export const OVERLAY_KINDS = ["punch_in", "keyword", "lower_third", "list", "arrow", "highlight"] as const;
|
|
15
|
+
|
|
16
|
+
export type OverlayKind = (typeof OVERLAY_KINDS)[number];
|
|
17
|
+
|
|
18
|
+
/** An overlay's size step: the zoom of a `punch_in`, the type size of the others. */
|
|
19
|
+
export const OVERLAY_SIZES = ["s", "m", "l"] as const;
|
|
20
|
+
|
|
21
|
+
export type OverlaySize = (typeof OVERLAY_SIZES)[number];
|
|
22
|
+
|
|
23
|
+
/** The side of the frame a text overlay sits on. */
|
|
24
|
+
export const OVERLAY_SIDES = ["left", "right"] as const;
|
|
25
|
+
|
|
26
|
+
export type OverlaySide = (typeof OVERLAY_SIDES)[number];
|
|
27
|
+
|
|
28
|
+
/** The shortest an overlay stays on screen: shorter does not read. */
|
|
29
|
+
export const MIN_OVERLAY_SECONDS = 1;
|
|
30
|
+
/** The longest an overlay stays on screen. */
|
|
31
|
+
export const MAX_OVERLAY_SECONDS = 8;
|
|
32
|
+
/** The longest `keyword` text. */
|
|
33
|
+
export const MAX_OVERLAY_KEYWORD_LENGTH = 24;
|
|
34
|
+
/** The longest `lower_third` text. */
|
|
35
|
+
export const MAX_OVERLAY_LOWER_THIRD_LENGTH = 40;
|
|
36
|
+
/** The longest point of a `list`. */
|
|
37
|
+
export const MAX_OVERLAY_LIST_ITEM_LENGTH = 32;
|
|
38
|
+
|
|
39
|
+
/** A word of the film's transcript: the `occurrence`-th word (1 first) that reads `text`, compared like fillers are. */
|
|
40
|
+
export interface EdlOverlayWord {
|
|
41
|
+
text: string;
|
|
42
|
+
occurrence?: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A point (`arrow`) or a rectangle (`highlight`) of the film's frame, in px from its top left corner. */
|
|
46
|
+
export interface EdlOverlayAnchor {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
width?: number;
|
|
50
|
+
height?: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface EdlOverlayStyle {
|
|
54
|
+
size?: OverlaySize;
|
|
55
|
+
side?: OverlaySide;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface EdlOverlay {
|
|
59
|
+
kind: OverlayKind;
|
|
60
|
+
/** The word it starts on (its start in film time); give this or `at`. */
|
|
61
|
+
at_word?: EdlOverlayWord;
|
|
62
|
+
/** The film second it starts at; give this or `at_word`. */
|
|
63
|
+
at?: number;
|
|
64
|
+
/** Seconds on screen (`MIN_OVERLAY_SECONDS` to `MAX_OVERLAY_SECONDS`). */
|
|
65
|
+
duration: number;
|
|
66
|
+
/** The `keyword` or the `lower_third` text. */
|
|
67
|
+
text?: string;
|
|
68
|
+
/** The `list` points (2 to 4). */
|
|
69
|
+
items?: string[];
|
|
70
|
+
/** The `arrow` point or the `highlight` rectangle. */
|
|
71
|
+
anchor?: EdlOverlayAnchor;
|
|
72
|
+
style?: EdlOverlayStyle;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** What each kind needs and refuses: its text, its points or its anchor. */
|
|
76
|
+
const KIND_FIELDS: Record<OverlayKind, { text: boolean; items: boolean; anchor: "none" | "point" | "rect" }> = {
|
|
77
|
+
punch_in: { text: false, items: false, anchor: "none" },
|
|
78
|
+
keyword: { text: true, items: false, anchor: "none" },
|
|
79
|
+
lower_third: { text: true, items: false, anchor: "none" },
|
|
80
|
+
list: { text: false, items: true, anchor: "none" },
|
|
81
|
+
arrow: { text: false, items: false, anchor: "point" },
|
|
82
|
+
highlight: { text: false, items: false, anchor: "rect" },
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const TEXT_LIMITS: Partial<Record<OverlayKind, number>> = { keyword: MAX_OVERLAY_KEYWORD_LENGTH, lower_third: MAX_OVERLAY_LOWER_THIRD_LENGTH };
|
|
86
|
+
|
|
87
|
+
const overlayText = z.string().trim().min(1, "is empty");
|
|
88
|
+
|
|
89
|
+
export const overlaySchema = z
|
|
90
|
+
.strictObject({
|
|
91
|
+
kind: z.enum(OVERLAY_KINDS).describe("punch_in (an emphasis zoom on a word), keyword, lower_third, list, arrow or highlight."),
|
|
92
|
+
at_word: z
|
|
93
|
+
.strictObject({
|
|
94
|
+
text: overlayText.describe("The word as the transcript has it; compared without case and punctuation."),
|
|
95
|
+
occurrence: z.number().int().min(1).optional().describe("Which time the film says it (1 the first, the default)."),
|
|
96
|
+
})
|
|
97
|
+
.optional()
|
|
98
|
+
.describe("The transcript word the overlay starts on (its start after the cut); give this or at."),
|
|
99
|
+
at: z.number().min(0).optional().describe("The film second the overlay starts at; give this or at_word."),
|
|
100
|
+
duration: z.number().min(MIN_OVERLAY_SECONDS).max(MAX_OVERLAY_SECONDS).describe(`Seconds on screen (${MIN_OVERLAY_SECONDS}-${MAX_OVERLAY_SECONDS}).`),
|
|
101
|
+
text: overlayText.optional().describe(`The keyword (up to ${MAX_OVERLAY_KEYWORD_LENGTH} characters) or the lower third (up to ${MAX_OVERLAY_LOWER_THIRD_LENGTH}).`),
|
|
102
|
+
items: z
|
|
103
|
+
.array(overlayText.max(MAX_OVERLAY_LIST_ITEM_LENGTH, `is longer than ${MAX_OVERLAY_LIST_ITEM_LENGTH} characters`))
|
|
104
|
+
.min(2, "a list needs 2 to 4 points")
|
|
105
|
+
.max(4, "a list needs 2 to 4 points")
|
|
106
|
+
.optional()
|
|
107
|
+
.describe(`The list's points: 2 to 4, up to ${MAX_OVERLAY_LIST_ITEM_LENGTH} characters each.`),
|
|
108
|
+
anchor: z
|
|
109
|
+
.strictObject({
|
|
110
|
+
x: z.number().min(0).describe("Px from the frame's left edge."),
|
|
111
|
+
y: z.number().min(0).describe("Px from the frame's top edge."),
|
|
112
|
+
width: z.number().positive().optional().describe("The highlight's width in px."),
|
|
113
|
+
height: z.number().positive().optional().describe("The highlight's height in px."),
|
|
114
|
+
})
|
|
115
|
+
.optional()
|
|
116
|
+
.describe("The point an arrow points at, or the rectangle a highlight marks (x, y its top left), in px of the film's frame."),
|
|
117
|
+
style: z
|
|
118
|
+
.strictObject({
|
|
119
|
+
size: z.enum(OVERLAY_SIZES).optional().describe("s, m (the default) or l: the punch-in's zoom (108, 112, 115 %) or the type size."),
|
|
120
|
+
side: z.enum(OVERLAY_SIDES).optional().describe("The side a keyword, lower third or list sits on."),
|
|
121
|
+
})
|
|
122
|
+
.optional()
|
|
123
|
+
.describe("The overlay's size step and side; colours and fonts are the brand's."),
|
|
124
|
+
})
|
|
125
|
+
.superRefine((overlay, context) => {
|
|
126
|
+
const fields = KIND_FIELDS[overlay.kind];
|
|
127
|
+
if ((overlay.at_word === undefined) === (overlay.at === undefined)) context.addIssue({ code: "custom", path: [], message: "needs exactly one of at_word and at" });
|
|
128
|
+
if (fields.text && overlay.text === undefined) context.addIssue({ code: "custom", path: ["text"], message: `a ${overlay.kind} needs its text` });
|
|
129
|
+
if (!fields.text && overlay.text !== undefined) context.addIssue({ code: "custom", path: ["text"], message: `a ${overlay.kind} draws no text; leave it out` });
|
|
130
|
+
const limit = TEXT_LIMITS[overlay.kind];
|
|
131
|
+
if (limit !== undefined && overlay.text !== undefined && overlay.text.length > limit) {
|
|
132
|
+
context.addIssue({ code: "custom", path: ["text"], message: `is longer than ${limit} characters` });
|
|
133
|
+
}
|
|
134
|
+
if (fields.items && overlay.items === undefined) context.addIssue({ code: "custom", path: ["items"], message: "a list needs 2 to 4 points" });
|
|
135
|
+
if (!fields.items && overlay.items !== undefined) context.addIssue({ code: "custom", path: ["items"], message: `a ${overlay.kind} draws no points; leave them out` });
|
|
136
|
+
if (fields.anchor === "none" && overlay.anchor !== undefined) context.addIssue({ code: "custom", path: ["anchor"], message: `a ${overlay.kind} has no anchor; leave it out` });
|
|
137
|
+
if (fields.anchor !== "none" && overlay.anchor === undefined) context.addIssue({ code: "custom", path: ["anchor"], message: `${overlay.kind === "arrow" ? "an arrow" : "a highlight"} needs its anchor` });
|
|
138
|
+
const isRect = overlay.anchor?.width !== undefined && overlay.anchor.height !== undefined;
|
|
139
|
+
if (fields.anchor === "rect" && overlay.anchor !== undefined && !isRect) context.addIssue({ code: "custom", path: ["anchor"], message: "a highlight needs the anchor's width and height" });
|
|
140
|
+
if (fields.anchor === "point" && (overlay.anchor?.width !== undefined || overlay.anchor?.height !== undefined)) {
|
|
141
|
+
context.addIssue({ code: "custom", path: ["anchor"], message: "an arrow points at a point: leave width and height out" });
|
|
142
|
+
}
|
|
143
|
+
if (overlay.kind !== "keyword" && overlay.kind !== "lower_third" && overlay.kind !== "list" && overlay.style?.side !== undefined) {
|
|
144
|
+
context.addIssue({ code: "custom", path: ["style", "side"], message: `a ${overlay.kind} has no side; leave it out` });
|
|
145
|
+
}
|
|
146
|
+
});
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { CAPTION_LINE_HEIGHT, CAPTION_PILL_PADDING, type CaptionLayout } from "../compose/timeline.js";
|
|
2
|
+
import type { TimedWord } from "../voice/voiceover.js";
|
|
3
|
+
import { applySegmentCaption, CAPTION_SAFE_ZONES } from "./captions.js";
|
|
4
|
+
import { getEdlDuration, getSegmentStarts, findSegmentAt, type Edl } from "./edl.js";
|
|
5
|
+
import { getFootageEdit, type FootageFilm } from "./film.js";
|
|
6
|
+
import { FOOTAGE_FPS } from "./normalize.js";
|
|
7
|
+
import type { EdlOverlay, OverlaySide, OverlaySize } from "./overlay-schema.js";
|
|
8
|
+
import { getSegmentZoomEases } from "./compose.js";
|
|
9
|
+
import { normalizeWord } from "./words.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An EDL's overlays resolved for the render and the draft (issue #1200): each one's film time (from its word through
|
|
13
|
+
* the cut, or its second), the segment it plays in, and where it sits in the frame, inside the platform safe zone and
|
|
14
|
+
* clear of the captions. `resolveEdlOverlays` refuses, with a reason per overlay, anything the render could not draw
|
|
15
|
+
* cleanly; the app's own budget (how many, how often) goes on top through `overlayMinSpacing`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** How far a `punch_in` zooms the picture, by size step (100 % to this, then back). */
|
|
19
|
+
export const PUNCH_IN_SCALES: Record<OverlaySize, number> = { s: 1.08, m: 1.12, l: 1.15 };
|
|
20
|
+
/** The `punch_in`'s ease into its zoom and back out, in seconds (shorter when the overlay is short). */
|
|
21
|
+
export const PUNCH_IN_EASE_SECONDS = 0.35;
|
|
22
|
+
/** A text overlay's type size in px of a 1080 px wide frame, by kind and size step. */
|
|
23
|
+
export const OVERLAY_FONT_SIZES: Record<"keyword" | "lower_third" | "list", Record<OverlaySize, number>> = {
|
|
24
|
+
keyword: { s: 64, m: 84, l: 108 },
|
|
25
|
+
lower_third: { s: 44, m: 52, l: 60 },
|
|
26
|
+
list: { s: 40, m: 48, l: 56 },
|
|
27
|
+
};
|
|
28
|
+
/** A text overlay's line height and its box's padding, in font sizes. */
|
|
29
|
+
export const OVERLAY_LINE_HEIGHT = 1.15;
|
|
30
|
+
export const OVERLAY_LIST_LINE_HEIGHT = 1.4;
|
|
31
|
+
export const OVERLAY_PADDING_EM = { x: 0.6, y: 0.35 } as const;
|
|
32
|
+
/** The room kept between an overlay and the safe zone's edge or the captions, in px. */
|
|
33
|
+
export const OVERLAY_MARGIN = 24;
|
|
34
|
+
/** How far an arrow's tail sits from the point it points at, in px. */
|
|
35
|
+
const ARROW_REACH = { x: 220, y: 180 } as const;
|
|
36
|
+
/** The smallest highlight rectangle, in px. */
|
|
37
|
+
const MIN_HIGHLIGHT_SIDE = 40;
|
|
38
|
+
/** The safe zone of a frame that is not a 1080×1920 vertical: 80 px on every side. */
|
|
39
|
+
const DEFAULT_SAFE_MARGIN = 80;
|
|
40
|
+
|
|
41
|
+
/** A box in the film's frame, in px. */
|
|
42
|
+
export interface OverlayBox {
|
|
43
|
+
left: number;
|
|
44
|
+
top: number;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface OverlayPoint {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface OverlayBase {
|
|
55
|
+
/** The overlay's place in `edl.overlays`. */
|
|
56
|
+
index: number;
|
|
57
|
+
/** Film seconds. */
|
|
58
|
+
start: number;
|
|
59
|
+
end: number;
|
|
60
|
+
/** The segment it plays in. */
|
|
61
|
+
segment: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A text overlay's box: `left` and `top` of its outer edge, its width the most it may take (it shrinks to its text). */
|
|
65
|
+
export type ResolvedOverlay =
|
|
66
|
+
| (OverlayBase & { kind: "punch_in"; scale: number; ease: number })
|
|
67
|
+
| (OverlayBase & { kind: "keyword" | "lower_third"; text: string; fontSize: number; side: OverlaySide; box: OverlayBox })
|
|
68
|
+
| (OverlayBase & { kind: "list"; items: string[]; fontSize: number; side: OverlaySide; box: OverlayBox })
|
|
69
|
+
| (OverlayBase & { kind: "arrow"; from: OverlayPoint; to: OverlayPoint })
|
|
70
|
+
| (OverlayBase & { kind: "highlight"; rect: OverlayBox });
|
|
71
|
+
|
|
72
|
+
export type ResolvedOverlaysResult = { ok: true; overlays: ResolvedOverlay[] } | { ok: false; problems: string[] };
|
|
73
|
+
|
|
74
|
+
export interface ResolveOverlaysInput {
|
|
75
|
+
film: Pick<FootageFilm, "captions" | "captionMaxLines" | "format" | "captionPreset" | "edit" | "overlayMinSpacing">;
|
|
76
|
+
edl: Edl;
|
|
77
|
+
/** The film's words in film time (`remapWords`). */
|
|
78
|
+
words: TimedWord[];
|
|
79
|
+
frame: { width: number; height: number };
|
|
80
|
+
/** The film's caption box (`getFootageCaptionLayout`). */
|
|
81
|
+
caption: CaptionLayout;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The part of the frame no platform interface covers: a 9:16 film's caption preset zone (`all` without one), else 80 px. */
|
|
85
|
+
export function getOverlaySafeZone(film: Pick<FootageFilm, "format" | "captionPreset">, frame: { width: number; height: number }): { top: number; bottom: number; left: number; right: number } {
|
|
86
|
+
if (film.format === "9:16" && frame.width === 1080 && frame.height === 1920) return CAPTION_SAFE_ZONES[film.captionPreset ?? "all"];
|
|
87
|
+
return { top: DEFAULT_SAFE_MARGIN, bottom: DEFAULT_SAFE_MARGIN, left: DEFAULT_SAFE_MARGIN, right: DEFAULT_SAFE_MARGIN };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The rows a caption card can take in a segment (its box moved by the segment's `caption`), or null without captions. */
|
|
91
|
+
function getCaptionBand(input: ResolveOverlaysInput, segment: number): { top: number; bottom: number } | null {
|
|
92
|
+
if (!input.film.captions) return null;
|
|
93
|
+
const place = applySegmentCaption(input.caption, input.edl.segments[segment]?.caption);
|
|
94
|
+
const lines = input.film.captionMaxLines ?? 2;
|
|
95
|
+
const height = Math.ceil(lines * place.fontSize * CAPTION_LINE_HEIGHT + 2 * CAPTION_PILL_PADDING.y);
|
|
96
|
+
if (place.bottom !== undefined) return { top: input.frame.height - place.bottom - height, bottom: input.frame.height - place.bottom };
|
|
97
|
+
return { top: place.top, bottom: place.top + height };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The film second an overlay starts at, or the reason its word cannot be found. */
|
|
101
|
+
function findOverlayStart(overlay: EdlOverlay, words: TimedWord[]): { ok: true; start: number } | { ok: false; error: string } {
|
|
102
|
+
if (overlay.at !== undefined) return { ok: true, start: overlay.at };
|
|
103
|
+
const wanted = overlay.at_word as NonNullable<EdlOverlay["at_word"]>;
|
|
104
|
+
const key = normalizeWord(wanted.text);
|
|
105
|
+
const occurrence = wanted.occurrence ?? 1;
|
|
106
|
+
const matches = words.filter((word) => normalizeWord(word.text) === key);
|
|
107
|
+
const word = matches[occurrence - 1];
|
|
108
|
+
if (word === undefined) {
|
|
109
|
+
const said = matches.length === 0 ? "the film never says it" : `the film says it ${matches.length} time${matches.length === 1 ? "" : "s"}`;
|
|
110
|
+
return { ok: false, error: `at_word: no word "${wanted.text}"${occurrence > 1 ? ` (occurrence ${occurrence})` : ""} in the cut; ${said}` };
|
|
111
|
+
}
|
|
112
|
+
return { ok: true, start: word.start };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const r1 = (value: number): number => Math.round(value * 10) / 10;
|
|
116
|
+
const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The overlays of an EDL resolved to film time and placed, or every reason one cannot be drawn: its word is not said,
|
|
120
|
+
* it is too short or runs past the cut or into the next segment, two overlap, two start closer than
|
|
121
|
+
* `overlayMinSpacing`, a text overlay does not fit between the safe zone and the captions, an anchor leaves the safe
|
|
122
|
+
* zone or sits on the captions, or a `punch_in` falls on a `kenburns` segment or inside a zoom cut's ease. An EDL
|
|
123
|
+
* without overlays resolves to none.
|
|
124
|
+
*/
|
|
125
|
+
export function resolveEdlOverlays(input: ResolveOverlaysInput): ResolvedOverlaysResult {
|
|
126
|
+
const overlays = input.edl.overlays ?? [];
|
|
127
|
+
if (overlays.length === 0) return { ok: true, overlays: [] };
|
|
128
|
+
const { frame, film, edl } = input;
|
|
129
|
+
const cutEnd = getEdlDuration(edl);
|
|
130
|
+
const starts = getSegmentStarts(edl);
|
|
131
|
+
const eases = getSegmentZoomEases(edl, getFootageEdit(film));
|
|
132
|
+
const zone = getOverlaySafeZone(film, frame);
|
|
133
|
+
const problems: string[] = [];
|
|
134
|
+
const resolved: ResolvedOverlay[] = [];
|
|
135
|
+
overlays.forEach((overlay, index) => {
|
|
136
|
+
const at = `overlays[${index}]`;
|
|
137
|
+
const found = findOverlayStart(overlay, input.words);
|
|
138
|
+
if (!found.ok) {
|
|
139
|
+
problems.push(`${at}.${found.error}`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const start = r3(found.start);
|
|
143
|
+
const end = r3(start + overlay.duration);
|
|
144
|
+
if (end > cutEnd + 0.001) {
|
|
145
|
+
problems.push(`${at}: ends at ${end} s, past the cut's end (${cutEnd} s)`);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const segment = findSegmentAt(edl, start);
|
|
149
|
+
const segmentStart = starts[segment] as number;
|
|
150
|
+
const segmentEnd = r3(segmentStart + ((edl.segments[segment]?.end ?? 0) - (edl.segments[segment]?.start ?? 0)));
|
|
151
|
+
const segmentId = edl.segments[segment]?.id ?? "";
|
|
152
|
+
if (end > segmentEnd + 0.01) {
|
|
153
|
+
problems.push(`${at}: runs ${r1(end - segmentEnd)} s past the cut at ${segmentEnd} s; keep it inside segment "${segmentId}" (${segmentStart}-${segmentEnd} s) or shorten it`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const base = { index, start, end, segment };
|
|
157
|
+
const placed = placeOverlay(overlay, base, { zone, frame, band: getCaptionBand(input, segment) });
|
|
158
|
+
if (!placed.ok) {
|
|
159
|
+
problems.push(`${at}: ${placed.error}`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (placed.overlay.kind === "punch_in") {
|
|
163
|
+
if (edl.segments[segment]?.motion === "kenburns") {
|
|
164
|
+
problems.push(`${at}: segment "${segmentId}" has a Ken Burns zoom, which owns the picture's scale; put the punch-in on a still segment`);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const easeEnd = r3(segmentStart + (eases[segment] ?? 0) / FOOTAGE_FPS);
|
|
168
|
+
if (start < easeEnd) {
|
|
169
|
+
problems.push(`${at}: starts at ${start} s, inside the zoom cut's ease of segment "${segmentId}" (until ${easeEnd} s); start it later`);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
resolved.push(placed.overlay);
|
|
174
|
+
});
|
|
175
|
+
const ordered = [...resolved].sort((a, b) => a.start - b.start);
|
|
176
|
+
const spacing = film.overlayMinSpacing ?? 0;
|
|
177
|
+
ordered.forEach((overlay, place) => {
|
|
178
|
+
const previous = ordered[place - 1];
|
|
179
|
+
if (previous === undefined) return;
|
|
180
|
+
if (overlay.start < previous.end - 0.001) {
|
|
181
|
+
problems.push(`overlays[${overlay.index}]: starts at ${overlay.start} s while overlays[${previous.index}] is on screen (until ${previous.end} s); one overlay at a time`);
|
|
182
|
+
} else if (overlay.start - previous.start < spacing - 0.001) {
|
|
183
|
+
problems.push(`overlays[${overlay.index}]: starts ${r1(overlay.start - previous.start)} s after overlays[${previous.index}]; the film keeps overlays ${spacing} s apart (overlayMinSpacing)`);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return problems.length > 0 ? { ok: false, problems } : { ok: true, overlays: ordered };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface Placement {
|
|
190
|
+
zone: { top: number; bottom: number; left: number; right: number };
|
|
191
|
+
frame: { width: number; height: number };
|
|
192
|
+
band: { top: number; bottom: number } | null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
type Placed = { ok: true; overlay: ResolvedOverlay } | { ok: false; error: string };
|
|
196
|
+
|
|
197
|
+
/** The rows a text overlay may use: the safe zone's height above the captions (or below them when they sit high). */
|
|
198
|
+
function getTextRegion(place: Placement): { top: number; bottom: number } {
|
|
199
|
+
const top = place.zone.top;
|
|
200
|
+
const bottom = place.frame.height - place.zone.bottom;
|
|
201
|
+
if (place.band === null) return { top, bottom };
|
|
202
|
+
const isLow = (place.band.top + place.band.bottom) / 2 > place.frame.height / 2;
|
|
203
|
+
return isLow ? { top, bottom: Math.min(bottom, place.band.top - OVERLAY_MARGIN) } : { top: Math.max(top, place.band.bottom + OVERLAY_MARGIN), bottom };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Whether a row range overlaps the caption band. */
|
|
207
|
+
function isOnCaptions(place: Placement, top: number, bottom: number): boolean {
|
|
208
|
+
return place.band !== null && top < place.band.bottom && bottom > place.band.top;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function isInsideZone(place: Placement, point: OverlayPoint): boolean {
|
|
212
|
+
const { zone, frame } = place;
|
|
213
|
+
return point.x >= zone.left && point.x <= frame.width - zone.right && point.y >= zone.top && point.y <= frame.height - zone.bottom;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function placeOverlay(overlay: EdlOverlay, base: OverlayBase, place: Placement): Placed {
|
|
217
|
+
const size = overlay.style?.size ?? "m";
|
|
218
|
+
if (overlay.kind === "punch_in") {
|
|
219
|
+
const ease = r3(Math.min(PUNCH_IN_EASE_SECONDS, (base.end - base.start) / 2));
|
|
220
|
+
return { ok: true, overlay: { ...base, kind: "punch_in", scale: PUNCH_IN_SCALES[size], ease } };
|
|
221
|
+
}
|
|
222
|
+
const { zone, frame } = place;
|
|
223
|
+
const scale = frame.width / 1080;
|
|
224
|
+
if (overlay.kind === "arrow" || overlay.kind === "highlight") {
|
|
225
|
+
const anchor = overlay.anchor as NonNullable<EdlOverlay["anchor"]>;
|
|
226
|
+
if (overlay.kind === "arrow") {
|
|
227
|
+
const to = { x: anchor.x, y: anchor.y };
|
|
228
|
+
if (!isInsideZone(place, to)) return { ok: false, error: `the arrow's point (${to.x}, ${to.y}) is outside the platform safe zone` };
|
|
229
|
+
if (isOnCaptions(place, to.y, to.y)) return { ok: false, error: `the arrow's point (${to.x}, ${to.y}) sits on the captions` };
|
|
230
|
+
const clampX = (x: number) => Math.min(frame.width - zone.right, Math.max(zone.left, x));
|
|
231
|
+
const clampY = (y: number) => Math.min(frame.height - zone.bottom, Math.max(zone.top, y));
|
|
232
|
+
const dx = Math.round(ARROW_REACH.x * scale);
|
|
233
|
+
const dy = Math.round(ARROW_REACH.y * scale);
|
|
234
|
+
// The tail sits towards the frame's middle and above the point (below it near the top), so the arrow reads inward.
|
|
235
|
+
const from = { x: clampX(to.x > frame.width / 2 ? to.x - dx : to.x + dx), y: clampY(to.y - dy >= zone.top ? to.y - dy : to.y + dy) };
|
|
236
|
+
if (isOnCaptions(place, Math.min(from.y, to.y), Math.max(from.y, to.y))) return { ok: false, error: "the arrow would cross the captions; point at something further from them" };
|
|
237
|
+
return { ok: true, overlay: { ...base, kind: "arrow", from, to } };
|
|
238
|
+
}
|
|
239
|
+
const rect = { left: anchor.x, top: anchor.y, width: anchor.width ?? 0, height: anchor.height ?? 0 };
|
|
240
|
+
if (rect.width < MIN_HIGHLIGHT_SIDE || rect.height < MIN_HIGHLIGHT_SIDE) return { ok: false, error: `the highlight is smaller than ${MIN_HIGHLIGHT_SIDE}×${MIN_HIGHLIGHT_SIDE} px` };
|
|
241
|
+
const corner = { x: rect.left + rect.width, y: rect.top + rect.height };
|
|
242
|
+
if (!isInsideZone(place, { x: rect.left, y: rect.top }) || !isInsideZone(place, corner)) return { ok: false, error: "the highlight reaches outside the platform safe zone" };
|
|
243
|
+
if (isOnCaptions(place, rect.top, corner.y)) return { ok: false, error: "the highlight overlaps the captions" };
|
|
244
|
+
return { ok: true, overlay: { ...base, kind: "highlight", rect } };
|
|
245
|
+
}
|
|
246
|
+
const side = overlay.style?.side ?? (overlay.kind === "keyword" ? "right" : "left");
|
|
247
|
+
const fontSize = Math.round(OVERLAY_FONT_SIZES[overlay.kind][size] * scale);
|
|
248
|
+
const padY = Math.round(fontSize * OVERLAY_PADDING_EM.y);
|
|
249
|
+
const lines = overlay.kind === "list" ? (overlay.items ?? []).length : 1;
|
|
250
|
+
const lineHeight = overlay.kind === "list" ? OVERLAY_LIST_LINE_HEIGHT : OVERLAY_LINE_HEIGHT;
|
|
251
|
+
const height = Math.ceil(lines * fontSize * lineHeight + 2 * padY);
|
|
252
|
+
const region = getTextRegion(place);
|
|
253
|
+
const regionHeight = region.bottom - region.top;
|
|
254
|
+
const margin = Math.round(OVERLAY_MARGIN * scale);
|
|
255
|
+
const top =
|
|
256
|
+
overlay.kind === "lower_third"
|
|
257
|
+
? region.bottom - height
|
|
258
|
+
: overlay.kind === "keyword"
|
|
259
|
+
? Math.round(region.top + regionHeight * 0.4 - height / 2)
|
|
260
|
+
: Math.round(region.top + regionHeight * 0.15);
|
|
261
|
+
if (top < region.top || top + height > region.bottom) {
|
|
262
|
+
return { ok: false, error: `the ${overlay.kind.replace("_", " ")} (${height} px tall) does not fit between the platform safe zone and the captions; use a smaller size or fewer points` };
|
|
263
|
+
}
|
|
264
|
+
const box = { left: zone.left + margin, top, width: frame.width - zone.left - zone.right - 2 * margin, height };
|
|
265
|
+
if (overlay.kind === "list") return { ok: true, overlay: { ...base, kind: "list", items: overlay.items ?? [], fontSize, side, box } };
|
|
266
|
+
return { ok: true, overlay: { ...base, kind: overlay.kind, text: overlay.text ?? "", fontSize, side, box } };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The texts the overlays draw, for the glyph check. */
|
|
270
|
+
export function getOverlayTexts(overlays: readonly ResolvedOverlay[]): string[] {
|
|
271
|
+
return overlays.flatMap((overlay) => (overlay.kind === "keyword" || overlay.kind === "lower_third" ? [overlay.text] : overlay.kind === "list" ? overlay.items : []));
|
|
272
|
+
}
|
package/src/footage/pipeline.ts
CHANGED
|
@@ -15,6 +15,8 @@ import { checkMusicFileType, describeAudioProbe, probeAudio } from "./audio.js";
|
|
|
15
15
|
import { prepareClipSounds, type SpeechPeaks, type SpeechPreGain } from "./clip-sound.js";
|
|
16
16
|
import { readCachedTranscript, writeCacheFile, writeTranscript } from "./cache.js";
|
|
17
17
|
import { composeFootage, getFootageFilmSeconds, getFootageSfxCues } from "./compose.js";
|
|
18
|
+
import { getCaptionHighlight } from "./caption-highlight.js";
|
|
19
|
+
import { getOverlayTexts, resolveEdlOverlays } from "./overlays.js";
|
|
18
20
|
import { findMissingCaptionGlyphs, getCaptionBounds, getFootageCaptionLayout } from "./captions.js";
|
|
19
21
|
import { err, getProviderFootageFailure, ok, type FootageResult } from "./failure.js";
|
|
20
22
|
import { findLowDiskProblems, getFreeBytes, getRenderTempDir, type FreeBytesReader } from "./disk.js";
|
|
@@ -729,10 +731,14 @@ async function runRenderFootage(
|
|
|
729
731
|
const { buildDir, log, signal } = options;
|
|
730
732
|
const finishVideoProblems = options.finishVideo === undefined ? [] : findFinishVideoProblems(options.finishVideo);
|
|
731
733
|
if (finishVideoProblems.length > 0) return err(finishVideoProblems.join(" "), { kind: "input" });
|
|
734
|
+
const highlight = film.captions && film.captionStyle === "highlight" ? getCaptionHighlight(film, options.brand.colors) : null;
|
|
735
|
+
if (highlight !== null && !highlight.ok) return err(`footage film ${film.id}: ${highlight.error}`, { kind: "input" });
|
|
732
736
|
const lowDisk = findLowDiskProblems({ temp: getRenderTempDir(process.env, options.tempDir), build: buildDir }, options.readFreeBytes ?? getFreeBytes);
|
|
733
737
|
if (lowDisk.length > 0) return err(`not enough disk space to render: ${lowDisk.join(" ")}`);
|
|
734
738
|
const seconds = getFootageFilmSeconds(film, edl);
|
|
735
739
|
const words = remapWords(edl, transcript.words, film.cut.fillers);
|
|
740
|
+
const overlays = resolveEdlOverlays({ film, edl, words, frame: getFrame(film), caption: getFootageCaptionLayout(film, options.layout ?? {}) });
|
|
741
|
+
if (!overlays.ok) return err(`footage film ${film.id}: the EDL's overlays cannot be drawn: ${overlays.problems.join("; ")}`, { kind: "input" });
|
|
736
742
|
const music = await getMusic(film, edl, clips, seconds, options);
|
|
737
743
|
if (!music.ok) return music;
|
|
738
744
|
if (music.value !== null && typeof music.value !== "string") {
|
|
@@ -843,7 +849,7 @@ async function runRenderFootage(
|
|
|
843
849
|
const layout = { ...base, caption: getFootageCaptionLayout(film, options.layout ?? {}) };
|
|
844
850
|
const missing = findMissingCaptionGlyphs({
|
|
845
851
|
fonts: options.brand.fonts,
|
|
846
|
-
captions: film.captions ? words.map((word) => word.text) : [],
|
|
852
|
+
captions: [...(film.captions ? words.map((word) => word.text) : []), ...getOverlayTexts(overlays.overlays)],
|
|
847
853
|
endCard: getEndCardTexts(film.endCard),
|
|
848
854
|
brandName: options.brand.name,
|
|
849
855
|
});
|
|
@@ -870,6 +876,7 @@ async function runRenderFootage(
|
|
|
870
876
|
},
|
|
871
877
|
brandName: options.brand.name,
|
|
872
878
|
locale: options.brand.locale,
|
|
879
|
+
...(overlays.overlays.length === 0 ? {} : { overlays: overlays.overlays }),
|
|
873
880
|
});
|
|
874
881
|
writeFileSync(join(buildDir, "index.html"), html);
|
|
875
882
|
mkdirSync(dirname(options.output), { recursive: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { extname } from "node:path";
|
|
2
2
|
|
|
3
3
|
import { footageCacheKey, getFootageCachePath } from "./cache.js";
|
|
4
|
-
import { getAudioCodecArgs } from "./clip-sound.js";
|
|
4
|
+
import { getAudioCodecArgs, type SpeechPeaks } from "./clip-sound.js";
|
|
5
5
|
import { getSoundSpan, type Edl } from "./edl.js";
|
|
6
6
|
import type { ClipRole } from "./film.js";
|
|
7
7
|
import { FOOTAGE_SAMPLE_RATE } from "./normalize.js";
|
|
@@ -206,11 +206,14 @@ export type SpeechRangeCacheResolver = (range: SpeechRange, clipKey: string) =>
|
|
|
206
206
|
const seconds = (ms: number): string => (ms / 1000).toFixed(3);
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
|
-
* One range of a clip's sound (`audio`, read from its start) for the isolation provider
|
|
210
|
-
*
|
|
209
|
+
* One range of a clip's sound (`audio`, read from its start) for the isolation provider. A `.wav` output keeps the
|
|
210
|
+
* clip sound's own format, lossless (issue #1139): 32-bit float PCM with `peaks: "float"`, so a peak above full scale
|
|
211
|
+
* reaches the provider unclipped (issue #1193), else 24-bit PCM. Any other output is encoded as `getAudioCodecArgs`
|
|
212
|
+
* encodes it. The range keeps the sound's channels: no downmix, so no level change between the two formats.
|
|
211
213
|
*/
|
|
212
|
-
export function buildRangeAudioArgs(audio: string, range: Pick<SpeechRange, "startMs" | "endMs">, output: string): string[] {
|
|
213
|
-
const
|
|
214
|
+
export function buildRangeAudioArgs(audio: string, range: Pick<SpeechRange, "startMs" | "endMs">, output: string, options: { peaks?: SpeechPeaks } = {}): string[] {
|
|
215
|
+
const wavCodec = options.peaks === "float" ? "pcm_f32le" : "pcm_s24le";
|
|
216
|
+
const codec = extname(output).toLowerCase() === ".wav" ? ["-c:a", wavCodec] : getAudioCodecArgs(output);
|
|
214
217
|
return ["-v", "error", "-y", "-ss", seconds(range.startMs), "-t", seconds(range.endMs - range.startMs), "-i", audio, "-vn", ...codec, output];
|
|
215
218
|
}
|
|
216
219
|
|