@softure-ai/marketing-kit 0.1.12 → 0.3.1
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 +27 -0
- package/README.md +109 -4
- package/dist/cli/footage.d.ts +6 -0
- package/dist/cli/footage.d.ts.map +1 -0
- package/dist/cli/footage.js +95 -0
- package/dist/cli/footage.js.map +1 -0
- package/dist/cli/main.js +21 -5
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/options.d.ts +18 -3
- package/dist/cli/options.d.ts.map +1 -1
- package/dist/cli/options.js +41 -2
- package/dist/cli/options.js.map +1 -1
- package/dist/compose/compose.d.ts.map +1 -1
- package/dist/compose/compose.js +1 -22
- package/dist/compose/compose.js.map +1 -1
- package/dist/compose/html.d.ts +6 -0
- package/dist/compose/html.d.ts.map +1 -0
- package/dist/compose/html.js +24 -0
- package/dist/compose/html.js.map +1 -0
- package/dist/config/actions-schema.d.ts +14 -14
- package/dist/config/config.d.ts +19 -3
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +90 -2
- package/dist/config/config.js.map +1 -1
- package/dist/config/schema.d.ts +152 -70
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +140 -10
- package/dist/config/schema.js.map +1 -1
- package/dist/config/shot-steps.d.ts +16 -16
- package/dist/footage/cache.d.ts +23 -0
- package/dist/footage/cache.d.ts.map +1 -0
- package/dist/footage/cache.js +51 -0
- package/dist/footage/cache.js.map +1 -0
- package/dist/footage/compose.d.ts +50 -0
- package/dist/footage/compose.d.ts.map +1 -0
- package/dist/footage/compose.js +166 -0
- package/dist/footage/compose.js.map +1 -0
- package/dist/footage/edl.d.ts +83 -0
- package/dist/footage/edl.d.ts.map +1 -0
- package/dist/footage/edl.js +166 -0
- package/dist/footage/edl.js.map +1 -0
- package/dist/footage/elevenlabs.d.ts +31 -0
- package/dist/footage/elevenlabs.d.ts.map +1 -0
- package/dist/footage/elevenlabs.js +140 -0
- package/dist/footage/elevenlabs.js.map +1 -0
- package/dist/footage/fake.d.ts +38 -0
- package/dist/footage/fake.d.ts.map +1 -0
- package/dist/footage/fake.js +66 -0
- package/dist/footage/fake.js.map +1 -0
- package/dist/footage/film.d.ts +103 -0
- package/dist/footage/film.d.ts.map +1 -0
- package/dist/footage/film.js +29 -0
- package/dist/footage/film.js.map +1 -0
- package/dist/footage/music.d.ts +37 -0
- package/dist/footage/music.d.ts.map +1 -0
- package/dist/footage/music.js +63 -0
- package/dist/footage/music.js.map +1 -0
- package/dist/footage/normalize.d.ts +41 -0
- package/dist/footage/normalize.d.ts.map +1 -0
- package/dist/footage/normalize.js +114 -0
- package/dist/footage/normalize.js.map +1 -0
- package/dist/footage/pipeline.d.ts +105 -0
- package/dist/footage/pipeline.d.ts.map +1 -0
- package/dist/footage/pipeline.js +385 -0
- package/dist/footage/pipeline.js.map +1 -0
- package/dist/footage/probe.d.ts +64 -0
- package/dist/footage/probe.d.ts.map +1 -0
- package/dist/footage/probe.js +138 -0
- package/dist/footage/probe.js.map +1 -0
- package/dist/footage/providers.d.ts +61 -0
- package/dist/footage/providers.d.ts.map +1 -0
- package/dist/footage/providers.js +13 -0
- package/dist/footage/providers.js.map +1 -0
- package/dist/footage/render.d.ts +20 -0
- package/dist/footage/render.d.ts.map +1 -0
- package/dist/footage/render.js +76 -0
- package/dist/footage/render.js.map +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/messages/index.d.ts +10 -22
- package/dist/messages/index.d.ts.map +1 -1
- package/dist/messages/index.js +8 -6
- package/dist/messages/index.js.map +1 -1
- package/dist/render/render.d.ts +6 -0
- package/dist/render/render.d.ts.map +1 -1
- package/dist/render/render.js +1 -1
- package/dist/render/render.js.map +1 -1
- package/package.json +1 -1
- package/schema/marketing.schema.json +339 -3
- package/src/cli/footage.ts +87 -0
- package/src/cli/main.ts +20 -5
- package/src/cli/options.ts +51 -4
- package/src/compose/compose.ts +1 -25
- package/src/compose/html.ts +28 -0
- package/src/config/config.ts +101 -5
- package/src/config/schema.ts +146 -12
- package/src/footage/cache.ts +66 -0
- package/src/footage/compose.ts +213 -0
- package/src/footage/edl.ts +204 -0
- package/src/footage/elevenlabs.ts +154 -0
- package/src/footage/fake.ts +92 -0
- package/src/footage/film.ts +111 -0
- package/src/footage/music.ts +86 -0
- package/src/footage/normalize.ts +133 -0
- package/src/footage/pipeline.ts +447 -0
- package/src/footage/probe.ts +172 -0
- package/src/footage/providers.ts +71 -0
- package/src/footage/render.ts +82 -0
- package/src/index.ts +110 -3
- package/src/messages/index.ts +16 -8
- package/src/render/render.ts +1 -1
- package/dist/messages/pl.d.ts +0 -3
- package/dist/messages/pl.d.ts.map +0 -1
- package/dist/messages/pl.js +0 -21
- package/dist/messages/pl.js.map +0 -1
- package/src/messages/pl.ts +0 -22
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { VideoFormat } from "../compose/timeline.js";
|
|
2
|
+
import type { EndCard } from "../film.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A footage film: filmed clips (a person talking to camera, b-roll) cut by their transcript into a captioned
|
|
6
|
+
* vertical film. Built from `marketing.json` (`footage[]`) or passed to `renderFootageFilm` as it is.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** `talk`: someone speaks, so the cut follows the words. `broll`: pictures without speech, kept whole with a slow zoom. */
|
|
10
|
+
export const CLIP_ROLES = ["talk", "broll"] as const;
|
|
11
|
+
|
|
12
|
+
export type ClipRole = (typeof CLIP_ROLES)[number];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* How a clip whose aspect differs from the film's fills the frame: `crop` (scaled to cover, edges cut), `blur` (the
|
|
16
|
+
* whole picture over a blurred, enlarged copy of itself) or `auto` (crop when the aspects are within 15 %, else blur).
|
|
17
|
+
*/
|
|
18
|
+
export const CLIP_FITS = ["auto", "crop", "blur"] as const;
|
|
19
|
+
|
|
20
|
+
export type ClipFit = (typeof CLIP_FITS)[number];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How a segment of the cut starts: `cut` (hard), `fade` (a short cross-fade from the previous segment), `zoom` (a
|
|
24
|
+
* punch-in that hides a jump cut inside one talking clip) or `whoosh` (a hard cut with the whoosh sound).
|
|
25
|
+
*/
|
|
26
|
+
export const CUT_TRANSITIONS = ["cut", "fade", "zoom", "whoosh"] as const;
|
|
27
|
+
|
|
28
|
+
export type CutTransition = (typeof CUT_TRANSITIONS)[number];
|
|
29
|
+
|
|
30
|
+
export interface FootageClip {
|
|
31
|
+
/** Unique within the film; the EDL refers to the clip by it. */
|
|
32
|
+
id: string;
|
|
33
|
+
/** A local file (absolute path) or an `https://` URL, downloaded once into the build folder. */
|
|
34
|
+
source: string;
|
|
35
|
+
role: ClipRole;
|
|
36
|
+
fit: ClipFit;
|
|
37
|
+
/** The part of the source the film uses, in seconds; `end: null` is the source's end. */
|
|
38
|
+
trim: { start: number; end: number | null };
|
|
39
|
+
/** What the clip says, for `--placeholder` only: spread evenly over the clip as a free stand-in transcript. */
|
|
40
|
+
script: string | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Where the music under the film comes from. `prompt` and `video` are paid (ElevenLabs Music, Video to Music). */
|
|
44
|
+
export type MusicSource =
|
|
45
|
+
| { kind: "none" }
|
|
46
|
+
| { kind: "file"; path: string }
|
|
47
|
+
| { kind: "prompt"; prompt: string }
|
|
48
|
+
| { kind: "video"; description: string; tags: string[] };
|
|
49
|
+
|
|
50
|
+
export interface FootageMusic {
|
|
51
|
+
source: MusicSource;
|
|
52
|
+
/** The music's volume while nobody speaks (0-1). */
|
|
53
|
+
volume: number;
|
|
54
|
+
/** The music's volume under speech (0-1). */
|
|
55
|
+
duckedVolume: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** How the transcript turns into the cut (`buildEdl`). */
|
|
59
|
+
export interface CutOptions {
|
|
60
|
+
/** Words cut out wherever they stand, compared without case, punctuation and repeated letters. */
|
|
61
|
+
fillers: string[];
|
|
62
|
+
/** A silence between two words longer than this is cut (seconds). */
|
|
63
|
+
pauseSeconds: number;
|
|
64
|
+
/** Seconds kept before the first and after the last word of every kept run. */
|
|
65
|
+
padSeconds: number;
|
|
66
|
+
/** The cut's longest length in seconds; later segments are shortened or dropped. Null: no limit. */
|
|
67
|
+
maxSeconds: number | null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Default transitions by kind of cut; a segment of the EDL may name its own. */
|
|
71
|
+
export interface FootageTransitions {
|
|
72
|
+
/** A cut inside one talking clip (a removed filler or pause). */
|
|
73
|
+
jump: CutTransition;
|
|
74
|
+
/** A cut from one clip to another. */
|
|
75
|
+
clip: CutTransition;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface FootageFilm {
|
|
79
|
+
id: string;
|
|
80
|
+
title: string;
|
|
81
|
+
format: VideoFormat;
|
|
82
|
+
/** ISO 639 code the clips speak (`pl`, `en`): the transcript's language and the default fillers. */
|
|
83
|
+
language: string;
|
|
84
|
+
clips: FootageClip[];
|
|
85
|
+
/** Clean the talking clips' voice (ElevenLabs Voice Isolator, paid) before transcribing them. */
|
|
86
|
+
isolateVoice: boolean;
|
|
87
|
+
cut: CutOptions;
|
|
88
|
+
transitions: FootageTransitions;
|
|
89
|
+
music: FootageMusic;
|
|
90
|
+
/** Word-by-word captions from the transcript. */
|
|
91
|
+
captions: boolean;
|
|
92
|
+
/** The closing card after the last segment; null: the film ends with its last segment. */
|
|
93
|
+
endCard: EndCard | null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Filler words per language, written with repeated letters collapsed (`yyy` and `yyyy` are both `y`). */
|
|
97
|
+
export const DEFAULT_FILLERS: Record<string, string[]> = {
|
|
98
|
+
pl: ["y", "e", "yhm", "yh", "ym", "em", "hm", "mhm", "eh", "uh"],
|
|
99
|
+
en: ["um", "uh", "uhm", "er", "erm", "hm", "mhm", "ah"],
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** The default fillers of a language; none for a language without a list. */
|
|
103
|
+
export function getDefaultFillers(language: string): string[] {
|
|
104
|
+
return DEFAULT_FILLERS[language] ?? [];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const DEFAULT_CUT: Omit<CutOptions, "fillers"> = { pauseSeconds: 0.6, padSeconds: 0.12, maxSeconds: null };
|
|
108
|
+
|
|
109
|
+
export const DEFAULT_TRANSITIONS: FootageTransitions = { jump: "zoom", clip: "fade" };
|
|
110
|
+
|
|
111
|
+
export const DEFAULT_MUSIC_VOLUME = { volume: 0.35, duckedVolume: 0.1 } as const;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { TimedWord } from "../voice/voiceover.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Music under the voice: loud between sentences, ducked while someone speaks. The envelope is a list of keyframes
|
|
5
|
+
* computed from the film's word times; ffmpeg applies it to the music file (`volumeExpression`), so the composition
|
|
6
|
+
* plays an already ducked track.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface VolumeKeyframe {
|
|
10
|
+
t: number;
|
|
11
|
+
volume: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface DuckingOptions {
|
|
15
|
+
/** The music's volume between sentences and under speech. */
|
|
16
|
+
volume: number;
|
|
17
|
+
duckedVolume: number;
|
|
18
|
+
/** Seconds the music takes to go down before the first word, and to come back after the last. */
|
|
19
|
+
attack?: number;
|
|
20
|
+
release?: number;
|
|
21
|
+
/** Two words closer than this stay one stretch of speech. */
|
|
22
|
+
gap?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const r3 = (value: number): number => Math.round(value * 1000) / 1000 || 0;
|
|
26
|
+
|
|
27
|
+
/** Stretches of speech: the words joined when less than `gap` seconds apart. */
|
|
28
|
+
export function getSpeechSpans(words: TimedWord[], gap: number): { start: number; end: number }[] {
|
|
29
|
+
const spans: { start: number; end: number }[] = [];
|
|
30
|
+
for (const word of [...words].sort((a, b) => a.start - b.start)) {
|
|
31
|
+
const last = spans.at(-1);
|
|
32
|
+
if (last !== undefined && word.start - last.end < gap) last.end = Math.max(last.end, word.end);
|
|
33
|
+
else spans.push({ start: word.start, end: word.end });
|
|
34
|
+
}
|
|
35
|
+
return spans;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The music's volume over time as keyframes (linear between them): `volume`, down to `duckedVolume` by the first word
|
|
40
|
+
* of each stretch of speech, back up `release` seconds after its last word. Stretches too close for the music to
|
|
41
|
+
* come back up merge.
|
|
42
|
+
*/
|
|
43
|
+
export function duckingKeyframes(words: TimedWord[], options: DuckingOptions): VolumeKeyframe[] {
|
|
44
|
+
const attack = options.attack ?? 0.25;
|
|
45
|
+
const release = options.release ?? 0.5;
|
|
46
|
+
const spans = getSpeechSpans(words, Math.max(options.gap ?? 0.6, attack + release));
|
|
47
|
+
const keyframes: VolumeKeyframe[] = [];
|
|
48
|
+
const push = (t: number, volume: number) => {
|
|
49
|
+
const time = r3(Math.max(0, t));
|
|
50
|
+
const last = keyframes.at(-1);
|
|
51
|
+
if (last !== undefined && time <= last.t) {
|
|
52
|
+
last.volume = volume;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
keyframes.push({ t: time, volume });
|
|
56
|
+
};
|
|
57
|
+
if (spans.length === 0 || (spans[0]?.start ?? 0) - attack > 0) push(0, options.volume);
|
|
58
|
+
for (const span of spans) {
|
|
59
|
+
push(span.start - attack, options.volume);
|
|
60
|
+
push(span.start, options.duckedVolume);
|
|
61
|
+
push(span.end, options.duckedVolume);
|
|
62
|
+
push(span.end + release, options.volume);
|
|
63
|
+
}
|
|
64
|
+
return keyframes;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const n = (value: number): string => String(r3(value));
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* An expression for ffmpeg's `volume` filter (`eval=frame`, time `t`): the keyframes as a sum of linear pieces, each
|
|
71
|
+
* switched on by its own time window, so a long film needs no nesting.
|
|
72
|
+
*/
|
|
73
|
+
export function volumeExpression(keyframes: VolumeKeyframe[]): string {
|
|
74
|
+
const first = keyframes[0];
|
|
75
|
+
const last = keyframes.at(-1);
|
|
76
|
+
if (first === undefined || last === undefined) return "1";
|
|
77
|
+
const pieces = [`lt(t,${n(first.t)})*${n(first.volume)}`];
|
|
78
|
+
keyframes.slice(0, -1).forEach((from, index) => {
|
|
79
|
+
const to = keyframes[index + 1] as VolumeKeyframe;
|
|
80
|
+
const slope = (to.volume - from.volume) / (to.t - from.t);
|
|
81
|
+
const value = slope === 0 ? n(from.volume) : `(${n(from.volume)}+${String(Math.round(slope * 1e6) / 1e6)}*(t-${n(from.t)}))`;
|
|
82
|
+
pieces.push(`gte(t,${n(from.t)})*lt(t,${n(to.t)})*${value}`);
|
|
83
|
+
});
|
|
84
|
+
pieces.push(`gte(t,${n(last.t)})*${n(last.volume)}`);
|
|
85
|
+
return pieces.join("+");
|
|
86
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
import type { ClipFit, FootageClip } from "./film.js";
|
|
4
|
+
import { getTrimmedDuration, type FootageProbe, type HdrKind } from "./probe.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One intermediate format for every clip, so the composition can cut between them freely: the film's frame at
|
|
8
|
+
* 30 fps, upright (ffmpeg applies the stored rotation while decoding), SDR BT.709 (HDR tone-mapped), filled by a crop
|
|
9
|
+
* or a blurred copy, a keyframe every half second (the renderer seeks into each segment), and 48 kHz stereo AAC
|
|
10
|
+
* (silence when the clip has no sound), so the speech track can be cut from any clip alike.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const FOOTAGE_FPS = 30;
|
|
14
|
+
export const FOOTAGE_SAMPLE_RATE = 48_000;
|
|
15
|
+
/** Within this difference of aspect ratios `auto` crops; beyond it, it fills with a blurred copy. */
|
|
16
|
+
const CROP_ASPECT_TOLERANCE = 0.15;
|
|
17
|
+
|
|
18
|
+
export interface Frame {
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The fit `auto` resolves to for this picture in this frame. */
|
|
24
|
+
export function resolveFit(fit: ClipFit, probe: Pick<FootageProbe, "displayWidth" | "displayHeight">, frame: Frame): "crop" | "blur" {
|
|
25
|
+
if (fit !== "auto") return fit;
|
|
26
|
+
const clipAspect = probe.displayWidth / probe.displayHeight;
|
|
27
|
+
const frameAspect = frame.width / frame.height;
|
|
28
|
+
return Math.abs(clipAspect - frameAspect) / frameAspect <= CROP_ASPECT_TOLERANCE ? "crop" : "blur";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const TRANSFER_INPUT: Record<HdrKind, string> = { pq: "smpte2084", hlg: "arib-std-b67", "dolby-vision": "arib-std-b67" };
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* HDR to SDR BT.709 on the CPU: to linear light (zscale), Hable tone curve, back to BT.709. A Dolby Vision phone
|
|
35
|
+
* clip is read through its HLG base layer.
|
|
36
|
+
*/
|
|
37
|
+
export function toneMapFilter(hdr: HdrKind | null, transfer: string | null): string[] {
|
|
38
|
+
if (hdr === null) return [];
|
|
39
|
+
const input = transfer === "smpte2084" || transfer === "arib-std-b67" ? transfer : TRANSFER_INPUT[hdr];
|
|
40
|
+
return [
|
|
41
|
+
`zscale=tin=${input}:pin=bt2020:min=bt2020nc:t=linear:npl=100`,
|
|
42
|
+
"format=gbrpf32le",
|
|
43
|
+
"zscale=p=bt709",
|
|
44
|
+
"tonemap=tonemap=hable:desat=0",
|
|
45
|
+
"zscale=t=bt709:m=bt709:r=tv",
|
|
46
|
+
// Back to 8-bit before scaling: the blur fill on float frames crashed ffmpeg 6.1.
|
|
47
|
+
"format=yuv420p",
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The video filter graph from input 0's picture to `[v]`. */
|
|
52
|
+
export function buildVideoFilter(options: { fit: "crop" | "blur"; frame: Frame; hdr: HdrKind | null; transfer: string | null }): string {
|
|
53
|
+
const { width, height } = options.frame;
|
|
54
|
+
const head = [...toneMapFilter(options.hdr, options.transfer), `fps=${FOOTAGE_FPS}`].join(",");
|
|
55
|
+
const cover = `scale=${width}:${height}:force_original_aspect_ratio=increase,crop=${width}:${height}`;
|
|
56
|
+
const tail = "setsar=1,format=yuv420p";
|
|
57
|
+
if (options.fit === "crop") return `[0:v]${head},${cover},${tail}[v]`;
|
|
58
|
+
return [
|
|
59
|
+
`[0:v]${head},split=2[bg][fg]`,
|
|
60
|
+
`[bg]scale=${Math.round(width / 4)}:${Math.round(height / 4)}:force_original_aspect_ratio=increase,crop=${Math.round(width / 4)}:${Math.round(height / 4)},boxblur=20:2,scale=${width}:${height},eq=brightness=-0.06[back]`,
|
|
61
|
+
`[fg]scale=${width}:${height}:force_original_aspect_ratio=decrease[front]`,
|
|
62
|
+
`[back][front]overlay=(W-w)/2:(H-h)/2,${tail}[v]`,
|
|
63
|
+
].join(";");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface NormalizeInput {
|
|
67
|
+
clip: FootageClip;
|
|
68
|
+
/** The local file (a URL's downloaded copy). */
|
|
69
|
+
file: string;
|
|
70
|
+
probe: FootageProbe;
|
|
71
|
+
frame: Frame;
|
|
72
|
+
output: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** ffmpeg's arguments for one clip; pure, so the graph is tested without ffmpeg. */
|
|
76
|
+
export function buildNormalizeArgs(input: NormalizeInput): string[] {
|
|
77
|
+
const { clip, file, probe, frame, output } = input;
|
|
78
|
+
const duration = getTrimmedDuration(clip, probe);
|
|
79
|
+
const fit = resolveFit(clip.fit, probe, frame);
|
|
80
|
+
const seek = clip.trim.start > 0 ? ["-ss", String(clip.trim.start)] : [];
|
|
81
|
+
const silence = probe.hasAudio ? [] : ["-f", "lavfi", "-i", `anullsrc=r=${FOOTAGE_SAMPLE_RATE}:cl=stereo`];
|
|
82
|
+
return [
|
|
83
|
+
"-v",
|
|
84
|
+
"error",
|
|
85
|
+
"-y",
|
|
86
|
+
...seek,
|
|
87
|
+
"-i",
|
|
88
|
+
file,
|
|
89
|
+
...silence,
|
|
90
|
+
"-t",
|
|
91
|
+
duration.toFixed(3),
|
|
92
|
+
"-filter_complex",
|
|
93
|
+
buildVideoFilter({ fit, frame, hdr: probe.hdr, transfer: probe.colorTransfer }),
|
|
94
|
+
"-map",
|
|
95
|
+
"[v]",
|
|
96
|
+
"-map",
|
|
97
|
+
probe.hasAudio ? "0:a:0" : "1:a",
|
|
98
|
+
"-c:v",
|
|
99
|
+
"libx264",
|
|
100
|
+
"-preset",
|
|
101
|
+
"veryfast",
|
|
102
|
+
"-crf",
|
|
103
|
+
"18",
|
|
104
|
+
"-g",
|
|
105
|
+
String(FOOTAGE_FPS / 2),
|
|
106
|
+
"-color_primaries",
|
|
107
|
+
"bt709",
|
|
108
|
+
"-color_trc",
|
|
109
|
+
"bt709",
|
|
110
|
+
"-colorspace",
|
|
111
|
+
"bt709",
|
|
112
|
+
"-c:a",
|
|
113
|
+
"aac",
|
|
114
|
+
"-b:a",
|
|
115
|
+
"192k",
|
|
116
|
+
"-ar",
|
|
117
|
+
String(FOOTAGE_SAMPLE_RATE),
|
|
118
|
+
"-ac",
|
|
119
|
+
"2",
|
|
120
|
+
"-movflags",
|
|
121
|
+
"+faststart",
|
|
122
|
+
output,
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Runs ffmpeg for one clip; throws with the clip's id when it fails (a broken file is not an expected outcome here). */
|
|
127
|
+
export function normalizeFootage(input: NormalizeInput): void {
|
|
128
|
+
const result = spawnSync("ffmpeg", buildNormalizeArgs(input), { stdio: ["ignore", "inherit", "inherit"] });
|
|
129
|
+
if (result.error !== undefined) throw new Error(`Normalizing clip ${input.clip.id}: ffmpeg did not start (${result.error.message}).`);
|
|
130
|
+
if (result.status !== 0) {
|
|
131
|
+
throw new Error(`Normalizing clip ${input.clip.id} (${input.file}): ffmpeg ended with code ${String(result.status)} (signal ${result.signal ?? "-"}).`);
|
|
132
|
+
}
|
|
133
|
+
}
|