@softure-ai/marketing-kit 0.25.0 → 0.27.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 +22 -0
- package/README.md +8 -1
- package/dist/footage/brand-style.d.ts +57 -0
- package/dist/footage/brand-style.d.ts.map +1 -0
- package/dist/footage/brand-style.js +49 -0
- package/dist/footage/brand-style.js.map +1 -0
- package/dist/footage/compose.d.ts +5 -0
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +10 -3
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/draft-boxes.d.ts +32 -0
- package/dist/footage/draft-boxes.d.ts.map +1 -0
- package/dist/footage/draft-boxes.js +28 -0
- package/dist/footage/draft-boxes.js.map +1 -0
- package/dist/footage/draft-overlays.d.ts +22 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -1
- package/dist/footage/draft-overlays.js +39 -9
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/draft-text-width.d.ts +19 -0
- package/dist/footage/draft-text-width.d.ts.map +1 -0
- package/dist/footage/draft-text-width.js +59 -0
- package/dist/footage/draft-text-width.js.map +1 -0
- package/dist/footage/draft.d.ts +11 -0
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +63 -15
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/edl.d.ts +7 -0
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +1 -1
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/overlay-html.d.ts +2 -0
- package/dist/footage/overlay-html.d.ts.map +1 -1
- package/dist/footage/overlay-html.js +16 -5
- package/dist/footage/overlay-html.js.map +1 -1
- package/dist/footage/overlay-schema.d.ts +10 -0
- package/dist/footage/overlay-schema.d.ts.map +1 -1
- package/dist/footage/overlay-schema.js +7 -0
- package/dist/footage/overlay-schema.js.map +1 -1
- package/dist/footage/overlays.d.ts +11 -1
- package/dist/footage/overlays.d.ts.map +1 -1
- package/dist/footage/overlays.js +45 -5
- package/dist/footage/overlays.js.map +1 -1
- package/dist/footage/pipeline.d.ts +6 -0
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +1 -0
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/og/character-map.d.ts +2 -0
- package/dist/og/character-map.d.ts.map +1 -1
- package/dist/og/character-map.js +12 -8
- package/dist/og/character-map.js.map +1 -1
- package/dist/og/index.d.ts +1 -0
- package/dist/og/index.d.ts.map +1 -1
- package/dist/og/index.js +1 -0
- package/dist/og/index.js.map +1 -1
- package/dist/og/photo-cover.d.ts +6 -0
- package/dist/og/photo-cover.d.ts.map +1 -1
- package/dist/og/photo-cover.js +12 -3
- package/dist/og/photo-cover.js.map +1 -1
- package/package.json +1 -1
- package/schema/edl.schema.json +12 -1
- package/src/footage/brand-style.ts +77 -0
- package/src/footage/compose.ts +13 -3
- package/src/footage/draft-boxes.ts +60 -0
- package/src/footage/draft-overlays.ts +43 -10
- package/src/footage/draft-text-width.ts +67 -0
- package/src/footage/draft.ts +111 -16
- package/src/footage/edl.ts +1 -1
- package/src/footage/overlay-html.ts +16 -6
- package/src/footage/overlay-schema.ts +9 -0
- package/src/footage/overlays.ts +44 -5
- package/src/footage/pipeline.ts +7 -0
- package/src/index.ts +23 -0
- package/src/og/character-map.ts +12 -6
- package/src/og/index.ts +1 -0
- package/src/og/photo-cover.ts +18 -3
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getCornerRadiusPx, type BrandStyle, type CornerRadius } from "./brand-style.js";
|
|
2
|
+
import { getDraftBoxEvents } from "./draft-boxes.js";
|
|
1
3
|
import { toAssColor } from "./draft-color.js";
|
|
2
4
|
import { getCounterSeconds, getOverlayColors, getTypingTimes, type OverlayColors } from "./overlay-html.js";
|
|
3
5
|
import {
|
|
@@ -132,6 +134,17 @@ interface DraftContext {
|
|
|
132
134
|
locale: string;
|
|
133
135
|
/** The font family per role, when it is not the styles' own. */
|
|
134
136
|
fonts: Partial<Record<OverlayFontRole, string>>;
|
|
137
|
+
/** The brand's style: the cards' radius, shadow and border; absent: each kind's own corner, no shadow, no border. */
|
|
138
|
+
style?: BrandStyle;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A card's corner in px: its own token, else the brand style's (a search bar stays a pill unless it names its own),
|
|
143
|
+
* else `own` (the kind's look before the style).
|
|
144
|
+
*/
|
|
145
|
+
export function getDraftCardRadius(overlay: { kind: string; cornerRadius?: CornerRadius | null }, box: { height: number }, context: Pick<DraftContext, "style" | "scale">, own: number): number {
|
|
146
|
+
const token = overlay.cornerRadius ?? (context.style === undefined ? null : overlay.kind === "search_bar" ? "pill" : context.style.cornerRadius);
|
|
147
|
+
return token === null ? own : getCornerRadiusPx(token, box.height, context.scale);
|
|
135
148
|
}
|
|
136
149
|
|
|
137
150
|
/** One stretch of an overlay's text: what shows from `from` to `to`, and its tags. */
|
|
@@ -185,9 +198,30 @@ function getTextTags(overlay: ResolvedOverlay, colors: OverlayColors, context: D
|
|
|
185
198
|
].join("");
|
|
186
199
|
}
|
|
187
200
|
|
|
188
|
-
/**
|
|
189
|
-
function
|
|
190
|
-
return fontSize * 0.42;
|
|
201
|
+
/** A card's own corner without a brand style: the render's `.ov-card` (0.42 em), a search bar's full pill. */
|
|
202
|
+
function getOwnCardRadius(overlay: Pick<ResolvedOverlay, "kind">, box: { height: number }, fontSize: number): number {
|
|
203
|
+
return overlay.kind === "search_bar" ? box.height / 2 : fontSize * 0.42;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* A card's drawn box on layer 3 with the overlay's entrance: one fill without a brand style, else the style's shadow,
|
|
208
|
+
* fill and border (`getDraftBoxEvents`), at the brand style's corner or the overlay's own (`getDraftCardRadius`).
|
|
209
|
+
*/
|
|
210
|
+
function getCardShapeEvents(overlay: ResolvedOverlay, box: OverlayBox, fontSize: number, colors: { background: string; accent: string }, entrance: "fade" | "slide" | "none", context: DraftContext): string[] {
|
|
211
|
+
const radius = getDraftCardRadius(overlay, box, context, getOwnCardRadius(overlay, box, fontSize));
|
|
212
|
+
if (context.style === undefined) return [getShapeEvent(overlay, getRoundedRectDrawing(box, radius), colors.background, entrance, context.scale)];
|
|
213
|
+
return getDraftBoxEvents({
|
|
214
|
+
layer: 3,
|
|
215
|
+
at: `${toAssTime(overlay.start)},${toAssTime(overlay.end)}`,
|
|
216
|
+
styleName: "OverlayShape",
|
|
217
|
+
box,
|
|
218
|
+
radius,
|
|
219
|
+
color: colors.background,
|
|
220
|
+
accent: colors.accent,
|
|
221
|
+
style: context.style,
|
|
222
|
+
scale: context.scale,
|
|
223
|
+
motion: getMotionTags(entrance, true, true, { x: 0, y: 0, dy: SLIDE_PX * context.scale }),
|
|
224
|
+
});
|
|
191
225
|
}
|
|
192
226
|
|
|
193
227
|
/**
|
|
@@ -211,15 +245,15 @@ function getSideTextEvents(overlay: Extract<ResolvedOverlay, { kind: "keyword" |
|
|
|
211
245
|
const span = { start: overlay.start, end: overlay.end };
|
|
212
246
|
const tags = `\\an${align}\\fs${fontSize}${getTextTags(overlay, colors, context, OVERLAY_FONT_ROLES[overlay.kind])}`;
|
|
213
247
|
const text = (pos: OverlayPoint, steps: TextStep[]) => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, entrance, slidePx: SLIDE_PX * context.scale });
|
|
214
|
-
const shape =
|
|
248
|
+
const shape = getCardShapeEvents(overlay, card, fontSize, colors, entrance, context);
|
|
215
249
|
if (overlay.kind === "list") {
|
|
216
250
|
// One event per point, on the render's line height (libass's own line spacing is tighter), all shown at once.
|
|
217
251
|
const step = fontSize * OVERLAY_LIST_LINE_HEIGHT;
|
|
218
252
|
const lead = (step - fontSize * OVERLAY_LINE_HEIGHT) / 2;
|
|
219
|
-
return [shape, ...getSideTextLines(overlay).flatMap((line, index) => text({ x, y: y + lead + index * step }, [{ from: span.start, to: span.end, text: toAssText(line) }]))];
|
|
253
|
+
return [...shape, ...getSideTextLines(overlay).flatMap((line, index) => text({ x, y: y + lead + index * step }, [{ from: span.start, to: span.end, text: toAssText(line) }]))];
|
|
220
254
|
}
|
|
221
255
|
// A keyword or a lower third types in only when its entrance says so.
|
|
222
|
-
return [shape, ...text({ x, y }, overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(overlay.text) }] : getTypedSteps(overlay.text, span, overlay.typing))];
|
|
256
|
+
return [...shape, ...text({ x, y }, overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(overlay.text) }] : getTypedSteps(overlay.text, span, overlay.typing))];
|
|
223
257
|
}
|
|
224
258
|
|
|
225
259
|
type CardOverlay = Extract<ResolvedOverlay, { kind: "hook_title" | "search_bar" | "place_card" | "counter" | "date_stamp" }>;
|
|
@@ -241,8 +275,7 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
241
275
|
const entrance = overlay.entrance === null || overlay.entrance === "type" ? (overlay.typing !== null ? "fade" : DEFAULT_ENTRANCES[overlay.kind]) : overlay.entrance;
|
|
242
276
|
const slidePx = SLIDE_PX * context.scale;
|
|
243
277
|
const span = { start: overlay.start, end: overlay.end };
|
|
244
|
-
const
|
|
245
|
-
const events = [getShapeEvent(overlay, getRoundedRectDrawing(box, radius), colors.background, entrance, context.scale)];
|
|
278
|
+
const events = getCardShapeEvents(overlay, box, fontSize, colors, entrance, context);
|
|
246
279
|
const padX = r0(fontSize * OVERLAY_PADDING_EM.x);
|
|
247
280
|
const padY = r0(fontSize * OVERLAY_PADDING_EM.y);
|
|
248
281
|
const centerX = box.left + box.width / 2;
|
|
@@ -333,9 +366,9 @@ export function buildDraftOverlayEvents(
|
|
|
333
366
|
overlays: readonly ResolvedOverlay[],
|
|
334
367
|
colors: OverlayColors,
|
|
335
368
|
frame: { width: number; height: number },
|
|
336
|
-
options: { fonts?: Partial<Record<OverlayFontRole, string>>; locale?: string } = {},
|
|
369
|
+
options: { fonts?: Partial<Record<OverlayFontRole, string>>; locale?: string; style?: BrandStyle } = {},
|
|
337
370
|
): string[] {
|
|
338
|
-
const context: DraftContext = { brand: colors, scale: frame.width / 1080, locale: options.locale ?? "en-US", fonts: options.fonts ?? {} };
|
|
371
|
+
const context: DraftContext = { brand: colors, scale: frame.width / 1080, locale: options.locale ?? "en-US", fonts: options.fonts ?? {}, ...(options.style === undefined ? {} : { style: options.style }) };
|
|
339
372
|
return overlays.flatMap((overlay) => {
|
|
340
373
|
if (overlay.kind === "punch_in") return [];
|
|
341
374
|
if (overlay.kind === "arrow" || overlay.kind === "highlight") return getMarkEvents(overlay, context);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { readCharacterMap } from "../og/character-map.js";
|
|
2
|
+
import { OutOfBounds, readFontTables, readInt16, readUint16 } from "../og/font-tables.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The width of a line of text as libass draws it in a footage draft, measured from the draft font's own advance
|
|
6
|
+
* widths (`hmtx` through `cmap`), so the draft can draw a rounded caption pill that fits its text (libass sizes only
|
|
7
|
+
* its square `BorderStyle 3` box itself). libass scales a font the VSFilter way: `usWinAscent + usWinDescent` (OS/2,
|
|
8
|
+
* else the `hhea` ascender and descender) is the font size, so a line is one font size tall and an advance is
|
|
9
|
+
* `advance * fontSize / (winAscent + winDescent)`. Kerning is not read: a few px on a line, inside the pill's padding.
|
|
10
|
+
*/
|
|
11
|
+
export type DraftTextMeasure = (text: string, fontSize: number) => number;
|
|
12
|
+
|
|
13
|
+
interface Metrics {
|
|
14
|
+
/** The font's units per libass font size: `usWinAscent + usWinDescent`. */
|
|
15
|
+
unitsPerSize: number;
|
|
16
|
+
advances: (glyph: number) => number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function readMetrics(font: Buffer): Metrics | null {
|
|
20
|
+
const tables = readFontTables(font);
|
|
21
|
+
if (!tables.ok) return null;
|
|
22
|
+
const hhea = tables.value.get("hhea");
|
|
23
|
+
const hmtx = tables.value.get("hmtx");
|
|
24
|
+
if (hhea === undefined || hmtx === undefined) return null;
|
|
25
|
+
const os2 = tables.value.get("OS/2");
|
|
26
|
+
const winSum = os2 === undefined ? 0 : readUint16(os2, 74) + readUint16(os2, 76);
|
|
27
|
+
const unitsPerSize = winSum > 0 ? winSum : readInt16(hhea, 4) - readInt16(hhea, 6);
|
|
28
|
+
const count = readUint16(hhea, 34);
|
|
29
|
+
if (unitsPerSize <= 0 || count === 0 || hmtx.length < count * 4) return null;
|
|
30
|
+
// Glyphs past `numberOfHMetrics` share the last advance (OpenType `hmtx`).
|
|
31
|
+
return { unitsPerSize, advances: (glyph) => readUint16(hmtx, Math.min(glyph, count - 1) * 4) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A measure of the draft font `font` (a TrueType or OpenType file), or null when its tables cannot be read; the
|
|
36
|
+
* caller then falls back to an estimate. A character the font lacks is measured as its `.notdef` glyph, as drawn.
|
|
37
|
+
*/
|
|
38
|
+
export function createDraftTextMeasure(font: Buffer): DraftTextMeasure | null {
|
|
39
|
+
try {
|
|
40
|
+
const metrics = readMetrics(font);
|
|
41
|
+
const characters = readCharacterMap(font);
|
|
42
|
+
if (metrics === null || !characters.ok) return null;
|
|
43
|
+
const map = characters.value;
|
|
44
|
+
return (text, fontSize) => {
|
|
45
|
+
let units = 0;
|
|
46
|
+
for (const character of text) units += metrics.advances(map.getGlyph(character.codePointAt(0) ?? 0));
|
|
47
|
+
return Math.ceil((units * fontSize) / metrics.unitsPerSize);
|
|
48
|
+
};
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error instanceof OutOfBounds) return null;
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Words broken into lines that fit `width` by `measure`, greedily as a browser breaks the render's pill: each line is
|
|
57
|
+
* its words, and a word wider than a line stands alone on its own.
|
|
58
|
+
*/
|
|
59
|
+
export function wrapDraftLine(words: readonly string[], width: number, fontSize: number, measure: DraftTextMeasure): string[][] {
|
|
60
|
+
const lines: string[][] = [];
|
|
61
|
+
for (const word of words) {
|
|
62
|
+
const last = lines[lines.length - 1];
|
|
63
|
+
if (last !== undefined && measure([...last, word].join(" "), fontSize) <= width) last.push(word);
|
|
64
|
+
else lines.push([word]);
|
|
65
|
+
}
|
|
66
|
+
return lines;
|
|
67
|
+
}
|
package/src/footage/draft.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { copyFileSync, existsSync, mkdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, join, resolve } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
@@ -11,6 +11,11 @@ import { getCaptionChunkLayouts, getCaptionSpans, getFootageCaptionChunks, getFo
|
|
|
11
11
|
import { getSegmentScales, getSegmentZoomEases } from "./compose.js";
|
|
12
12
|
import { toAssColor } from "./draft-color.js";
|
|
13
13
|
import { buildDraftOverlayEvents, getDraftOverlayStyles } from "./draft-overlays.js";
|
|
14
|
+
import { getCaptionCornerRadius, getCornerRadiusPx, getStylePadding, type BrandStyle } from "./brand-style.js";
|
|
15
|
+
import { getDraftBoxEvents } from "./draft-boxes.js";
|
|
16
|
+
import { createDraftTextMeasure, wrapDraftLine, type DraftTextMeasure } from "./draft-text-width.js";
|
|
17
|
+
import { CAPTION_PILL_PADDING } from "../compose/timeline.js";
|
|
18
|
+
import { estimateTextWidth } from "./overlays.js";
|
|
14
19
|
import type { OverlayColors } from "./overlay-html.js";
|
|
15
20
|
import { resolveEdlOverlays, type OverlayFontRole, type ResolvedOverlay } from "./overlays.js";
|
|
16
21
|
import { chooseFootageDraftFont } from "./draft-font.js";
|
|
@@ -138,6 +143,14 @@ export interface FootageDraftCaptionsInput {
|
|
|
138
143
|
overlayFonts?: Partial<Record<OverlayFontRole, string>>;
|
|
139
144
|
/** How a counter groups its number (BCP 47); default `en-US`. */
|
|
140
145
|
locale?: string;
|
|
146
|
+
/**
|
|
147
|
+
* The brand's style (`FootageBrand.style`): a `highlight` chunk is drawn on a rounded pill of its radius, padding,
|
|
148
|
+
* shadow and border, its lines broken by `measure`; the overlay cards take its radius, shadow and border. Absent:
|
|
149
|
+
* libass's square box, as before.
|
|
150
|
+
*/
|
|
151
|
+
style?: BrandStyle;
|
|
152
|
+
/** The width of a line in the captions' font (`createDraftTextMeasure`); absent or null: the `OVERLAY_CHAR_EM` estimate. */
|
|
153
|
+
measure?: DraftTextMeasure | null;
|
|
141
154
|
}
|
|
142
155
|
|
|
143
156
|
/** The pieces of a `highlight` chunk's span: cut wherever a word lights up or goes out (in centiseconds), with the words lit in each. */
|
|
@@ -149,35 +162,105 @@ function getHighlightPieces(chunk: { words: TimedWord[] }, span: { start: number
|
|
|
149
162
|
return cuts.slice(0, -1).map((at, index) => ({ from: at, to: cuts[index + 1] as number, lit: lights.map((light) => light.on <= at && at < light.off) }));
|
|
150
163
|
}
|
|
151
164
|
|
|
165
|
+
/** Words joined for one ASS line: a space, or `\\N` after the words a drawn pill's lines end on. */
|
|
166
|
+
function joinWords(words: readonly string[], breaks: ReadonlySet<number>): string {
|
|
167
|
+
return words.map((word, index) => (index === 0 ? word : `${breaks.has(index - 1) ? "\\N" : " "}${word}`)).join("");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** How a chunk's events are laid out: its line breaks, and whether a drawn pill stands under it (so libass draws no box). */
|
|
171
|
+
interface ChunkLayout {
|
|
172
|
+
breaks: ReadonlySet<number>;
|
|
173
|
+
hasPill: boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const BOXLESS_LAYOUT: ChunkLayout = { breaks: new Set(), hasPill: false };
|
|
177
|
+
/** The tags that hide libass's own box of a `BorderStyle 3` style, for text over a drawn pill. */
|
|
178
|
+
const NO_BOX = "{\\3a&HFF&\\4a&HFF&}";
|
|
179
|
+
|
|
152
180
|
/**
|
|
153
181
|
* A `highlight` chunk as ASS events: its span cut wherever a word lights up or goes out, each piece showing the chunk
|
|
154
182
|
* with the words lit then in `highlight` (a word stays lit for the render's 0.32 s from its start).
|
|
155
183
|
*/
|
|
156
|
-
function buildHighlightEvents(chunk: { words: TimedWord[] }, span: { start: number; end: number }, colors: { text: string; highlight: string }, styleName: string): string[] {
|
|
184
|
+
function buildHighlightEvents(chunk: { words: TimedWord[] }, span: { start: number; end: number }, colors: { text: string; highlight: string }, styleName: string, layout: ChunkLayout = BOXLESS_LAYOUT): string[] {
|
|
157
185
|
return getHighlightPieces(chunk, span).map((piece) => {
|
|
158
|
-
const
|
|
159
|
-
return `Dialogue: 0,${toAssTime(piece.from / 100)},${toAssTime(piece.to / 100)},${styleName},,0,0,0,,${
|
|
186
|
+
const words = chunk.words.map((word, wordIndex) => (piece.lit[wordIndex] === true ? `{\\1c${colors.highlight}&}${toAssText(word.text)}{\\1c${colors.text}&}` : toAssText(word.text)));
|
|
187
|
+
return `Dialogue: 0,${toAssTime(piece.from / 100)},${toAssTime(piece.to / 100)},${styleName},,0,0,0,,${layout.hasPill ? NO_BOX : ""}${joinWords(words, layout.breaks)}`;
|
|
160
188
|
});
|
|
161
189
|
}
|
|
162
190
|
|
|
163
191
|
/**
|
|
164
192
|
* A `box` highlight chunk as ASS events (issue #1199), three layers per piece of its span. libass draws a
|
|
165
193
|
* `BorderStyle 3` box per glyph, in each glyph's own `\3c` and `\3a`, so the layers share one layout: 0 is the pill
|
|
166
|
-
* (its text hidden), 1 the lit word's box (every other glyph's box transparent, grown by
|
|
167
|
-
* pill's), 2 the text alone (no box) with the lit word in its box text colour.
|
|
194
|
+
* (its text hidden; left out over a drawn pill), 1 the lit word's box (every other glyph's box transparent, grown by
|
|
195
|
+
* `boxPadding` instead of the pill's), 2 the text alone (no box) with the lit word in its box text colour.
|
|
168
196
|
*/
|
|
169
|
-
function buildHighlightBoxEvents(
|
|
197
|
+
function buildHighlightBoxEvents(
|
|
198
|
+
chunk: { words: TimedWord[] },
|
|
199
|
+
span: { start: number; end: number },
|
|
200
|
+
colors: { text: string; box: string; boxText: string },
|
|
201
|
+
boxPadding: number,
|
|
202
|
+
styleName: string,
|
|
203
|
+
layout: ChunkLayout = BOXLESS_LAYOUT,
|
|
204
|
+
): string[] {
|
|
170
205
|
return getHighlightPieces(chunk, span).flatMap((piece) => {
|
|
171
206
|
const at = `${toAssTime(piece.from / 100)},${toAssTime(piece.to / 100)},${styleName},,0,0,0,,`;
|
|
172
207
|
const shown = chunk.words.map((word) => toAssText(word.text));
|
|
173
|
-
const pill = `{\\1a&HFF&}${shown.
|
|
174
|
-
const box = `{\\1a&HFF&\\bord${boxPadding}\\3a&HFF&}${
|
|
175
|
-
|
|
208
|
+
const pill = `{\\1a&HFF&}${joinWords(shown, layout.breaks)}`;
|
|
209
|
+
const box = `{\\1a&HFF&\\bord${boxPadding}\\3a&HFF&}${joinWords(
|
|
210
|
+
shown.map((text, index) => (piece.lit[index] === true ? `{\\3c${colors.box}&\\3a&H00&}${text}{\\3a&HFF&}` : text)),
|
|
211
|
+
layout.breaks,
|
|
212
|
+
)}`;
|
|
213
|
+
const text = `{\\3a&HFF&\\4a&HFF&}${joinWords(
|
|
214
|
+
shown.map((word, index) => (piece.lit[index] === true ? `{\\1c${colors.boxText}&}${word}{\\1c${colors.text}&}` : word)),
|
|
215
|
+
layout.breaks,
|
|
216
|
+
)}`;
|
|
176
217
|
const isLit = piece.lit.some((lit) => lit);
|
|
177
|
-
return [`Dialogue: 0,${at}${pill}
|
|
218
|
+
return [...(layout.hasPill ? [] : [`Dialogue: 0,${at}${pill}`]), ...(isLit ? [`Dialogue: 1,${at}${box}`] : []), `Dialogue: 2,${at}${text}`];
|
|
178
219
|
});
|
|
179
220
|
}
|
|
180
221
|
|
|
222
|
+
/** The pill of a chunk drawn in the brand's style: its lines (broken by width) and its shadow, box and border events. */
|
|
223
|
+
interface DrawnPill {
|
|
224
|
+
breaks: Set<number>;
|
|
225
|
+
events: string[];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface DrawnPillInput {
|
|
229
|
+
words: readonly string[];
|
|
230
|
+
span: { start: number; end: number };
|
|
231
|
+
place: CaptionLayout;
|
|
232
|
+
frame: Frame;
|
|
233
|
+
style: BrandStyle;
|
|
234
|
+
measure: DraftTextMeasure;
|
|
235
|
+
colors: { background: string; accent: string };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* A chunk's rounded pill (`style`): its words broken greedily into lines that fit the caption box less the padding,
|
|
240
|
+
* the pill as wide as the widest line and as tall as the lines (libass draws a line one font size tall) plus the
|
|
241
|
+
* padding, centred in the box and hung from its foot (or its top) as the text is.
|
|
242
|
+
*/
|
|
243
|
+
function getDrawnPill(input: DrawnPillInput): DrawnPill {
|
|
244
|
+
const { place, frame, style, measure } = input;
|
|
245
|
+
const scale = frame.width / 1080;
|
|
246
|
+
const pad = getStylePadding(CAPTION_PILL_PADDING, style.padding);
|
|
247
|
+
const areaWidth = frame.width - place.left - place.right;
|
|
248
|
+
const lines = wrapDraftLine(input.words, areaWidth - 2 * pad.x, place.fontSize, measure);
|
|
249
|
+
const breaks = new Set<number>();
|
|
250
|
+
let counted = 0;
|
|
251
|
+
for (const line of lines.slice(0, -1)) {
|
|
252
|
+
counted += line.length;
|
|
253
|
+
breaks.add(counted - 1);
|
|
254
|
+
}
|
|
255
|
+
const width = Math.min(areaWidth, Math.max(...lines.map((line) => measure(line.join(" "), place.fontSize))) + 2 * pad.x);
|
|
256
|
+
const height = lines.length * place.fontSize + 2 * pad.y;
|
|
257
|
+
const textTop = place.bottom === undefined ? place.top : frame.height - place.bottom - lines.length * place.fontSize;
|
|
258
|
+
const box = { left: place.left + (areaWidth - width) / 2, top: textTop - pad.y, width, height };
|
|
259
|
+
const at = `${toAssTime(input.span.start)},${toAssTime(input.span.end)}`;
|
|
260
|
+
const radius = getCornerRadiusPx(getCaptionCornerRadius(style), height, scale);
|
|
261
|
+
return { breaks, events: getDraftBoxEvents({ layer: 0, at, styleName: "CaptionShape", box, radius, color: input.colors.background, accent: input.colors.accent, style, scale }) };
|
|
262
|
+
}
|
|
263
|
+
|
|
181
264
|
/** The highlight look the draft draws: `text` for a `phrase` film; a `box` film without its colours is an input error. */
|
|
182
265
|
function getDraftHighlightLook(film: Pick<FootageFilm, "captionStyle" | "captionHighlightStyle">, colors: FootageDraftCaptionColors): CaptionHighlightLook {
|
|
183
266
|
if (film.captionStyle !== "highlight") return { style: "text", color: colors.captionHighlight };
|
|
@@ -246,7 +329,8 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
246
329
|
// A chunk in a segment's own box gets a style of that box (Caption2, Caption3, ...); the film's box stays `Caption`.
|
|
247
330
|
const styles = [toStyle("Caption", caption)];
|
|
248
331
|
const moved: CaptionLayout[] = [];
|
|
249
|
-
const
|
|
332
|
+
const places = getCaptionChunkLayouts(chunks, input.edl, caption);
|
|
333
|
+
const styleNames = places.map((place) => {
|
|
250
334
|
if (isSameCaptionPlace(place, caption)) return "Caption";
|
|
251
335
|
let index = moved.findIndex((other) => isSameCaptionPlace(other, place));
|
|
252
336
|
if (index === -1) {
|
|
@@ -259,11 +343,19 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
259
343
|
const lit = getDraftHighlightLook(input.film, colors);
|
|
260
344
|
const boxColors = lit.style === "box" ? { text: highlight.text, box: toAssColor(lit.box).replace(/^&H../, "&H"), boxText: toAssColor(lit.text).replace(/^&H../, "&H") } : null;
|
|
261
345
|
const boxPadding = Math.max(1, Math.round(caption.fontSize * CAPTION_HIGHLIGHT_BOX_PADDING_EM));
|
|
346
|
+
// With the brand's style a `highlight` chunk stands on a drawn rounded pill (its lines broken here), not libass's box.
|
|
347
|
+
const style = isHighlight ? input.style : undefined;
|
|
348
|
+
const measure = input.measure ?? ((line: string, size: number) => estimateTextWidth(line, size));
|
|
349
|
+
const pillColors = { background: colors.captionBackground, accent: lit.style === "box" ? lit.box : colors.captionHighlight };
|
|
262
350
|
const events = chunks.flatMap((chunk, index) => {
|
|
263
351
|
const span = spans[index] as { start: number; end: number };
|
|
264
352
|
const styleName = styleNames[index] ?? "Caption";
|
|
265
|
-
|
|
266
|
-
|
|
353
|
+
const pill =
|
|
354
|
+
style === undefined ? null : getDrawnPill({ words: chunk.words.map((word) => word.text.replace(/\u00a0/g, " ")), span, place: places[index] ?? caption, frame, style, measure, colors: pillColors });
|
|
355
|
+
const layout: ChunkLayout = pill === null ? BOXLESS_LAYOUT : { breaks: pill.breaks, hasPill: true };
|
|
356
|
+
const drawn = pill?.events ?? [];
|
|
357
|
+
if (isHighlight && boxColors !== null) return [...drawn, ...buildHighlightBoxEvents(chunk, span, boxColors, boxPadding, styleName, layout)];
|
|
358
|
+
if (isHighlight) return [...drawn, ...buildHighlightEvents(chunk, span, highlight, styleName, layout)];
|
|
267
359
|
const line = toAssText(chunk.words.map((word) => word.text).join(" "));
|
|
268
360
|
return [`Dialogue: 0,${toAssTime(span.start)},${toAssTime(span.end)},${styleName},,0,0,0,,${line}`];
|
|
269
361
|
});
|
|
@@ -277,7 +369,8 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
277
369
|
"",
|
|
278
370
|
"[V4+ Styles]",
|
|
279
371
|
"Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding",
|
|
280
|
-
...styles.map((
|
|
372
|
+
...styles.map((line) => `Style: ${line}`),
|
|
373
|
+
...(style === undefined || chunks.length === 0 ? [] : [`Style: CaptionShape,${family},${String(caption.fontSize)},&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1`]),
|
|
281
374
|
...(overlays.length === 0 ? [] : getDraftOverlayStyles(family, input.overlayColors ?? FOOTAGE_DRAFT_OVERLAY_COLORS)),
|
|
282
375
|
"",
|
|
283
376
|
"[Events]",
|
|
@@ -286,6 +379,7 @@ export function buildFootageDraftCaptions(input: FootageDraftCaptionsInput): str
|
|
|
286
379
|
...buildDraftOverlayEvents(overlays, input.overlayColors ?? FOOTAGE_DRAFT_OVERLAY_COLORS, input.frame, {
|
|
287
380
|
...(input.overlayFonts === undefined ? {} : { fonts: input.overlayFonts }),
|
|
288
381
|
...(input.locale === undefined ? {} : { locale: input.locale }),
|
|
382
|
+
...(input.style === undefined ? {} : { style: input.style }),
|
|
289
383
|
}),
|
|
290
384
|
"",
|
|
291
385
|
].join("\n");
|
|
@@ -526,7 +620,7 @@ export interface RenderFootageDraftOptions extends Pick<FootageRunOptions, "buil
|
|
|
526
620
|
* OpenType file; DejaVu Sans when it has none) and its caption colours. Without it, DejaVu Sans and
|
|
527
621
|
* `FOOTAGE_DRAFT_CAPTION_COLORS`.
|
|
528
622
|
*/
|
|
529
|
-
brand?: { colors: FootageDraftCaptionColors & Partial<OverlayColors>; fonts: Pick<FootageBrand["fonts"], "body"> & Partial<Pick<FootageBrand["fonts"], "heading" | "interface">>; locale?: string };
|
|
623
|
+
brand?: { colors: FootageDraftCaptionColors & Partial<OverlayColors>; fonts: Pick<FootageBrand["fonts"], "body"> & Partial<Pick<FootageBrand["fonts"], "heading" | "interface">>; locale?: string; style?: BrandStyle };
|
|
530
624
|
/**
|
|
531
625
|
* ffmpeg's threads for the draft's decoders, filter graph and encoder (`buildFootageDraftArgs`); by default ffmpeg's
|
|
532
626
|
* own choice, which follows the host's cores. Set it from a CPU-limited container's quota.
|
|
@@ -658,6 +752,7 @@ async function runRenderFootageDraft(
|
|
|
658
752
|
...(overlays.length === 0 ? {} : { overlays, overlayColors }),
|
|
659
753
|
...(Object.keys(roleFonts).length === 0 ? {} : { overlayFonts: Object.fromEntries(Object.entries(roleFonts).map(([role, chosen]) => [role, chosen.family])) }),
|
|
660
754
|
...(options.brand?.locale === undefined ? {} : { locale: options.brand.locale }),
|
|
755
|
+
...(options.brand?.style === undefined ? {} : { style: options.brand.style, measure: createDraftTextMeasure(readFileSync(font.file)) }),
|
|
661
756
|
});
|
|
662
757
|
if (captions !== null) {
|
|
663
758
|
writeFileSync(join(draftDir, "captions.ass"), captions);
|
package/src/footage/edl.ts
CHANGED
|
@@ -109,7 +109,7 @@ export const edlSchema = z
|
|
|
109
109
|
.max(40)
|
|
110
110
|
.optional()
|
|
111
111
|
.describe(
|
|
112
|
-
"Small graphics and emphasis zooms placed on a word of the transcript (at_word) or a film second (at), one at a time, each inside one segment: punch_in, keyword, lower_third, list, arrow, highlight, search_bar, place_card, counter, date_stamp; and a hook_title at the top, which may stay across cuts beside the others. Without it, none.",
|
|
112
|
+
"Small graphics and emphasis zooms placed on a word of the transcript (at_word) or a film second (at), one at a time, each inside one shot (one segment, or segments of one clip joined by plain cuts, with no Ken Burns zoom and the same caption box; a punch_in inside one segment): punch_in, keyword, lower_third, list, arrow, highlight, search_bar, place_card, counter, date_stamp; and a hook_title at the top, which may stay across cuts beside the others. Without it, none.",
|
|
113
113
|
),
|
|
114
114
|
})
|
|
115
115
|
.describe("The edit decision list of a footage film (edl.json).");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BrandColors } from "../config/colors.js";
|
|
2
2
|
import { escapeHtml } from "../compose/html.js";
|
|
3
|
+
import { getCornerRadiusCss, getStyleBorderCss, getStyleShadowCss, type BrandStyle } from "./brand-style.js";
|
|
3
4
|
import type { OverlayEntrance } from "./overlay-schema.js";
|
|
4
5
|
import { OVERLAY_LINE_HEIGHT, OVERLAY_LIST_LINE_HEIGHT, OVERLAY_PADDING_EM, OVERLAY_TITLE_LINE_HEIGHT, SEARCH_BAR_PADDING_EM, formatOverlayNumber, type ResolvedOverlay } from "./overlays.js";
|
|
5
6
|
|
|
@@ -54,7 +55,7 @@ export function getTypingTimes(start: number, text: string, speed: number): numb
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
/** The CSS every overlay kind shares, written once when the film has any drawn overlay. */
|
|
57
|
-
function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interface: string }): string[] {
|
|
58
|
+
function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interface: string }, style?: BrandStyle, scale = 1): string[] {
|
|
58
59
|
return [
|
|
59
60
|
`.ov{position:absolute;display:flex;pointer-events:none}`,
|
|
60
61
|
`.ov.right{justify-content:flex-end}`,
|
|
@@ -81,6 +82,14 @@ function getOverlayCss(colors: OverlayColors, fonts: { heading: string; interfac
|
|
|
81
82
|
`.ov-date:not(.right) .ov-card{align-items:flex-start}`,
|
|
82
83
|
`.ov-date .ov-sub{font-weight:600;margin-top:0}`,
|
|
83
84
|
`.ty .ch{opacity:0}`,
|
|
85
|
+
// The brand's style (after the kinds' own rules, so it wins over them; the search bar stays a pill).
|
|
86
|
+
...(style === undefined
|
|
87
|
+
? []
|
|
88
|
+
: [
|
|
89
|
+
`.ov-card{border-radius:${getCornerRadiusCss(style.cornerRadius, scale)};box-shadow:${getStyleShadowCss(style, scale)};border:${getStyleBorderCss(style, colors.accent, scale)}}`,
|
|
90
|
+
`.ov-search{border-radius:999px}`,
|
|
91
|
+
...(style.border === "none" ? [] : [`.ov-keyword .ov-card{border-bottom:.12em solid ${colors.accent}}`]),
|
|
92
|
+
]),
|
|
84
93
|
];
|
|
85
94
|
}
|
|
86
95
|
|
|
@@ -119,10 +128,11 @@ function toTypedHtml(text: string): string {
|
|
|
119
128
|
}
|
|
120
129
|
|
|
121
130
|
/** The inline colours of a card that has its own. */
|
|
122
|
-
function getCardStyle(overlay: ResolvedOverlay, colors: OverlayColors): string {
|
|
131
|
+
function getCardStyle(overlay: ResolvedOverlay, colors: OverlayColors, scale = 1): string {
|
|
123
132
|
if (overlay.kind === "punch_in") return "";
|
|
124
133
|
const own = overlay.colors;
|
|
125
134
|
const parts = [own.card === undefined ? "" : `background:${colors.background}`, own.text === undefined ? "" : `color:${colors.foreground}`];
|
|
135
|
+
if (overlay.cornerRadius !== undefined && overlay.cornerRadius !== null) parts.push(`border-radius:${getCornerRadiusCss(overlay.cornerRadius, scale)}`);
|
|
126
136
|
if (overlay.kind === "keyword" && own.accent !== undefined) parts.push(`border-bottom-color:${colors.accent}`);
|
|
127
137
|
const style = parts.filter((part) => part !== "").join(";");
|
|
128
138
|
return style === "" ? "" : ` style="${style}"`;
|
|
@@ -156,7 +166,7 @@ interface MarkupContext {
|
|
|
156
166
|
function addSideText(overlay: Extract<ResolvedOverlay, { kind: "keyword" | "lower_third" | "list" }>, id: string, context: MarkupContext, out: OverlayMarkup): void {
|
|
157
167
|
const { box, fontSize, side } = overlay;
|
|
158
168
|
const colors = getOverlayColors(overlay, context.colors);
|
|
159
|
-
const cardStyle = getCardStyle(overlay, colors);
|
|
169
|
+
const cardStyle = getCardStyle(overlay, colors, context.scale);
|
|
160
170
|
const dotStyle = overlay.colors.accent === undefined ? "" : ` style="background:${colors.accent}"`;
|
|
161
171
|
const isTyped = overlay.typing !== null && overlay.kind !== "list";
|
|
162
172
|
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"}`;
|
|
@@ -217,7 +227,7 @@ function addCard(overlay: CardOverlay, id: string, context: MarkupContext, out:
|
|
|
217
227
|
const { box, fontSize } = overlay;
|
|
218
228
|
const { classes, body, typed } = getCardBody(overlay, id, colors, context.locale);
|
|
219
229
|
const style = `left:${box.left}px;top:${box.top}px;width:${box.width}px;height:${box.height}px;font-size:${fontSize}px;align-items:flex-start`;
|
|
220
|
-
out.html.push(clipDiv(overlay, id, `ov ${classes}${overlay.typing === null ? "" : " ty"}`, style, body.replace("__STYLE__", getCardStyle(overlay, colors))));
|
|
230
|
+
out.html.push(clipDiv(overlay, id, `ov ${classes}${overlay.typing === null ? "" : " ty"}`, style, body.replace("__STYLE__", getCardStyle(overlay, colors, context.scale))));
|
|
221
231
|
const entrance = overlay.entrance ?? (overlay.typing !== null ? "type" : DEFAULT_ENTRANCES[overlay.kind]);
|
|
222
232
|
out.tweens.push(...getEntranceTweens(`#${id} .ov-card`, entrance, overlay.start));
|
|
223
233
|
out.tweens.push(...getTypingTweens(id, overlay, typed));
|
|
@@ -291,12 +301,12 @@ function addMark(overlay: Extract<ResolvedOverlay, { kind: "arrow" | "highlight"
|
|
|
291
301
|
*/
|
|
292
302
|
export function getOverlayMarkup(
|
|
293
303
|
overlays: readonly ResolvedOverlay[],
|
|
294
|
-
input: { colors: OverlayColors; headingFont: string; interfaceFont?: string; locale?: string; frame: { width: number; height: number } },
|
|
304
|
+
input: { colors: OverlayColors; headingFont: string; interfaceFont?: string; locale?: string; frame: { width: number; height: number }; style?: BrandStyle },
|
|
295
305
|
): OverlayMarkup {
|
|
296
306
|
const drawn = overlays.filter((overlay): overlay is Exclude<ResolvedOverlay, { kind: "punch_in" }> => overlay.kind !== "punch_in");
|
|
297
307
|
if (drawn.length === 0) return { html: [], css: [], tweens: [] };
|
|
298
308
|
const context: MarkupContext = { colors: input.colors, scale: input.frame.width / 1080, locale: input.locale ?? "en-US", frame: input.frame };
|
|
299
|
-
const out: OverlayMarkup = { html: [], css: getOverlayCss(input.colors, { heading: input.headingFont, interface: input.interfaceFont ?? "inherit" }), tweens: [] };
|
|
309
|
+
const out: OverlayMarkup = { html: [], css: getOverlayCss(input.colors, { heading: input.headingFont, interface: input.interfaceFont ?? "inherit" }, input.style, context.scale), tweens: [] };
|
|
300
310
|
for (const overlay of drawn) {
|
|
301
311
|
const id = `ov${overlay.index}`;
|
|
302
312
|
if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") addSideText(overlay, id, context, out);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
+
import { CORNER_RADII, type CornerRadius } from "./brand-style.js";
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* An EDL's overlays (issue #1200): small graphics and an emphasis zoom placed on a word of the transcript or at a film
|
|
5
7
|
* second, drawn by the render and the draft alike from a fixed catalogue. Their shape lives here so the EDL schema can
|
|
@@ -105,6 +107,8 @@ export interface EdlOverlayStyle {
|
|
|
105
107
|
/** Characters per second of the `type` entrance and the search bar's query. */
|
|
106
108
|
typing_speed?: number;
|
|
107
109
|
colors?: EdlOverlayColors;
|
|
110
|
+
/** Its card's corner in place of the brand style's (`BrandStyle.cornerRadius`); not on a punch_in, arrow or highlight. */
|
|
111
|
+
corner_radius?: CornerRadius;
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
export interface EdlOverlay {
|
|
@@ -255,6 +259,7 @@ function checkOverlayStyle(overlay: EdlOverlay, issue: (path: string[], message:
|
|
|
255
259
|
issue(["style", "entrance"], entrances.length === 0 ? `${article(kind)} has no entrance; leave it out` : `${article(kind)} enters by ${entrances.join(", ")}`);
|
|
256
260
|
}
|
|
257
261
|
if (style.typing_speed !== undefined && !isTypedOverlay(overlay)) issue(["style", "typing_speed"], "only a typed entrance or a search bar has a typing speed");
|
|
262
|
+
if (style.corner_radius !== undefined && (kind === "punch_in" || kind === "arrow" || kind === "highlight")) issue(["style", "corner_radius"], `${article(kind)} draws no card; leave corner_radius out`);
|
|
258
263
|
if (style.colors === undefined) return;
|
|
259
264
|
if (kind === "punch_in") issue(["style", "colors"], "a punch_in draws nothing to colour; leave colors out");
|
|
260
265
|
if ((kind === "arrow" || kind === "highlight") && (style.colors.card !== undefined || style.colors.text !== undefined)) {
|
|
@@ -340,6 +345,10 @@ export const overlaySchema = z
|
|
|
340
345
|
})
|
|
341
346
|
.optional()
|
|
342
347
|
.describe("The overlay's own colours in place of the brand's."),
|
|
348
|
+
corner_radius: z
|
|
349
|
+
.enum(CORNER_RADII)
|
|
350
|
+
.optional()
|
|
351
|
+
.describe("The card's corner: none, s, m, l or pill; the brand style's without it (no punch_in, arrow or highlight)."),
|
|
343
352
|
})
|
|
344
353
|
.optional()
|
|
345
354
|
.describe("The overlay's look: size, side, position, entrance, typing speed and colours; fonts are the brand's."),
|
package/src/footage/overlays.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "./overlay-schema.js";
|
|
18
18
|
import { getSegmentZoomEases } from "./compose.js";
|
|
19
19
|
import { normalizeWord } from "./words.js";
|
|
20
|
+
import type { CornerRadius } from "./brand-style.js";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* An EDL's overlays resolved for the render and the draft (issue #1200): each one's film time (from its word through
|
|
@@ -114,6 +115,8 @@ export interface OverlayLook {
|
|
|
114
115
|
typing: number | null;
|
|
115
116
|
/** Its own colours in place of the brand's (empty: the brand's). */
|
|
116
117
|
colors: EdlOverlayColors;
|
|
118
|
+
/** Its card's own corner (`style.corner_radius`), else null: the brand style's, or the kind's own without one. */
|
|
119
|
+
cornerRadius?: CornerRadius | null;
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
type Drawn = OverlayBase & OverlayLook;
|
|
@@ -252,9 +255,41 @@ export function getDrawnOverlayCard(overlay: ResolvedOverlay): OverlayBox | null
|
|
|
252
255
|
return { left: side === "right" ? box.left + box.width - width : box.left, top: box.top, width, height: box.height };
|
|
253
256
|
}
|
|
254
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Why the cut that starts segment `index` ends a shot, or null for a jump cut inside one shot (RV-136 of an adopting
|
|
260
|
+
* app): the segment plays the same clip as the one before, starts on a plain `cut`, neither has a Ken Burns zoom, and
|
|
261
|
+
* both keep the same caption box. Only across such a cut does the frame stay the same, so an overlay may run on.
|
|
262
|
+
*/
|
|
263
|
+
export function findShotBreak(edl: Pick<Edl, "segments">, index: number): string | null {
|
|
264
|
+
const segment = edl.segments[index];
|
|
265
|
+
const previous = edl.segments[index - 1];
|
|
266
|
+
if (segment === undefined || previous === undefined) return "the cut's end";
|
|
267
|
+
if (segment.clip !== previous.clip) return `segment "${segment.id}" plays another clip`;
|
|
268
|
+
if (segment.transition !== "cut") return `segment "${segment.id}" starts on a ${segment.transition}, not a plain cut`;
|
|
269
|
+
if (segment.motion === "kenburns" || previous.motion === "kenburns") return `a Ken Burns zoom at segment "${segment.id}"`;
|
|
270
|
+
if (segment.caption?.bottom !== previous.caption?.bottom || segment.caption?.top !== previous.caption?.top) return `segment "${segment.id}" moves the captions`;
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The film seconds an overlay starting in `segment` may reach: on across every jump cut inside one shot
|
|
276
|
+
* (`findShotBreak`) until `end`, then the first cut that breaks the shot with its reason. A punch-in zooms its own
|
|
277
|
+
* segment's picture, so it never crosses a cut.
|
|
278
|
+
*/
|
|
279
|
+
function findShotSpan(edl: Edl, starts: readonly number[], at: { segment: number; end: number; isPunchIn: boolean }): { last: number; end: number; reason: string } {
|
|
280
|
+
const getEnd = (index: number): number => r3((starts[index] as number) + ((edl.segments[index]?.end ?? 0) - (edl.segments[index]?.start ?? 0)));
|
|
281
|
+
let last = at.segment;
|
|
282
|
+
for (;;) {
|
|
283
|
+
const reason = at.isPunchIn ? "a punch-in stays in its segment" : findShotBreak(edl, last + 1);
|
|
284
|
+
if (reason !== null || at.end <= getEnd(last) + 0.01) return { last, end: getEnd(last), reason: reason ?? "" };
|
|
285
|
+
last += 1;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
255
289
|
/**
|
|
256
290
|
* The overlays of an EDL resolved to film time and placed, or every reason one cannot be drawn: its word is not said,
|
|
257
|
-
* it is too short or runs past the cut or
|
|
291
|
+
* it is too short or runs past the cut or across a cut that changes the shot (`findShotBreak`: another clip, a
|
|
292
|
+
* transition, a Ken Burns zoom, moved captions; a `hook_title` may stay across any cut, a `punch_in` across none), two overlap,
|
|
258
293
|
* two start closer than `overlayMinSpacing`, a text overlay does not fit between the safe zone and the captions, an
|
|
259
294
|
* anchor leaves the safe zone or sits on the captions, or a `punch_in` falls on a `kenburns` segment or inside a zoom
|
|
260
295
|
* cut's ease. A `hook_title` lives in the top band: it does not count against one overlay at a time or the spacing,
|
|
@@ -285,11 +320,14 @@ export function resolveEdlOverlays(input: ResolveOverlaysInput): ResolvedOverlay
|
|
|
285
320
|
}
|
|
286
321
|
const segment = findSegmentAt(edl, start);
|
|
287
322
|
const segmentStart = starts[segment] as number;
|
|
288
|
-
const segmentEnd = r3(segmentStart + ((edl.segments[segment]?.end ?? 0) - (edl.segments[segment]?.start ?? 0)));
|
|
289
323
|
const segmentId = edl.segments[segment]?.id ?? "";
|
|
290
|
-
if (overlay.kind !== "hook_title"
|
|
291
|
-
|
|
292
|
-
|
|
324
|
+
if (overlay.kind !== "hook_title") {
|
|
325
|
+
const shot = findShotSpan(edl, starts, { segment, end, isPunchIn: overlay.kind === "punch_in" });
|
|
326
|
+
if (end > shot.end + 0.01) {
|
|
327
|
+
const inside = shot.last === segment ? `segment "${segmentId}"` : `segments "${segmentId}" to "${edl.segments[shot.last]?.id ?? ""}"`;
|
|
328
|
+
problems.push(`${at}: runs ${r1(end - shot.end)} s past the cut at ${shot.end} s (${shot.reason}); keep it inside ${inside} (${segmentStart}-${shot.end} s) or shorten it`);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
293
331
|
}
|
|
294
332
|
const base = { index, start, end, segment };
|
|
295
333
|
const placed = placeOverlay(overlay, base, { zone, frame, band: getCaptionBand(input, segment) });
|
|
@@ -388,6 +426,7 @@ function getLook(overlay: EdlOverlay): OverlayLook {
|
|
|
388
426
|
entrance: overlay.style?.entrance ?? null,
|
|
389
427
|
typing: isTypedOverlay(overlay) ? (overlay.style?.typing_speed ?? DEFAULT_OVERLAY_TYPING_SPEED) : null,
|
|
390
428
|
colors: { ...overlay.style?.colors },
|
|
429
|
+
cornerRadius: overlay.style?.corner_radius ?? null,
|
|
391
430
|
};
|
|
392
431
|
}
|
|
393
432
|
|
package/src/footage/pipeline.ts
CHANGED
|
@@ -80,6 +80,7 @@ import {
|
|
|
80
80
|
} from "./publish.js";
|
|
81
81
|
import { describePaidSteps, toPaidAudio, type FootageCharge, type FootageProgress, type FootageProviders, type FootageStage, type PaidAudio, type PaidStep } from "./providers.js";
|
|
82
82
|
import { buildAudioArgs, buildCutPreviewArgs, buildLastFrameArgs, buildMusicArgs, buildSpeechArgs, getSpeechCutOptions } from "./render.js";
|
|
83
|
+
import type { BrandStyle } from "./brand-style.js";
|
|
83
84
|
|
|
84
85
|
export { getEdlPath } from "./paid.js";
|
|
85
86
|
|
|
@@ -121,6 +122,11 @@ export interface FootageBrand {
|
|
|
121
122
|
*/
|
|
122
123
|
fonts: { heading: BrandFont | null; body: BrandFont | null; interface?: BrandFont | null };
|
|
123
124
|
logo: string | null;
|
|
125
|
+
/**
|
|
126
|
+
* One look for every box (`brand-style.ts`): the caption pill's and each overlay card's corner radius, the pill's
|
|
127
|
+
* padding, a soft shadow and a thin accent border, in the draft and the render. Absent: each box as before.
|
|
128
|
+
*/
|
|
129
|
+
style?: BrandStyle;
|
|
124
130
|
}
|
|
125
131
|
|
|
126
132
|
export interface FootageRunOptions {
|
|
@@ -882,6 +888,7 @@ async function runRenderFootage(
|
|
|
882
888
|
brandName: options.brand.name,
|
|
883
889
|
locale: options.brand.locale,
|
|
884
890
|
...(overlays.overlays.length === 0 ? {} : { overlays: overlays.overlays }),
|
|
891
|
+
...(options.brand.style === undefined ? {} : { style: options.brand.style }),
|
|
885
892
|
});
|
|
886
893
|
writeFileSync(join(buildDir, "index.html"), html);
|
|
887
894
|
mkdirSync(dirname(options.output), { recursive: true });
|