@softure-ai/marketing-kit 0.36.2 → 0.37.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 CHANGED
@@ -4,6 +4,25 @@ Newest first. Each version lists what changed for an app that uses `@softure-ai/
4
4
  production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
5
5
  "Definition of done"). Versions before the first one below are described in their GitHub Releases (`marketing-kit@x.y.z`).
6
6
 
7
+ ## 0.37.0
8
+
9
+ - **Draft in pieces:** `renderFootageDraft` takes `assembly`: `"pieces"` (the new default) draws the picture
10
+ `segmentsPerPiece` segments per ffmpeg run (default `FOOTAGE_DRAFT_PIECE_SEGMENTS`, 4) and joins the pieces with the
11
+ captions burned in once, so its memory is one piece's whatever the number of cuts; `"single"` keeps the one ffmpeg
12
+ run, its command byte for byte as before (a test pins it), whose memory grows with every cut (a 146 s cut of 51
13
+ segments from 1080x1920 sources needs about 3.8 GB). A piece that starts on a fade or a drawn transition draws the
14
+ segment before it and cuts it away, so both assemblies give the same frames at every border. The result names its
15
+ `assembly` and `pieces`. A failed piece's step is `The footage draft's piece N of M` (one run's stays
16
+ `The footage draft`). An app that wants the old behaviour passes `assembly: "single"`.
17
+ - **Memory estimate:** `estimateFootageDraftMemory({ edl, frame, assembly, segmentsPerPiece })` answers the decoders
18
+ of the draft's largest ffmpeg run and its peak working memory by the kit's estimate (250 MB plus about 70 MB per
19
+ decoder of a 1080x1920 source), for an app that warns before a draft its worker cannot hold.
20
+ - **New builders:** `planFootageDraftPieces`, `buildFootageDraftPieceArgs`, `buildFootageDraftJoinArgs`,
21
+ `FOOTAGE_DRAFT_ASSEMBLIES`, types `DraftPiece`, `FootageDraftAssembly`, `FootageDraftMemory`.
22
+ - **Tests:** `tests/draft-assembly.test.ts` compares both assemblies frame by frame on a cut with every transition and
23
+ a split screen, and measures each ffmpeg run's peak memory: drafts of 51 and 150 cuts in pieces stay at one piece's,
24
+ where one run grows with the cuts.
25
+
7
26
  ## 0.36.2
8
27
 
9
28
  - **Security (CodeQL `js/bad-code-sanitization`, #1245):** the dropped-letter tween writes its letter turns into the
package/README.md CHANGED
@@ -1303,9 +1303,24 @@ import { checkFootageTools, cutFootage, prepareFootage, renderFootageDraft, tran
1303
1303
 
1304
1304
  const problems = await checkFootageTools({ needsRender: false, needsDraft: true }); // ass (libass + libfreetype), xfade, zoompan
1305
1305
  const draft = await renderFootageDraft(film, clips, transcript, edl, { buildDir, output: "draft.mp4", width: 540, brand, cacheDir, providers, log, signal: job.signal, onProgress });
1306
- // draft.value: { output, music, captionFont, seconds, width, height, bytes, declick, loudness, mix }: H.264 yuv420p and AAC with fast start, exactly the cut's length
1306
+ // draft.value: { output, music, captionFont, seconds, assembly, pieces, width, height, bytes, declick, loudness, mix }: H.264 yuv420p and AAC with fast start, exactly the cut's length
1307
1307
  ```
1308
1308
 
1309
+ **Assembly, pieces or one run (`assembly`).** By default (`"pieces"`) the picture is drawn `segmentsPerPiece`
1310
+ segments at a time (`FOOTAGE_DRAFT_PIECE_SEGMENTS`, 4), each piece by its own short ffmpeg into
1311
+ `<buildDir>/draft/pieces/`, then the pieces are joined by the concat demuxer with the captions burned in once over the
1312
+ whole film and the sound muxed. A piece whose first segment starts on a fade or a drawn transition starts its graph one
1313
+ segment early and cuts that segment away, so the outgoing tail plays under it exactly as in one run: the frames match
1314
+ the one-run draft within the second encode's grain (a test compares them at every border). Memory is one piece's
1315
+ (five decoders at most, plus a split screen's bands) whatever the cut's length; a draft of 150 cuts costs what one of
1316
+ 50 does, and takes a little longer. `"single"` draws the whole cut in one ffmpeg run (`buildFootageDraftArgs`,
1317
+ unchanged): faster, but every segment keeps its decoder for the whole run, so memory grows with the number of cuts
1318
+ (about 70 MB per cut of a 1080x1920 source). `estimateFootageDraftMemory({ edl, frame, assembly })` answers the
1319
+ largest run's decoders and its peak by that estimate, so an app can warn before a draft its worker cannot hold.
1320
+ `planFootageDraftPieces`, `buildFootageDraftPieceArgs` and `buildFootageDraftJoinArgs` are the pure builders of the
1321
+ pieces. The pieces are removed after the join; a failed draft leaves them in the draft folder for its snapshot, and a
1322
+ failed piece's step is named `The footage draft's piece N of M`.
1323
+
1309
1324
  What the draft matches and what it leaves out:
1310
1325
 
1311
1326
  - **Captions follow `captionStyle`.** The cards are the render's (`getFootageCaptionChunks`, kept words included). `phrase`: the render's phrases in white with a dark outline and shadow.
@@ -1338,10 +1353,12 @@ What the draft matches and what it leaves out:
1338
1353
  `warning` on a near miss) and `mix` (what the stage did); a mix that misses its target fails with
1339
1354
  `{ kind: "loudness" }`. `loudness: null` and `mixLoudness: null` skip those stages as in the render.
1340
1355
  - **Left out:** the end card, the cover and the sound effects (whoosh, pop); the mix has speech and music only.
1341
- - `buildFootageDraftArgs`, `buildFootageDraftCaptions` (an ASS file) and `planFootageDraft` are the pure builders, for an
1342
- app that runs ffmpeg its own way. ffmpeg runs in `<buildDir>/draft/`, so the captions and font paths are relative.
1356
+ - `buildFootageDraftArgs` (one run), `buildFootageDraftPieceArgs` and `buildFootageDraftJoinArgs` (pieces),
1357
+ `buildFootageDraftCaptions` (an ASS file), `planFootageDraft` and `planFootageDraftPieces` are the pure builders, for
1358
+ an app that runs ffmpeg its own way. ffmpeg runs in `<buildDir>/draft/`, so the captions and font paths are relative.
1343
1359
  - `onProgress` reports the stage `draft` (the speech track, its declick when the film sets one, its loudness pass, the
1344
- music track when it plays, the mix, then the film).
1360
+ music track when it plays, the mix, then the film; in pieces the pieces take the film's first 80 % and the join the
1361
+ rest).
1345
1362
  - `threads` sets ffmpeg's threads for every segment's decoder, the filter graph and the encoder. ffmpeg otherwise
