@softure-ai/marketing-kit 0.34.0 → 0.36.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 +59 -0
- package/NOTICE +6 -0
- package/README.md +49 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +1 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/schema.d.ts +10 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +9 -3
- package/dist/config/schema.js.map +1 -1
- package/dist/footage/captions.d.ts +22 -2
- package/dist/footage/captions.d.ts.map +1 -1
- package/dist/footage/captions.js +23 -4
- package/dist/footage/captions.js.map +1 -1
- package/dist/footage/compose.d.ts +11 -1
- package/dist/footage/compose.d.ts.map +1 -1
- package/dist/footage/compose.js +51 -17
- 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 +14 -1
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +117 -17
- 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 +42 -0
- package/dist/footage/edl.d.ts.map +1 -1
- package/dist/footage/edl.js +72 -2
- package/dist/footage/edl.js.map +1 -1
- package/dist/footage/film.d.ts +29 -5
- package/dist/footage/film.d.ts.map +1 -1
- package/dist/footage/film.js +13 -3
- 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 +265 -8
- package/dist/footage/overlays.js.map +1 -1
- package/dist/footage/picture.d.ts +10 -2
- package/dist/footage/picture.d.ts.map +1 -1
- package/dist/footage/picture.js +53 -13
- package/dist/footage/picture.js.map +1 -1
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +14 -4
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/footage/split-screen.d.ts +167 -0
- package/dist/footage/split-screen.d.ts.map +1 -0
- package/dist/footage/split-screen.js +233 -0
- package/dist/footage/split-screen.js.map +1 -0
- 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 +167 -11
- package/schema/marketing.schema.json +19 -4
- package/src/config/config.ts +1 -0
- package/src/config/schema.ts +9 -3
- package/src/footage/captions.ts +32 -4
- package/src/footage/compose.ts +44 -11
- package/src/footage/draft-overlays.ts +217 -2
- package/src/footage/draft.ts +137 -17
- package/src/footage/drawn-transitions.ts +214 -0
- package/src/footage/edl.ts +67 -2
- package/src/footage/film.ts +23 -4
- 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 +311 -10
- package/src/footage/picture.ts +58 -15
- package/src/footage/pipeline.ts +14 -4
- package/src/footage/split-screen.ts +319 -0
- package/src/footage/tools.ts +1 -1
- package/src/index.ts +62 -0
package/src/footage/pipeline.ts
CHANGED
|
@@ -16,8 +16,9 @@ import { prepareClipSounds, type SpeechPeaks, type SpeechPreGain } from "./clip-
|
|
|
16
16
|
import { readCachedTranscript, writeCacheFile, writeTranscript } from "./cache.js";
|
|
17
17
|
import { composeFootage, getFootageFilmSeconds, getFootageSfxCues } from "./compose.js";
|
|
18
18
|
import { getCaptionHighlight } from "./caption-highlight.js";
|
|
19
|
-
import { getOverlayTextsByRole, resolveEdlOverlays } from "./overlays.js";
|
|
20
|
-
import {
|
|
19
|
+
import { getOverlayTextsByRole, isHandFontNeeded, resolveEdlOverlays } from "./overlays.js";
|
|
20
|
+
import { HAND_FONT } from "./hand-font.js";
|
|
21
|
+
import { findMissingCaptionGlyphs, getCaptionBounds, getFootageCaptionLayout, toCaptionDisplayText } from "./captions.js";
|
|
21
22
|
import { err, getProviderFootageFailure, ok, type FootageResult } from "./failure.js";
|
|
22
23
|
import { findLowDiskProblems, getFreeBytes, getRenderTempDir, type FreeBytesReader } from "./disk.js";
|
|
23
24
|
import { buildEdl, getEdlDuration, readEdl, remapWords, validateEdl, type Edl } from "./edl.js";
|
|
@@ -49,6 +50,7 @@ import {
|
|
|
49
50
|
} from "./loudness.js";
|
|
50
51
|
import { duckingKeyframes, getDuckingOptions } from "./music.js";
|
|
51
52
|
import { FOOTAGE_FPS, normalizeFootage, type Frame, type NormalizeEncoder } from "./normalize.js";
|
|
53
|
+
import { writeSplitLayers } from "./split-screen.js";
|
|
52
54
|
import { buildPictureConcatArgs, buildPictureList, buildPicturePieceArgs, getPictureFrames, planFootagePicture } from "./picture.js";
|
|
53
55
|
import { describeProbe, getTrimmedDuration, probeFootage, type FootageProbe } from "./probe.js";
|
|
54
56
|
import {
|
|
@@ -849,6 +851,11 @@ async function runRenderFootage(
|
|
|
849
851
|
if (!prepared.ok) return prepared;
|
|
850
852
|
const musicAsset = musicFile === null ? null : "assets/music.mp3";
|
|
851
853
|
const fonts = copyFonts(options.brand.fonts, join(assetsDir, "fonts"));
|
|
854
|
+
// A note card and an end word are handwritten in the kit's own font, copied next to the brand's.
|
|
855
|
+
if (isHandFontNeeded(overlays.overlays)) {
|
|
856
|
+
mkdirSync(dirname(join(buildDir, HAND_FONT.asset)), { recursive: true });
|
|
857
|
+
cpSync(HAND_FONT.file, join(buildDir, HAND_FONT.asset));
|
|
858
|
+
}
|
|
852
859
|
// The logo card's own logo wins over the brand's; it keeps its extension, so a PNG is drawn as a PNG.
|
|
853
860
|
const logoSource = (film.endCard?.layout === "logo" ? film.endCard.logo : undefined) ?? options.brand.logo;
|
|
854
861
|
const logoAsset = logoSource === null ? null : `assets/logo${extname(logoSource).toLowerCase() || ".svg"}`;
|
|
@@ -859,7 +866,7 @@ async function runRenderFootage(
|
|
|
859
866
|
const layout = { ...base, caption: getFootageCaptionLayout(film, options.layout ?? {}) };
|
|
860
867
|
const missing = findMissingCaptionGlyphs({
|
|
861
868
|
fonts: options.brand.fonts,
|
|
862
|
-
captions: film.captions ? words.map((word) => word.text) : [],
|
|
869
|
+
captions: film.captions ? words.map((word) => toCaptionDisplayText(film, word.text, options.brand.locale)) : [],
|
|
863
870
|
overlays: getOverlayTextsByRole(overlays.overlays, options.brand.locale),
|
|
864
871
|
endCard: getEndCardTexts(film.endCard),
|
|
865
872
|
brandName: options.brand.name,
|
|
@@ -1163,10 +1170,13 @@ async function buildPicture(input: BuildPictureInput): Promise<void> {
|
|
|
1163
1170
|
mkdirSync(dir, { recursive: true });
|
|
1164
1171
|
const aborting = input.signal === undefined ? {} : { signal: input.signal };
|
|
1165
1172
|
const files: string[] = [];
|
|
1173
|
+
const frame = getFrame(input.film);
|
|
1174
|
+
const layers = writeSplitLayers(input.edl.segments, frame, dir);
|
|
1166
1175
|
for (const [index, piece] of pieces.entries()) {
|
|
1167
1176
|
const file = join(dir, `${String(index).padStart(3, "0")}.mp4`);
|
|
1168
1177
|
const done = piece.frame / FOOTAGE_FPS;
|
|
1169
|
-
|
|
1178
|
+
const layer = layers[input.edl.segments[index]?.id ?? ""];
|
|
1179
|
+
await runFfmpeg(`The picture of segment ${index + 1}`, buildPicturePieceArgs({ piece, clips: input.clips, frame, output: file, ...(input.encoder === undefined ? {} : { encoder: input.encoder }), ...(layer === undefined ? {} : { splitLayer: layer }) }), {
|
|
1170
1180
|
...aborting,
|
|
1171
1181
|
output: file,
|
|
1172
1182
|
onSeconds: (seconds) => input.onSeconds(done + seconds),
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { Resvg } from "@resvg/resvg-js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
import { HAND_FONT, measureHandText } from "./hand-font.js";
|
|
8
|
+
import { FOOTAGE_FPS, type Frame } from "./normalize.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A split screen: a segment's picture made of three shots stacked in horizontal bands, as reels compare three places.
|
|
12
|
+
* Each band plays its own clip from its own second for the segment's length, cropped to the band (a `focus` picks how
|
|
13
|
+
* high), and carries a short handwritten label with a drawn curved arrow pointing into it. The segment's sound stays
|
|
14
|
+
* its own (`clip`, or `audio`).
|
|
15
|
+
*
|
|
16
|
+
* The draft (`draft.ts`) and the render's picture (`picture.ts`) build the bands with one filter builder
|
|
17
|
+
* (`buildSplitScreenFilters`) and lay the same layer over them: the labels, the arrows and the thin lines between the
|
|
18
|
+
* bands drawn once as an SVG (`getSplitLayerSvg`) and rasterised by resvg at the path's frame size
|
|
19
|
+
* (`renderSplitLayerPng`), so both paths show the same picture. The handwriting is the kit's own hand font (Caveat,
|
|
20
|
+
* OFL); the arrows are curves made in code.
|
|
21
|
+
*
|
|
22
|
+
* The labels zig-zag: the top band's sits low on the left with its arrow rising into the shot, the middle band's high
|
|
23
|
+
* on the right, the bottom band's high on the left with arrows falling into theirs. That keeps the frame's top (the
|
|
24
|
+
* platform's header) and its foot (the platform's buttons) clear and leaves the lower half of the middle band free for
|
|
25
|
+
* the captions (`getSplitCaption`, `findSplitCaptionProblems`).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export const SPLIT_LAYOUTS = ["split3"] as const;
|
|
29
|
+
|
|
30
|
+
export type SplitLayout = (typeof SPLIT_LAYOUTS)[number];
|
|
31
|
+
|
|
32
|
+
/** How many bands a `split3` has. */
|
|
33
|
+
export const SPLIT_BANDS = 3;
|
|
34
|
+
|
|
35
|
+
/** The longest label, in characters; a label must also fit its width (`MAX_LABEL_WIDTH_SHARE` of the frame). */
|
|
36
|
+
export const MAX_SPLIT_LABEL_CHARACTERS = 24;
|
|
37
|
+
|
|
38
|
+
/** A label's handwriting size, in px of a 1080 px wide frame. */
|
|
39
|
+
const LABEL_SIZE = 60;
|
|
40
|
+
/** The widest a label may be, as a share of the frame's width (the arrow needs the rest). */
|
|
41
|
+
const MAX_LABEL_WIDTH_SHARE = 0.5;
|
|
42
|
+
/** A label's distance from the frame's side, in px of a 1080 px wide frame. */
|
|
43
|
+
const LABEL_SIDE = 64;
|
|
44
|
+
/** The arrow's stroke and its head's strokes, in px of a 1080 px wide frame. */
|
|
45
|
+
const ARROW_STROKE = 6;
|
|
46
|
+
const ARROW_HEAD = 30;
|
|
47
|
+
/** The line between two bands, in px of a 1080 px wide frame. */
|
|
48
|
+
const BAND_LINE = 4;
|
|
49
|
+
/** How far a label's shadow falls and blurs, in px of a 1080 px wide frame. */
|
|
50
|
+
const SHADOW_OFFSET = 3;
|
|
51
|
+
const SHADOW_BLUR = 4;
|
|
52
|
+
|
|
53
|
+
/** One band of a split screen: its clip, the second it starts from, its label, and how high the crop sits. */
|
|
54
|
+
export interface EdlSplitBand {
|
|
55
|
+
clip: string;
|
|
56
|
+
/** Seconds in the trimmed clip where the band's shot starts; it plays for the segment's length. */
|
|
57
|
+
start: number;
|
|
58
|
+
/** A short handwritten label (one line, at most `MAX_SPLIT_LABEL_CHARACTERS`). */
|
|
59
|
+
label: string;
|
|
60
|
+
/** Where the band's crop sits in the shot's height, 0 (its top) to 1 (its foot); absent: 0.5, the middle. */
|
|
61
|
+
focus?: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A segment's split screen (`EdlSegment.split`). */
|
|
65
|
+
export interface EdlSplit {
|
|
66
|
+
layout: SplitLayout;
|
|
67
|
+
bands: [EdlSplitBand, EdlSplitBand, EdlSplitBand];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const bandSchema = z.strictObject({
|
|
71
|
+
clip: z.string().min(1).describe("The band's clip id."),
|
|
72
|
+
start: z.number().min(0).describe("Seconds in that trimmed clip where the band's shot starts; it plays for the segment's length."),
|
|
73
|
+
label: z
|
|
74
|
+
.string()
|
|
75
|
+
.trim()
|
|
76
|
+
.min(1, "a band needs a label")
|
|
77
|
+
.max(MAX_SPLIT_LABEL_CHARACTERS, `a label is at most ${String(MAX_SPLIT_LABEL_CHARACTERS)} characters`)
|
|
78
|
+
.regex(/^[^\n\r]*$/, "a label is one line")
|
|
79
|
+
.describe(`A short handwritten label, one line, at most ${String(MAX_SPLIT_LABEL_CHARACTERS)} characters (a place's name).`),
|
|
80
|
+
focus: z.number().min(0).max(1).optional().describe("Where the band's crop sits in the shot's height: 0 its top, 1 its foot; 0.5 (the middle) without it."),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export const splitSchema = z
|
|
84
|
+
.strictObject({
|
|
85
|
+
layout: z.enum(SPLIT_LAYOUTS).describe("split3: three shots stacked in horizontal bands."),
|
|
86
|
+
bands: z.tuple([bandSchema, bandSchema, bandSchema]).describe("The three bands, top to bottom."),
|
|
87
|
+
})
|
|
88
|
+
.describe(
|
|
89
|
+
"A split screen: the segment's picture is three shots stacked in bands, each with a handwritten label and a drawn arrow; the segment's sound stays its own. Still (no camera, Ken Burns, zoom or stutter), not the cut's last segment, and the segment after it starts on a plain cut.",
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
/** A rectangle of the frame, in px. */
|
|
93
|
+
export interface SplitBox {
|
|
94
|
+
x: number;
|
|
95
|
+
y: number;
|
|
96
|
+
width: number;
|
|
97
|
+
height: number;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Where one band sits and where its label and arrow go, in px of the frame. */
|
|
101
|
+
export interface SplitBandPlace {
|
|
102
|
+
/** The band's rectangle (full width). */
|
|
103
|
+
band: SplitBox;
|
|
104
|
+
/** The label's side: its text starts at `x` (left) or ends at it (right). */
|
|
105
|
+
side: "left" | "right";
|
|
106
|
+
/** The label's baseline. */
|
|
107
|
+
labelX: number;
|
|
108
|
+
labelY: number;
|
|
109
|
+
/** Where the arrow points, in the band's shot. */
|
|
110
|
+
arrowTo: { x: number; y: number };
|
|
111
|
+
/** The stretch of the frame's height the label and its arrow take (captions keep off it). */
|
|
112
|
+
reserved: { top: number; bottom: number };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const round = (value: number): number => Math.round(value);
|
|
116
|
+
|
|
117
|
+
/** An even size of at least 2 px, as yuv420p needs. */
|
|
118
|
+
function toEven(value: number): number {
|
|
119
|
+
return Math.max(2, 2 * Math.floor(value / 2));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The three bands' heights: equal and even, the last one taking what rounding leaves. */
|
|
123
|
+
export function getSplitBandHeights(frame: Frame): [number, number, number] {
|
|
124
|
+
const band = toEven(frame.height / SPLIT_BANDS);
|
|
125
|
+
return [band, band, frame.height - 2 * band];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Each band's rectangle, label place and arrow target. The top band's label sits at 78 % of its height on the left,
|
|
130
|
+
* its arrow rising to the shot's middle; the middle band's at 24 % on the right and the bottom band's at 22 % on the
|
|
131
|
+
* left, their arrows falling into the shot.
|
|
132
|
+
*/
|
|
133
|
+
export function getSplitPlaces(frame: Frame): [SplitBandPlace, SplitBandPlace, SplitBandPlace] {
|
|
134
|
+
const scale = frame.width / 1080;
|
|
135
|
+
const heights = getSplitBandHeights(frame);
|
|
136
|
+
const tops = [0, heights[0], heights[0] + heights[1]];
|
|
137
|
+
const side = round(LABEL_SIDE * scale);
|
|
138
|
+
const label = LABEL_SIZE * scale;
|
|
139
|
+
const place = (index: 0 | 1 | 2): SplitBandPlace => {
|
|
140
|
+
const top = tops[index] as number;
|
|
141
|
+
const height = heights[index];
|
|
142
|
+
const band = { x: 0, y: top, width: frame.width, height };
|
|
143
|
+
if (index === 0) {
|
|
144
|
+
const labelY = round(top + 0.78 * height);
|
|
145
|
+
const arrowTo = { x: round(0.56 * frame.width), y: round(top + 0.42 * height) };
|
|
146
|
+
return { band, side: "left", labelX: side, labelY, arrowTo, reserved: { top: arrowTo.y, bottom: round(labelY + 0.35 * label) } };
|
|
147
|
+
}
|
|
148
|
+
const labelY = round(top + (index === 1 ? 0.24 : 0.22) * height);
|
|
149
|
+
const arrowTo = { x: round((index === 1 ? 0.42 : 0.58) * frame.width), y: round(top + (index === 1 ? 0.46 : 0.42) * height) };
|
|
150
|
+
return { band, side: index === 1 ? "right" : "left", labelX: index === 1 ? frame.width - side : side, labelY, arrowTo, reserved: { top: round(labelY - label), bottom: arrowTo.y } };
|
|
151
|
+
};
|
|
152
|
+
return [place(0), place(1), place(2)];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** How wide `label` is written, in px of the frame. */
|
|
156
|
+
function measureLabel(label: string, frame: Frame): number {
|
|
157
|
+
return measureHandText(label, LABEL_SIZE * (frame.width / 1080));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** What makes a split's labels unusable in this frame: a label too wide for its band (empty when they all fit). */
|
|
161
|
+
export function findSplitLabelProblems(split: EdlSplit, frame: Frame, at: string): string[] {
|
|
162
|
+
const limit = round(frame.width * MAX_LABEL_WIDTH_SHARE);
|
|
163
|
+
return split.bands.flatMap((band, index) => {
|
|
164
|
+
const width = measureLabel(band.label, frame);
|
|
165
|
+
return width > limit ? [`${at}.bands[${String(index)}].label: "${band.label}" is ${String(width)} px wide, more than ${String(limit)} px; shorten it`] : [];
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const f1 = (value: number): string => String(Math.round(value * 10) / 10);
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The arrow from the label's end to the band's shot: a curve bowed to one side, slightly uneven like a hand's stroke,
|
|
173
|
+
* and its head's two strokes along the curve's last direction.
|
|
174
|
+
*/
|
|
175
|
+
export function getSplitArrowPaths(from: { x: number; y: number }, to: { x: number; y: number }, scale: number): { curve: string; head: string } {
|
|
176
|
+
const dx = to.x - from.x;
|
|
177
|
+
const dy = to.y - from.y;
|
|
178
|
+
const length = Math.hypot(dx, dy) || 1;
|
|
179
|
+
// A normal that bows the curve away from the frame's centre line, a third of the way and two thirds unevenly.
|
|
180
|
+
const nx = -dy / length;
|
|
181
|
+
const ny = dx / length;
|
|
182
|
+
const bow = length * 0.22;
|
|
183
|
+
const c1 = { x: from.x + dx * 0.3 + nx * bow, y: from.y + dy * 0.3 + ny * bow };
|
|
184
|
+
const c2 = { x: from.x + dx * 0.72 + nx * bow * 0.8, y: from.y + dy * 0.72 + ny * bow * 0.8 };
|
|
185
|
+
const tx = to.x - c2.x;
|
|
186
|
+
const ty = to.y - c2.y;
|
|
187
|
+
const angle = Math.atan2(ty, tx);
|
|
188
|
+
const head = ARROW_HEAD * scale;
|
|
189
|
+
const wing = (turn: number): string => `M${f1(to.x - head * Math.cos(angle + turn))} ${f1(to.y - head * Math.sin(angle + turn))} L${f1(to.x)} ${f1(to.y)}`;
|
|
190
|
+
return {
|
|
191
|
+
curve: `M${f1(from.x)} ${f1(from.y)} C${f1(c1.x)} ${f1(c1.y)} ${f1(c2.x)} ${f1(c2.y)} ${f1(to.x)} ${f1(to.y)}`,
|
|
192
|
+
head: `${wing(0.5)} ${wing(-0.45)}`,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const escapeXml = (text: string): string => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
197
|
+
|
|
198
|
+
/** The layer over the bands, as an SVG of the frame's size: the lines between the bands, each label and its arrow. */
|
|
199
|
+
export function getSplitLayerSvg(split: EdlSplit, frame: Frame): string {
|
|
200
|
+
const scale = frame.width / 1080;
|
|
201
|
+
const places = getSplitPlaces(frame);
|
|
202
|
+
const line = BAND_LINE * scale;
|
|
203
|
+
const size = LABEL_SIZE * scale;
|
|
204
|
+
const gap = 18 * scale;
|
|
205
|
+
const parts: string[] = [];
|
|
206
|
+
for (const place of places.slice(1)) {
|
|
207
|
+
parts.push(`<rect x="0" y="${f1(place.band.y - line / 2)}" width="${String(frame.width)}" height="${f1(line)}" fill="#111111"/>`);
|
|
208
|
+
}
|
|
209
|
+
split.bands.forEach((band, index) => {
|
|
210
|
+
const place = places[index] as SplitBandPlace;
|
|
211
|
+
const width = measureLabel(band.label, frame);
|
|
212
|
+
const isLeft = place.side === "left";
|
|
213
|
+
// The arrow starts beside the label's end, at its x-height, and points into the shot.
|
|
214
|
+
const from = { x: isLeft ? place.labelX + width + gap : place.labelX - width - gap, y: place.labelY - (index === 0 ? size * 0.55 : size * 0.2) };
|
|
215
|
+
const arrow = getSplitArrowPaths(from, place.arrowTo, scale);
|
|
216
|
+
parts.push(
|
|
217
|
+
`<g filter="url(#shadow)">`,
|
|
218
|
+
`<text x="${f1(place.labelX)}" y="${f1(place.labelY)}" text-anchor="${isLeft ? "start" : "end"}" font-family="${HAND_FONT.family}" font-weight="600" font-size="${f1(size)}" fill="#ffffff">${escapeXml(band.label)}</text>`,
|
|
219
|
+
`<path d="${arrow.curve}" fill="none" stroke="#ffffff" stroke-width="${f1(ARROW_STROKE * scale)}" stroke-linecap="round"/>`,
|
|
220
|
+
`<path d="${arrow.head}" fill="none" stroke="#ffffff" stroke-width="${f1(ARROW_STROKE * scale)}" stroke-linecap="round" stroke-linejoin="round"/>`,
|
|
221
|
+
`</g>`,
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
const shadow = `<filter id="shadow" x="-10%" y="-10%" width="120%" height="120%"><feDropShadow dx="0" dy="${f1(SHADOW_OFFSET * scale)}" stdDeviation="${f1(SHADOW_BLUR * scale)}" flood-color="#000000" flood-opacity="0.55"/></filter>`;
|
|
225
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${String(frame.width)}" height="${String(frame.height)}" viewBox="0 0 ${String(frame.width)} ${String(frame.height)}"><defs>${shadow}</defs>${parts.join("")}</svg>`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The layer as a transparent PNG of the frame's size, drawn by resvg with the kit's hand font only. */
|
|
229
|
+
export function renderSplitLayerPng(split: EdlSplit, frame: Frame): Buffer {
|
|
230
|
+
const svg = getSplitLayerSvg(split, frame);
|
|
231
|
+
return new Resvg(svg, { fitTo: { mode: "original" }, font: { loadSystemFonts: false, fontFiles: [HAND_FONT.file], defaultFontFamily: HAND_FONT.family } }).render().asPng();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Writes each split segment's layer into `dir` at `frame`'s size (`split-<segment id>.png`) and answers the file
|
|
236
|
+
* names by segment id, joined to `dir` (or bare with `isRelative`, for an ffmpeg run in `dir`). None without a split.
|
|
237
|
+
*/
|
|
238
|
+
export function writeSplitLayers(segments: readonly { id: string; split?: EdlSplit | undefined }[], frame: Frame, dir: string, isRelative = false): Record<string, string> {
|
|
239
|
+
const files: Record<string, string> = {};
|
|
240
|
+
for (const segment of segments) {
|
|
241
|
+
if (segment.split === undefined) continue;
|
|
242
|
+
const name = `split-${segment.id}.png`;
|
|
243
|
+
writeFileSync(join(dir, name), renderSplitLayerPng(segment.split, frame));
|
|
244
|
+
files[segment.id] = isRelative ? name : join(dir, name);
|
|
245
|
+
}
|
|
246
|
+
return files;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface SplitScreenFiltersInput {
|
|
250
|
+
/** The three bands' input labels (their clips, already seeked to the band's start). */
|
|
251
|
+
inputs: readonly [string, string, string];
|
|
252
|
+
/** The layer's input label (`renderSplitLayerPng` looped as a video). */
|
|
253
|
+
layer: string;
|
|
254
|
+
split: EdlSplit;
|
|
255
|
+
frame: Frame;
|
|
256
|
+
/** Filters each band runs after its crop (frame rate, length), the same for all three. */
|
|
257
|
+
fit: readonly string[];
|
|
258
|
+
/** The label the composed picture goes out on (yuv420p, the frame's size). */
|
|
259
|
+
output: string;
|
|
260
|
+
/** A prefix for the graph's inner labels, unique in the graph. */
|
|
261
|
+
prefix: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The filter chains (to join with `;`) that crop each shot to its band (scaled to cover it, the crop at its `focus`),
|
|
266
|
+
* stack the three and lay the layer over them.
|
|
267
|
+
*/
|
|
268
|
+
export function buildSplitScreenFilters(input: SplitScreenFiltersInput): string[] {
|
|
269
|
+
const { frame, prefix: p } = input;
|
|
270
|
+
const heights = getSplitBandHeights(frame);
|
|
271
|
+
const bands = input.split.bands.map((band, index) => {
|
|
272
|
+
const height = heights[index] as number;
|
|
273
|
+
const focus = band.focus ?? 0.5;
|
|
274
|
+
const chain = [
|
|
275
|
+
`scale=${String(frame.width)}:${String(height)}:force_original_aspect_ratio=increase`,
|
|
276
|
+
`crop=${String(frame.width)}:${String(height)}:(iw-ow)/2:(ih-oh)*${String(focus)}`,
|
|
277
|
+
"setsar=1",
|
|
278
|
+
...input.fit,
|
|
279
|
+
];
|
|
280
|
+
return `[${input.inputs[index] as string}]${chain.join(",")}[${p}b${String(index)}]`;
|
|
281
|
+
});
|
|
282
|
+
return [
|
|
283
|
+
...bands,
|
|
284
|
+
`[${p}b0][${p}b1][${p}b2]vstack=inputs=3[${p}stack]`,
|
|
285
|
+
`[${input.layer}]format=rgba[${p}layer]`,
|
|
286
|
+
`[${p}stack][${p}layer]overlay=0:0:format=auto:shortest=1,format=yuv420p,setsar=1,settb=1/${String(FOOTAGE_FPS)},setpts=N,fps=${String(FOOTAGE_FPS)}[${input.output}]`,
|
|
287
|
+
];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** The ffmpeg input of a layer PNG: one image looped at the film's rate for `seconds`. */
|
|
291
|
+
export function getSplitLayerInputArgs(file: string, seconds: number, fps: number): string[] {
|
|
292
|
+
return ["-loop", "1", "-framerate", String(fps), "-t", String(seconds), "-i", file];
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* The caption box a split segment takes so its captions sit in the lower half of the middle band, clear of every
|
|
297
|
+
* label and arrow: its foot at 94 % of the middle band's height, in px above the frame's foot.
|
|
298
|
+
*/
|
|
299
|
+
export function getSplitCaption(frame: Frame): { bottom: number } {
|
|
300
|
+
const places = getSplitPlaces(frame);
|
|
301
|
+
const middle = places[1].band;
|
|
302
|
+
return { bottom: frame.height - round(middle.y + 0.94 * middle.height) };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Whether a caption box (its foot or its top, and the height of a card of `lines` lines) would cover a split's label
|
|
307
|
+
* or arrow: the stretch of the frame's height it takes against every band's reserved stretch. Empty when clear.
|
|
308
|
+
*/
|
|
309
|
+
export function findSplitCaptionProblems(input: { at: string; caption: { bottom?: number; top?: number } | undefined; frame: Frame; cardHeight: number; lines?: number }): string[] {
|
|
310
|
+
const { caption, frame } = input;
|
|
311
|
+
const at = `${input.at}.caption`;
|
|
312
|
+
if (caption?.bottom === undefined && caption?.top === undefined) return [`${at}: a split screen sets its own caption box, clear of its labels (bottom ${String(getSplitCaption(frame).bottom)} px puts the captions in the middle band)`];
|
|
313
|
+
const height = input.cardHeight * (input.lines ?? 2);
|
|
314
|
+
const foot = caption.bottom === undefined ? (caption.top as number) + height : frame.height - caption.bottom;
|
|
315
|
+
const top = caption.bottom === undefined ? (caption.top as number) : foot - height;
|
|
316
|
+
const covered = getSplitPlaces(frame).findIndex((place) => top < place.reserved.bottom && place.reserved.top < foot);
|
|
317
|
+
if (covered === -1) return [];
|
|
318
|
+
return [`${at}: the captions (${String(round(top))}-${String(round(foot))} px) would cover band ${String(covered + 1)}'s label or arrow; bottom ${String(getSplitCaption(frame).bottom)} px puts them in the middle band`];
|
|
319
|
+
}
|
package/src/footage/tools.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface FootageToolsOptions {
|
|
|
36
36
|
export const REQUIRED_DECODERS = ["hevc", "h264"] as const;
|
|
37
37
|
export const REQUIRED_FILTERS = ["zscale", "tonemap", "lut3d"] as const;
|
|
38
38
|
/** What the fast draft needs on top: libass (with libfreetype) for the captions, `xfade` for fades, `zoompan` for Ken Burns. */
|
|
39
|
-
export const DRAFT_FILTERS = ["ass", "xfade", "zoompan"] as const;
|
|
39
|
+
export const DRAFT_FILTERS = ["ass", "xfade", "zoompan", "gblur", "geq", "rotate", "blend", "noise", "interleave", "hstack", "vstack"] as const;
|
|
40
40
|
|
|
41
41
|
const DRAFT_INSTALL_HINT = "install an ffmpeg built with libass and libfreetype (macOS: brew install ffmpeg, Debian/Ubuntu: apt install ffmpeg)";
|
|
42
42
|
const INSTALL_HINT = "install an ffmpeg built with libzimg (macOS: brew install ffmpeg, Debian/Ubuntu: apt install ffmpeg)";
|
package/src/index.ts
CHANGED
|
@@ -102,6 +102,13 @@ export {
|
|
|
102
102
|
OVERLAY_PINS,
|
|
103
103
|
OVERLAY_LIST_LAYOUTS,
|
|
104
104
|
MAX_OVERLAY_SUBTITLE_DELAY,
|
|
105
|
+
MAX_END_WORD_SECONDS,
|
|
106
|
+
MAX_OVERLAY_END_WORD_LENGTH,
|
|
107
|
+
MAX_OVERLAY_NOTE_LENGTH,
|
|
108
|
+
MIN_END_WORD_SECONDS,
|
|
109
|
+
OVERLAY_BACKDROP_KINDS,
|
|
110
|
+
OVERLAY_BACKDROPS,
|
|
111
|
+
OVERLAY_NOTE_STYLES,
|
|
105
112
|
OVERLAY_KINDS,
|
|
106
113
|
OVERLAY_POSITIONS,
|
|
107
114
|
OVERLAY_POSITIONS_BY_KIND,
|
|
@@ -115,7 +122,9 @@ export {
|
|
|
115
122
|
type EdlOverlayStyle,
|
|
116
123
|
type EdlOverlayWord,
|
|
117
124
|
type OverlayAlign,
|
|
125
|
+
type OverlayBackdrop,
|
|
118
126
|
type OverlayKeywordAlign,
|
|
127
|
+
type OverlayNoteStyle,
|
|
119
128
|
type OverlayEasing,
|
|
120
129
|
type OverlayEntrance,
|
|
121
130
|
type OverlayExit,
|
|
@@ -148,6 +157,7 @@ export {
|
|
|
148
157
|
type StyleShadow,
|
|
149
158
|
} from "./footage/brand-style.js";
|
|
150
159
|
export { createDraftTextMeasure, wrapDraftLine, type DraftTextMeasure } from "./footage/draft-text-width.js";
|
|
160
|
+
export { HAND_FONT } from "./footage/hand-font.js";
|
|
151
161
|
export {
|
|
152
162
|
OVERLAY_FONT_ROLES,
|
|
153
163
|
OVERLAY_FONT_SIZES,
|
|
@@ -172,6 +182,11 @@ export {
|
|
|
172
182
|
getOverlaySafeZone,
|
|
173
183
|
getOverlayTexts,
|
|
174
184
|
getOverlayTextsByRole,
|
|
185
|
+
getNoteColors,
|
|
186
|
+
isHandFontNeeded,
|
|
187
|
+
isTitleBand,
|
|
188
|
+
timeNote,
|
|
189
|
+
wrapNoteText,
|
|
175
190
|
resolveEdlOverlays,
|
|
176
191
|
type OverlayBox,
|
|
177
192
|
type OverlayFontRole,
|
|
@@ -188,6 +203,8 @@ export {
|
|
|
188
203
|
getEntranceScaleAt,
|
|
189
204
|
getExitMotion,
|
|
190
205
|
getListItemStarts,
|
|
206
|
+
getDropLetterTimes,
|
|
207
|
+
getDropOffsetAt,
|
|
191
208
|
type OverlayEase,
|
|
192
209
|
type OverlayEntranceMotion,
|
|
193
210
|
type OverlayExitMotion,
|
|
@@ -366,6 +383,9 @@ export {
|
|
|
366
383
|
CAPTION_MIN_FONT_SCALE,
|
|
367
384
|
CAPTION_PRESETS,
|
|
368
385
|
CAPTION_STYLES,
|
|
386
|
+
CAPTION_RIBBON,
|
|
387
|
+
CAPTION_RIBBON_MAX_TILT,
|
|
388
|
+
CAPTION_RIBBON_TILT,
|
|
369
389
|
CAPTION_HIGHLIGHT_STYLES,
|
|
370
390
|
CAPTION_ENTRANCES,
|
|
371
391
|
DEFAULT_EDIT,
|
|
@@ -559,6 +579,44 @@ export {
|
|
|
559
579
|
type CameraEase,
|
|
560
580
|
type EdlCamera,
|
|
561
581
|
} from "./footage/camera.js";
|
|
582
|
+
export {
|
|
583
|
+
DRAWN_TRANSITIONS,
|
|
584
|
+
DRAWN_TRANSITION_FRAMES,
|
|
585
|
+
FRAME_TIMING,
|
|
586
|
+
PAPER_FADE_FRAMES,
|
|
587
|
+
STUTTER_FRAMES,
|
|
588
|
+
STUTTER_SCALE,
|
|
589
|
+
WHIP_OUT_FRAMES,
|
|
590
|
+
buildDrawnTransitionFilters,
|
|
591
|
+
getCardFrame,
|
|
592
|
+
getTransitionOverlapFrames,
|
|
593
|
+
isDrawnTransition,
|
|
594
|
+
type DrawnTransition,
|
|
595
|
+
type DrawnTransitionFiltersInput,
|
|
596
|
+
} from "./footage/drawn-transitions.js";
|
|
597
|
+
export {
|
|
598
|
+
MAX_SPLIT_LABEL_CHARACTERS,
|
|
599
|
+
SPLIT_BANDS,
|
|
600
|
+
SPLIT_LAYOUTS,
|
|
601
|
+
buildSplitScreenFilters,
|
|
602
|
+
findSplitCaptionProblems,
|
|
603
|
+
findSplitLabelProblems,
|
|
604
|
+
getSplitArrowPaths,
|
|
605
|
+
getSplitBandHeights,
|
|
606
|
+
getSplitCaption,
|
|
607
|
+
getSplitLayerInputArgs,
|
|
608
|
+
getSplitLayerSvg,
|
|
609
|
+
getSplitPlaces,
|
|
610
|
+
renderSplitLayerPng,
|
|
611
|
+
splitSchema,
|
|
612
|
+
writeSplitLayers,
|
|
613
|
+
type EdlSplit,
|
|
614
|
+
type EdlSplitBand,
|
|
615
|
+
type SplitBandPlace,
|
|
616
|
+
type SplitBox,
|
|
617
|
+
type SplitLayout,
|
|
618
|
+
type SplitScreenFiltersInput,
|
|
619
|
+
} from "./footage/split-screen.js";
|
|
562
620
|
export { findRetakes, splitFilmSentences, splitSentences, type RetakeKind, type RetakeSuggestion, type Sentence } from "./footage/sentences.js";
|
|
563
621
|
export {
|
|
564
622
|
CAPTION_SAFE_ZONES,
|
|
@@ -570,6 +628,9 @@ export {
|
|
|
570
628
|
getCaptionKeepsWithNext,
|
|
571
629
|
getFootageCaptionChunks,
|
|
572
630
|
getCaptionPresetLayout,
|
|
631
|
+
getCaptionRibbonTilt,
|
|
632
|
+
getRibbonCaptionExtent,
|
|
633
|
+
toCaptionDisplayText,
|
|
573
634
|
getCaptionSpans,
|
|
574
635
|
getFootageCaptionLayout,
|
|
575
636
|
getSegmentCaptionLayout,
|
|
@@ -580,6 +641,7 @@ export {
|
|
|
580
641
|
type MissingCaptionGlyphs,
|
|
581
642
|
type PhraseChunk,
|
|
582
643
|
type PhraseChunkOptions,
|
|
644
|
+
type RibbonCaptionExtent,
|
|
583
645
|
type SafeZone,
|
|
584
646
|
} from "./footage/captions.js";
|
|
585
647
|
export {
|