@softure-ai/marketing-kit 0.1.5 → 0.1.7

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.
Files changed (91) hide show
  1. package/README.md +49 -12
  2. package/dist/cli/main.js +15 -9
  3. package/dist/cli/main.js.map +1 -1
  4. package/dist/cli/options.d.ts +14 -1
  5. package/dist/cli/options.d.ts.map +1 -1
  6. package/dist/cli/options.js +22 -9
  7. package/dist/cli/options.js.map +1 -1
  8. package/dist/cli/voice.d.ts +5 -0
  9. package/dist/cli/voice.d.ts.map +1 -1
  10. package/dist/cli/voice.js +28 -8
  11. package/dist/cli/voice.js.map +1 -1
  12. package/dist/compose/compose.d.ts +3 -3
  13. package/dist/compose/compose.d.ts.map +1 -1
  14. package/dist/compose/compose.js +7 -7
  15. package/dist/compose/compose.js.map +1 -1
  16. package/dist/compose/timeline.d.ts +19 -0
  17. package/dist/compose/timeline.d.ts.map +1 -1
  18. package/dist/compose/timeline.js +42 -0
  19. package/dist/compose/timeline.js.map +1 -1
  20. package/dist/config/config.d.ts +5 -0
  21. package/dist/config/config.d.ts.map +1 -1
  22. package/dist/config/config.js +3 -1
  23. package/dist/config/config.js.map +1 -1
  24. package/dist/config/day.d.ts +5 -0
  25. package/dist/config/day.d.ts.map +1 -0
  26. package/dist/config/day.js +10 -0
  27. package/dist/config/day.js.map +1 -0
  28. package/dist/config/schema.d.ts +9 -0
  29. package/dist/config/schema.d.ts.map +1 -1
  30. package/dist/config/schema.js +22 -1
  31. package/dist/config/schema.js.map +1 -1
  32. package/dist/film.d.ts +3 -1
  33. package/dist/film.d.ts.map +1 -1
  34. package/dist/film.js.map +1 -1
  35. package/dist/index.d.ts +5 -3
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +5 -3
  38. package/dist/index.js.map +1 -1
  39. package/dist/posts/posts.d.ts +2 -1
  40. package/dist/posts/posts.d.ts.map +1 -1
  41. package/dist/posts/posts.js +1 -1
  42. package/dist/posts/posts.js.map +1 -1
  43. package/dist/record/record.d.ts +1 -1
  44. package/dist/record/record.d.ts.map +1 -1
  45. package/dist/record/record.js +2 -2
  46. package/dist/record/record.js.map +1 -1
  47. package/dist/render/render.js +10 -10
  48. package/dist/render/render.js.map +1 -1
  49. package/dist/voice/batch.d.ts +28 -0
  50. package/dist/voice/batch.d.ts.map +1 -0
  51. package/dist/voice/batch.js +46 -0
  52. package/dist/voice/batch.js.map +1 -0
  53. package/dist/voice/cache.d.ts +11 -2
  54. package/dist/voice/cache.d.ts.map +1 -1
  55. package/dist/voice/cache.js +30 -5
  56. package/dist/voice/cache.js.map +1 -1
  57. package/dist/voice/elevenlabs.d.ts.map +1 -1
  58. package/dist/voice/elevenlabs.js +11 -1
  59. package/dist/voice/elevenlabs.js.map +1 -1
  60. package/dist/voice/pace.d.ts +22 -0
  61. package/dist/voice/pace.d.ts.map +1 -0
  62. package/dist/voice/pace.js +39 -0
  63. package/dist/voice/pace.js.map +1 -0
  64. package/dist/voice/produce.d.ts +8 -0
  65. package/dist/voice/produce.d.ts.map +1 -1
  66. package/dist/voice/produce.js +26 -5
  67. package/dist/voice/produce.js.map +1 -1
  68. package/dist/voice/provider.d.ts +2 -0
  69. package/dist/voice/provider.d.ts.map +1 -1
  70. package/dist/voice/provider.js.map +1 -1
  71. package/package.json +1 -1
  72. package/schema/marketing.schema.json +31 -0
  73. package/src/cli/main.ts +14 -9
  74. package/src/cli/options.ts +24 -7
  75. package/src/cli/voice.ts +28 -9
  76. package/src/compose/compose.ts +9 -9
  77. package/src/compose/timeline.ts +55 -0
  78. package/src/config/config.ts +9 -2
  79. package/src/config/day.ts +9 -0
  80. package/src/config/schema.ts +25 -1
  81. package/src/film.ts +3 -2
  82. package/src/index.ts +10 -2
  83. package/src/posts/posts.ts +3 -2
  84. package/src/record/record.ts +3 -3
  85. package/src/render/render.ts +10 -10
  86. package/src/voice/batch.ts +65 -0
  87. package/src/voice/cache.ts +33 -5
  88. package/src/voice/elevenlabs.ts +11 -1
  89. package/src/voice/pace.ts +55 -0
  90. package/src/voice/produce.ts +31 -6
  91. package/src/voice/provider.ts +2 -0
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Paid calls are spaced so a batch of films never reaches the provider as a burst (FIRE_TRACKER sent 26 in about ten
3
+ * minutes from a shell loop and drew an ElevenLabs policy warning). The time of the last paid call is read from the
4
+ * cache itself: every paid call writes `<key>.json` right after the response, so pacing also holds across separate
5
+ * runs of the CLI and needs no state file.
6
+ */
7
+ export interface PaceOptions {
8
+ /** The voiceover cache: recordings at its root (the flat layout) and in one folder per video. */
9
+ cacheDir: string;
10
+ /** The least time between two paid calls; 0 turns pacing off. */
11
+ minIntervalSeconds: number;
12
+ /** Injected in tests; `Date.now` otherwise. */
13
+ now?: () => number;
14
+ /** Injected in tests; a timer otherwise. */
15
+ sleep?: (milliseconds: number) => Promise<void>;
16
+ log: (line: string) => void;
17
+ }
18
+ /** When the newest recording in the cache was written, in epoch milliseconds; null for an empty or missing cache. */
19
+ export declare function findLastRecordingTime(cacheDir: string): number | null;
20
+ /** Waits until `minIntervalSeconds` have passed since the newest recording in the cache; returns the seconds waited. */
21
+ export declare function waitForPace(options: PaceOptions): Promise<number>;
22
+ //# sourceMappingURL=pace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pace.d.ts","sourceRoot":"","sources":["../../src/voice/pace.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,MAAM,WAAW,WAAW;IAC1B,iGAAiG;IACjG,QAAQ,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAeD,qHAAqH;AACrH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIrE;AAED,wHAAwH;AACxH,wBAAsB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAWvE"}
@@ -0,0 +1,39 @@
1
+ import { existsSync, readdirSync, statSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ const sleepFor = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
4
+ function listWordFiles(dir) {
5
+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
6
+ const path = join(dir, entry.name);
7
+ if (entry.isFile() && entry.name.endsWith(".json"))
8
+ return [path];
9
+ if (!entry.isDirectory())
10
+ return [];
11
+ return readdirSync(path, { withFileTypes: true })
12
+ .filter((inner) => inner.isFile() && inner.name.endsWith(".json"))
13
+ .map((inner) => join(path, inner.name));
14
+ });
15
+ }
16
+ /** When the newest recording in the cache was written, in epoch milliseconds; null for an empty or missing cache. */
17
+ export function findLastRecordingTime(cacheDir) {
18
+ if (!existsSync(cacheDir))
19
+ return null;
20
+ const times = listWordFiles(cacheDir).map((path) => statSync(path).mtimeMs);
21
+ return times.length === 0 ? null : Math.max(...times);
22
+ }
23
+ /** Waits until `minIntervalSeconds` have passed since the newest recording in the cache; returns the seconds waited. */
24
+ export async function waitForPace(options) {
25
+ const { cacheDir, minIntervalSeconds, log } = options;
26
+ if (minIntervalSeconds <= 0)
27
+ return 0;
28
+ const last = findLastRecordingTime(cacheDir);
29
+ if (last === null)
30
+ return 0;
31
+ const now = (options.now ?? Date.now)();
32
+ const remaining = Math.ceil((last + minIntervalSeconds * 1000 - now) / 1000);
33
+ if (remaining <= 0)
34
+ return 0;
35
+ log(`voiceover: the last paid recording in ${cacheDir} is under ${minIntervalSeconds} s old (voice.minIntervalSeconds); waiting ${remaining} s before the next call.`);
36
+ await (options.sleep ?? sleepFor)(remaining * 1000);
37
+ return remaining;
38
+ }
39
+ //#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, type TtsProvider, type TtsResult } from "./provider.js";
3
4
  export interface ProduceVoiceoverOptions {
4
5
  cacheDir: string;
5
6
  input: TtsInput;
7
+ /** The film the voiceover belongs to: its recordings live in `<cacheDir>/<videoId>/`. Without it, the flat layout. */
8
+ videoId?: string;
6
9
  provider: TtsProvider;
7
10
  /** Only `true` lets the provider spend money. */
8
11
  isCommit: boolean;
12
+ /** Spacing of paid calls (`voice.minIntervalSeconds`); without it, no wait. Never applies to a cache hit or a dry run. */
13
+ pace?: Omit<PaceOptions, "cacheDir" | "log">;
9
14
  log: (line: string) => void;
10
15
  }
