@softure-ai/marketing-kit 0.34.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 +30 -0
- package/NOTICE +6 -0
- package/README.md +26 -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/compose.d.ts +2 -1
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +16 -3
- 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 +188 -4
- package/dist/footage/draft-overlays.js.map +1 -1
- package/dist/footage/draft.d.ts +11 -0
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +45 -3
- 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 +16 -0
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +24 -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 +134 -8
- 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 +48 -6
- package/dist/footage/overlay-schema.d.ts.map +1 -1
- package/dist/footage/overlay-schema.js +71 -18
- package/dist/footage/overlay-schema.js.map +1 -1
- package/dist/footage/overlays.d.ts +125 -1
- package/dist/footage/overlays.d.ts.map +1 -1
- package/dist/footage/overlays.js +260 -8
- package/dist/footage/overlays.js.map +1 -1
- package/dist/footage/picture.d.ts +5 -2
- package/dist/footage/picture.d.ts.map +1 -1
- package/dist/footage/picture.js +30 -8
- 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 +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- 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 +38 -11
- package/schema/marketing.schema.json +10 -2
- package/src/config/schema.ts +1 -1
- package/src/footage/compose.ts +14 -3
- package/src/footage/draft-overlays.ts +217 -2
- package/src/footage/draft.ts +54 -3
- package/src/footage/drawn-transitions.ts +214 -0
- package/src/footage/edl.ts +21 -1
- package/src/footage/film.ts +3 -2
- package/src/footage/hand-font.ts +47 -0
- package/src/footage/overlay-html.ts +141 -7
- package/src/footage/overlay-motion.ts +49 -0
- package/src/footage/overlay-schema.ts +78 -19
- package/src/footage/overlays.ts +306 -10
- package/src/footage/picture.ts +35 -10
- package/src/footage/pipeline.ts +7 -1
- package/src/footage/tools.ts +1 -1
- package/src/index.ts +32 -0
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { getCornerRadiusPx, type BrandStyle, type CornerRadius } from "./brand-style.js";
|
|
2
2
|
import { getDraftBoxEvents } from "./draft-boxes.js";
|
|
3
3
|
import { toAssColor } from "./draft-color.js";
|
|
4
|
+
import { HAND_FONT, getHandFontAssSize } from "./hand-font.js";
|
|
4
5
|
import { getCounterSeconds, getOverlayColors, getPlaceCardTimes, getTypingTimes, type OverlayColors } from "./overlay-html.js";
|
|
5
6
|
import {
|
|
7
|
+
DROP_LETTER_SECONDS,
|
|
8
|
+
NOTE_GROW_FROM_SCALE,
|
|
9
|
+
NOTE_GROW_SECONDS,
|
|
10
|
+
NOTE_TICK_SECONDS,
|
|
6
11
|
OVERLAY_EASES,
|
|
12
|
+
getDropLetterTimes,
|
|
7
13
|
PIN_DROP_SECONDS,
|
|
8
14
|
PIN_DROP_SHARE,
|
|
9
15
|
UNDERLINE_EM,
|
|
@@ -16,6 +22,7 @@ import {
|
|
|
16
22
|
} from "./overlay-motion.js";
|
|
17
23
|
import type { OverlayEntrance } from "./overlay-schema.js";
|
|
18
24
|
import {
|
|
25
|
+
NOTE_LINE_HEIGHT,
|
|
19
26
|
OVERLAY_FONT_ROLES,
|
|
20
27
|
OVERLAY_LINE_HEIGHT,
|
|
21
28
|
OVERLAY_LIST_LINE_HEIGHT,
|
|
@@ -27,6 +34,12 @@ import {
|
|
|
27
34
|
getDrawnOverlayCard,
|
|
28
35
|
getListCardsByItem,
|
|
29
36
|
getListItemTimes,
|
|
37
|
+
getNoteCentre,
|
|
38
|
+
getNoteColors,
|
|
39
|
+
getNotePaperPoints,
|
|
40
|
+
getNoteTextBox,
|
|
41
|
+
getNoteTickPoints,
|
|
42
|
+
getNoteWordsByLine,
|
|
30
43
|
getOverlayPadding,
|
|
31
44
|
getPlaceCardPinRow,
|
|
32
45
|
getPlaceCardPinSize,
|
|
@@ -374,6 +387,73 @@ function getWipePanelEvent(overlay: Pick<ResolvedOverlay, "start">, drawing: str
|
|
|
374
387
|
return [`Dialogue: 3,${toAssTime(overlay.start)},${toAssTime(overlay.start + motion.entrance.seconds)},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${tags}\\1c${toTagColor(accent)}\\p1}${drawing}{\\p0}`];
|
|
375
388
|
}
|
|
376
389
|
|
|
390
|
+
/** The same motion with no entrance of its own: a part whose letters or words come in by themselves. */
|
|
391
|
+
function getPlainMotion(motion: DraftMotion): DraftMotion {
|
|
392
|
+
return { ...motion, name: "none", entrance: { kind: "none" } };
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* A dropped text as one line of ASS: each letter transparent until its second (`times`, from `getDropLetterTimes`),
|
|
397
|
+
* then fading in over half a fall. libass moves whole events only, so the draft shows the letters arriving on their
|
|
398
|
+
* times without the fall the render draws.
|
|
399
|
+
*/
|
|
400
|
+
export function getDropText(text: string, times: readonly number[], eventStart: number): string {
|
|
401
|
+
const fade = toMs(DROP_LETTER_SECONDS / 2);
|
|
402
|
+
return [...toAssText(text)]
|
|
403
|
+
.map((char, index) => {
|
|
404
|
+
if (char.trim() === "") return char;
|
|
405
|
+
const from = toMs((times[index] ?? eventStart) - eventStart);
|
|
406
|
+
return `{\\alpha&HFF&\\t(${from},${from + fade},\\alpha&H00&)}${char}`;
|
|
407
|
+
})
|
|
408
|
+
.join("");
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** A highlight mark's padding round its text and its corner, in font sizes (as the render's `.ov-mark`). */
|
|
412
|
+
const MARK_PADDING_EM = { x: 0.22, y: 0.04 } as const;
|
|
413
|
+
const MARK_RADIUS_EM = 0.14;
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* A highlight backdrop's marks under one line of text (`style.backdrop` highlight): a tight rounded box in the card
|
|
417
|
+
* colour, its width the text shown so far (each typed letter widens it, as the render's box grows), anchored where
|
|
418
|
+
* the text is (`x` its left, middle or right edge, `top` its top).
|
|
419
|
+
*/
|
|
420
|
+
function getBackdropMarkEvents(input: {
|
|
421
|
+
text: string;
|
|
422
|
+
x: number;
|
|
423
|
+
align: "left" | "center" | "right";
|
|
424
|
+
top: number;
|
|
425
|
+
fontSize: number;
|
|
426
|
+
colour: string;
|
|
427
|
+
motion: DraftMotion;
|
|
428
|
+
span: { start: number; end: number };
|
|
429
|
+
typing: number | null;
|
|
430
|
+
/** When the line starts typing, if not at the span's start (a second line of a title). */
|
|
431
|
+
typeFrom?: number;
|
|
432
|
+
}): string[] {
|
|
433
|
+
const { fontSize, span } = input;
|
|
434
|
+
const pad = { x: fontSize * MARK_PADDING_EM.x, y: fontSize * MARK_PADDING_EM.y };
|
|
435
|
+
const height = fontSize * OVERLAY_LINE_HEIGHT + 2 * pad.y;
|
|
436
|
+
const boxFor = (shown: string): OverlayBox => {
|
|
437
|
+
const width = estimateTextWidth(shown, fontSize) + 2 * pad.x;
|
|
438
|
+
const left = input.align === "left" ? input.x - pad.x : input.align === "right" ? input.x + pad.x - width : input.x - width / 2;
|
|
439
|
+
return { left, top: input.top - pad.y, width, height };
|
|
440
|
+
};
|
|
441
|
+
const clean = toAssText(input.text);
|
|
442
|
+
const steps =
|
|
443
|
+
input.typing === null
|
|
444
|
+
? [{ from: span.start, to: span.end, shown: clean }]
|
|
445
|
+
: getTypingTimes(input.typeFrom ?? span.start, clean, input.typing).map((at, index, times) => ({ from: Math.min(at, span.end), to: Math.min(times[index + 1] ?? span.end, span.end), shown: [...clean].slice(0, index + 1).join("").trimEnd() }));
|
|
446
|
+
const visible = steps.filter((step) => step.to > step.from && step.shown.length > 0);
|
|
447
|
+
return visible.map((step, index) =>
|
|
448
|
+
getShapeEvent({ start: step.from, end: step.to }, getRoundedRectDrawing(boxFor(step.shown), fontSize * MARK_RADIUS_EM), input.colour, input.motion, 3, {
|
|
449
|
+
start: step.from,
|
|
450
|
+
end: step.to,
|
|
451
|
+
isFirst: index === 0,
|
|
452
|
+
isLast: index === visible.length - 1,
|
|
453
|
+
}),
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
|
|
377
457
|
/** A keyword's underline: an accent bar under its text, drawn from the left once the keyword is in. */
|
|
378
458
|
function getUnderlineEvent(overlay: Extract<ResolvedOverlay, { kind: "keyword" }>, card: OverlayBox, colour: string, motion: DraftMotion): string[] {
|
|
379
459
|
if (overlay.underline !== true) return [];
|
|
@@ -414,7 +494,11 @@ function getSideTextEvents(overlay: Extract<ResolvedOverlay, { kind: "keyword" |
|
|
|
414
494
|
const span = { start: overlay.start, end: overlay.end };
|
|
415
495
|
const tags = `\\an${align}\\fs${fontSize}${getTextTags(overlay, colors, context, OVERLAY_FONT_ROLES[overlay.kind])}`;
|
|
416
496
|
const text = (pos: OverlayPoint, steps: TextStep[], own = motion) => getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: own });
|
|
417
|
-
const
|
|
497
|
+
const isMarked = overlay.kind === "keyword" && overlay.backdrop === "highlight";
|
|
498
|
+
const shape = isMarked
|
|
499
|
+
? getBackdropMarkEvents({ text: overlay.text, x, align: isCentred ? "center" : isRight ? "right" : "left", top: y, fontSize, colour: colors.background, motion, span, typing: overlay.typing })
|
|
500
|
+
: getCardShapeEvents(overlay, card, fontSize, colors, motion, context);
|
|
501
|
+
if (overlay.entrance === "drop") return [...shape, ...text({ x, y }, [{ from: span.start, to: span.end, text: getDropText(overlay.text, getDropLetterTimes(span.start, overlay.text), span.start) }], getPlainMotion(motion))];
|
|
418
502
|
// A keyword or a lower third types in only when its entrance says so.
|
|
419
503
|
const steps = overlay.entrance === null ? [{ from: span.start, to: span.end, text: toAssText(overlay.text) }] : getTypedSteps(overlay.text, span, overlay.typing, isCentred);
|
|
420
504
|
return [...shape, ...text({ x, y }, steps), ...(overlay.kind === "keyword" ? getUnderlineEvent(overlay, card, colors.accent, motion) : [])];
|
|
@@ -550,7 +634,8 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
550
634
|
const name = overlay.entrance === null || overlay.entrance === "type" ? (overlay.typing !== null ? "fade" : DEFAULT_ENTRANCES[overlay.kind]) : overlay.entrance;
|
|
551
635
|
const motion = getDraftMotion(overlay, name, box, context);
|
|
552
636
|
const span = { start: overlay.start, end: overlay.end };
|
|
553
|
-
const
|
|
637
|
+
const isMarked = overlay.kind === "hook_title" && overlay.backdrop === "highlight";
|
|
638
|
+
const events = isMarked ? [] : getCardShapeEvents(overlay, box, fontSize, colors, motion, context);
|
|
554
639
|
const { x: padX, y: padY } = getOverlayPadding(overlay);
|
|
555
640
|
const centerX = box.left + box.width / 2;
|
|
556
641
|
const tagsFor = (role: OverlayFontRole) => getTextTags(overlay, colors, context, role);
|
|
@@ -582,6 +667,25 @@ function getCardEvents(overlay: CardOverlay, context: DraftContext): string[] {
|
|
|
582
667
|
const lineHeight = overlay.kind === "hook_title" ? OVERLAY_LINE_HEIGHT : OVERLAY_TITLE_LINE_HEIGHT;
|
|
583
668
|
const titleMotion = times.title > span.start ? withFadeEntrance(motion) : motion;
|
|
584
669
|
let typedBefore = 0;
|
|
670
|
+
if (overlay.kind === "hook_title" && (isMarked || overlay.entrance === "drop")) {
|
|
671
|
+
const letters = getDropLetterTimes(span.start, overlay.lines.join(""));
|
|
672
|
+
overlay.lines.forEach((line) => {
|
|
673
|
+
const lineStart = overlay.typing === null ? span.start : span.start + typedBefore / overlay.typing;
|
|
674
|
+
if (isMarked) {
|
|
675
|
+
const align = isLeft ? "left" : "center";
|
|
676
|
+
events.push(...getBackdropMarkEvents({ text: line, x: lineX, align, top: y, fontSize, colour: colors.background, motion, span, typing: overlay.typing, typeFrom: lineStart }));
|
|
677
|
+
}
|
|
678
|
+
const steps =
|
|
679
|
+
overlay.entrance === "drop"
|
|
680
|
+
? [{ from: span.start, to: span.end, text: getDropText(line, letters.slice(typedBefore, typedBefore + [...line].length), span.start) }]
|
|
681
|
+
: getTypedSteps(line, { start: lineStart, end: span.end }, overlay.typing, !isLeft);
|
|
682
|
+
const isQuiet = overlay.entrance === "drop" || (!isLeft && overlay.typing !== null);
|
|
683
|
+
events.push(...text({ x: lineX, y }, lineAlign, fontSize, "heading", isLeft && overlay.entrance !== "drop" ? steps.map((step, index) => (index === 0 ? { ...step, from: span.start } : step)) : steps, isQuiet ? plain : motion));
|
|
684
|
+
typedBefore += [...line].length;
|
|
685
|
+
y += fontSize * lineHeight;
|
|
686
|
+
});
|
|
687
|
+
return events;
|
|
688
|
+
}
|
|
585
689
|
overlay.lines.forEach((line) => {
|
|
586
690
|
// The lines type one after the other, as the render's characters do; a left line holds its place transparent
|
|
587
691
|
// from the start, a centred one shows its typed part only (`getTypedSteps`).
|
|
@@ -650,6 +754,115 @@ function getMarkEvents(overlay: Extract<ResolvedOverlay, { kind: "arrow" | "high
|
|
|
650
754
|
return [`Dialogue: 3,${at},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${fade}\\1a&HFF&\\3c${accent}\\bord${stroke}\\p1}${shape}{\\p0}`];
|
|
651
755
|
}
|
|
652
756
|
|
|
757
|
+
/** A polygon as an ASS drawing. */
|
|
758
|
+
function getPolygonDrawing(points: readonly OverlayPoint[]): string {
|
|
759
|
+
const [first, ...rest] = points;
|
|
760
|
+
if (first === undefined) return "";
|
|
761
|
+
return `m ${r0(first.x)} ${r0(first.y)} l ${rest.map((point) => `${r0(point.x)} ${r0(point.y)}`).join(" ")}`;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/** A stroke along `points` `width` px wide as an ASS drawing: one quad per segment and a square cap at each joint. */
|
|
765
|
+
function getStrokeDrawing(points: readonly OverlayPoint[], width: number): string {
|
|
766
|
+
const half = width / 2;
|
|
767
|
+
const parts: string[] = [];
|
|
768
|
+
points.slice(1).forEach((to, index) => {
|
|
769
|
+
const from = points[index] as OverlayPoint;
|
|
770
|
+
const length = Math.hypot(to.x - from.x, to.y - from.y) || 1;
|
|
771
|
+
const n = { x: (-(to.y - from.y) / length) * half, y: ((to.x - from.x) / length) * half };
|
|
772
|
+
const u = { x: ((to.x - from.x) / length) * half, y: ((to.y - from.y) / length) * half };
|
|
773
|
+
parts.push(getPolygonDrawing([
|
|
774
|
+
{ x: from.x - u.x + n.x, y: from.y - u.y + n.y },
|
|
775
|
+
{ x: to.x + u.x + n.x, y: to.y + u.y + n.y },
|
|
776
|
+
{ x: to.x + u.x - n.x, y: to.y + u.y - n.y },
|
|
777
|
+
{ x: from.x - u.x - n.x, y: from.y - u.y - n.y },
|
|
778
|
+
]));
|
|
779
|
+
});
|
|
780
|
+
return parts.join(" ");
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* A note: its paper's torn outline and a soft shadow (layer 3), turned by its tilt about its middle (`\org`, `\frz`);
|
|
785
|
+
* a card's handwritten words each fading in on its said second, a strip's capitals typed in after it grows; the tick
|
|
786
|
+
* drawn from the left after the last word (layer 4). A strip's grow is the same `NOTE_GROW_FROM_SCALE` to full size.
|
|
787
|
+
*/
|
|
788
|
+
function getNoteEvents(overlay: Extract<ResolvedOverlay, { kind: "note" }>, context: DraftContext): string[] {
|
|
789
|
+
const colors = getNoteColors(overlay);
|
|
790
|
+
const centre = getNoteCentre(overlay);
|
|
791
|
+
const turn = `\\org(${r0(centre.x)},${r0(centre.y)})\\frz${overlay.tilt}`;
|
|
792
|
+
const isStrip = overlay.noteStyle === "strip";
|
|
793
|
+
const frame = { width: 1080 * context.scale, height: 1920 * context.scale };
|
|
794
|
+
const easing = overlay.easing ?? "smooth";
|
|
795
|
+
const grow: OverlayEntranceMotion = { kind: "tween", from: { opacity: 1, scale: NOTE_GROW_FROM_SCALE, y: 0, blur: 0 }, seconds: NOTE_GROW_SECONDS, ease: "power2.out" };
|
|
796
|
+
const name = overlay.entrance ?? (isStrip ? "pop" : "none");
|
|
797
|
+
const motion: DraftMotion = {
|
|
798
|
+
name,
|
|
799
|
+
entrance: isStrip && overlay.entrance === null ? grow : getEntranceMotion(name, easing, frame),
|
|
800
|
+
exit: getExitMotion({ exit: overlay.exit ?? "auto", entrance: overlay.entrance ?? "fade", easing, frame }),
|
|
801
|
+
card: overlay.box,
|
|
802
|
+
scale: context.scale,
|
|
803
|
+
isSnappy: easing === "snappy",
|
|
804
|
+
isCardMoved: name === "pop",
|
|
805
|
+
};
|
|
806
|
+
const at = { isFirst: true, isLast: true, ms: toMs(overlay.end - overlay.start) };
|
|
807
|
+
const shapeTags = getMotionTags(motion, { ...at, pos: { x: 0, y: 0 }, part: "card" });
|
|
808
|
+
const time = `${toAssTime(overlay.start)},${toAssTime(overlay.end)}`;
|
|
809
|
+
const paper = getPolygonDrawing(getNotePaperPoints(overlay));
|
|
810
|
+
const shadowOffset = r0(6 * context.scale);
|
|
811
|
+
const shadow = getPolygonDrawing(getNotePaperPoints({ ...overlay, box: { ...overlay.box, top: overlay.box.top + shadowOffset } }));
|
|
812
|
+
const events = [
|
|
813
|
+
`Dialogue: 3,${time},OverlayShape,,0,0,0,,{\\an7${shapeTags.position}${shapeTags.rest}${turn}\\blur${r0(10 * context.scale)}\\1c&H000000&\\1a&HB0&\\p1}${shadow}{\\p0}`,
|
|
814
|
+
`Dialogue: 3,${time},OverlayShape,,0,0,0,,{\\an7${shapeTags.position}${shapeTags.rest}${turn}\\1c${toTagColor(colors.paper)}\\p1}${paper}{\\p0}`,
|
|
815
|
+
];
|
|
816
|
+
const textBox = getNoteTextBox(overlay);
|
|
817
|
+
const lineHeight = overlay.fontSize * NOTE_LINE_HEIGHT;
|
|
818
|
+
const font = isStrip ? `${context.fonts.heading === undefined ? "" : `\\fn${context.fonts.heading}`}\\b1` : `\\fn${HAND_FONT.family}\\b0`;
|
|
819
|
+
const textMotion = getPlainMotion(motion);
|
|
820
|
+
// libass sizes the hand font by its ascent and descent: its \\fs is scaled so the letters match the render's.
|
|
821
|
+
const assSize = isStrip ? overlay.fontSize : getHandFontAssSize(overlay.fontSize);
|
|
822
|
+
const tags = `\\an7\\fs${assSize}${font}\\1c${toTagColor(colors.ink)}${turn}`;
|
|
823
|
+
getNoteWordsByLine(overlay).forEach((words, index) => {
|
|
824
|
+
const pos = { x: textBox.left, y: textBox.top + index * lineHeight };
|
|
825
|
+
const line = overlay.lines[index] as string;
|
|
826
|
+
const span = { start: overlay.start, end: overlay.end };
|
|
827
|
+
if (isStrip) {
|
|
828
|
+
const before = overlay.lines.slice(0, index).join("").length;
|
|
829
|
+
const typing = overlay.typing ?? 14;
|
|
830
|
+
const steps = getTypedSteps(line, { start: overlay.start + before / typing, end: overlay.end }, typing).map((step, stepIndex) => (stepIndex === 0 ? { ...step, from: overlay.start } : step));
|
|
831
|
+
events.push(...getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps, motion: textMotion }));
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
const fade = 100;
|
|
835
|
+
const shown = words.map((word) => `{\\alpha&HFF&\\t(${toMs(word.at - span.start)},${toMs(word.at - span.start) + fade},\\alpha&H00&)}${toAssText(word.text)}`).join(" ");
|
|
836
|
+
events.push(...getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: [{ from: span.start, to: span.end, text: shown }], motion: textMotion }));
|
|
837
|
+
});
|
|
838
|
+
if (overlay.tickAt !== null) {
|
|
839
|
+
const points = getNoteTickPoints(overlay);
|
|
840
|
+
const xs = points.map((point) => point.x);
|
|
841
|
+
const ys = points.map((point) => point.y);
|
|
842
|
+
const room = overlay.fontSize * 0.2;
|
|
843
|
+
const clip = { x0: r0(Math.min(...xs) - room), y0: r0(Math.min(...ys) - room), x1: r0(Math.max(...xs) + room), y1: r0(Math.max(...ys) + room) };
|
|
844
|
+
const draw = `${toClip({ ...clip, x1: clip.x0 })}\\t(0,${toMs(NOTE_TICK_SECONDS)},${toClip(clip)})`;
|
|
845
|
+
const fade = motion.exit.kind === "none" ? "" : `\\fad(0,${FADE_OUT_MS})`;
|
|
846
|
+
events.push(`Dialogue: 4,${toAssTime(overlay.tickAt)},${toAssTime(overlay.end)},OverlayShape,,0,0,0,,{\\an7\\pos(0,0)${fade}${draw}${turn}\\1c${toTagColor(colors.tick)}\\p1}${getStrokeDrawing(points, overlay.fontSize * 0.12)}{\\p0}`);
|
|
847
|
+
}
|
|
848
|
+
return events;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/** An end word: one big handwritten line at the top, no card, white with a soft shadow, its letters dropping in (or its own entrance). */
|
|
852
|
+
function getEndWordEvents(overlay: Extract<ResolvedOverlay, { kind: "end_word" }>, context: DraftContext): string[] {
|
|
853
|
+
const name = overlay.entrance ?? "drop";
|
|
854
|
+
const motion = getDraftMotion(overlay, name, overlay.box, context);
|
|
855
|
+
const colour = overlay.colors.text ?? "#ffffff";
|
|
856
|
+
const tags = `\\an8\\fs${getHandFontAssSize(overlay.fontSize)}\\fn${HAND_FONT.family}\\b0\\1c${toTagColor(colour)}\\shad${r0(3 * context.scale)}\\4c&H000000&\\4a&H90&`;
|
|
857
|
+
const pos = { x: overlay.box.left + overlay.box.width / 2, y: overlay.box.top };
|
|
858
|
+
const span = { start: overlay.start, end: overlay.end };
|
|
859
|
+
if (name === "drop") {
|
|
860
|
+
const text = getDropText(overlay.text, getDropLetterTimes(span.start, overlay.text), span.start);
|
|
861
|
+
return getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: [{ from: span.start, to: span.end, text }], motion: getPlainMotion(motion) });
|
|
862
|
+
}
|
|
863
|
+
return getTextEvents({ layer: 4, style: "OverlayPlain", pos, tags, steps: [{ from: span.start, to: span.end, text: toAssText(overlay.text) }], motion });
|
|
864
|
+
}
|
|
865
|
+
|
|
653
866
|
/**
|
|
654
867
|
* The overlays as ASS events, layers 3 and 4. `fonts` names the heading and interface families where they are not the
|
|
655
868
|
* styles' own (the captions' font); `locale` groups a counter's number as the render does.
|
|
@@ -665,6 +878,8 @@ export function buildDraftOverlayEvents(
|
|
|
665
878
|
if (overlay.kind === "punch_in") return [];
|
|
666
879
|
if (overlay.kind === "arrow" || overlay.kind === "highlight") return getMarkEvents(overlay, context);
|
|
667
880
|
if (overlay.kind === "keyword" || overlay.kind === "lower_third" || overlay.kind === "list") return getSideTextEvents(overlay, context);
|
|
881
|
+
if (overlay.kind === "note") return getNoteEvents(overlay, context);
|
|
882
|
+
if (overlay.kind === "end_word") return getEndWordEvents(overlay, context);
|
|
668
883
|
return getCardEvents(overlay, context);
|
|
669
884
|
});
|
|
670
885
|
}
|
package/src/footage/draft.ts
CHANGED
|
@@ -10,13 +10,15 @@ import { CAPTION_HIGHLIGHT_BOX_PADDING_EM, CAPTION_HIGHLIGHT_SECONDS, CAPTION_UN
|
|
|
10
10
|
import { getCaptionChunkLayouts, getCaptionSpans, getFootageCaptionChunks, getFootageCaptionLayout, isSameCaptionPlace, type CaptionWordsFilm } from "./captions.js";
|
|
11
11
|
import { getCameraMoveFrames, getCameraOrigin, getCameraScaleExpression, type CameraAnchor, type EdlCamera } from "./camera.js";
|
|
12
12
|
import { getSegmentFadeFrames, getSegmentScales, getSegmentZoomEases } from "./compose.js";
|
|
13
|
+
import { buildDrawnTransitionFilters, DRAWN_TRANSITION_FRAMES, FRAME_TIMING, isDrawnTransition, STUTTER_FRAMES, type DrawnTransition } from "./drawn-transitions.js";
|
|
13
14
|
import { toAssColor } from "./draft-color.js";
|
|
14
15
|
import { buildDraftOverlayEvents, getDraftOverlayStyles, getRoundedRectDrawing } from "./draft-overlays.js";
|
|
15
16
|
import { getCaptionCornerRadius, getCornerRadiusPx, getStylePadding, type BrandStyle } from "./brand-style.js";
|
|
16
17
|
import { getDraftBoxEvents } from "./draft-boxes.js";
|
|
17
18
|
import { createDraftTextMeasure, wrapDraftLine, type DraftTextMeasure } from "./draft-text-width.js";
|
|
18
19
|
import { CAPTION_PILL_PADDING } from "../compose/timeline.js";
|
|
19
|
-
import { estimateTextWidth } from "./overlays.js";
|
|
20
|
+
import { estimateTextWidth, isHandFontNeeded } from "./overlays.js";
|
|
21
|
+
import { HAND_FONT } from "./hand-font.js";
|
|
20
22
|
import type { OverlayColors } from "./overlay-html.js";
|
|
21
23
|
import { resolveEdlOverlays, type OverlayFontRole, type ResolvedOverlay } from "./overlays.js";
|
|
22
24
|
import { chooseFootageDraftFont } from "./draft-font.js";
|
|
@@ -472,6 +474,13 @@ export interface DraftSegmentPlan {
|
|
|
472
474
|
start: number;
|
|
473
475
|
/** The cross-fade from the segment before, in seconds; 0 for a plain cut. */
|
|
474
476
|
fade: number;
|
|
477
|
+
/**
|
|
478
|
+
* The drawn transition from the segment before (`whip`, `card`, `paper`) and its frames, over which the outgoing
|
|
479
|
+
* segment plays on under this one as under a fade; null for any other cut, or a segment too short for it.
|
|
480
|
+
*/
|
|
481
|
+
drawn: { kind: DrawnTransition; frames: number } | null;
|
|
482
|
+
/** Whether the segment starts on a `stutter`: `STUTTER_FRAMES` frames at the full frame, then `scale`. */
|
|
483
|
+
isStutter: boolean;
|
|
475
484
|
/** The zoom the segment starts at (`getSegmentScales`). */
|
|
476
485
|
scale: number;
|
|
477
486
|
/** The zoom it ends at: above `scale` for a `kenburns` segment, `scale` otherwise. */
|
|
@@ -502,13 +511,25 @@ export function planFootageDraft(film: Pick<FootageFilm, "edit">, edl: Edl, over
|
|
|
502
511
|
const eases = getSegmentZoomEases(edl, edit);
|
|
503
512
|
const starts = getSegmentStarts(edl);
|
|
504
513
|
const fades = edl.segments.map((segment, index) => r3(Math.min(getSegmentFadeFrames(edl, index, edit) / FOOTAGE_FPS, segment.end - segment.start)));
|
|
514
|
+
// A drawn transition only on a segment longer than its frames (the EDL check refuses a shorter one).
|
|
515
|
+
const drawn = edl.segments.map((segment, index) =>
|
|
516
|
+
index > 0 && isDrawnTransition(segment.transition) && Math.round((segment.end - segment.start) * FOOTAGE_FPS) > DRAWN_TRANSITION_FRAMES[segment.transition]
|
|
517
|
+
? { kind: segment.transition, frames: DRAWN_TRANSITION_FRAMES[segment.transition] }
|
|
518
|
+
: null,
|
|
519
|
+
);
|
|
520
|
+
const overlaps = edl.segments.map((_, index) => {
|
|
521
|
+
const own = drawn[index];
|
|
522
|
+
return own === null || own === undefined ? (fades[index] as number) : r3(own.frames / FOOTAGE_FPS);
|
|
523
|
+
});
|
|
505
524
|
return edl.segments.map((segment, index) => {
|
|
506
525
|
const scale = scales[index] as number;
|
|
507
526
|
return {
|
|
508
527
|
length: r3(segment.end - segment.start),
|
|
509
|
-
seconds: r3(segment.end - segment.start + (
|
|
528
|
+
seconds: r3(segment.end - segment.start + (overlaps[index + 1] ?? 0)),
|
|
510
529
|
start: starts[index] as number,
|
|
511
530
|
fade: fades[index] as number,
|
|
531
|
+
drawn: drawn[index] ?? null,
|
|
532
|
+
isStutter: segment.transition === "stutter",
|
|
512
533
|
scale,
|
|
513
534
|
endScale: segment.camera !== undefined ? segment.camera.to : segment.motion === "kenburns" ? r4(scale * kenBurnsScale) : scale,
|
|
514
535
|
startScale: (eases[index] as number) > 0 ? (scales[index - 1] as number) : scale,
|
|
@@ -542,6 +563,8 @@ function buildPictureFilters(plan: DraftSegmentPlan, draft: Frame): string[] {
|
|
|
542
563
|
`zoompan=z='${zoom}':x='(iw-iw/zoom)*${origin.x}':y='(ih-ih/zoom)*${origin.y}':d=1:s=${draft.width}x${draft.height}:fps=${FOOTAGE_FPS}`;
|
|
543
564
|
// The zoom runs over the segment's own length, as the render's tween does, and holds through a fade's tail.
|
|
544
565
|
const frames = Math.max(1, Math.round(plan.length * FOOTAGE_FPS));
|
|
566
|
+
// A stutter: the full frame for its first frames, then its tight framing (it has no move and no punch-in).
|
|
567
|
+
if (plan.isStutter) return [zoompan(`if(lt(on,${STUTTER_FRAMES}),1,${plan.scale})`)];
|
|
545
568
|
const own =
|
|
546
569
|
plan.easeFrames > 0
|
|
547
570
|
? `${plan.startScale}+(${r4(plan.scale - plan.startScale)})*(1-pow(1-min(on/${plan.easeFrames},1),2))`
|
|
@@ -562,6 +585,28 @@ function buildPictureFilters(plan: DraftSegmentPlan, draft: Frame): string[] {
|
|
|
562
585
|
return [`scale=${size}`];
|
|
563
586
|
}
|
|
564
587
|
|
|
588
|
+
/**
|
|
589
|
+
* A drawn transition in the draft: the cut so far is split where the incoming segment starts, its tail (the outgoing
|
|
590
|
+
* segment playing on) blended with the incoming head as the render's picture blends them, and the rest of the
|
|
591
|
+
* incoming segment follows.
|
|
592
|
+
*/
|
|
593
|
+
function buildDrawnJoin(input: { joined: string; incoming: string; output: string; plan: DraftSegmentPlan; drawn: { kind: DrawnTransition; frames: number }; frame: Frame; index: number }): string[] {
|
|
594
|
+
const { joined, incoming, output, drawn, index } = input;
|
|
595
|
+
const at = Math.round(input.plan.start * FOOTAGE_FPS);
|
|
596
|
+
const p = `d${String(index)}`;
|
|
597
|
+
return [
|
|
598
|
+
`[${joined}]split[${p}a][${p}b]`,
|
|
599
|
+
`[${p}a]trim=end_frame=${String(at)},setpts=PTS-STARTPTS,${FRAME_TIMING}[${p}head]`,
|
|
600
|
+
`[${p}b]trim=start_frame=${String(at)}:end_frame=${String(at + drawn.frames)},setpts=PTS-STARTPTS,${FRAME_TIMING}[${p}tail]`,
|
|
601
|
+
`[${incoming}]split[${p}c][${p}d]`,
|
|
602
|
+
`[${p}c]trim=end_frame=${String(drawn.frames)},setpts=PTS-STARTPTS,${FRAME_TIMING}[${p}in]`,
|
|
603
|
+
`[${p}d]trim=start_frame=${String(drawn.frames)},setpts=PTS-STARTPTS,${FRAME_TIMING}[${p}rest]`,
|
|
604
|
+
...buildDrawnTransitionFilters({ kind: drawn.kind, outgoing: `${p}tail`, incoming: `${p}in`, output: `${p}blend`, frame: input.frame, prefix: `${p}t` }),
|
|
605
|
+
// concat changes the time base; a later xfade needs both of its inputs on the segments' own.
|
|
606
|
+
`[${p}head][${p}blend][${p}rest]concat=n=3:v=1:a=0,settb=1/${FOOTAGE_FPS},fps=${FOOTAGE_FPS}[${output}]`,
|
|
607
|
+
];
|
|
608
|
+
}
|
|
609
|
+
|
|
565
610
|
/**
|
|
566
611
|
* The ffmpeg arguments of the draft: each segment read from its own seek into its clip, zoomed and scaled to the
|
|
567
612
|
* draft's width, joined by `xfade` at `fade` cuts and `concat` at the others, the captions burned in (`ass`), the
|
|
@@ -601,6 +646,11 @@ export function buildFootageDraftArgs(input: FootageDraftArgsInput): string[] {
|
|
|
601
646
|
plans.forEach((plan, index) => {
|
|
602
647
|
if (index === 0) return;
|
|
603
648
|
const label = `j${index}`;
|
|
649
|
+
if (plan.drawn !== null) {
|
|
650
|
+
parts.push(...buildDrawnJoin({ joined, incoming: `v${index}`, output: label, plan, drawn: plan.drawn, frame: draft, index }));
|
|
651
|
+
joined = label;
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
604
654
|
parts.push(
|
|
605
655
|
plan.fade > 0
|
|
606
656
|
? `[${joined}][v${index}]xfade=transition=fade:duration=${plan.fade}:offset=${plan.start}[${label}]`
|
|
@@ -803,7 +853,8 @@ async function runRenderFootageDraft(
|
|
|
803
853
|
if (captions !== null) {
|
|
804
854
|
writeFileSync(join(draftDir, "captions.ass"), captions);
|
|
805
855
|
mkdirSync(join(draftDir, "fonts"));
|
|
806
|
-
|
|
856
|
+
const handFont = isHandFontNeeded(overlays) ? [HAND_FONT.file] : [];
|
|
857
|
+
for (const file of new Set([font.file, ...Object.values(roleFonts).map((chosen) => chosen.file), ...handFont])) copyFileSync(file, join(draftDir, "fonts", basename(file)));
|
|
807
858
|
if (brandFont === null && options.brand?.fonts.body != null) {
|
|
808
859
|
log(`draft: the brand's body font ${options.brand.fonts.body.family} has no TrueType or OpenType file ffmpeg can read; the captions use ${FOOTAGE_DRAFT_FONT.family}.`);
|
|
809
860
|
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { Frame } from "./normalize.js";
|
|
2
|
+
import { FOOTAGE_FPS } from "./normalize.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Drawn transitions between two shots, the same frames in the draft (`draft.ts`) and the render's picture
|
|
6
|
+
* (`picture.ts`): both give the outgoing segment a tail that plays on under the incoming one, as a dissolve does, and
|
|
7
|
+
* blend the tail with the incoming head through `buildDrawnTransitionFilters`. Nothing is taken from outside the code:
|
|
8
|
+
* the paper's grain is ffmpeg's noise, its torn edge a sum of sines.
|
|
9
|
+
*
|
|
10
|
+
* - `whip`: the outgoing shot slides left faster and faster under a growing horizontal blur (8 frames), the incoming
|
|
11
|
+
* one slides in from the right still blurred, lands from 110 % and comes sharp (6 frames). No sound of its own.
|
|
12
|
+
* - `card`: the incoming shot appears in the middle as a small card (a quarter of the frame, tilted 3°, rounded
|
|
13
|
+
* corners) and grows over the outgoing one until it fills the frame, eased out.
|
|
14
|
+
* - `paper`: a paper grain settles over the outgoing shot (4 frames), then a torn edge opens from the middle onto the
|
|
15
|
+
* incoming one (8 frames).
|
|
16
|
+
*
|
|
17
|
+
* The `stutter` is not drawn here: it is a scale (the first `STUTTER_FRAMES` frames at the full frame, then the
|
|
18
|
+
* segment's tight framing), set where the other zooms are (`getSegmentScales`, the draft's zoom).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export const DRAWN_TRANSITIONS = ["whip", "card", "paper"] as const;
|
|
22
|
+
|
|
23
|
+
export type DrawnTransition = (typeof DRAWN_TRANSITIONS)[number];
|
|
24
|
+
|
|
25
|
+
/** Each drawn transition's length in frames at 30 fps (the reference reels, measured). */
|
|
26
|
+
export const DRAWN_TRANSITION_FRAMES: Readonly<Record<DrawnTransition, number>> = { whip: 14, card: 13, paper: 12 };
|
|
27
|
+
|
|
28
|
+
/** The whip's outgoing half; the rest of its frames are the incoming shot landing. */
|
|
29
|
+
export const WHIP_OUT_FRAMES = 8;
|
|
30
|
+
|
|
31
|
+
/** The paper's grain fade-in over the outgoing shot, before the tear opens. */
|
|
32
|
+
export const PAPER_FADE_FRAMES = 4;
|
|
33
|
+
|
|
34
|
+
/** How many frames a stutter shows the full frame before its tight framing. */
|
|
35
|
+
export const STUTTER_FRAMES = 5;
|
|
36
|
+
|
|
37
|
+
/** The stutter's tight framing when the segment sets no camera of its own. */
|
|
38
|
+
export const STUTTER_SCALE = 1.5;
|
|
39
|
+
|
|
40
|
+
/** How far the whip slides on each side, as a share of the frame's width. */
|
|
41
|
+
const WHIP_TRAVEL = 0.6;
|
|
42
|
+
/** The whip's horizontal blur on its outgoing frames, as a share of the frame's width (0: sharp). */
|
|
43
|
+
const WHIP_OUT_BLUR = [0, 0, 0, 0.002, 0.006, 0.014, 0.028, 0.05] as const;
|
|
44
|
+
/** The whip's blur on its incoming frames, falling to sharp. */
|
|
45
|
+
const WHIP_IN_BLUR = [0.042, 0.022, 0.01, 0.004, 0.0015, 0] as const;
|
|
46
|
+
/** The whip's landing zoom on the incoming shot. */
|
|
47
|
+
const WHIP_LANDING_SCALE = 1.1;
|
|
48
|
+
|
|
49
|
+
/** The card's first size (a share of the frame), tilt in radians (3°) and corner radius (a share of the width). */
|
|
50
|
+
const CARD_START_SCALE = 0.25;
|
|
51
|
+
const CARD_START_TILT = 0.0524;
|
|
52
|
+
const CARD_CORNER = 0.035;
|
|
53
|
+
|
|
54
|
+
/** The paper's colour, how strongly its grain multiplies the outgoing shot, how far the tear opens and its rim. */
|
|
55
|
+
const PAPER_COLOR = "0xEDE6D8";
|
|
56
|
+
const PAPER_STRENGTH = 0.55;
|
|
57
|
+
const PAPER_OPEN = 0.62;
|
|
58
|
+
const PAPER_RIM = 0.012;
|
|
59
|
+
/** The torn edge across the height: a sum of sines (amplitude as a share of the width, frequency, phase). */
|
|
60
|
+
const PAPER_TEAR: readonly (readonly [number, number, number])[] = [
|
|
61
|
+
[0.035, 31, 1.3],
|
|
62
|
+
[0.02, 83, 0.7],
|
|
63
|
+
[0.012, 197, 2.1],
|
|
64
|
+
[0.006, 421, 0.4],
|
|
65
|
+
];
|
|
66
|
+
/** The paper's white at the torn rim (luma, limited range). */
|
|
67
|
+
const PAPER_RIM_LUMA = 232;
|
|
68
|
+
|
|
69
|
+
const r4 = (value: number): number => Math.round(value * 10000) / 10000 || 0;
|
|
70
|
+
|
|
71
|
+
/** Whether a transition is one of the drawn ones. */
|
|
72
|
+
export function isDrawnTransition(transition: string): transition is DrawnTransition {
|
|
73
|
+
return (DRAWN_TRANSITIONS as readonly string[]).includes(transition);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The frames the outgoing segment plays on under the incoming one: a fade's own or the film's, a drawn transition's own, else 0. */
|
|
77
|
+
export function getTransitionOverlapFrames(segment: { transition: string; fadeFrames?: number | undefined }, filmFadeFrames: number): number {
|
|
78
|
+
if (segment.transition === "fade") return segment.fadeFrames ?? filmFadeFrames;
|
|
79
|
+
return isDrawnTransition(segment.transition) ? DRAWN_TRANSITION_FRAMES[segment.transition] : 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface DrawnTransitionFiltersInput {
|
|
83
|
+
kind: DrawnTransition;
|
|
84
|
+
/** The outgoing tail's label: exactly the transition's frames, the frame's size, yuv420p at 30 fps. */
|
|
85
|
+
outgoing: string;
|
|
86
|
+
/** The incoming head's label, the same. */
|
|
87
|
+
incoming: string;
|
|
88
|
+
/** The label the blended frames go out on (as many frames, yuv420p, 30 fps). */
|
|
89
|
+
output: string;
|
|
90
|
+
frame: Frame;
|
|
91
|
+
/** A prefix for the graph's inner labels, unique in the graph. */
|
|
92
|
+
prefix: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The filter chains (to join with `;`) that blend an outgoing tail and an incoming head into the transition's frames. */
|
|
96
|
+
export function buildDrawnTransitionFilters(input: DrawnTransitionFiltersInput): string[] {
|
|
97
|
+
switch (input.kind) {
|
|
98
|
+
case "whip":
|
|
99
|
+
return buildWhipFilters(input);
|
|
100
|
+
case "card":
|
|
101
|
+
return buildCardFilters(input);
|
|
102
|
+
case "paper":
|
|
103
|
+
return buildPaperFilters(input);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The film's time base with every frame numbered on it, after a `trim`, a blend or a `concat`: each frame then has its
|
|
109
|
+
* place, so a `concat` lays the pieces end to end. (An `fps` filter here drops the last frame of a stream whose frames
|
|
110
|
+
* carry no duration, as `overlay`, `blend` and `interleave` leave them.)
|
|
111
|
+
*/
|
|
112
|
+
export const FRAME_TIMING = `settb=1/${FOOTAGE_FPS},setpts=N`;
|
|
113
|
+
|
|
114
|
+
/** The closing filters every transition ends on: the film's pixel format, square pixels and frame rate. */
|
|
115
|
+
function closeStream(): string {
|
|
116
|
+
return `format=yuv420p,setsar=1,${FRAME_TIMING}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** One `gblur` per frame of `sigmas` (shares of the width), horizontal only, on that frame alone; none for a sharp frame. */
|
|
120
|
+
function blurSteps(sigmas: readonly number[], width: number): string[] {
|
|
121
|
+
return sigmas.flatMap((share, frame) => (share > 0 ? [`gblur=sigma=${r4(share * width)}:sigmaV=0:enable='eq(n,${String(frame)})'`] : []));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function buildWhipFilters(input: DrawnTransitionFiltersInput): string[] {
|
|
125
|
+
const { width: w, height: h } = input.frame;
|
|
126
|
+
const p = input.prefix;
|
|
127
|
+
const inFrames = DRAWN_TRANSITION_FRAMES.whip - WHIP_OUT_FRAMES;
|
|
128
|
+
const last = WHIP_OUT_FRAMES - 1;
|
|
129
|
+
const land = inFrames - 1;
|
|
130
|
+
// The slide wraps the shot around (a strip of the shot beside itself), so the blur streaks never show an edge.
|
|
131
|
+
const out = [`hstack`, `crop=w=${w}:h=${h}:x='${w}*${WHIP_TRAVEL}*pow(n/${last},2)':y=0`, ...blurSteps(WHIP_OUT_BLUR, w), "setpts=PTS-STARTPTS", FRAME_TIMING];
|
|
132
|
+
const into = [
|
|
133
|
+
`hstack`,
|
|
134
|
+
`crop=w=${w}:h=${h}:x='${w}*(1-${WHIP_TRAVEL}*pow(1-(n+1)/${inFrames},2))':y=0`,
|
|
135
|
+
`zoompan=z='${WHIP_LANDING_SCALE}-${r4(WHIP_LANDING_SCALE - 1)}*(1-pow(1-on/${land},2))':x='(iw-iw/zoom)/2':y='(ih-ih/zoom)/2':d=1:s=${w}x${h}:fps=${FOOTAGE_FPS}`,
|
|
136
|
+
...blurSteps(WHIP_IN_BLUR, w),
|
|
137
|
+
"setpts=PTS-STARTPTS",
|
|
138
|
+
FRAME_TIMING,
|
|
139
|
+
];
|
|
140
|
+
return [
|
|
141
|
+
`[${input.outgoing}]trim=end_frame=${WHIP_OUT_FRAMES},setpts=PTS-STARTPTS,split[${p}o1][${p}o2]`,
|
|
142
|
+
`[${p}o1][${p}o2]${out.join(",")}[${p}out]`,
|
|
143
|
+
`[${input.incoming}]trim=start_frame=${WHIP_OUT_FRAMES}:end_frame=${DRAWN_TRANSITION_FRAMES.whip},setpts=PTS-STARTPTS,split[${p}i1][${p}i2]`,
|
|
144
|
+
`[${p}i1][${p}i2]${into.join(",")}[${p}in]`,
|
|
145
|
+
`[${p}out][${p}in]concat=n=2:v=1:a=0,${closeStream()}[${input.output}]`,
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The card's size, tilt and corner on frame `k` (0-based) of `frames`, eased out (`1 - (1 - t)^2`) to the full frame. */
|
|
150
|
+
export function getCardFrame(k: number, frames: number = DRAWN_TRANSITION_FRAMES.card): { scale: number; tilt: number; corner: number } {
|
|
151
|
+
const eased = 1 - (1 - (k + 1) / frames) ** 2;
|
|
152
|
+
return { scale: r4(CARD_START_SCALE + (1 - CARD_START_SCALE) * eased), tilt: r4(CARD_START_TILT * (1 - eased)), corner: r4(CARD_CORNER * (1 - eased)) };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** An even size of at least 2 px, as yuv420p needs. */
|
|
156
|
+
function toEven(value: number): number {
|
|
157
|
+
return Math.max(2, 2 * Math.floor(value / 2));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function buildCardFilters(input: DrawnTransitionFiltersInput): string[] {
|
|
161
|
+
const { width: w, height: h } = input.frame;
|
|
162
|
+
const p = input.prefix;
|
|
163
|
+
const frames = DRAWN_TRANSITION_FRAMES.card;
|
|
164
|
+
// Each frame is its own chain at a fixed size: a size that changes mid-stream breaks `geq` and `rotate`.
|
|
165
|
+
const labels = Array.from({ length: frames }, (_, k) => `${p}c${String(k)}`);
|
|
166
|
+
const chains = labels.map((label, k) => {
|
|
167
|
+
const { scale, tilt, corner } = getCardFrame(k, frames);
|
|
168
|
+
const radius = r4(corner * w);
|
|
169
|
+
const chain = [`trim=start_frame=${String(k)}:end_frame=${String(k + 1)}`, `scale=${String(toEven(w * scale))}:${String(toEven(h * scale))}`];
|
|
170
|
+
if (radius >= 0.5) {
|
|
171
|
+
chain.push(`geq=lum='lum(X,Y)':cb='cb(X,Y)':cr='cr(X,Y)':a='255*lte(hypot(max(0,abs(X-W/2)-(W/2-${radius})),max(0,abs(Y-H/2)-(H/2-${radius}))),${radius})'`);
|
|
172
|
+
}
|
|
173
|
+
if (tilt > 0) chain.push(`rotate=${tilt}:c=black@0:ow=rotw(${tilt}):oh=roth(${tilt})`);
|
|
174
|
+
chain.push(`pad=${w}:${h}:(ow-iw)/2:(oh-ih)/2:color=black@0`, "setsar=1");
|
|
175
|
+
return `[${p}s${String(k)}]${chain.join(",")}[${label}]`;
|
|
176
|
+
});
|
|
177
|
+
return [
|
|
178
|
+
`[${input.incoming}]trim=end_frame=${frames},setpts=PTS-STARTPTS,format=yuva420p,split=${frames}${labels.map((_, k) => `[${p}s${String(k)}]`).join("")}`,
|
|
179
|
+
...chains,
|
|
180
|
+
// One-frame chains keep their own times, so `interleave` lays them out in order (a `concat` of them drops frames).
|
|
181
|
+
`${labels.map((label) => `[${label}]`).join("")}interleave=nb_inputs=${frames}[${p}card]`,
|
|
182
|
+
`[${input.outgoing}]trim=end_frame=${frames},setpts=PTS-STARTPTS,format=yuv420p[${p}under]`,
|
|
183
|
+
`[${p}under][${p}card]overlay=0:0:format=auto,${closeStream()}[${input.output}]`,
|
|
184
|
+
];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** The paper's tear: a sum of sines along the height, as a share of the width (the `blend` expression's `Y` and `H`). */
|
|
188
|
+
function getTearExpression(): string {
|
|
189
|
+
return `(${PAPER_TEAR.map(([amplitude, frequency, phase]) => `${amplitude}*sin(Y/H*${frequency}+${phase})`).join("+")})`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** How far the tear has opened on frame `N` (the `blend` expression's frame), as a share of the width; closed during the grain's fade. */
|
|
193
|
+
function getOpenExpression(frames: number): string {
|
|
194
|
+
const opening = frames - PAPER_FADE_FRAMES;
|
|
195
|
+
return `if(lt(N,${PAPER_FADE_FRAMES}),-1,${PAPER_OPEN}*(0.5-0.5*cos(PI*(N-${PAPER_FADE_FRAMES}+1)/${opening})))`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function buildPaperFilters(input: DrawnTransitionFiltersInput): string[] {
|
|
199
|
+
const { width: w, height: h } = input.frame;
|
|
200
|
+
const p = input.prefix;
|
|
201
|
+
const frames = DRAWN_TRANSITION_FRAMES.paper;
|
|
202
|
+
const strength = `min(1,(N+1)/${PAPER_FADE_FRAMES})*${PAPER_STRENGTH}`;
|
|
203
|
+
// Below 0 inside the tear (the incoming shot), up to the rim the torn paper's white, beyond it the papered shot.
|
|
204
|
+
const edge = `(abs(X/W-0.5)-(${getOpenExpression(frames)})-${getTearExpression()})`;
|
|
205
|
+
const tear = (rim: number): string => `'if(lt(${edge},0),A,if(lt(${edge},${PAPER_RIM}),${String(rim)},B))'`;
|
|
206
|
+
return [
|
|
207
|
+
// A static grain (no temporal noise) softened more along the height, as paper fibres run.
|
|
208
|
+
`color=c=${PAPER_COLOR}:s=${w}x${h}:r=${FOOTAGE_FPS},trim=end_frame=${frames},format=yuv420p,noise=c0s=28:c0f=a,gblur=sigma=${r4(Math.max(0.6, w / 900))}:sigmaV=${r4(Math.max(1.5, w / 360))}[${p}grain]`,
|
|
209
|
+
`[${input.outgoing}]trim=end_frame=${frames},setpts=PTS-STARTPTS,format=yuv420p[${p}under]`,
|
|
210
|
+
`[${input.incoming}]trim=end_frame=${frames},setpts=PTS-STARTPTS,format=yuv420p[${p}over]`,
|
|
211
|
+
`[${p}under][${p}grain]blend=c0_expr='A*(1-${strength})+A*B/255*${strength}':c1_expr='A*(1-${strength})+B*${strength}':c2_expr='A*(1-${strength})+B*${strength}'[${p}papered]`,
|
|
212
|
+
`[${p}over][${p}papered]blend=c0_expr=${tear(PAPER_RIM_LUMA)}:c1_expr=${tear(128)}:c2_expr=${tear(128)},${closeStream()}[${input.output}]`,
|
|
213
|
+
];
|
|
214
|
+
}
|