1346
1363
  follows the host's cores, not a container's CPU quota, and the draft opens one decoder per segment: pass the
1347
1364
  worker's CPU limit (`threads: 1` on a 1-CPU worker), as with `normalize.threads`. The extra threads buy no speed
@@ -167,12 +167,87 @@ export interface DraftSegmentPlan {
167
167
  */
168
168
  export declare function planFootageDraft(film: Pick<FootageFilm, "edit">, edl: Edl, overlays?: readonly ResolvedOverlay[]): DraftSegmentPlan[];
169
169
  /**
170
- * The ffmpeg arguments of the draft: each segment read from its own seek into its clip, zoomed and scaled to the
171
- * draft's width, joined by `xfade` at `fade` cuts and `concat` at the others, the captions burned in (`ass`), the
172
- * film's mix copied under it (or the speech and music tracks mixed and encoded to AAC); H.264 yuv420p with fast start,
173
- * exactly the cut's length.
170
+ * The ffmpeg arguments of the draft in one run (`assembly: "single"`): each segment read from its own seek into its
171
+ * clip, zoomed and scaled to the draft's width, joined by `xfade` at `fade` cuts and `concat` at the others, the
172
+ * captions burned in (`ass`), the film's mix copied under it (or the speech and music tracks mixed and encoded to AAC);
173
+ * H.264 yuv420p with fast start, exactly the cut's length. Every segment keeps its own decoder for the whole run, so
174
+ * its memory grows with the number of cuts (`estimateFootageDraftMemory`).
174
175
  */
175
176
  export declare function buildFootageDraftArgs(input: FootageDraftArgsInput): string[];
177
+ /** How a footage draft's picture is assembled: in pieces then joined (bounded memory), or in one ffmpeg run. */
178
+ export declare const FOOTAGE_DRAFT_ASSEMBLIES: readonly ["pieces", "single"];
179
+ export type FootageDraftAssembly = (typeof FOOTAGE_DRAFT_ASSEMBLIES)[number];
180
+ /** How many segments a piece of a `pieces` draft holds by default: one ffmpeg run decodes at most these (and a lead). */
181
+ export declare const FOOTAGE_DRAFT_PIECE_SEGMENTS = 4;
182
+ /** One piece of a `pieces` draft: a run of whole segments, cut out of a graph that may start one segment earlier. */
183
+ export interface DraftPiece {
184
+ /** The piece's first and last segment. */
185
+ first: number;
186
+ last: number;
187
+ /**
188
+ * The segment the piece's graph starts from: `first - 1` when segment `first` starts on a fade or a drawn transition
189
+ * (its outgoing tail plays under it, as in the one-run draft), `first` otherwise.
190
+ */
191
+ from: number;
192
+ /** The frames of the graph's stream before segment `first`: the lead segment's own, trimmed away. */
193
+ skipFrames: number;
194
+ /** The piece's first film frame and its frame count: the pieces cover the cut's frames without a gap. */
195
+ frame: number;
196
+ frames: number;
197
+ }
198
+ /**
199
+ * The pieces of a `pieces` draft: `segmentsPerPiece` segments each (a positive whole number), the last piece what is
200
+ * left. Throws on an EDL without segments.
201
+ */
202
+ export declare function planFootageDraftPieces(plans: readonly DraftSegmentPlan[], seconds: number, segmentsPerPiece?: number): DraftPiece[];
203
+ export interface FootageDraftPieceArgsInput extends Omit<FootageDraftArgsInput, "speech" | "music" | "mix" | "captions" | "fontsDir"> {
204
+ piece: DraftPiece;
205
+ }
206
+ /**
207
+ * One piece's ffmpeg arguments: its segments (and a lead segment's tail) as the one-run draft draws them, cut to the
208
+ * piece's own frames, H.264 without sound or captions. A piece decodes only its own segments, so its memory does not
209
+ * grow with the cut.
210
+ */
211
+ export declare function buildFootageDraftPieceArgs(input: FootageDraftPieceArgsInput): string[];
212
+ export interface FootageDraftJoinArgsInput extends Pick<FootageDraftArgsInput, "speech" | "music" | "mix" | "captions" | "fontsDir" | "threads" | "output"> {
213
+ /** The concat demuxer's list of the pieces (`buildPictureList`). */
214
+ list: string;
215
+ /** The cut's length. */
216
+ seconds: number;
217
+ }
218
+ /**
219
+ * The join of a `pieces` draft: the pieces read one after the other by the concat demuxer (one decoder), the captions
220
+ * burned in once over the whole film, the sound as the one-run draft takes it, the same encoder and length.
221
+ */
222
+ export declare function buildFootageDraftJoinArgs(input: FootageDraftJoinArgsInput): string[];
223
+ export interface FootageDraftMemoryInput {
224
+ /** The cut's segments; only a split screen's bands count (each opens its own decoder). */
225
+ edl: {
226
+ segments: readonly {
227
+ split?: {
228
+ bands: readonly unknown[];
229
+ } | undefined;
230
+ }[];
231
+ };
232
+ /** The normalized clips' frame (the film's): a decoder's memory grows with its pixels. */
233
+ frame: Frame;
234
+ assembly: FootageDraftAssembly;
235
+ /** The segments of a piece (`pieces`); default `FOOTAGE_DRAFT_PIECE_SEGMENTS`. */
236
+ segmentsPerPiece?: number;
237
+ }
238
+ /** What a draft's largest ffmpeg run decodes at once, and the working memory that takes by the kit's estimate. */
239
+ export interface FootageDraftMemory {
240
+ /** The decoders of the largest run: every segment's (three for a split screen) in `single`, a piece's in `pieces`. */
241
+ decoders: number;
242
+ /** The estimated peak working memory of that run, in MB (`250 + decoders x 70 x pixels / 1080x1920`). */
243
+ peakMb: number;
244
+ }
245
+ /**
246
+ * The draft's peak memory by the kit's estimate, before it runs: a `single` draft opens every segment's decoder at
247
+ * once, a `pieces` draft at most one piece's (with a lead segment). An app compares it with its worker's memory limit
248
+ * and warns before a draft that would not fit.
249
+ */
250
+ export declare function estimateFootageDraftMemory(input: FootageDraftMemoryInput): FootageDraftMemory;
176
251
  export interface RenderFootageDraftOptions extends Pick<FootageRunOptions, "buildDir" | "log" | "signal" | "onProgress" | "onFfmpegFailure">, Partial<Pick<FootageRunOptions, "cacheDir" | "providers">> {
177
252
  /** The draft MP4. */
178
253
  output: string;
@@ -196,6 +271,15 @@ export interface RenderFootageDraftOptions extends Pick<FootageRunOptions, "buil
196
271
  * own choice, which follows the host's cores. Set it from a CPU-limited container's quota.
197
272
  */
198
273
  threads?: number;
274
+ /**
275
+ * How the picture is assembled. `pieces` (the default): `segmentsPerPiece` segments per ffmpeg run, written to
276
+ * `<buildDir>/draft/pieces/` and joined with the captions burned in once, so the memory is one piece's whatever the
277
+ * cut's length; slower. `single`: one ffmpeg run over the whole cut (`buildFootageDraftArgs`), faster, its memory
278
+ * growing with the number of cuts (`estimateFootageDraftMemory`).
279
+ */
280
+ assembly?: FootageDraftAssembly;
281
+ /** The segments of a piece in `pieces`; default `FOOTAGE_DRAFT_PIECE_SEGMENTS`. A positive whole number. */
282
+ segmentsPerPiece?: number;
199
283
  }
200
284
  /** The draft's music: the film has none, it played (a file, or generated music from the cache), or it is not cached yet. */
201
285
  export type FootageDraftMusic = "none" | "played" | "not_cached";
@@ -206,6 +290,9 @@ export interface FootageDraft {
206
290
  captionFont: string | null;
207
291
  /** The draft's length: the cut's. */
208
292
  seconds: number;
293
+ /** How the picture was assembled, and in how many pieces (1 for `single`). */
294
+ assembly: FootageDraftAssembly;
295
+ pieces: number;
209
296
  width: number;
210
297
  height: number;
211
298
  bytes: number;
@@ -221,8 +308,9 @@ export interface FootageDraft {
221
308
  }
222
309
  /**
223
310
  * Makes the draft of a cut film: the speech track, the ducked music track (when it costs nothing), the captions file
224
- * and its font in `<buildDir>/draft/`, then one ffmpeg run (`buildFootageDraftArgs`). Spends nothing: no provider is
225
- * called; takes the same clips, transcript and EDL as `renderFootage`.
311
+ * and its font in `<buildDir>/draft/`, then the picture: in pieces joined with the captions (`assembly: "pieces"`, the
312
+ * default, memory bounded by one piece) or in one ffmpeg run (`"single"`, `buildFootageDraftArgs`). Spends nothing: no
313
+ * provider is called; takes the same clips, transcript and EDL as `renderFootage`.
226
314
  */
227
315
  export declare function renderFootageDraft(film: FootageFilm, clips: PreparedClip[], transcript: Extract<TranscribeOutcome, {
228
316
  kind: "ready";
@@ -1 +1 @@
1
- {"version":3,"file":"draft.d.ts","sourceRoot":"","sources":["../../src/footage/draft.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAA6J,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjN,OAAO,EAAkE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEhI,OAAO,EAAyG,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGrK,OAAO,EAA8D,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE/G,OAAO,EAAyC,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIrG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAsB,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAE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CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,iBAAiB,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAE1N"}
@@ -26,6 +26,7 @@ import { duckingKeyframes, getDuckingOptions } from "./music.js";
26
26
  import { buildSplitScreenFilters, getSplitLayerInputArgs, writeSplitLayers } from "./split-screen.js";
27
27
  import { FOOTAGE_FPS, getThreadArgs } from "./normalize.js";
28
28
  import { findFootageMusic, getFfmpegReporting, getFrame, getSpeechChainFiles, mixFootage, } from "./pipeline.js";
29
+ import { buildPictureList } from "./picture.js";
29
30
  import { runFfmpeg, withFfmpegFailureReporting } from "./process.js";
30
31
  import { buildMusicArgs, buildSpeechArgs, getSpeechCutOptions } from "./render.js";
31
32
  /**
@@ -440,8 +441,7 @@ function buildPictureFilters(plan, draft) {
440
441
  * incoming segment follows.
441
442
  */
442
443
  function buildDrawnJoin(input) {
443
- const { joined, incoming, output, drawn, index } = input;
444
- const at = Math.round(input.plan.start * FOOTAGE_FPS);
444
+ const { joined, incoming, output, drawn, index, at } = input;
445
445
  const p = `d${String(index)}`;
446
446
  return [
447
447
  `[${joined}]split[${p}a][${p}b]`,
@@ -456,16 +456,12 @@ function buildDrawnJoin(input) {
456
456
  ];
457
457
  }
458
458
  /**
459
- * The ffmpeg arguments of the draft: each segment read from its own seek into its clip, zoomed and scaled to the
460
- * draft's width, joined by `xfade` at `fade` cuts and `concat` at the others, the captions burned in (`ass`), the
461
- * film's mix copied under it (or the speech and music tracks mixed and encoded to AAC); H.264 yuv420p with fast start,
462
- * exactly the cut's length.
459
+ * Segments `first` to `last` read from their clips, zoomed and joined as the draft joins them (`xfade` at a fade,
460
+ * `concat` at the others, a drawn transition blended in), on a stream that starts at segment `first`'s start. The
461
+ * whole cut (`first` 0) gives exactly the one-run draft's graph.
463
462
  */
464
- export function buildFootageDraftArgs(input) {
463
+ function buildDraftPictureGraph({ input, plans, draft, threads, first, last }) {
465
464
  const { edl } = input;
466
- const draft = getFootageDraftFrame(input.frame, input.width);
467
- const plans = planFootageDraft(input.film, edl, input.overlays ?? []);
468
- const threads = getThreadArgs(input.threads, "draft.threads");
469
465
  const inputs = [];
470
466
  const parts = [];
471
467
  let inputCount = 0;
@@ -475,7 +471,9 @@ export function buildFootageDraftArgs(input) {
475
471
  throw new Error(`No file for clip "${id}" of the EDL.`);
476
472
  return clip;
477
473
  };
478
- edl.segments.forEach((segment, index) => {
474
+ const base = plans[first].start;
475
+ for (let index = first; index <= last; index += 1) {
476
+ const segment = edl.segments[index];
479
477
  const plan = plans[index];
480
478
  const fit = [
481
479
  "setsar=1",
@@ -495,67 +493,67 @@ export function buildFootageDraftArgs(input) {
495
493
  const layer = input.splitLayers?.[segment.id];
496
494
  if (layer === undefined)
497
495
  throw new Error(`No split layer for segment "${segment.id}" of the EDL.`);
498
- const first = inputCount;
496
+ const bandsFrom = inputCount;
499
497
  for (const band of split.bands)
500
498
  inputs.push(...threads.output, "-ss", String(r3(band.start)), "-t", String(plan.seconds), "-i", getClip(band.clip));
501
499
  inputs.push(...getSplitLayerInputArgs(layer, plan.seconds, FOOTAGE_FPS));
502
500
  inputCount += 4;
503
- const bands = [`${String(first)}:v`, `${String(first + 1)}:v`, `${String(first + 2)}:v`];
504
- parts.push(...buildSplitScreenFilters({ inputs: bands, layer: `${String(first + 3)}:v`, split, frame: draft, fit: ["setpts=PTS-STARTPTS", ...fit], output: `v${index}`, prefix: `sp${String(index)}` }));
505
- return;
501
+ const bands = [`${String(bandsFrom)}:v`, `${String(bandsFrom + 1)}:v`, `${String(bandsFrom + 2)}:v`];
502
+ parts.push(...buildSplitScreenFilters({ inputs: bands, layer: `${String(bandsFrom + 3)}:v`, split, frame: draft, fit: ["setpts=PTS-STARTPTS", ...fit], output: `v${index}`, prefix: `sp${String(index)}` }));
503
+ continue;
506
504
  }
507
505
  // Before an input, -threads sizes that input's decoder: one decoder runs per segment.
508
506
  inputs.push(...threads.output, "-ss", String(r3(segment.start)), "-t", String(plan.seconds), "-i", getClip(segment.clip));
509
507
  parts.push(`[${inputCount}:v]${["setpts=PTS-STARTPTS", ...buildPictureFilters(plan, draft), ...fit].join(",")}[v${index}]`);
510
508
  inputCount += 1;
511
- });
512
- let joined = "v0";
513
- plans.forEach((plan, index) => {
514
- if (index === 0)
515
- return;
509
+ }
510
+ let joined = `v${String(first)}`;
511
+ for (let index = first + 1; index <= last; index += 1) {
512
+ const plan = plans[index];
516
513
  const label = `j${index}`;
514
+ // The joined stream starts at segment `first`: offsets are counted from there (from 0 for the whole cut).
515
+ const start = base === 0 ? plan.start : r3(plan.start - base);
517
516
  if (plan.drawn !== null) {
518
- parts.push(...buildDrawnJoin({ joined, incoming: `v${index}`, output: label, plan, drawn: plan.drawn, frame: draft, index }));
517
+ const at = base === 0 ? Math.round(plan.start * FOOTAGE_FPS) : Math.round(plan.start * FOOTAGE_FPS) - Math.round(base * FOOTAGE_FPS);
518
+ parts.push(...buildDrawnJoin({ joined, incoming: `v${index}`, output: label, at, drawn: plan.drawn, frame: draft, index }));
519
519
  joined = label;
520
- return;
520
+ continue;
521
521
  }
522
522
  parts.push(plan.fade > 0
523
- ? `[${joined}][v${index}]xfade=transition=fade:duration=${plan.fade}:offset=${plan.start}[${label}]`
523
+ ? `[${joined}][v${index}]xfade=transition=fade:duration=${plan.fade}:offset=${start}[${label}]`
524
524
  : // concat changes the time base; xfade needs both of its inputs on the segments' own.
525
525
  `[${joined}][v${index}]concat=n=2:v=1:a=0,settb=1/${FOOTAGE_FPS},fps=${FOOTAGE_FPS}[${label}]`);
526
526
  joined = label;
527
- });
528
- if (input.captions !== null) {
529
- parts.push(`[${joined}]ass=filename=${input.captions}${input.fontsDir === null ? "" : `:fontsdir=${input.fontsDir}`}[draft]`);
530
- }
531
- else {
532
- parts.push(`[${joined}]null[draft]`);
533
527
  }
534
- const soundInput = inputCount;
528
+ return { inputs, parts, joined, inputCount };
529
+ }
530
+ /** The draft's sound read from input `soundInput` on: the film's prepared mix copied, or the speech (and music) mixed. */
531
+ function getDraftSound(input, soundInput) {
535
532
  const mix = input.mix ?? null;
536
533
  const music = mix === null ? (input.music ?? null) : null;
537
- if (music !== null)
538
- parts.push(`[${soundInput}:a][${soundInput + 1}:a]amix=inputs=2:duration=first:normalize=0[sound]`);
539
- const seconds = getEdlDuration(edl);
540
- // A prepared mix is copied: it was measured as encoded, and a second encode would move its loudness and true peak.
541
- const audioCodec = mix === null ? ["-c:a", "aac", "-b:a", DRAFT_AUDIO_BITRATE] : ["-c:a", "copy"];
534
+ return {
535
+ inputs: ["-i", mix ?? input.speech, ...(music === null ? [] : ["-i", music])],
536
+ parts: music === null ? [] : [`[${soundInput}:a][${soundInput + 1}:a]amix=inputs=2:duration=first:normalize=0[sound]`],
537
+ map: music === null ? `${soundInput}:a` : "[sound]",
538
+ // A prepared mix is copied: it was measured as encoded, and a second encode would move its loudness and true peak.
539
+ codec: mix === null ? ["-c:a", "aac", "-b:a", DRAFT_AUDIO_BITRATE] : ["-c:a", "copy"],
540
+ };
541
+ }
542
+ /** The filter that burns the captions into `joined` (or passes it through) as `[draft]`. */
543
+ function getCaptionsFilter(joined, input) {
544
+ if (input.captions === null)
545
+ return `[${joined}]null[draft]`;
546
+ return `[${joined}]ass=filename=${input.captions}${input.fontsDir === null ? "" : `:fontsdir=${input.fontsDir}`}[draft]`;
547
+ }
548
+ /** The draft's output: the picture and sound mapped, exactly `seconds` long, H.264 yuv420p with fast start. */
549
+ function getDraftOutputArgs(input) {
542
550
  return [
543
- "-v",
544
- "error",
545
- "-y",
546
- ...threads.global,
547
- ...inputs,
548
- "-i",
549
- mix ?? input.speech,
550
- ...(music === null ? [] : ["-i", music]),
551
- "-filter_complex",
552
- parts.join(";"),
553
551
  "-map",
554
552
  "[draft]",
555
553
  "-map",
556
- music === null ? `${soundInput}:a` : "[sound]",
554
+ input.sound.map,
557
555
  "-t",
558
- String(seconds),
556
+ String(input.seconds),
559
557
  "-c:v",
560
558
  "libx264",
561
559
  "-preset",
@@ -564,13 +562,141 @@ export function buildFootageDraftArgs(input) {
564
562
  String(DRAFT_CRF),
565
563
  "-pix_fmt",
566
564
  "yuv420p",
567
- ...audioCodec,
565
+ ...input.sound.codec,
568
566
  "-movflags",
569
567
  "+faststart",
568
+ ...input.threads,
569
+ input.output,
570
+ ];
571
+ }
572
+ /**
573
+ * The ffmpeg arguments of the draft in one run (`assembly: "single"`): each segment read from its own seek into its
574
+ * clip, zoomed and scaled to the draft's width, joined by `xfade` at `fade` cuts and `concat` at the others, the
575
+ * captions burned in (`ass`), the film's mix copied under it (or the speech and music tracks mixed and encoded to AAC);
576
+ * H.264 yuv420p with fast start, exactly the cut's length. Every segment keeps its own decoder for the whole run, so
577
+ * its memory grows with the number of cuts (`estimateFootageDraftMemory`).
578
+ */
579
+ export function buildFootageDraftArgs(input) {
580
+ const { edl } = input;
581
+ const draft = getFootageDraftFrame(input.frame, input.width);
582
+ const plans = planFootageDraft(input.film, edl, input.overlays ?? []);
583
+ const threads = getThreadArgs(input.threads, "draft.threads");
584
+ const graph = buildDraftPictureGraph({ input, plans, draft, threads, first: 0, last: edl.segments.length - 1 });
585
+ const sound = getDraftSound(input, graph.inputCount);
586
+ const parts = [...graph.parts, getCaptionsFilter(graph.joined, input), ...sound.parts];
587
+ return ["-v", "error", "-y", ...threads.global, ...graph.inputs, ...sound.inputs, "-filter_complex", parts.join(";"), ...getDraftOutputArgs({ sound, seconds: getEdlDuration(edl), threads: threads.output, output: input.output })];
588
+ }
589
+ /** How a footage draft's picture is assembled: in pieces then joined (bounded memory), or in one ffmpeg run. */
590
+ export const FOOTAGE_DRAFT_ASSEMBLIES = ["pieces", "single"];
591
+ /** How many segments a piece of a `pieces` draft holds by default: one ffmpeg run decodes at most these (and a lead). */
592
+ export const FOOTAGE_DRAFT_PIECE_SEGMENTS = 4;
593
+ /** The CRF of a piece: near transparent, so the join's one encode at the draft's CRF sets the draft's quality. */
594
+ const DRAFT_PIECE_CRF = 16;
595
+ /** The film frame a film second falls on. */
596
+ function toDraftFrame(seconds) {
597
+ return Math.round(seconds * FOOTAGE_FPS);
598
+ }
599
+ /**
600
+ * The pieces of a `pieces` draft: `segmentsPerPiece` segments each (a positive whole number), the last piece what is
601
+ * left. Throws on an EDL without segments.
602
+ */
603
+ export function planFootageDraftPieces(plans, seconds, segmentsPerPiece = FOOTAGE_DRAFT_PIECE_SEGMENTS) {
604
+ if (!Number.isInteger(segmentsPerPiece) || segmentsPerPiece < 1)
605
+ throw new Error(`draft.segmentsPerPiece must be a positive whole number, got ${segmentsPerPiece}.`);
606
+ if (plans.length === 0)
607
+ throw new Error("The EDL has no segments.");
608
+ const pieces = [];
609
+ for (let first = 0; first < plans.length; first += segmentsPerPiece) {
610
+ const last = Math.min(plans.length, first + segmentsPerPiece) - 1;
611
+ const plan = plans[first];
612
+ const from = first > 0 && (plan.fade > 0 || plan.drawn !== null) ? first - 1 : first;
613
+ const frame = toDraftFrame(plan.start);
614
+ const next = plans[last + 1];
615
+ const end = next === undefined ? toDraftFrame(seconds) : toDraftFrame(next.start);
616
+ pieces.push({ first, last, from, skipFrames: frame - toDraftFrame(plans[from].start), frame, frames: Math.max(1, end - frame) });
617
+ }
618
+ return pieces;
619
+ }
620
+ /**
621
+ * One piece's ffmpeg arguments: its segments (and a lead segment's tail) as the one-run draft draws them, cut to the
622
+ * piece's own frames, H.264 without sound or captions. A piece decodes only its own segments, so its memory does not
623
+ * grow with the cut.
624
+ */
625
+ export function buildFootageDraftPieceArgs(input) {
626
+ const { piece } = input;
627
+ const draft = getFootageDraftFrame(input.frame, input.width);
628
+ const plans = planFootageDraft(input.film, input.edl, input.overlays ?? []);
629
+ const threads = getThreadArgs(input.threads, "draft.threads");
630
+ const full = { ...input, speech: "", captions: null, fontsDir: null };
631
+ const graph = buildDraftPictureGraph({ input: full, plans, draft, threads, first: piece.from, last: piece.last });
632
+ const cut = `[${graph.joined}]trim=start_frame=${String(piece.skipFrames)}:end_frame=${String(piece.skipFrames + piece.frames)},setpts=PTS-STARTPTS[picture]`;
633
+ return [
634
+ "-v",
635
+ "error",
636
+ "-y",
637
+ ...threads.global,
638
+ ...graph.inputs,
639
+ "-filter_complex",
640
+ [...graph.parts, cut].join(";"),
641
+ "-map",
642
+ "[picture]",
643
+ "-an",
644
+ "-frames:v",
645
+ String(piece.frames),
646
+ "-c:v",
647
+ "libx264",
648
+ "-preset",
649
+ "veryfast",
650
+ "-crf",
651
+ String(DRAFT_PIECE_CRF),
652
+ "-pix_fmt",
653
+ "yuv420p",
570
654
  ...threads.output,
571
655
  input.output,
572
656
  ];
573
657
  }
658
+ /**
659
+ * The join of a `pieces` draft: the pieces read one after the other by the concat demuxer (one decoder), the captions
660
+ * burned in once over the whole film, the sound as the one-run draft takes it, the same encoder and length.
661
+ */
662
+ export function buildFootageDraftJoinArgs(input) {
663
+ const threads = getThreadArgs(input.threads, "draft.threads");
664
+ const sound = getDraftSound(input, 1);
665
+ const parts = [getCaptionsFilter("0:v", input), ...sound.parts];
666
+ return ["-v", "error", "-y", ...threads.global, ...threads.output, "-f", "concat", "-safe", "0", "-i", input.list, ...sound.inputs, "-filter_complex", parts.join(";"), ...getDraftOutputArgs({ sound, seconds: input.seconds, threads: threads.output, output: input.output })];
667
+ }
668
+ /** The working memory of a draft's ffmpeg run that does not grow with the cut (the encoder, libass, the graph's base). */
669
+ const DRAFT_BASE_MB = 250;
670
+ /** One decoder of a 1080x1920 source with its zoom and frame queues, as measured on a production worker (about 70 MB). */
671
+ const DRAFT_DECODER_MB_AT_1080P = 70;
672
+ const FULL_HD_PIXELS = 1080 * 1920;
673
+ /** The decoders a segment opens: its clip, or a split screen's three bands. */
674
+ function countDecoders(segment) {
675
+ return segment.split === undefined ? 1 : segment.split.bands.length;
676
+ }
677
+ /**
678
+ * The draft's peak memory by the kit's estimate, before it runs: a `single` draft opens every segment's decoder at
679
+ * once, a `pieces` draft at most one piece's (with a lead segment). An app compares it with its worker's memory limit
680
+ * and warns before a draft that would not fit.
681
+ */
682
+ export function estimateFootageDraftMemory(input) {
683
+ const segments = input.edl.segments;
684
+ const per = segments.map(countDecoders);
685
+ let decoders = per.reduce((sum, count) => sum + count, 0);
686
+ if (input.assembly === "pieces") {
687
+ const size = input.segmentsPerPiece ?? FOOTAGE_DRAFT_PIECE_SEGMENTS;
688
+ if (!Number.isInteger(size) || size < 1)
689
+ throw new Error(`draft.segmentsPerPiece must be a positive whole number, got ${size}.`);
690
+ decoders = 0;
691
+ for (let first = 0; first < per.length; first += size) {
692
+ // A lead segment is counted whenever there is one before: the estimate does not read transitions.
693
+ const piece = per.slice(Math.max(0, first - 1), first + size).reduce((sum, count) => sum + count, 0);
694
+ decoders = Math.max(decoders, piece);
695
+ }
696
+ }
697
+ const decoderMb = (DRAFT_DECODER_MB_AT_1080P * input.frame.width * input.frame.height) / FULL_HD_PIXELS;
698
+ return { decoders, peakMb: Math.round(DRAFT_BASE_MB + decoders * decoderMb) };
699
+ }
574
700
  /**
575
701
  * The music the draft can play without spending: the film's own file, or generated music already in the paid cache
576
702
  * (looked up as the render looks it up, `findFootageMusic`). Never calls a provider.
@@ -599,8 +725,9 @@ async function findDraftMusic(film, edl, clips, options) {
599
725
  }
600
726
  /**
601
727
  * Makes the draft of a cut film: the speech track, the ducked music track (when it costs nothing), the captions file
602
- * and its font in `<buildDir>/draft/`, then one ffmpeg run (`buildFootageDraftArgs`). Spends nothing: no provider is
603
- * called; takes the same clips, transcript and EDL as `renderFootage`.
728
+ * and its font in `<buildDir>/draft/`, then the picture: in pieces joined with the captions (`assembly: "pieces"`, the
729
+ * default, memory bounded by one piece) or in one ffmpeg run (`"single"`, `buildFootageDraftArgs`). Spends nothing: no
730
+ * provider is called; takes the same clips, transcript and EDL as `renderFootage`.
604
731
  */
605
732
  export function renderFootageDraft(film, clips, transcript, edl, options) {
606
733
  return withFfmpegFailureReporting(getFfmpegReporting(options), () => runRenderFootageDraft(film, clips, transcript, edl, options));
@@ -723,24 +850,26 @@ async function runRenderFootageDraft(film, clips, transcript, edl, options) {
723
850
  }
724
851
  report("film", 0);
725
852
  const splitLayers = writeSplitLayers(edl.segments, getFootageDraftFrame(frame, options.width), draftDir, true);
853
+ const assembly = options.assembly ?? "pieces";
726
854
  // Run in the draft folder: the captions file and the font folder are relative names, so no path needs escaping in the filter graph.
727
- const args = buildFootageDraftArgs({
855
+ const picture = {
728
856
  film,
729
857
  edl,
730
858
  clips: clipFiles,
731
- speech: speechFile,
732
- music: musicFile,
733
- mix: prepared?.audioFile ?? null,
734
859
  frame,
735
860
  ...(options.width === undefined ? {} : { width: options.width }),
736
861
  ...(options.threads === undefined ? {} : { threads: options.threads }),
737
- captions: captions === null ? null : "captions.ass",
738
862
  ...(overlays.length === 0 ? {} : { overlays }),
739
- fontsDir: captions === null ? null : "fonts",
740
863
  ...(Object.keys(splitLayers).length === 0 ? {} : { splitLayers }),
741
- output,
742
- });
743
- await runFfmpeg("The footage draft", args, { ...aborting, output, cwd: draftDir, onSeconds: (done) => report("film", done) });
864
+ };
865
+ const sound = { speech: speechFile, music: musicFile, mix: prepared?.audioFile ?? null, captions: captions === null ? null : "captions.ass", fontsDir: captions === null ? null : "fonts" };
866
+ let pieceCount = 1;
867
+ if (assembly === "single") {
868
+ await runFfmpeg("The footage draft", buildFootageDraftArgs({ ...picture, ...sound, output }), { ...aborting, output, cwd: draftDir, onSeconds: (done) => report("film", done) });
869
+ }
870
+ else {
871
+ pieceCount = await assembleDraftInPieces({ picture, sound, seconds, draftDir, output, aborting, segmentsPerPiece: options.segmentsPerPiece, onSeconds: (done) => report("film", done) });
872
+ }
744
873
  const measured = await measureDraftLoudness(output, mixLoudness, prepared !== null, aborting);
745
874
  if (!measured.ok)
746
875
  return measured;
@@ -761,6 +890,8 @@ async function runRenderFootageDraft(film, clips, transcript, edl, options) {
761
890
  music: draftMusic,
762
891
  captionFont: captions === null ? null : font.family,
763
892
  seconds,
893
+ assembly,
894
+ pieces: pieceCount,
764
895
  width: draft.width,
765
896
  height: draft.height,
766
897
  bytes,
@@ -769,6 +900,43 @@ async function runRenderFootageDraft(film, clips, transcript, edl, options) {
769
900
  mix: prepared?.mix ?? null,
770
901
  });
771
902
  }
903
+ /** The share of the film step the pieces take; the join takes the rest. */
904
+ const PIECES_SHARE = 0.8;
905
+ /**
906
+ * Draws the picture piece by piece into `<draftDir>/pieces/` (one ffmpeg at a time), then joins the pieces with the
907
+ * captions and the sound into `output`. The pieces are removed after the join; a failed run leaves them for its
908
+ * snapshot. Answers the number of pieces.
909
+ */
910
+ async function assembleDraftInPieces(run) {
911
+ const { picture, aborting, draftDir } = run;
912
+ const plans = planFootageDraft(picture.film, picture.edl, picture.overlays ?? []);
913
+ const pieces = planFootageDraftPieces(plans, run.seconds, run.segmentsPerPiece);
914
+ const piecesDir = join(draftDir, "pieces");
915
+ mkdirSync(piecesDir, { recursive: true });
916
+ const files = [];
917
+ for (const [index, piece] of pieces.entries()) {
918
+ const name = `piece-${String(index).padStart(4, "0")}.mp4`;
919
+ const file = join(piecesDir, name);
920
+ const at = piece.frame / FOOTAGE_FPS;
921
+ await runFfmpeg(`The footage draft's piece ${String(index + 1)} of ${String(pieces.length)}`, buildFootageDraftPieceArgs({ ...picture, piece, output: join("pieces", name) }), {
922
+ ...aborting,
923
+ output: file,
924
+ cwd: draftDir,
925
+ onSeconds: (done) => run.onSeconds(Math.min(run.seconds, at + done) * PIECES_SHARE),
926
+ });
927
+ files.push(name);
928
+ }
929
+ const list = join(piecesDir, "pieces.txt");
930
+ writeFileSync(list, buildPictureList(files));
931
+ await runFfmpeg("The footage draft's join", buildFootageDraftJoinArgs({ ...run.sound, list: join("pieces", "pieces.txt"), seconds: run.seconds, ...(picture.threads === undefined ? {} : { threads: picture.threads }), output: run.output }), {
932
+ ...aborting,
933
+ output: run.output,
934
+ cwd: draftDir,
935
+ onSeconds: (done) => run.onSeconds(run.seconds * PIECES_SHARE + Math.min(run.seconds, done) * (1 - PIECES_SHARE)),
936
+ });
937
+ rmSync(piecesDir, { recursive: true, force: true });
938
+ return pieces.length;
939
+ }
772
940
  /**
773
941
  * The written draft's sound measured as `finishFootage` measures the finished film: held to `mixLoudness` when the mix
774
942
  * stage made it (a miss fails, a near miss inside `warnTolerance` carries `warning`), reported otherwise; null when