@softure-ai/marketing-kit 0.33.0 → 0.35.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 +53 -0
- package/NOTICE +6 -0
- package/README.md +39 -0
- package/dist/config/schema.d.ts +8 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -1
- package/dist/config/schema.js.map +1 -1
- package/dist/footage/camera.d.ts +67 -0
- package/dist/footage/camera.d.ts.map +1 -0
- package/dist/footage/camera.js +89 -0
- package/dist/footage/camera.js.map +1 -0
- package/dist/footage/compose.d.ts +7 -1
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +45 -10
- package/dist/footage/compose.js.map +1 -1
- package/dist/footage/draft-overlays.d.ts +6 -0
- package/dist/footage/draft-overlays.d.ts.map +1 -1
- package/dist/footage/draft-overlays.js +194 -9
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/draft.d.ts +21 -2
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +70 -31
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/drawn-transitions.d.ts +63 -0
- package/dist/footage/drawn-transitions.d.ts.map +1 -0
- package/dist/footage/drawn-transitions.js +177 -0
- package/dist/footage/drawn-transitions.js.map +1 -0
- package/dist/footage/edl.d.ts +39 -0
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +48 -1
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/film.d.ts +4 -3
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.js +3 -2
- package/dist/footage/film.js.map +1 -1
- package/dist/footage/hand-font.d.ts +16 -0
- package/dist/footage/hand-font.d.ts.map +1 -0
- package/dist/footage/hand-font.js +43 -0
- package/dist/footage/hand-font.js.map +1 -0
- package/dist/footage/overlay-html.d.ts +1 -0
- package/dist/footage/overlay-html.d.ts.map +1 -1
- package/dist/footage/overlay-html.js +138 -9
- package/dist/footage/overlay-html.js.map +1 -1
- package/dist/footage/overlay-motion.d.ts +35 -0
- package/dist/footage/overlay-motion.d.ts.map +1 -1
- package/dist/footage/overlay-motion.js +45 -0
- package/dist/footage/overlay-motion.js.map +1 -1
- package/dist/footage/overlay-schema.d.ts +57 -8
- package/dist/footage/overlay-schema.d.ts.map +1 -1
- package/dist/footage/overlay-schema.js +87 -21
- package/dist/footage/overlay-schema.js.map +1 -1
- package/dist/footage/overlays.d.ts +127 -1
- package/dist/footage/overlays.d.ts.map +1 -1
- package/dist/footage/overlays.js +277 -12
- package/dist/footage/overlays.js.map +1 -1
- package/dist/footage/picture.d.ts +8 -2
- package/dist/footage/picture.d.ts.map +1 -1
- package/dist/footage/picture.js +41 -15
- package/dist/footage/picture.js.map +1 -1
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +7 -1
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/footage/tools.d.ts +1 -1
- package/dist/footage/tools.d.ts.map +1 -1
- package/dist/footage/tools.js +1 -1
- package/dist/footage/tools.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/fonts/Caveat-SemiBold-Latin.ttf +0 -0
- package/fonts/LICENSE-Caveat.txt +93 -0
- package/fonts/README.md +14 -0
- package/package.json +1 -1
- package/schema/edl.schema.json +108 -13
- package/schema/marketing.schema.json +10 -2
- package/src/config/schema.ts +1 -1
- package/src/footage/camera.ts +129 -0
- package/src/footage/compose.ts +42 -11
- package/src/footage/draft-overlays.ts +223 -7
- package/src/footage/draft.ts +83 -32
- package/src/footage/drawn-transitions.ts +214 -0
- package/src/footage/edl.ts +45 -1
- package/src/footage/film.ts +3 -2
- package/src/footage/hand-font.ts +47 -0
- package/src/footage/overlay-html.ts +145 -8
- package/src/footage/overlay-motion.ts +49 -0
- package/src/footage/overlay-schema.ts +100 -23
- package/src/footage/overlays.ts +332 -15
- package/src/footage/picture.ts +48 -17
- package/src/footage/pipeline.ts +7 -1
- package/src/footage/tools.ts +1 -1
- package/src/index.ts +56 -0
package/src/footage/overlays.ts
CHANGED
|
@@ -15,14 +15,17 @@ import {
|
|
|
15
15
|
type OverlayExit,
|
|
16
16
|
type OverlayKind,
|
|
17
17
|
type OverlayListLayout,
|
|
18
|
+
type OverlayNoteStyle,
|
|
18
19
|
type OverlayPosition,
|
|
19
20
|
type OverlaySide,
|
|
20
21
|
type OverlaySize,
|
|
21
22
|
} from "./overlay-schema.js";
|
|
23
|
+
import { isCameraMoving, isSameCamera } from "./camera.js";
|
|
22
24
|
import { getSegmentZoomEases } from "./compose.js";
|
|
23
25
|
import { normalizeWord } from "./words.js";
|
|
24
|
-
import { getListItemStarts } from "./overlay-motion.js";
|
|
26
|
+
import { NOTE_FIRST_WORD_LEAD, NOTE_TICK_DELAY, getListItemStarts } from "./overlay-motion.js";
|
|
25
27
|
import { STYLE_PADDING_SCALES, type BrandStyle, type CornerRadius } from "./brand-style.js";
|
|
28
|
+
import { measureHandText } from "./hand-font.js";
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* An EDL's overlays resolved for the render and the draft (issue #1200): each one's film time (from its word through
|
|
@@ -49,7 +52,29 @@ export const OVERLAY_FONT_SIZES: Record<TextOverlayKind, Record<OverlaySize, num
|
|
|
49
52
|
place_card: { s: 70, m: 92, l: 118 },
|
|
50
53
|
counter: { s: 84, m: 108, l: 132 },
|
|
51
54
|
date_stamp: { s: 30, m: 36, l: 44 },
|
|
55
|
+
note: { s: 46, m: 56, l: 68 },
|
|
56
|
+
end_word: { s: 120, m: 150, l: 180 },
|
|
52
57
|
};
|
|
58
|
+
/** A note strip's type size (its capitals), in px of a 1080 px wide frame; a note card's is `OVERLAY_FONT_SIZES.note`. */
|
|
59
|
+
export const NOTE_STRIP_FONT_SIZES: Record<OverlaySize, number> = { s: 38, m: 46, l: 54 };
|
|
60
|
+
/** A note's line height, and its padding round the text, in font sizes. */
|
|
61
|
+
export const NOTE_LINE_HEIGHT = 1.2;
|
|
62
|
+
export const NOTE_PADDING_EM = { x: 0.55, y: 0.4 } as const;
|
|
63
|
+
/** How deep a note's torn edge cuts into the paper, in font sizes (the card's foot, the strip's top). */
|
|
64
|
+
export const NOTE_TEAR_EM = 0.22;
|
|
65
|
+
/** The points along a note's torn edge. */
|
|
66
|
+
export const NOTE_TEAR_POINTS = 14;
|
|
67
|
+
/** A note's tick: its size and its gap after the last line, in font sizes. */
|
|
68
|
+
export const NOTE_TICK_EM = { size: 0.9, gap: 0.3 } as const;
|
|
69
|
+
/** The most words a line of a note card takes, and the most lines a note takes. */
|
|
70
|
+
export const MAX_NOTE_LINE_WORDS = 6;
|
|
71
|
+
export const MAX_NOTE_LINES = 4;
|
|
72
|
+
/** The share of the safe zone's width a note may take: a small card beside the subject, not a banner. */
|
|
73
|
+
export const NOTE_WIDTH_SHARE = 0.62;
|
|
74
|
+
/** A note's tilt in degrees, counter-clockwise positive as ASS turns (a note on the left leans back, on the right forward). */
|
|
75
|
+
export const NOTE_TILT = { card: 3, strip: 2 } as const;
|
|
76
|
+
/** A note's paper and ink without its own colours: an off-white paper and near-black ink, a green tick. */
|
|
77
|
+
export const NOTE_COLORS = { paper: "#fbf8f1", ink: "#1d1f24", tick: "#2f9e4f" } as const;
|
|
53
78
|
/** A second line's type size in main font sizes: the hook title's place label, the subtitle, the unit, the stamp's place. */
|
|
54
79
|
export const OVERLAY_SECONDARY_SCALE = { hook_title: 0.55, place_card: 0.55, counter: 0.5, date_stamp: 0.78 } as const;
|
|
55
80
|
/** A place card's subtitle size in title sizes, by its `subtitle_size` (RV-131 of an adopting app: 0.42 read tiny). */
|
|
@@ -97,6 +122,9 @@ export const OVERLAY_FONT_ROLES: Record<TextOverlayKind, OverlayFontRole> = {
|
|
|
97
122
|
list: "interface",
|
|
98
123
|
search_bar: "interface",
|
|
99
124
|
date_stamp: "interface",
|
|
125
|
+
// A note strip types in the heading font; a note card and an end word are handwritten (the kit's own `HAND_FONT`).
|
|
126
|
+
note: "heading",
|
|
127
|
+
end_word: "heading",
|
|
100
128
|
};
|
|
101
129
|
|
|
102
130
|
/** A box in the film's frame, in px. */
|
|
@@ -147,7 +175,18 @@ type Drawn = OverlayBase & OverlayLook;
|
|
|
147
175
|
*/
|
|
148
176
|
export type ResolvedOverlay =
|
|
149
177
|
| (OverlayBase & { kind: "punch_in"; scale: number; ease: number })
|
|
150
|
-
| (Drawn & {
|
|
178
|
+
| (Drawn & {
|
|
179
|
+
kind: "keyword";
|
|
180
|
+
text: string;
|
|
181
|
+
fontSize: number;
|
|
182
|
+
side: OverlaySide;
|
|
183
|
+
box: OverlayBox;
|
|
184
|
+
underline?: boolean;
|
|
185
|
+
/** Its card sits in the middle of `box`, its text centred (`style.align` center); absent: on its side. */
|
|
186
|
+
isCentred?: boolean;
|
|
187
|
+
/** Its text on a tight box (`style.backdrop` highlight); absent: the card. */
|
|
188
|
+
backdrop?: "highlight";
|
|
189
|
+
})
|
|
151
190
|
| (Drawn & { kind: "lower_third"; text: string; fontSize: number; side: OverlaySide; box: OverlayBox })
|
|
152
191
|
| (Drawn & {
|
|
153
192
|
kind: "list";
|
|
@@ -163,7 +202,17 @@ export type ResolvedOverlay =
|
|
|
163
202
|
})
|
|
164
203
|
| (Drawn & { kind: "arrow"; from: OverlayPoint; to: OverlayPoint })
|
|
165
204
|
| (Drawn & { kind: "highlight"; rect: OverlayBox })
|
|
166
|
-
| (Drawn & {
|
|
205
|
+
| (Drawn & {
|
|
206
|
+
kind: "hook_title";
|
|
207
|
+
lines: string[];
|
|
208
|
+
place: string | null;
|
|
209
|
+
fontSize: number;
|
|
210
|
+
placeFontSize: number;
|
|
211
|
+
align?: OverlayAlign;
|
|
212
|
+
box: OverlayBox;
|
|
213
|
+
/** Each line on its own tight box (`style.backdrop` highlight); absent: the card. */
|
|
214
|
+
backdrop?: "highlight";
|
|
215
|
+
})
|
|
167
216
|
| (Drawn & { kind: "search_bar"; text: string; fontSize: number; box: OverlayBox })
|
|
168
217
|
| (Drawn & {
|
|
169
218
|
kind: "place_card";
|
|
@@ -179,7 +228,27 @@ export type ResolvedOverlay =
|
|
|
179
228
|
subtitleDelay?: number;
|
|
180
229
|
})
|
|
181
230
|
| (Drawn & { kind: "counter"; value: number; from: number; decimals: number; unit: string | null; fontSize: number; unitFontSize: number; box: OverlayBox })
|
|
182
|
-
| (Drawn & { kind: "date_stamp"; text: string; place: string | null; fontSize: number; placeFontSize: number; side: OverlaySide; box: OverlayBox })
|
|
231
|
+
| (Drawn & { kind: "date_stamp"; text: string; place: string | null; fontSize: number; placeFontSize: number; side: OverlaySide; box: OverlayBox })
|
|
232
|
+
| (Drawn & {
|
|
233
|
+
kind: "note";
|
|
234
|
+
noteStyle: OverlayNoteStyle;
|
|
235
|
+
/** Its lines as drawn (a strip's in capitals). */
|
|
236
|
+
lines: string[];
|
|
237
|
+
fontSize: number;
|
|
238
|
+
side: OverlaySide;
|
|
239
|
+
/** Its paper, unturned; it is drawn turned by `tilt` degrees about its middle. */
|
|
240
|
+
box: OverlayBox;
|
|
241
|
+
tilt: number;
|
|
242
|
+
/** The torn edge's depth at each of `NOTE_TEAR_POINTS` points, 0 to 1 of `NOTE_TEAR_EM`. */
|
|
243
|
+
tear: number[];
|
|
244
|
+
/** The film second each word comes in at, in reading order (a card's words as they are said); null: a strip, typed. */
|
|
245
|
+
wordTimes: number[] | null;
|
|
246
|
+
/** Whether a hand tick is drawn after its last word (`style.tick`). */
|
|
247
|
+
tick: boolean;
|
|
248
|
+
/** The film second its tick starts being drawn; null without one. */
|
|
249
|
+
tickAt: number | null;
|
|
250
|
+
})
|
|
251
|
+
| (Drawn & { kind: "end_word"; text: string; fontSize: number; box: OverlayBox });
|
|
183
252
|
|
|
184
253
|
export type ResolvedOverlaysResult = { ok: true; overlays: ResolvedOverlay[] } | { ok: false; problems: string[] };
|
|
185
254
|
|
|
@@ -254,6 +323,22 @@ export function estimateTextWidth(text: string, fontSize: number): number {
|
|
|
254
323
|
return Math.ceil([...text].length * OVERLAY_CHAR_EM * fontSize - 1e-6);
|
|
255
324
|
}
|
|
256
325
|
|
|
326
|
+
/** A line's width at a font size, in px. */
|
|
327
|
+
export type TextMeasure = (text: string, fontSize: number) => number;
|
|
328
|
+
|
|
329
|
+
/** How a note's line is measured: a card's handwriting from the hand font itself, a strip's capitals by their own wider average. */
|
|
330
|
+
export function getNoteMeasure(noteStyle: OverlayNoteStyle): TextMeasure {
|
|
331
|
+
return noteStyle === "card" ? measureHandText : measureStripText;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** A strip's capitals per character, in font sizes: bold capitals run about 0.72 em, plus the strip's letter spacing. */
|
|
335
|
+
export const NOTE_STRIP_CHAR_EM = 0.76;
|
|
336
|
+
|
|
337
|
+
/** How wide a strip's capitals are at `fontSize`: wider than `estimateTextWidth`'s mixed-case average. */
|
|
338
|
+
function measureStripText(text: string, fontSize: number): number {
|
|
339
|
+
return Math.ceil([...text].length * NOTE_STRIP_CHAR_EM * fontSize - 1e-6);
|
|
340
|
+
}
|
|
341
|
+
|
|
257
342
|
/** Text broken into lines at spaces so each fits `width` at `fontSize` by the estimate; a word longer than a line stands alone. */
|
|
258
343
|
export function wrapOverlayText(text: string, fontSize: number, width: number): string[] {
|
|
259
344
|
const lines: string[] = [];
|
|
@@ -321,13 +406,13 @@ export function getDrawnOverlayCard(overlay: ResolvedOverlay): OverlayBox | null
|
|
|
321
406
|
return getSideTextCard(overlay, getSideTextLines(overlay), overlay.box.height);
|
|
322
407
|
}
|
|
323
408
|
|
|
324
|
-
/** The card of a side text fitted to `lines`, `height` tall from the box's top: on its side, or in the box's middle. */
|
|
409
|
+
/** The card of a side text fitted to `lines`, `height` tall from the box's top: on its side, or in the box's middle (a centred list or keyword). */
|
|
325
410
|
function getSideTextCard(overlay: SideTextOverlay, lines: readonly string[], height: number): OverlayBox {
|
|
326
411
|
const { box, fontSize, side } = overlay;
|
|
327
412
|
const padX = getOverlayPadding(overlay).x;
|
|
328
413
|
const textWidth = Math.max(0, ...lines.map((line) => estimateTextWidth(line, fontSize)));
|
|
329
414
|
const width = Math.min(box.width, Math.ceil(textWidth + 2 * padX));
|
|
330
|
-
const isCentred = overlay.kind === "list" && overlay.isCentred === true;
|
|
415
|
+
const isCentred = (overlay.kind === "list" || overlay.kind === "keyword") && overlay.isCentred === true;
|
|
331
416
|
const left = isCentred ? box.left + Math.round((box.width - width) / 2) : side === "right" ? box.left + box.width - width : box.left;
|
|
332
417
|
return { left, top: box.top, width, height };
|
|
333
418
|
}
|
|
@@ -378,6 +463,7 @@ export function findShotBreak(edl: Pick<Edl, "segments">, index: number): string
|
|
|
378
463
|
if (segment.clip !== previous.clip) return `segment "${segment.id}" plays another clip`;
|
|
379
464
|
if (segment.transition !== "cut") return `segment "${segment.id}" starts on a ${segment.transition}, not a plain cut`;
|
|
380
465
|
if (segment.motion === "kenburns" || previous.motion === "kenburns") return `a Ken Burns zoom at segment "${segment.id}"`;
|
|
466
|
+
if (isCameraMoving(segment.camera) || isCameraMoving(previous.camera) || !isSameCamera(segment.camera, previous.camera)) return `a camera move or a new framing at segment "${segment.id}"`;
|
|
381
467
|
if (segment.caption?.bottom !== previous.caption?.bottom || segment.caption?.top !== previous.caption?.top) return `segment "${segment.id}" moves the captions`;
|
|
382
468
|
return null;
|
|
383
469
|
}
|
|
@@ -432,7 +518,7 @@ export function resolveEdlOverlays(input: ResolveOverlaysInput): ResolvedOverlay
|
|
|
432
518
|
const segment = findSegmentAt(edl, start);
|
|
433
519
|
const segmentStart = starts[segment] as number;
|
|
434
520
|
const segmentId = edl.segments[segment]?.id ?? "";
|
|
435
|
-
if (overlay.kind
|
|
521
|
+
if (!isTitleBand(overlay.kind)) {
|
|
436
522
|
const shot = findShotSpan(edl, starts, { segment, end, isPunchIn: overlay.kind === "punch_in" });
|
|
437
523
|
if (end > shot.end + 0.01) {
|
|
438
524
|
const inside = shot.last === segment ? `segment "${segmentId}"` : `segments "${segmentId}" to "${edl.segments[shot.last]?.id ?? ""}"`;
|
|
@@ -457,11 +543,20 @@ export function resolveEdlOverlays(input: ResolveOverlaysInput): ResolvedOverlay
|
|
|
457
543
|
// The first point comes in with the card, so the card never stands empty (RV-144 of an adopting app).
|
|
458
544
|
placed.overlay.itemStarts = getListItemStarts({ start, end, count: placed.overlay.items.length, ...(times === undefined ? {} : { words: times }) }).map((at, item) => (item === 0 ? start : at));
|
|
459
545
|
}
|
|
546
|
+
if (placed.overlay.kind === "note") {
|
|
547
|
+
const timed = timeNote(placed.overlay, input.words);
|
|
548
|
+
placed.overlay.wordTimes = timed.wordTimes;
|
|
549
|
+
placed.overlay.tickAt = timed.tickAt;
|
|
550
|
+
}
|
|
460
551
|
if (placed.overlay.kind === "punch_in") {
|
|
461
552
|
if (edl.segments[segment]?.motion === "kenburns") {
|
|
462
553
|
problems.push(`${at}: segment "${segmentId}" has a Ken Burns zoom, which owns the picture's scale; put the punch-in on a still segment`);
|
|
463
554
|
return;
|
|
464
555
|
}
|
|
556
|
+
if (edl.segments[segment]?.camera !== undefined) {
|
|
557
|
+
problems.push(`${at}: segment "${segmentId}" has a camera (a move or a framing), which owns the picture's scale; put the punch-in on a segment without one`);
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
465
560
|
const easeEnd = r3(segmentStart + (eases[segment] ?? 0) / FOOTAGE_FPS);
|
|
466
561
|
if (start < easeEnd) {
|
|
467
562
|
problems.push(`${at}: starts at ${start} s, inside the zoom cut's ease of segment "${segmentId}" (until ${easeEnd} s); start it later`);
|
|
@@ -475,6 +570,11 @@ export function resolveEdlOverlays(input: ResolveOverlaysInput): ResolvedOverlay
|
|
|
475
570
|
return problems.length > 0 ? { ok: false, problems } : { ok: true, overlays: ordered };
|
|
476
571
|
}
|
|
477
572
|
|
|
573
|
+
/** The kinds that live in the top band (a hook title, an end word): not counted against one overlay at a time. */
|
|
574
|
+
export function isTitleBand(kind: OverlayKind): boolean {
|
|
575
|
+
return kind === "hook_title" || kind === "end_word";
|
|
576
|
+
}
|
|
577
|
+
|
|
478
578
|
/** Whether two overlays are on screen at the same time. */
|
|
479
579
|
function isConcurrent(a: ResolvedOverlay, b: ResolvedOverlay): boolean {
|
|
480
580
|
return a.start < b.end - 0.001 && b.start < a.end - 0.001;
|
|
@@ -483,7 +583,7 @@ function isConcurrent(a: ResolvedOverlay, b: ResolvedOverlay): boolean {
|
|
|
483
583
|
/** Two overlays on screen at once, two too close, two hook titles at once, or a drawing on a hook title while it shows. */
|
|
484
584
|
function findTimingProblems(ordered: readonly ResolvedOverlay[], spacing: number): string[] {
|
|
485
585
|
const problems: string[] = [];
|
|
486
|
-
const counted = ordered.filter((overlay) => overlay.kind
|
|
586
|
+
const counted = ordered.filter((overlay) => !isTitleBand(overlay.kind));
|
|
487
587
|
counted.forEach((overlay, place) => {
|
|
488
588
|
const previous = counted[place - 1];
|
|
489
589
|
if (previous === undefined) return;
|
|
@@ -493,17 +593,18 @@ function findTimingProblems(ordered: readonly ResolvedOverlay[], spacing: number
|
|
|
493
593
|
problems.push(`overlays[${overlay.index}]: starts ${r1(overlay.start - previous.start)} s after overlays[${previous.index}]; the film keeps overlays ${spacing} s apart (overlayMinSpacing)`);
|
|
494
594
|
}
|
|
495
595
|
});
|
|
496
|
-
const titles = ordered.filter((overlay)
|
|
596
|
+
const titles = ordered.filter((overlay): overlay is Extract<ResolvedOverlay, { kind: "hook_title" | "end_word" }> => isTitleBand(overlay.kind));
|
|
497
597
|
titles.forEach((title, place) => {
|
|
598
|
+
const name = title.kind.replace("_", " ");
|
|
498
599
|
const previous = titles[place - 1];
|
|
499
600
|
if (previous !== undefined && isConcurrent(title, previous)) {
|
|
500
|
-
problems.push(`overlays[${title.index}]: starts at ${title.start} s while the
|
|
601
|
+
problems.push(`overlays[${title.index}]: starts at ${title.start} s while the ${previous.kind.replace("_", " ")} overlays[${previous.index}] is on screen (until ${previous.end} s); one title at the top at a time`);
|
|
501
602
|
}
|
|
502
603
|
const titleBox = title.box;
|
|
503
604
|
for (const other of counted) {
|
|
504
605
|
const bounds = getOverlayBounds(other);
|
|
505
606
|
if (bounds === null || !isConcurrent(title, other) || !isOverlapping(bounds, titleBox)) continue;
|
|
506
|
-
problems.push(`overlays[${other.index}]: the ${other.kind.replace("_", " ")} would sit on the
|
|
607
|
+
problems.push(`overlays[${other.index}]: the ${other.kind.replace("_", " ")} would sit on the ${name} overlays[${title.index}] (on screen until ${title.end} s); move it lower or start it after the ${name}`);
|
|
507
608
|
}
|
|
508
609
|
});
|
|
509
610
|
return problems;
|
|
@@ -565,9 +666,149 @@ function placeOverlay(overlay: EdlOverlay, base: OverlayBase, place: Placement):
|
|
|
565
666
|
const drawn = { ...base, ...getLook(overlay), ...(place.padScale === 1 ? {} : { padScale: place.padScale }) };
|
|
566
667
|
if (overlay.kind === "arrow" || overlay.kind === "highlight") return placeMark(overlay, drawn, place);
|
|
567
668
|
if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") return placeSideText({ ...overlay, kind: overlay.kind }, drawn, place);
|
|
669
|
+
if (overlay.kind === "note") return placeNote(overlay, drawn, place);
|
|
670
|
+
if (overlay.kind === "end_word") return placeEndWord(overlay, drawn, place);
|
|
568
671
|
return placeCard({ ...overlay, kind: overlay.kind }, drawn, place);
|
|
569
672
|
}
|
|
570
673
|
|
|
674
|
+
/** A note's lines: broken at spaces to fit `width`, at most `MAX_NOTE_LINE_WORDS` words a line; null when a word alone is wider. */
|
|
675
|
+
export function wrapNoteText(text: string, fontSize: number, width: number, measure: TextMeasure = estimateTextWidth): string[] | null {
|
|
676
|
+
const lines: string[][] = [];
|
|
677
|
+
for (const word of text.split(/\s+/).filter((part) => part.length > 0)) {
|
|
678
|
+
if (measure(word, fontSize) > width) return null;
|
|
679
|
+
const last = lines[lines.length - 1];
|
|
680
|
+
if (last !== undefined && last.length < MAX_NOTE_LINE_WORDS && measure([...last, word].join(" "), fontSize) <= width) last.push(word);
|
|
681
|
+
else lines.push([word]);
|
|
682
|
+
}
|
|
683
|
+
return lines.map((line) => line.join(" "));
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/** A number from 0 to 1 for each of `count` points, the same for the same text: a torn edge that is not a pattern. */
|
|
687
|
+
export function getTornEdge(text: string, count = NOTE_TEAR_POINTS): number[] {
|
|
688
|
+
let seed = 2166136261;
|
|
689
|
+
for (const char of text) seed = Math.imul(seed ^ (char.codePointAt(0) ?? 0), 16777619) >>> 0;
|
|
690
|
+
return Array.from({ length: count }, () => {
|
|
691
|
+
seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;
|
|
692
|
+
return r3(0.25 + 0.75 * (seed / 4294967296));
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** A note's tick size and the gap before it, in px. */
|
|
697
|
+
export function getNoteTickSize(fontSize: number): { size: number; gap: number } {
|
|
698
|
+
return { size: Math.round(fontSize * NOTE_TICK_EM.size), gap: Math.round(fontSize * NOTE_TICK_EM.gap) };
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/** A note's padding round its text, in px. */
|
|
702
|
+
export function getNotePadding(fontSize: number): { x: number; y: number; tear: number } {
|
|
703
|
+
return { x: Math.round(fontSize * NOTE_PADDING_EM.x), y: Math.round(fontSize * NOTE_PADDING_EM.y), tear: Math.round(fontSize * NOTE_TEAR_EM) };
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/** A note's text block inside its paper: its left edge and top, in px (the tear takes the card's foot, the strip's top). */
|
|
707
|
+
export function getNoteTextBox(note: Pick<Extract<ResolvedOverlay, { kind: "note" }>, "box" | "fontSize" | "noteStyle" | "lines">): OverlayBox {
|
|
708
|
+
const pad = getNotePadding(note.fontSize);
|
|
709
|
+
const top = note.box.top + pad.y + (note.noteStyle === "strip" ? pad.tear : 0);
|
|
710
|
+
return { left: note.box.left + pad.x, top, width: note.box.width - 2 * pad.x, height: note.lines.length * note.fontSize * NOTE_LINE_HEIGHT };
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* A note: a paper card (handwritten, its words coming in as they are said) or a strip (typed capitals), on its side
|
|
715
|
+
* in the top or the middle of the room above the captions, at most `NOTE_WIDTH_SHARE` of the safe width; a text that
|
|
716
|
+
* takes more than `MAX_NOTE_LINES` lines is refused.
|
|
717
|
+
*/
|
|
718
|
+
function placeNote(overlay: EdlOverlay, drawn: Drawn, place: Placement): Placed {
|
|
719
|
+
const { zone, frame } = place;
|
|
720
|
+
const scale = frame.width / 1080;
|
|
721
|
+
const noteStyle = overlay.style?.note_style ?? "card";
|
|
722
|
+
const size = overlay.style?.size ?? "m";
|
|
723
|
+
const fontSize = Math.round((noteStyle === "strip" ? NOTE_STRIP_FONT_SIZES : OVERLAY_FONT_SIZES.note)[size] * scale);
|
|
724
|
+
const pad = getNotePadding(fontSize);
|
|
725
|
+
const margin = Math.round(OVERLAY_MARGIN * scale);
|
|
726
|
+
const room = Math.round((frame.width - zone.left - zone.right - 2 * margin) * NOTE_WIDTH_SHARE) - 2 * pad.x;
|
|
727
|
+
const text = noteStyle === "strip" ? (overlay.text ?? "").toUpperCase() : (overlay.text ?? "");
|
|
728
|
+
const measure = getNoteMeasure(noteStyle);
|
|
729
|
+
const lines = wrapNoteText(text, fontSize, room, measure);
|
|
730
|
+
if (lines === null) return { ok: false, error: "a word of the note is too wide for its card; shorten it or use a smaller size" };
|
|
731
|
+
if (lines.length > MAX_NOTE_LINES) return { ok: false, error: `the note takes ${lines.length} lines, more than ${MAX_NOTE_LINES}; shorten it or use a smaller size` };
|
|
732
|
+
const isTick = overlay.style?.tick === true;
|
|
733
|
+
const tick = getNoteTickSize(fontSize);
|
|
734
|
+
const lastWidth = measure(lines[lines.length - 1] ?? "", fontSize) + (isTick ? tick.gap + tick.size : 0);
|
|
735
|
+
const contentWidth = Math.max(lastWidth, ...lines.map((line) => measure(line, fontSize)));
|
|
736
|
+
if (contentWidth > room) return { ok: false, error: "the note's last line and its tick are too wide for its card; shorten it or leave the tick out" };
|
|
737
|
+
const width = Math.ceil(contentWidth + 2 * pad.x);
|
|
738
|
+
const height = Math.ceil(lines.length * fontSize * NOTE_LINE_HEIGHT + 2 * pad.y + pad.tear);
|
|
739
|
+
const region = getTextRegion(place);
|
|
740
|
+
const top = getPositionTop(region, overlay.style?.position ?? "top", height);
|
|
741
|
+
if (top < region.top || top + height > region.bottom) {
|
|
742
|
+
return { ok: false, error: `the note (${height} px tall) does not fit between the platform safe zone and the captions; use a smaller size or shorter text` };
|
|
743
|
+
}
|
|
744
|
+
const side = overlay.style?.side ?? "left";
|
|
745
|
+
const left = side === "right" ? frame.width - zone.right - margin - width : zone.left + margin;
|
|
746
|
+
const tilt = (side === "right" ? -1 : 1) * NOTE_TILT[noteStyle];
|
|
747
|
+
return {
|
|
748
|
+
ok: true,
|
|
749
|
+
overlay: { ...drawn, kind: "note", noteStyle, lines, fontSize, side, box: { left, top, width, height }, tilt, tear: getTornEdge(text), wordTimes: null, tick: isTick, tickAt: null },
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* A note card's word times and its tick's start: each word of the note comes in on the same word said inside its span
|
|
755
|
+
* (matched in order, compared like fillers are), a word not said with the one before it; when none is said, the words
|
|
756
|
+
* are spaced over the first part of the span. The card is there one frame before its first word, and no word comes
|
|
757
|
+
* later than 0.6 s before its end. A strip types its text (`getTypingTimes`), its tick after its last letter.
|
|
758
|
+
*/
|
|
759
|
+
export function timeNote(note: Extract<ResolvedOverlay, { kind: "note" }>, words: readonly TimedWord[]): { wordTimes: number[] | null; tickAt: number | null } {
|
|
760
|
+
// The tick comes after the last word, but never in the note's last 0.4 s nor before it starts.
|
|
761
|
+
const tickAfter = (at: number): number | null => (note.tick ? r3(Math.max(note.start, Math.min(note.end - 0.4, at + NOTE_TICK_DELAY))) : null);
|
|
762
|
+
const noteWords = note.lines.join(" ").split(" ");
|
|
763
|
+
const first = r3(note.start + NOTE_FIRST_WORD_LEAD);
|
|
764
|
+
const latest = r3(Math.max(first, note.end - 0.6));
|
|
765
|
+
if (note.noteStyle === "strip") {
|
|
766
|
+
const typed = note.typing ?? DEFAULT_OVERLAY_TYPING_SPEED;
|
|
767
|
+
const lastLetter = note.start + 0.3 + ([...note.lines.join("")].length - 1) / typed;
|
|
768
|
+
return { wordTimes: null, tickAt: tickAfter(lastLetter) };
|
|
769
|
+
}
|
|
770
|
+
const said = words.filter((word) => word.start >= note.start - 0.05 && word.start < note.end);
|
|
771
|
+
let cursor = 0;
|
|
772
|
+
let previous: number | null = null;
|
|
773
|
+
const matched = noteWords.map((word) => {
|
|
774
|
+
const key = normalizeWord(word);
|
|
775
|
+
const found = said.findIndex((spoken, index) => index >= cursor && normalizeWord(spoken.text) === key);
|
|
776
|
+
if (found === -1) return previous;
|
|
777
|
+
cursor = found + 1;
|
|
778
|
+
previous = said[found]?.start ?? null;
|
|
779
|
+
return previous;
|
|
780
|
+
});
|
|
781
|
+
const isSaid = matched.some((time) => time !== null);
|
|
782
|
+
const gap = Math.min(0.35, Math.max(0.12, ((note.end - note.start) * 0.5) / noteWords.length));
|
|
783
|
+
const times = noteWords.map((_word, index) => {
|
|
784
|
+
const at = isSaid ? (matched[index] ?? first) : first + index * gap;
|
|
785
|
+
return r3(Math.min(latest, Math.max(first, at)));
|
|
786
|
+
});
|
|
787
|
+
// Never earlier than the word before: a later word matched before an earlier one keeps the reading order.
|
|
788
|
+
for (let index = 1; index < times.length; index++) times[index] = Math.max(times[index] as number, times[index - 1] as number);
|
|
789
|
+
return { wordTimes: times, tickAt: tickAfter(times[times.length - 1] ?? first) };
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/** An end word: one big handwritten line at the top of the room, no card, shrunk to fit the width or refused. */
|
|
793
|
+
function placeEndWord(overlay: EdlOverlay, drawn: Drawn, place: Placement): Placed {
|
|
794
|
+
const { zone, frame } = place;
|
|
795
|
+
const scale = frame.width / 1080;
|
|
796
|
+
const margin = Math.round(OVERLAY_MARGIN * scale);
|
|
797
|
+
const room = frame.width - zone.left - zone.right - 2 * margin;
|
|
798
|
+
const text = (overlay.text ?? "").replace(/\s+/g, " ").trim();
|
|
799
|
+
let fontSize = Math.round(OVERLAY_FONT_SIZES.end_word[overlay.style?.size ?? "m"] * scale);
|
|
800
|
+
for (let shrink = 0; measureHandText(text, fontSize) > room; shrink++) {
|
|
801
|
+
if (shrink === MAX_TITLE_SHRINKS) return { ok: false, error: "the end word is too wide for one line even at a smaller size; shorten it or use a smaller size" };
|
|
802
|
+
fontSize = Math.round(fontSize * OVERLAY_TITLE_SHRINK);
|
|
803
|
+
}
|
|
804
|
+
const width = measureHandText(text, fontSize);
|
|
805
|
+
const height = Math.ceil(fontSize * OVERLAY_LINE_HEIGHT);
|
|
806
|
+
const region = getTextRegion(place);
|
|
807
|
+
if (region.top + height > region.bottom) return { ok: false, error: `the end word (${height} px tall) does not fit above the captions; use a smaller size` };
|
|
808
|
+
const left = Math.round(zone.left + margin + (room - width) / 2);
|
|
809
|
+
return { ok: true, overlay: { ...drawn, kind: "end_word", text, fontSize, box: { left, top: region.top, width, height } } };
|
|
810
|
+
}
|
|
811
|
+
|
|
571
812
|
/** An arrow's tail and point, or a highlight's rectangle. */
|
|
572
813
|
function placeMark(overlay: EdlOverlay, drawn: Drawn, place: Placement): Placed {
|
|
573
814
|
const { zone, frame } = place;
|
|
@@ -598,7 +839,9 @@ function placeMark(overlay: EdlOverlay, drawn: Drawn, place: Placement): Placed
|
|
|
598
839
|
function placeSideText(overlay: EdlOverlay & { kind: "keyword" | "lower_third" | "list" }, drawn: Drawn, place: Placement): Placed {
|
|
599
840
|
const { zone, frame } = place;
|
|
600
841
|
const scale = frame.width / 1080;
|
|
601
|
-
const
|
|
842
|
+
const align = overlay.kind === "keyword" ? overlay.style?.align : undefined;
|
|
843
|
+
// A keyword's align left or right is its side; center puts its card in the middle (`isCentred`).
|
|
844
|
+
const side = align === "left" || align === "right" ? align : (overlay.style?.side ?? (overlay.kind === "keyword" ? "right" : "left"));
|
|
602
845
|
const fontSize = Math.round(OVERLAY_FONT_SIZES[overlay.kind][overlay.style?.size ?? "m"] * scale);
|
|
603
846
|
const pad = getOverlayPadding({ fontSize, padScale: place.padScale });
|
|
604
847
|
const margin = Math.round(OVERLAY_MARGIN * scale);
|
|
@@ -624,7 +867,17 @@ function placeSideText(overlay: EdlOverlay & { kind: "keyword" | "lower_third" |
|
|
|
624
867
|
}
|
|
625
868
|
const fields = { text: overlay.text ?? "", fontSize, side, box };
|
|
626
869
|
if (overlay.kind === "lower_third") return { ok: true, overlay: { ...drawn, kind: "lower_third", ...fields } };
|
|
627
|
-
return {
|
|
870
|
+
return {
|
|
871
|
+
ok: true,
|
|
872
|
+
overlay: {
|
|
873
|
+
...drawn,
|
|
874
|
+
kind: "keyword",
|
|
875
|
+
...fields,
|
|
876
|
+
...(overlay.style?.underline === true ? { underline: true } : {}),
|
|
877
|
+
...(align === "center" ? { isCentred: true } : {}),
|
|
878
|
+
...(overlay.style?.backdrop === "highlight" ? { backdrop: "highlight" as const } : {}),
|
|
879
|
+
},
|
|
880
|
+
};
|
|
628
881
|
}
|
|
629
882
|
|
|
630
883
|
/** A list's chips before they are placed: their type size, each one's width, their common height, the row's width with its gaps. */
|
|
@@ -792,7 +1045,8 @@ function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card"
|
|
|
792
1045
|
// The hook title's place label carries a pin about one label line wide before it.
|
|
793
1046
|
const secondWidth = second === null ? 0 : estimateTextWidth(second, secondSize) + (isHook ? Math.round(secondSize * 1.1) : 0);
|
|
794
1047
|
if (secondWidth > room) return tooWide(metrics, isHook ? "place label" : "subtitle");
|
|
795
|
-
|
|
1048
|
+
// A title's align is center or left (the schema refuses right on it).
|
|
1049
|
+
const align: OverlayAlign = overlay.style?.align === "left" ? "left" : "center";
|
|
796
1050
|
const pin = !isHook && overlay.style?.pin !== undefined && overlay.style.pin !== "none" ? overlay.style.pin : undefined;
|
|
797
1051
|
const delay = !isHook && second !== null && overlay.style?.subtitle_delay !== undefined && overlay.style.subtitle_delay > 0 ? overlay.style.subtitle_delay : undefined;
|
|
798
1052
|
return {
|
|
@@ -800,7 +1054,7 @@ function measureTitle(overlay: EdlOverlay & { kind: "hook_title" | "place_card"
|
|
|
800
1054
|
content: {
|
|
801
1055
|
...getTitleContentSize({ kind: overlay.kind, lines, fontSize, second, secondSize, pin: pin !== undefined }),
|
|
802
1056
|
fields: isHook
|
|
803
|
-
? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize, align }
|
|
1057
|
+
? { kind: "hook_title", lines, place: second, fontSize, placeFontSize: secondSize, align, ...(overlay.style?.backdrop === "highlight" ? { backdrop: "highlight" } : {}) }
|
|
804
1058
|
: { kind: "place_card", lines, subtitle: second, fontSize, subtitleFontSize: secondSize, align, ...(pin === undefined ? {} : { pin }), ...(delay === undefined ? {} : { subtitleDelay: delay }) },
|
|
805
1059
|
},
|
|
806
1060
|
};
|
|
@@ -897,6 +1151,9 @@ export function getOverlayTextsByRole(overlays: readonly ResolvedOverlay[], loca
|
|
|
897
1151
|
texts.heading.push(formatOverlayNumber(overlay.value, overlay.decimals, locale), "0123456789", ...(overlay.unit === null ? [] : [overlay.unit]));
|
|
898
1152
|
} else if (overlay.kind === "date_stamp") {
|
|
899
1153
|
texts.interface.push(overlay.text, ...(overlay.place === null ? [] : [overlay.place]));
|
|
1154
|
+
} else if (overlay.kind === "note" && overlay.noteStyle === "strip") {
|
|
1155
|
+
// A note card and an end word are drawn in the kit's own handwriting, which covers every Latin letter.
|
|
1156
|
+
texts.heading.push(...overlay.lines);
|
|
900
1157
|
}
|
|
901
1158
|
}
|
|
902
1159
|
return texts;
|
|
@@ -907,3 +1164,63 @@ export function getOverlayTexts(overlays: readonly ResolvedOverlay[], locale = "
|
|
|
907
1164
|
const texts = getOverlayTextsByRole(overlays, locale);
|
|
908
1165
|
return [...texts.heading, ...texts.interface];
|
|
909
1166
|
}
|
|
1167
|
+
|
|
1168
|
+
type NoteOverlay = Extract<ResolvedOverlay, { kind: "note" }>;
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* A note's paper as a polygon in px of the frame, before its tilt: straight sides and a torn edge (`tear`) along the
|
|
1172
|
+
* card's foot or the strip's top, cutting at most `NOTE_TEAR_EM` into the paper. Both paths draw this outline.
|
|
1173
|
+
*/
|
|
1174
|
+
export function getNotePaperPoints(note: Pick<NoteOverlay, "box" | "fontSize" | "noteStyle" | "tear">): OverlayPoint[] {
|
|
1175
|
+
const { left, top, width, height } = note.box;
|
|
1176
|
+
const depth = getNotePadding(note.fontSize).tear;
|
|
1177
|
+
const last = Math.max(1, note.tear.length - 1);
|
|
1178
|
+
const torn = note.tear.map((share, index) => ({ x: r1(left + (width * index) / last), share }));
|
|
1179
|
+
if (note.noteStyle === "strip") {
|
|
1180
|
+
const edge = torn.map(({ x, share }) => ({ x, y: r1(top + depth * share) }));
|
|
1181
|
+
return [...edge, { x: left + width, y: top + height }, { x: left, y: top + height }];
|
|
1182
|
+
}
|
|
1183
|
+
const edge = torn.map(({ x, share }) => ({ x, y: r1(top + height - depth * share) })).reverse();
|
|
1184
|
+
return [{ x: left, y: top }, { x: left + width, y: top }, ...edge];
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
/** The middle of a note's paper: the point its tilt turns it about. */
|
|
1188
|
+
export function getNoteCentre(note: Pick<NoteOverlay, "box">): OverlayPoint {
|
|
1189
|
+
return { x: r1(note.box.left + note.box.width / 2), y: r1(note.box.top + note.box.height / 2) };
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/** A note's tick as three points of a hand-drawn check (down to the left, then a long stroke up), in px before the tilt. */
|
|
1193
|
+
export function getNoteTickPoints(note: Pick<NoteOverlay, "box" | "fontSize" | "noteStyle" | "lines">): OverlayPoint[] {
|
|
1194
|
+
const text = getNoteTextBox(note);
|
|
1195
|
+
const tick = getNoteTickSize(note.fontSize);
|
|
1196
|
+
const lastTop = text.top + (note.lines.length - 1) * note.fontSize * NOTE_LINE_HEIGHT;
|
|
1197
|
+
const x = text.left + getNoteMeasure(note.noteStyle)(note.lines[note.lines.length - 1] ?? "", note.fontSize) + tick.gap;
|
|
1198
|
+
const y = lastTop + (note.fontSize * NOTE_LINE_HEIGHT - tick.size) / 2;
|
|
1199
|
+
return [
|
|
1200
|
+
{ x: r1(x), y: r1(y + tick.size * 0.55) },
|
|
1201
|
+
{ x: r1(x + tick.size * 0.35), y: r1(y + tick.size * 0.9) },
|
|
1202
|
+
{ x: r1(x + tick.size), y: r1(y + tick.size * 0.08) },
|
|
1203
|
+
];
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
/** A note's words line by line, each with its film second (a card's `wordTimes`; a strip's are typed, so its start). */
|
|
1207
|
+
export function getNoteWordsByLine(note: Pick<NoteOverlay, "lines" | "wordTimes" | "start">): { text: string; at: number }[][] {
|
|
1208
|
+
let index = 0;
|
|
1209
|
+
return note.lines.map((line) =>
|
|
1210
|
+
line.split(" ").map((text) => {
|
|
1211
|
+
const at = note.wordTimes?.[index] ?? note.start;
|
|
1212
|
+
index += 1;
|
|
1213
|
+
return { text, at };
|
|
1214
|
+
}),
|
|
1215
|
+
);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
/** A note's paper, ink and tick colours: its own (`style.colors` card, text, accent), else paper, near-black and green. */
|
|
1219
|
+
export function getNoteColors(note: Pick<NoteOverlay, "colors">): { paper: string; ink: string; tick: string } {
|
|
1220
|
+
return { paper: note.colors.card ?? NOTE_COLORS.paper, ink: note.colors.text ?? NOTE_COLORS.ink, tick: note.colors.accent ?? NOTE_COLORS.tick };
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/** Whether the overlays draw in the kit's handwriting: a note card or an end word. */
|
|
1224
|
+
export function isHandFontNeeded(overlays: readonly ResolvedOverlay[]): boolean {
|
|
1225
|
+
return overlays.some((overlay) => overlay.kind === "end_word" || (overlay.kind === "note" && overlay.noteStyle === "card"));
|
|
1226
|
+
}
|
package/src/footage/picture.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { CAMERA_ORIGIN, getCameraOrigin, type CameraAnchor } from "./camera.js";
|
|
1
2
|
import { getSegmentScales } from "./compose.js";
|
|
3
|
+
import { buildDrawnTransitionFilters, FRAME_TIMING, getTransitionOverlapFrames, isDrawnTransition, type DrawnTransition } from "./drawn-transitions.js";
|
|
2
4
|
import { getEdlDuration, getSegmentStarts, type Edl } from "./edl.js";
|
|
3
5
|
import { getFootageEdit, type FootageFilm } from "./film.js";
|
|
4
6
|
import { FOOTAGE_FPS, getThreadArgs, type Frame, type NormalizeEncoder } from "./normalize.js";
|
|
@@ -11,27 +13,31 @@ import { FOOTAGE_FPS, getThreadArgs, type Frame, type NormalizeEncoder } from ".
|
|
|
11
13
|
*
|
|
12
14
|
* Every piece starts on a film frame and runs to the next segment's frame, so rounding never adds up along the cut.
|
|
13
15
|
* A cross-fade is drawn into the incoming piece: the outgoing segment's tail, held at the zoom it ends on, dissolves
|
|
14
|
-
* into the incoming clip (`xfade`), as the per-segment composition plays it.
|
|
15
|
-
* the
|
|
16
|
+
* into the incoming clip (`xfade`), as the per-segment composition plays it. A drawn transition (`whip`, `card`,
|
|
17
|
+
* `paper`) takes the same tail and blends it with the piece's head (`buildDrawnTransitionFilters`), as the draft does.
|
|
18
|
+
* Zoom cuts and Ken Burns stay tweens on the composition's video.
|
|
16
19
|
*/
|
|
17
20
|
|
|
18
|
-
/** The point a zoom keeps still, as the composition's `transform-origin: 50% 42%`. */
|
|
19
|
-
const ZOOM_ORIGIN = { x: 0.5, y: 0.42 } as const;
|
|
20
21
|
/** How far a segment marked `kenburns` zooms when the film's `kenBurnsPercent` is 0, as in the composition. */
|
|
21
22
|
const HAND_KEN_BURNS_PERCENT = 4;
|
|
22
23
|
const PICTURE_CRF = 18;
|
|
23
24
|
const DEFAULT_PICTURE_PRESET = "veryfast";
|
|
24
25
|
|
|
25
26
|
const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
|
|
27
|
+
const r4 = (value: number): number => Math.round(value * 10000) / 10000 || 0;
|
|
26
28
|
|
|
27
|
-
/** The outgoing segment's tail under a cross-fade. */
|
|
29
|
+
/** The outgoing segment's tail under a cross-fade or a drawn transition. */
|
|
28
30
|
export interface PictureFadeTail {
|
|
31
|
+
/** How the tail meets the piece: a drawn transition of exactly `frames`; absent: a dissolve. */
|
|
32
|
+
kind?: DrawnTransition;
|
|
29
33
|
clip: string;
|
|
30
34
|
/** Seconds in the clip: where the outgoing segment ends. */
|
|
31
35
|
start: number;
|
|
32
36
|
frames: number;
|
|
33
37
|
/** The zoom the outgoing segment ends on, held through the fade. */
|
|
34
38
|
scale: number;
|
|
39
|
+
/** The point that zoom keeps still: the outgoing segment's camera anchor; absent: the composition's origin. */
|
|
40
|
+
origin?: CameraAnchor;
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
/** One segment's piece of the picture. */
|
|
@@ -42,7 +48,7 @@ export interface PicturePiece {
|
|
|
42
48
|
/** The piece's first film frame. */
|
|
43
49
|
frame: number;
|
|
44
50
|
frames: number;
|
|
45
|
-
/** For a `fade` cut, the outgoing tail the piece
|
|
51
|
+
/** For a `fade` cut or a drawn transition, the outgoing tail the piece starts over; null for any other cut. */
|
|
46
52
|
fade: PictureFadeTail | null;
|
|
47
53
|
}
|
|
48
54
|
|
|
@@ -64,13 +70,21 @@ export function planFootagePicture(film: Pick<FootageFilm, "edit">, edl: Edl): P
|
|
|
64
70
|
const nextStart = starts[index + 1];
|
|
65
71
|
const frames = Math.max(1, (nextStart === undefined ? lastFrame : toFrame(nextStart)) - frame);
|
|
66
72
|
const previous = edl.segments[index - 1];
|
|
67
|
-
const
|
|
73
|
+
const overlap = index === 0 ? 0 : getTransitionOverlapFrames(segment, edit.fadeFrames);
|
|
74
|
+
const kind = segment.transition === "fade" ? "fade" : isDrawnTransition(segment.transition) ? segment.transition : null;
|
|
75
|
+
// A dissolve fits the piece; a drawn transition has its own frames, and a piece too short for them (the EDL check
|
|
76
|
+
// refuses one) plays a plain cut.
|
|
77
|
+
const fadeFrames = kind === "fade" ? Math.min(frames, overlap) : kind !== null && overlap < frames ? overlap : 0;
|
|
68
78
|
let fade: PictureFadeTail | null = null;
|
|
69
|
-
if (previous !== undefined && fadeFrames > 0) {
|
|
79
|
+
if (previous !== undefined && kind !== null && fadeFrames > 0) {
|
|
70
80
|
const previousScale = scales[index - 1] as number;
|
|
71
|
-
// The outgoing segment's Ken Burns tween ends
|
|
72
|
-
const
|
|
73
|
-
|
|
81
|
+
// The outgoing segment's Ken Burns tween or camera move ends by its end; its tail holds the zoom it reached.
|
|
82
|
+
const reached = previous.camera !== undefined ? previous.camera.to : previous.motion === "kenburns" ? r4(previousScale * kenBurnsScale) : previousScale;
|
|
83
|
+
// The composition zooms the whole picture to the incoming camera's start during the fade, so a camera's tail is
|
|
84
|
+
// baked at what is left of its zoom (never below the full frame: a fade into a tighter camera is a hard cut's job).
|
|
85
|
+
const isCamera = previous.camera !== undefined || segment.camera !== undefined;
|
|
86
|
+
const scale = isCamera ? r4(Math.max(1, reached / (scales[index] as number))) : reached;
|
|
87
|
+
fade = { ...(kind === "fade" ? {} : { kind }), clip: previous.clip, start: r3(previous.end), frames: fadeFrames, scale, origin: getCameraOrigin(previous.camera) };
|
|
74
88
|
}
|
|
75
89
|
return { clip: segment.clip, start: r3(segment.start), frame, frames, fade };
|
|
76
90
|
});
|
|
@@ -102,12 +116,12 @@ function fitStream(frames: number): string[] {
|
|
|
102
116
|
}
|
|
103
117
|
|
|
104
118
|
/**
|
|
105
|
-
* A crop to `scale` about
|
|
119
|
+
* A crop to `scale` about `origin` and back to the clip's `frame`; nothing at scale 1. The crop rounds, so
|
|
106
120
|
* scaling it by the factor could come back a pixel or two short of the incoming clip, which `xfade` refuses (#1057).
|
|
107
121
|
*/
|
|
108
|
-
function zoomFilters(scale: number, frame: Frame): string[] {
|
|
122
|
+
function zoomFilters(scale: number, frame: Frame, origin: CameraAnchor): string[] {
|
|
109
123
|
if (scale === 1) return [];
|
|
110
|
-
return [`crop=iw/${scale}:ih/${scale}:(iw-iw/${scale})*${
|
|
124
|
+
return [`crop=iw/${scale}:ih/${scale}:(iw-iw/${scale})*${origin.x}:(ih-ih/${scale})*${origin.y}`, `scale=${frame.width}:${frame.height}`];
|
|
111
125
|
}
|
|
112
126
|
|
|
113
127
|
export interface PicturePieceArgsInput {
|
|
@@ -136,13 +150,13 @@ export function buildPicturePieceArgs(input: PicturePieceArgsInput): string[] {
|
|
|
136
150
|
if (piece.fade !== null) {
|
|
137
151
|
const { fade } = piece;
|
|
138
152
|
inputs.push(...threads.output, "-ss", String(fade.start), "-t", seconds(fade.frames), "-i", getClip(fade.clip));
|
|
139
|
-
const tail = [...zoomFilters(fade.scale, input.frame), ...fitStream(fade.frames)];
|
|
140
|
-
graph = [
|
|
153
|
+
const tail = [...zoomFilters(fade.scale, input.frame, fade.origin ?? CAMERA_ORIGIN), ...fitStream(fade.frames)];
|
|
154
|
+
graph = fade.kind === undefined ? [
|
|
141
155
|
`[0:v]${fitStream(piece.frames).join(",")}[incoming]`,
|
|
142
156
|
`[1:v]${tail.join(",")}[outgoing]`,
|
|
143
157
|
// xfade's output is the outgoing tail plus the incoming piece minus the fade: the piece's own length.
|
|
144
158
|
`[outgoing][incoming]xfade=transition=fade:duration=${r3(fade.frames / FOOTAGE_FPS)}:offset=0,trim=end_frame=${piece.frames}[picture]`,
|
|
145
|
-
].join(";");
|
|
159
|
+
].join(";") : buildDrawnPieceGraph({ kind: fade.kind, piece, tail, frame: input.frame });
|
|
146
160
|
}
|
|
147
161
|
return [
|
|
148
162
|
"-v",
|
|
@@ -178,6 +192,23 @@ export function buildPicturePieceArgs(input: PicturePieceArgsInput): string[] {
|
|
|
178
192
|
];
|
|
179
193
|
}
|
|
180
194
|
|
|
195
|
+
/**
|
|
196
|
+
* A piece that starts on a drawn transition: its first `frames` blended with the outgoing tail, then the rest of its
|
|
197
|
+
* own frames (the plan gives a drawn transition only to a piece longer than it).
|
|
198
|
+
*/
|
|
199
|
+
function buildDrawnPieceGraph(input: { kind: DrawnTransition; piece: PicturePiece; tail: string[]; frame: Frame }): string {
|
|
200
|
+
const { piece } = input;
|
|
201
|
+
const frames = piece.fade?.frames ?? 0;
|
|
202
|
+
return [
|
|
203
|
+
`[0:v]${fitStream(piece.frames).join(",")},split[full1][full2]`,
|
|
204
|
+
`[full1]trim=end_frame=${frames},setpts=PTS-STARTPTS,${FRAME_TIMING}[incoming]`,
|
|
205
|
+
`[full2]trim=start_frame=${frames},setpts=PTS-STARTPTS,${FRAME_TIMING}[rest]`,
|
|
206
|
+
`[1:v]${input.tail.join(",")}[outgoing]`,
|
|
207
|
+
...buildDrawnTransitionFilters({ kind: input.kind, outgoing: "outgoing", incoming: "incoming", output: "blend", frame: input.frame, prefix: "dt" }),
|
|
208
|
+
`[blend][rest]concat=n=2:v=1:a=0,settb=1/${FOOTAGE_FPS},fps=${FOOTAGE_FPS}[picture]`,
|
|
209
|
+
].join(";");
|
|
210
|
+
}
|
|
211
|
+
|
|
181
212
|
/** The concat demuxer's list: one `file` line per piece, quotes escaped as the demuxer reads them. */
|
|
182
213
|
export function buildPictureList(files: readonly string[]): string {
|
|
183
214
|
return `${files.map((file) => `file '${file.replace(/'/g, "'\\''")}'`).join("\n")}\n`;
|