11
16
  export type VoiceoverOutcome = {
@@ -21,7 +26,10 @@ export type VoiceoverOutcome = {
21
26
  key: string;
22
27
  voiceover: Voiceover;
23
28
  estimate: TtsEstimate;
29
+ charged: number | null;
24
30
  };
31
+ /** The charge the provider reported, next to the estimate; the estimate stays an upper bound. */
32
+ export declare function describeCharge(provider: TtsProvider, estimate: TtsEstimate, charged: number | null): string;
25
33
  export declare function describeEstimate(provider: TtsProvider, estimate: TtsEstimate): string;
26
34
  /**
27
35
  * The voiceover from the cache, or a recording from the provider. The estimate is logged in every dry
@@ -1 +1 @@
1
- {"version":3,"file":"produce.d.ts","sourceRoot":"","sources":["../../src/voice/produce.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0D,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EAAW,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAE3G,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,QAAQ,CAAC;IAChB,QAAQ,EAAE,WAAW,CAAC;IACtB,iDAAiD;IACjD,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,I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MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE3G,iGAAiG;AACjG,wBAAgB,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAG3G;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,GAAG,MAAM,CAErF;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAgC7G"}
@@ -1,5 +1,13 @@
1
- import { getVoiceoverPaths, readCachedVoiceover, writeVoiceover } from "./cache.js";
1
+ import { dirname, join } from "node:path";
2
+ import { findStaleVoiceovers, getVoiceoverPaths, readCachedVoiceover, writeVoiceover } from "./cache.js";
3
+ import { waitForPace } from "./pace.js";
2
4
  import { err, ok } from "./provider.js";
5
+ /** The charge the provider reported, next to the estimate; the estimate stays an upper bound. */
6
+ export function describeCharge(provider, estimate, charged) {
7
+ if (charged === null)
8
+ return `voiceover: ${provider.id} did not report the charge; the estimate was at most ${estimate.maxCost} ${estimate.unit}.`;
9
+ return `voiceover: ${provider.id} charged ${charged} ${estimate.unit} for ${estimate.characters} characters (the estimate was at most ${estimate.maxCost}).`;
10
+ }
3
11
  export function describeEstimate(provider, estimate) {
4
12
  return `voiceover estimate (${provider.id}): ${estimate.characters} characters, at most ${estimate.maxCost} ${estimate.unit}.`;
5
13
  }
@@ -8,13 +16,22 @@ export function describeEstimate(provider, estimate) {
8
16
  * run and before every paid call; without `isCommit` the provider is never called.
9
17
  */
10
18
  export async function produceVoiceover(options) {
11
- const { cacheDir, input, provider, isCommit, log } = options;
12
- const paths = getVoiceoverPaths(cacheDir, input);
19
+ const { cacheDir, input, videoId, provider, isCommit, pace, log } = options;
20
+ const paths = getVoiceoverPaths(cacheDir, input, videoId);
13
21
  const cached = readCachedVoiceover(paths);
14
22
  if (!cached.ok)
15
23
  return cached;
24
+ if (videoId !== undefined) {
25
+ const stale = findStaleVoiceovers(cacheDir, videoId, paths.key);
26
+ if (stale.length > 0) {
27
+ log(`voiceover: ${join(cacheDir, videoId)} also holds ${stale.join(", ")}, which the current script does not use; delete them once no film needs them.`);
28
+ }
29
+ }
16
30
  if (cached.value !== null) {
17
31
  log(`voiceover: from the cache ${paths.key}, nothing spent.`);
32
+ if (videoId !== undefined && paths.layout === "flat") {
33
+ log(`voiceover: ${paths.key}.mp3 and .json sit in the cache root (the layout before 0.1.6); move them into ${join(cacheDir, videoId)}/ to keep them with their film.`);
34
+ }
18
35
  return ok({ kind: "cached", key: paths.key, voiceover: cached.value });
19
36
  }
20
37
  const estimate = provider.estimate(input);
@@ -23,11 +40,15 @@ export async function produceVoiceover(options) {
23
40
  log(`voiceover DRY RUN (voice ${input.voiceId}): nothing was sent. Run with --commit to pay and record.`);
24
41
  return ok({ kind: "dry-run", key: paths.key, estimate });
25
42
  }
43
+ if (pace !== undefined)
44
+ await waitForPace({ ...pace, cacheDir, log });
26
45
  const recording = await provider.synthesize(input);
27
46
  if (!recording.ok)
28
47
  return err(recording.error);
29
48
  const voiceover = writeVoiceover(cacheDir, paths, recording.value);
30
- log(`voiceover: recorded ${estimate.characters} characters, saved ${paths.key}.{mp3,json} in ${cacheDir} (commit them).`);
31
- return ok({ kind: "recorded", key: paths.key, voiceover, estimate });
49
+ const charged = recording.value.charged ?? null;
50
+ log(describeCharge(provider, estimate, charged));
51
+ log(`voiceover: recorded ${estimate.characters} characters, saved ${paths.key}.{mp3,json} in ${dirname(paths.audio)} (commit them).`);
52
+ return ok({ kind: "recorded", key: paths.key, voiceover, estimate, charged });
32
53
  }
33
54
  //# sourceMappingURL=produce.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"produce.js","sourceRoot":"","sources":["../../src/voice/produce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAkB,MAAM,YAAY,CAAC;AACpG,OAAO,EAAE,GAAG,EAAE,EAAE,EAAqE,MAAM,eAAe,CAAC;AAgB3G,MAAM,UAAU,gBAAgB,CAAC,QAAqB,EAAE,QAAqB;IAC3E,OAAO,uBAAuB,QAAQ,CAAC,EAAE,MAAM,QAAQ,CAAC,UAAU,wBAAwB,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,GAAG,CAAC;AACjI,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAgC;IACrE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC1C,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAC;IAC9B,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QAC1B,GAAG,CAAC,6BAA6B,KAAK,CAAC,GAAG,kBAAkB,CAAC,CAAC;QAC9D,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,MA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G,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC;IAChD,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,GAAG,CAAC,uBAAuB,QAAQ,CAAC,UAAU,sBAAsB,KAAK,CAAC,GAAG,kBAAkB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACtI,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;AAChF,CAAC"}
@@ -11,6 +11,8 @@ export interface TtsInput {
11
11
  export interface TtsRecording {
12
12
  audio: Buffer;
13
13
  words: TimedWord[];
14
+ /** What the provider says it charged, in the estimate's unit; null or absent when it does not say. */
15
+ charged?: number | null;
14
16
  }
15
17
  /** What a recording would cost, shown before anything is spent. */
16
18
  export interface TtsEstimate {
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/voice/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,yEAAyE;AACzE,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,sFAAsF;AACtF,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB;AAED,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC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AU,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,WAAW,CAAC;IACvC,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;CAC/D;AAED,eAAO,MAAM,EAAE,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,SAAS,CAAC,CAAC,CAA0B,CAAC;AACvE,eAAO,MAAM,GAAG,GAAI,CAAC,EAAE,OAAO,MAAM,KAAG,SAAS,CAAC,CAAC,CAA2B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/voice/provider.ts"],"names":[],"mappings":"AAsCA,MAAM,CAAC,MAAM,EAAE,GAAG,CAAI,KAAQ,EAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,GAAG,GAAG,CAAI,KAAa,EAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/voice/provider.ts"],"names":[],"mappings":"AAwCA,MAAM,CAAC,MAAM,EAAE,GAAG,CAAI,KAAQ,EAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,GAAG,GAAG,CAAI,KAAa,EAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softure-ai/marketing-kit",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "SOFTURE AI marketing kit: a CLI that turns a project's real app into a vertical film (cached voiceover, frame-by-frame recording, HTML composition, hyperframes render) plus per-platform post copy and OG images.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -470,6 +470,13 @@
470
470
  "minimum": 0.8,
471
471
  "maximum": 1.3
472
472
  },
473
+ "minIntervalSeconds": {
474
+ "default": 60,
475
+ "description": "Least seconds between two paid recordings (0-3600, default 60; 0 turns it off), counted from the newest file in cacheDir, so separate runs are spaced too.",
476
+ "type": "number",
477
+ "minimum": 0,
478
+ "maximum": 3600
479
+ },
473
480
  "cacheDir": {
474
481
  "default": "marketing/voiceover",
475
482
  "description": "The paid voiceover cache (<key>.mp3 and <key>.json), relative to the folder of marketing.json; commit it.",
@@ -2374,6 +2381,16 @@
2374
2381
  "additionalProperties": false
2375
2382
  },
2376
2383
  "description": "Camera moves over the opening frame, at least one."
2384
+ },
2385
+ "transition": {
2386
+ "default": "fade",
2387
+ "description": "How the opening frame hands over to the scene: fade (a 0.8 s cross-fade), rewind (0.8 s back through the scene in five dissolving frames) or cut.",
2388
+ "type": "string",
2389
+ "enum": [
2390
+ "fade",
2391
+ "rewind",
2392
+ "cut"
2393
+ ]
2377
2394
  }
2378
2395
  },
2379
2396
  "required": [
@@ -2383,6 +2400,11 @@
2383
2400
  "additionalProperties": false,
2384
2401
  "description": "The opening: the result frame the first sentence plays over."
2385
2402
  },
2403
+ "today": {
2404
+ "description": "The day the app is recorded as of (YYYY-MM-DD): pin it once the voiceover is paid for, so the numbers it says still match the screen in a later month. --today overrides it; without either, the day of the run.",
2405
+ "type": "string",
2406
+ "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
2407
+ },
2386
2408
  "screenGuard": {
2387
2409
  "minItems": 1,
2388
2410
  "type": "array",
@@ -2504,6 +2526,11 @@
2504
2526
  "type": "string"
2505
2527
  }
2506
2528
  },
2529
+ "disclosure": {
2530
+ "default": true,
2531
+ "description": "Whether social.disclosure follows this post's caption (default true).",
2532
+ "type": "boolean"
2533
+ },
2507
2534
  "codes": {
2508
2535
  "description": "Channel codes for this film only, per platform; each falls back to platforms.<platform>.code.",
2509
2536
  "type": "object",
@@ -2532,6 +2559,10 @@
2532
2559
  ],
2533
2560
  "additionalProperties": false
2534
2561
  }
2562
+ },
2563
+ "disclosure": {
2564
+ "description": "A paragraph after every post's caption, e.g. that the persona is an example and the voice is AI-generated; {persona} becomes the film's persona name. A post opts out with disclosure: false.",
2565
+ "type": "string"
2535
2566
  }
2536
2567
  },
2537
2568
  "required": [
package/src/cli/main.ts CHANGED
@@ -16,16 +16,16 @@ import { splitIntoBeats } from "../voice/voiceover.js";
16
16
  import { CliFailure, fail } from "./failure.js";
17
17
  import { loadFilm, type LoadedFilm } from "./films.js";
18
18
  import { writeOgImages } from "./og.js";
19
- import { readOptions, type FilmOptions, type ShotsOptions } from "./options.js";
19
+ import { getRecordingDay, readOptions, type FilmOptions, type ShotsOptions } from "./options.js";
20
20
  import { ensureServer } from "./server.js";
21
- import { getVoiceoverPaths, produceVoiceover, readJson, requireVoiceover } from "./voice.js";
21
+ import { getVoiceoverPaths, produceVoiceover, produceVoiceovers, readJson, requireVoiceover } from "./voice.js";
22
22
 
23
23
  /**
24
24
  * `softure-marketing`: the only way into the films.
25
25
  *
26
26
  * all <film> voiceover from the cache -> recording -> render -> post copy
27
- * voice <film> [--commit] voiceover (paid only with --commit)
28
- * record <film> [--today=YYYY-MM-DD] [--url=...]
27
+ * voice <film>... [--commit] voiceovers in order (paid only with --commit), spaced and stopped at the first error
28
+ * record <film> [--today=YYYY-MM-DD] [--url=...] (--today overrides the video's today)
29
29
  * render <film> [--quality=draft|standard|high]
30
30
  * preview <film>
31
31
  * posts <film>
@@ -48,16 +48,17 @@ async function record(config: MarketingConfig, film: LoadedFilm, options: FilmOp
48
48
  const voices = splitIntoBeats(voiceover.words, film.beats, film.voice.tempo);
49
49
  const server = await ensureServer(config, film, options.url);
50
50
  mkdirSync(getBuildDir(config, film), { recursive: true });
51
+ const recordingDay = getRecordingDay(options.today, film.today);
51
52
  let log: RecordingLog;
52
53
  try {
53
- console.log(`recording: ${server.url} frame by frame; this takes a few minutes.`);
54
+ console.log(`recording: ${server.url} frame by frame, the app as of ${recordingDay.day ?? "today"} (${recordingDay.source}); this takes a few minutes.`);
54
55
  log = await recordFilm({
55
56
  film,
56
57
  url: server.url,
57
58
  outDir: getBuildDir(config, film),
58
59
  voices,
59
60
  voiceoverKey: getVoiceoverPaths(config, film).key,
60
- today: options.today,
61
+ today: recordingDay.day ?? undefined,
61
62
  filmPath: film.scenePath,
62
63
  executablePath: process.env.PLAYWRIGHT_CHROMIUM_PATH || undefined,
63
64
  browser: {
@@ -192,12 +193,16 @@ async function main(argv: string[]): Promise<void> {
192
193
  await shots(config, options);
193
194
  return;
194
195
  }
196
+ if (options.command === "voice") {
197
+ // Every film is loaded before the first paid call, so a typo in the fifth id costs nothing.
198
+ const films: LoadedFilm[] = [];
199
+ for (const id of options.filmIds) films.push(await loadFilm(config, id));
200
+ await produceVoiceovers(config, films, options.isCommit);
201
+ return;
202
+ }
195
203
  const film = await loadFilm(config, options.filmId);
196
204
 
197
205
  switch (options.command) {
198
- case "voice":
199
- await produceVoiceover(config, film, options.isCommit);
200
- return;
201
206
  case "record":
202
207
  preflight(config, film, false);
203
208
  await record(config, film, options);
@@ -1,3 +1,4 @@
1
+ import { isCalendarDay } from "../config/day.js";
1
2
  import { DEFAULT_CONFIG_FILE, QUALITIES, type Quality } from "../config/schema.js";
2
3
 
3
4
  /**
@@ -17,10 +18,13 @@ const FILM_ID = /^[a-z0-9]+(-[a-z0-9]+)*$/;
17
18
 
18
19
  export interface FilmOptions {
19
20
  command: Exclude<Command, "og" | "shots">;
21
+ /** The first film named; the only one for every command but `voice`. */
20
22
  filmId: string;
23
+ /** Every film named, in order; `voice` takes several, the other commands one. */
24
+ filmIds: string[];
21
25
  /** `voice` really pays for the voiceover only with `--commit`. */
22
26
  isCommit: boolean;
23
- /** The day the app counts from, only to reproduce an old film. */
27
+ /** The day the app counts from; overrides the video's `today` for one run. */
24
28
  today?: string;
25
29
  /** Another address of the recorded page. */
26
30
  url?: string;
@@ -55,8 +59,8 @@ export const USAGE = [
55
59
  `Usage: softure-marketing <command> <film> [--config=${DEFAULT_CONFIG_FILE}]`,
56
60
  "",
57
61
  " all <film> voiceover from the cache -> recording -> render -> post copy",
58
- " voice <film> [--commit] voiceover; without --commit it only counts the characters",
59
- " record <film> [--today=YYYY-MM-DD] [--url=...]",
62
+ " voice <film>... [--commit] voiceovers in order; without --commit it only counts the characters",
63
+ " record <film> [--today=YYYY-MM-DD] [--url=...] --today overrides the video's \"today\"",
60
64
  " render <film> [--quality=draft|standard|high]",
61
65
  " preview <film> open the composition in the hyperframes preview",
62
66
  " posts <film> post copy for the configured platforms",
@@ -97,10 +101,13 @@ export function readOptions(argv: string[]): ReadOptionsResult {
97
101
  if (command === "shots") return readShotsOptions(positional, flags, configPath);
98
102
  const filmId = positional[0];
99
103
  if (filmId === undefined) return { ok: false, error: `name the film, e.g. softure-marketing ${command} <film>.` };
100
- if (positional.length > 1) return { ok: false, error: `one film at a time, got ${positional.join(", ")}.` };
101
- if (!FILM_ID.test(filmId)) return { ok: false, error: `film name "${filmId}": lowercase letters, digits and hyphens only.` };
104
+ if (positional.length > 1 && command !== "voice") return { ok: false, error: `one film at a time, got ${positional.join(", ")}; only voice takes several.` };
105
+ const badId = positional.find((id) => !FILM_ID.test(id));
106
+ if (badId !== undefined) return { ok: false, error: `film name "${badId}": lowercase letters, digits and hyphens only.` };
107
+ const repeated = positional.find((id, index) => positional.indexOf(id) !== index);
108
+ if (repeated !== undefined) return { ok: false, error: `film "${repeated}" is named twice.` };
102
109
  const today = flags.get("today");
103
- if (today !== undefined && !/^\d{4}-\d{2}-\d{2}$/.test(today)) return { ok: false, error: `--today=${today}: expected YYYY-MM-DD.` };
110
+ if (today !== undefined && !isCalendarDay(today)) return { ok: false, error: `--today=${today}: expected a real day as YYYY-MM-DD.` };
104
111
  const quality = flags.get("quality");
105
112
  if (quality !== undefined && !isQuality(quality)) return { ok: false, error: `--quality=${quality}: expected ${QUALITIES.join(" | ")}.` };
106
113
  const commit = flags.get("commit");
@@ -112,7 +119,7 @@ export function readOptions(argv: string[]): ReadOptionsResult {
112
119
  if (url === "true") return { ok: false, error: "--url needs an address, e.g. --url=http://localhost:3000/calculator." };
113
120
  return {
114
121
  ok: true,
115
- options: { command, filmId, isCommit: commit === "true", today, url, quality, configPath },
122
+ options: { command, filmId, filmIds: positional, isCommit: commit === "true", today, url, quality, configPath },
116
123
  };
117
124
  }
118
125
 
@@ -141,3 +148,13 @@ function readShotsOptions(positional: string[], flags: Map<string, string>, conf
141
148
  if (url !== undefined && !isHttpAddress(url)) return { ok: false, error: `--url=${url}: expected an address such as http://localhost:3000.` };
142
149
  return { ok: true, options: { command: "shots", shotId, url, configPath } };
143
150
  }
151
+
152
+ /** The day a recording starts its page clock at, and where it came from. */
153
+ export type RecordingDay = { day: string; source: "--today" | "videos[].today" } | { day: null; source: "the day of the run" };
154
+
155
+ /** `--today` wins over the video's `today`; without either, the page clock starts now. */
156
+ export function getRecordingDay(flag: string | undefined, configured: string | null): RecordingDay {
157
+ if (flag !== undefined) return { day: flag, source: "--today" };
158
+ if (configured !== null) return { day: configured, source: "videos[].today" };
159
+ return { day: null, source: "the day of the run" };
160
+ }
package/src/cli/voice.ts CHANGED
@@ -3,7 +3,8 @@ import { readFileSync } from "node:fs";
3
3
  import type { MarketingConfig } from "../config/config.js";
4
4
  import type { Film } from "../film.js";
5
5
  import { getVoiceoverPaths as getCachePaths, readCachedVoiceover, type Voiceover, type VoiceoverPaths } from "../voice/cache.js";
6
- import { produceVoiceover as produce } from "../voice/produce.js";
6
+ import { describeVoiceoverBatch, produceVoiceovers as produceBatch } from "../voice/batch.js";
7
+ import { produceVoiceover as produce, type ProduceVoiceoverOptions } from "../voice/produce.js";
7
8
  import type { TtsInput } from "../voice/provider.js";
8
9
  import { createTtsProvider } from "../voice/providers.js";
9
10
  import { voiceoverText } from "../voice/voiceover.js";
@@ -16,7 +17,7 @@ function getTtsInput(film: Film): TtsInput {
16
17
  }
17
18
 
18
19
  export function getVoiceoverPaths(config: MarketingConfig, film: Film): VoiceoverPaths {
19
- return getCachePaths(config.voice.cacheDir, getTtsInput(film));
20
+ return getCachePaths(config.voice.cacheDir, getTtsInput(film), film.id);
20
21
  }
21
22
 
22
23
  /** JSON from disk with the file name in the error, not a bare "Unexpected token". */
@@ -35,18 +36,36 @@ export function requireVoiceover(config: MarketingConfig, film: Film): Voiceover
35
36
  return cached.value;
36
37
  }
37
38
 
38
- /**
39
- * The voiceover from the cache, or a paid recording from the configured provider with `--commit`.
40
- * Without `--commit` it prints the cost estimate, spends nothing and returns null.
41
- */
42
- export async function produceVoiceover(config: MarketingConfig, film: Film, isCommit: boolean): Promise<Voiceover | null> {
43
- const result = await produce({
39
+ function getProduceOptions(config: MarketingConfig, film: Film, isCommit: boolean): ProduceVoiceoverOptions {
40
+ return {
44
41
  cacheDir: config.voice.cacheDir,
45
42
  input: getTtsInput(film),
43
+ videoId: film.id,
46
44
  provider: createTtsProvider(config.voice.provider, { env: process.env }),
47
45
  isCommit,
46
+ pace: { minIntervalSeconds: config.voice.minIntervalSeconds },
48
47
  log: (line) => console.log(line),
49
- });
48
+ };
49
+ }
50
+
51
+ /**
52
+ * The voiceover from the cache, or a paid recording from the configured provider with `--commit`.
53
+ * Without `--commit` it prints the cost estimate, spends nothing and returns null.
54
+ */
55
+ export async function produceVoiceover(config: MarketingConfig, film: Film, isCommit: boolean): Promise<Voiceover | null> {
56
+ const result = await produce(getProduceOptions(config, film, isCommit));
50
57
  if (!result.ok) fail(result.error);
51
58
  return result.value.kind === "dry-run" ? null : result.value.voiceover;
52
59
  }
60
+
61
+ /**
62
+ * `voice <film>...`: the films' voiceovers in order, paid calls spaced by `voice.minIntervalSeconds`. The first
63
+ * failure stops the batch; the summary names what was recorded, where it stopped and what was never sent.
64
+ */
65
+ export async function produceVoiceovers(config: MarketingConfig, films: Film[], isCommit: boolean): Promise<void> {
66
+ const result = await produceBatch(films.map((film) => ({ id: film.id, options: getProduceOptions(config, film, isCommit) })));
67
+ if (films.length > 1) console.log(["", ...describeVoiceoverBatch(result)].join("\n"));
68
+ if (result.failed === null) return;
69
+ if (films.length > 1) fail(`the batch stopped at ${result.failed.id}; ${result.notAttempted.length} ${result.notAttempted.length === 1 ? "film was" : "films were"} not sent. See above.`);
70
+ fail(result.failed.error);
71
+ }
@@ -3,13 +3,13 @@ import type { SfxEvent } from "../config/schema.js";
3
3
  import type { Film } from "../film.js";
4
4
  import { formatMessage, type MarketingMessages } from "../messages/index.js";
5
5
  import type { RecordingLog } from "../record/record.js";
6
- import { BROWSER_BAR_HEIGHT, cameraPose, captionChunks, widePose, type CameraPose, type Geometry } from "./timeline.js";
6
+ import { BROWSER_BAR_HEIGHT, cameraPose, captionChunks, getTransitionSeconds, widePose, type CameraPose, type Geometry } from "./timeline.js";
7
7
  import type { BeatVoice } from "../voice/voiceover.js";
8
8
 
9
9
  /**
10
10
  * HyperFrames composition from the recording: the phone (or, for a desktop recording, a browser window) with the real screen, a camera that follows
11
11
  * the thumb, a touch marker, captions in one place, the persona card, an opening from the result
12
- * frame with a rewind, the end card and sounds.
12
+ * frame with its transition into the scene (fade, rewind or cut), the end card and sounds.
13
13
  *
14
14
  * HyperFrames 0.8.85 contract: a root with `data-composition-id`, clips with
15
15
  * `data-start`/`data-duration`, `<audio>` with an `id`, a GSAP timeline `{ paused: true }` under
@@ -21,15 +21,14 @@ const COMPOSITION_ID = "film";
21
21
  /** Pause before the first word of the opening. */
22
22
  const HOOK_LEAD = 0.3;
23
23
  const HOOK_MIN = 3.8;
24
- const REWIND = 0.8;
25
24
  const END_TAIL = 1.6;
26
25
  /** The end card enters this long after the start of the last sentence. */
27
26
  const END_CARD_DELAY = 0.9;
28
27
 
29
28
  export interface ComposeAssets {
30
- /** Screen recording (mp4 from frames), the rewind clip, the opening frame, the last frame, the tempo-shifted voiceover. */
29
+ /** Screen recording (mp4 from frames), the transition clip (null for a cut), the opening frame, the last frame, the tempo-shifted voiceover. */
31
30
  screen: string;
32
- rewind: string;
31
+ transition: string | null;
33
32
  hookStill: string;
34
33
  lastFrame: string;
35
34
  voiceover: string;
@@ -186,7 +185,8 @@ export function filmTimes(film: Film, log: RecordingLog, voices: BeatVoice[]) {
186
185
  const last = log.beats.at(-1);
187
186
  if (firstBeat === undefined || last === undefined) throw new Error("The recording has no sentences: record the film again (softure-marketing record).");
188
187
  const firstFrame = firstBeat.f0;
189
- const offset = hook + REWIND - firstFrame / log.fps;
188
+ const transition = getTransitionSeconds(film.hook.transition);
189
+ const offset = hook + transition - firstFrame / log.fps;
190
190
  const at = (frame: number): number => r3(frame / log.fps + offset);
191
191
  const lastVoice = voice.get(last.id);
192
192
  if (lastVoice === undefined) throw new Error(`No voiceover for sentence "${last.id}".`);
@@ -198,7 +198,7 @@ export function filmTimes(film: Film, log: RecordingLog, voices: BeatVoice[]) {
198
198
  if (unplaced.length > 0) {
199
199
  throw new Error(`The recording has no sentences ${unplaced.join(", ")}: record the film again (softure-marketing record).`);
200
200
  }
201
- return { hook, rewind: REWIND, firstFrame, at, endCard, end, screenEnd: at(log.frames), voiceStart };
201
+ return { hook, transition, firstFrame, at, endCard, end, screenEnd: at(log.frames), voiceStart };
202
202
  }
203
203
 
204
204
  export function composeFilm(input: ComposeInput): string {
@@ -314,7 +314,7 @@ export function composeFilm(input: ComposeInput): string {
314
314
  .join("\n ");
315
315
 
316
316
  const personaOut = log.cues.find((cue) => cue.name === "persona-out");
317
- const screenStart = r3(times.hook + times.rewind);
317
+ const screenStart = r3(times.hook + times.transition);
318
318
  const screenDuration = r3(times.screenEnd - screenStart);
319
319
  const tail = r3(Math.max(0.04, times.end - times.screenEnd));
320
320
  const c = colors;
@@ -375,7 +375,7 @@ ${windowParts.css}
375
375
  ${windowParts.open}
376
376
  <div class="screen">
377
377
  <img id="hook" class="clip" src="${assets.hookStill}" data-start="0" data-duration="${times.hook}" />
378
- <video id="rewind" class="clip" src="${assets.rewind}" data-start="${times.hook}" data-duration="${times.rewind}" muted playsinline></video>
378
+ ${assets.transition === null || times.transition === 0 ? "" : `<video id="transition" class="clip" src="${assets.transition}" data-start="${times.hook}" data-duration="${times.transition}" muted playsinline></video>`}
379
379
  <video id="recording" class="clip" src="${assets.screen}" data-start="${screenStart}" data-media-start="${r3(times.firstFrame / log.fps)}" data-duration="${screenDuration}" muted playsinline></video>
380
380
  <img id="last" class="clip" src="${assets.lastFrame}" data-start="${times.screenEnd}" data-duration="${tail}" />
381
381
  ${taps.map((tap) => `<div class="touch" style="left:${tap.x}px;top:${tap.y}px"><div class="dot" id="td${tap.i}"></div><div class="ring" id="tr${tap.i}"></div></div>`).join("\n ")}
@@ -327,3 +327,58 @@ export function rewindFrames(first: number, still: number, count = 24): number[]
327
327
  if (count < 2) throw new Error("A rewind needs at least two frames.");
328
328
  return Array.from({ length: count }, (_, k) => Math.round(still - ((still - first) * k) / (count - 1)));
329
329
  }
330
+
331
+ /** How the opening frame hands over to the scene: a cross-fade, a rewind through the scene, or a hard cut. */
332
+ export const TRANSITIONS = ["fade", "rewind", "cut"] as const;
333
+
334
+ export type Transition = (typeof TRANSITIONS)[number];
335
+
336
+ const TRANSITION_SECONDS = 0.8;
337
+ /** Key frames of a rewind: few enough that each screen reads, joined by dissolves (24 blended frames flickered in FIRE). */
338
+ const REWIND_KEY_FRAMES = 5;
339
+ /** One dissolve between two key frames of a rewind. */
340
+ const REWIND_DISSOLVE = 0.2;
341
+
342
+ export function getTransitionSeconds(transition: Transition): number {
343
+ return transition === "cut" ? 0 : TRANSITION_SECONDS;
344
+ }
345
+
346
+ /** The recording frames the transition clip is made of, from the opening frame (`still`) to the scene's first (`first`). */
347
+ export function transitionFrames(transition: Transition, first: number, still: number): number[] {
348
+ if (still < first) throw new Error(`The opening frame (${still}) is before the start of the scene (${first}).`);
349
+ if (transition === "cut") return [];
350
+ if (transition === "fade") return [still, first];
351
+ return rewindFrames(first, still, REWIND_KEY_FRAMES);
352
+ }
353
+
354
+ export interface CrossfadeInput {
355
+ /** Still images in order, at least two. */
356
+ inputs: string[];
357
+ fps: number;
358
+ /** The clip's length. */
359
+ seconds: number;
360
+ output: string;
361
+ }
362
+
363
+ const r3 = (value: number) => Math.round(value * 1000) / 1000;
364
+
365
+ /**
366
+ * ffmpeg arguments of a clip that dissolves from still to still and lasts exactly `seconds`. Two stills fade over
367
+ * the whole clip; more are joined by `REWIND_DISSOLVE` dissolves, each still shown for the same time.
368
+ */
369
+ export function crossfadeArgs(input: CrossfadeInput): string[] {
370
+ const { inputs, fps, seconds, output } = input;
371
+ const count = inputs.length;
372
+ if (count < 2) throw new Error(`A cross-fade needs at least two stills, got ${count}.`);
373
+ const dissolve = count === 2 ? seconds : REWIND_DISSOLVE;
374
+ // count × each - (count - 1) × dissolve = seconds
375
+ const each = r3((seconds + (count - 1) * dissolve) / count);
376
+ const step = r3(each - dissolve);
377
+ const sources = inputs.flatMap((path) => ["-loop", "1", "-framerate", String(fps), "-t", String(each), "-i", path]);
378
+ const filters = inputs.slice(1).map((_, k) => {
379
+ const from = k === 0 ? "[0:v]" : `[v${k}]`;
380
+ const last = k === count - 2 ? ",format=yuv420p" : "";
381
+ return `${from}[${k + 1}:v]xfade=transition=fade:duration=${dissolve}:offset=${r3((k + 1) * step)}${last}[v${k + 1}]`;
382
+ });
383
+ return [...sources, "-filter_complex", filters.join(";"), "-map", `[v${count - 1}]`, "-t", String(seconds), "-r", String(fps), "-c:v", "libx264", "-crf", "16", "-pix_fmt", "yuv420p", output];
384
+ }