@aicopycoders/exodus 2026.11.200-beta.1 → 2026.11.500-beta.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.
|
@@ -23,11 +23,44 @@ export interface CutPace {
|
|
|
23
23
|
wordsPerMin: { ours: number | null; source: number | null };
|
|
24
24
|
deadAir: { over03s: number; longestSec: number };
|
|
25
25
|
/** The settings the cut was made with, from the manifest's `finishing`. */
|
|
26
|
-
finishing: {
|
|
27
|
-
|
|
26
|
+
finishing: {
|
|
27
|
+
cutPace: boolean;
|
|
28
|
+
captions: boolean;
|
|
29
|
+
cards: boolean;
|
|
30
|
+
finishLoudness: boolean;
|
|
31
|
+
targetSeconds?: number;
|
|
32
|
+
/** Each setting below is present only when it is on. */
|
|
33
|
+
captionsByLine?: true;
|
|
34
|
+
cleanVoice?: true;
|
|
35
|
+
limitPeaks?: true;
|
|
36
|
+
brollMinSec?: number;
|
|
37
|
+
speedUpSlowBroll?: true;
|
|
38
|
+
cutChecks?: true;
|
|
39
|
+
};
|
|
40
|
+
/** `limited`: limitPeaks' limiter ran after the loudness pass. */
|
|
41
|
+
loudness?: { lufs: number; truePeak: number; passes: 1 | 2; limited?: true };
|
|
42
|
+
/** Present only with cutChecks. */
|
|
43
|
+
checks?: CutChecks;
|
|
28
44
|
notes?: string[];
|
|
29
45
|
}
|
|
30
46
|
|
|
47
|
+
/** What cutChecks measured on the finished cut, and what fails its bars. */
|
|
48
|
+
export interface CutChecks {
|
|
49
|
+
/** Caption screens holding words of two script lines, in the cut's time before any speed-up; null when no captions were burned. */
|
|
50
|
+
lineMixes: Array<{ s: number; text: string }> | null;
|
|
51
|
+
/** The voice's loudness over everything under it; null with a song laid whole or a silent voice. */
|
|
52
|
+
voiceOverBedDb: number | null;
|
|
53
|
+
voiceLufs: number | null;
|
|
54
|
+
bedLufs: number | null;
|
|
55
|
+
repeats: Array<{ phrase: string; firstAt: number; againAt: number }>;
|
|
56
|
+
shortShots: Array<{ n: number; role: string; at: number; sec: number }>;
|
|
57
|
+
/** null when ffmpeg could not read the cut's motion. */
|
|
58
|
+
slowShots: Array<{ n: number; role: string; at: number; sec: number; motion: number; median: number }> | null;
|
|
59
|
+
lufs: number | null;
|
|
60
|
+
truePeak: number | null;
|
|
61
|
+
verdict: { pass: boolean; fails: string[] };
|
|
62
|
+
}
|
|
63
|
+
|
|
31
64
|
/** What the cut did with the manifest's `sound`: where each sound and bed played and how loud, and what it left out. */
|
|
32
65
|
export interface CutSound {
|
|
33
66
|
voiceLufs: number | null;
|
|
@@ -155,11 +155,18 @@ export const FINISH_LUFS = -14;
|
|
|
155
155
|
export const FINISH_TRUE_PEAK = -1.5;
|
|
156
156
|
export const FINISH_LRA = 11;
|
|
157
157
|
export const TRUE_PEAK_MAX_DB = -1;
|
|
158
|
+
/**
|
|
159
|
+
* limitPeaks: after the loudness pass, the sound oversampled 4x through a
|
|
160
|
+
* limiter at 0.8 (about -1.9 dB), so a peak between two samples is caught too.
|
|
161
|
+
* The cut is still measured after and refused over TRUE_PEAK_MAX_DB.
|
|
162
|
+
*/
|
|
163
|
+
export const PEAK_LIMITER = "aresample=192000,alimiter=limit=0.8:level=false:attack=2:release=60";
|
|
158
164
|
|
|
159
165
|
/**
|
|
160
166
|
* The manifest's finishing settings, or null when none is on. The worker
|
|
161
167
|
* writes them from the run's frozen kind settings, so a redo of the run cuts
|
|
162
|
-
* with the same ones.
|
|
168
|
+
* with the same ones. A setting added after the first four is present only
|
|
169
|
+
* when it is on and can act (captionsByLine needs captions).
|
|
163
170
|
*/
|
|
164
171
|
export function finishingOf(manifest) {
|
|
165
172
|
const f = manifest?.finishing;
|
|
@@ -170,9 +177,17 @@ export function finishingOf(manifest) {
|
|
|
170
177
|
cards: f.cards === true,
|
|
171
178
|
finishLoudness: f.finishLoudness === true,
|
|
172
179
|
};
|
|
173
|
-
|
|
180
|
+
const added = {
|
|
181
|
+
...(on.captions && f.captionsByLine === true ? { captionsByLine: true } : {}),
|
|
182
|
+
...(f.cleanVoice === true ? { cleanVoice: true } : {}),
|
|
183
|
+
...(on.finishLoudness && f.limitPeaks === true ? { limitPeaks: true } : {}),
|
|
184
|
+
...(Number.isFinite(f.brollMinSec) && f.brollMinSec > 0 ? { brollMinSec: f.brollMinSec } : {}),
|
|
185
|
+
...(f.speedUpSlowBroll === true ? { speedUpSlowBroll: true } : {}),
|
|
186
|
+
...(f.cutChecks === true ? { cutChecks: true } : {}),
|
|
187
|
+
};
|
|
188
|
+
if (!Object.values(on).some(Boolean) && Object.keys(added).length === 0) return null;
|
|
174
189
|
const target = f.targetSeconds;
|
|
175
|
-
return on.cutPace && Number.isFinite(target) && target > 0 ? { ...on, targetSeconds: target } : on;
|
|
190
|
+
return on.cutPace && Number.isFinite(target) && target > 0 ? { ...on, targetSeconds: target, ...added } : { ...on, ...added };
|
|
176
191
|
}
|
|
177
192
|
|
|
178
193
|
/**
|
|
@@ -198,6 +213,18 @@ const BED_FADE_SEC = 0.15;
|
|
|
198
213
|
export const MUSIC_UNDER_DB = 16.8;
|
|
199
214
|
const MUSIC_FALLBACK_DB = -20;
|
|
200
215
|
export const DUCK = { threshold: 0.05, ratio: 2.5, attack: 20, release: 350 };
|
|
216
|
+
/**
|
|
217
|
+
* cleanVoice: the voice's chain (rumble cut, light noise reduction, de-essing,
|
|
218
|
+
* gentle compression), and what happens to the room, sounds and music under
|
|
219
|
+
* it: down UNDER_VOICE.db, trimmed under `highpass` and over `lowpass` Hz, and
|
|
220
|
+
* ducked by a compressor keyed on the cleaned voice. It is the one duck: the
|
|
221
|
+
* music's own (DUCK) is left out. A reaction's tail is a voice, so it is
|
|
222
|
+
* neither cleaned nor ducked.
|
|
223
|
+
*/
|
|
224
|
+
export const VOICE_CLEAN =
|
|
225
|
+
"highpass=f=90,afftdn=nr=8:nf=-38,deesser=i=0.35,acompressor=threshold=0.125:ratio=2.5:attack=8:release=150:makeup=1.5";
|
|
226
|
+
export const UNDER_VOICE = { db: -6, highpass: 60, lowpass: 9000, duck: { threshold: 0.03, ratio: 5, attack: 15, release: 300 } };
|
|
227
|
+
const CLEAN_FILTERS = ["highpass", "lowpass", "afftdn", "deesser", "acompressor", "sidechaincompress"];
|
|
201
228
|
const SEGMENT_LUFS = -16;
|
|
202
229
|
/** A voice at or under this is no level to set a sound against. */
|
|
203
230
|
const VOICE_FLOOR_LUFS = -60;
|
|
@@ -1678,6 +1705,74 @@ export function buildTimeline({
|
|
|
1678
1705
|
};
|
|
1679
1706
|
}
|
|
1680
1707
|
|
|
1708
|
+
/**
|
|
1709
|
+
* brollMinSec: a cutaway on screen for less than `minSec` of the finished ad
|
|
1710
|
+
* (its time in the cut over `speed`) is left out, and the shot before it plays
|
|
1711
|
+
* on over its time: the cutaway that ends where it starts, its last frame held
|
|
1712
|
+
* if its clip runs out, else the scene under it. `clipSeconds(file)` is a
|
|
1713
|
+
* clip's length. Returns a line for each cutaway left out.
|
|
1714
|
+
*/
|
|
1715
|
+
export function holdBroll(timeline, minSec, speed, clipSeconds) {
|
|
1716
|
+
const kept = [];
|
|
1717
|
+
const left = [];
|
|
1718
|
+
for (const c of timeline.cutaways) {
|
|
1719
|
+
const shown = c.seconds / speed;
|
|
1720
|
+
if (shown >= minSec - 1e-6) {
|
|
1721
|
+
kept.push(c);
|
|
1722
|
+
continue;
|
|
1723
|
+
}
|
|
1724
|
+
const why = `cutaway ${c.sceneIndex}: ${shown.toFixed(2)}s on screen, under the ${minSec}s B-roll minimum, so it is left out and`;
|
|
1725
|
+
const before = kept.at(-1);
|
|
1726
|
+
if (before && Math.abs(before.startSec + before.seconds - c.startSec) < 0.5 / FPS) {
|
|
1727
|
+
before.seconds = roundMs(c.startSec + c.seconds - before.startSec);
|
|
1728
|
+
if (c.cutShortBy) before.cutShortBy = c.cutShortBy;
|
|
1729
|
+
else delete before.cutShortBy;
|
|
1730
|
+
const hold = before.source === "clip" ? roundMs(before.seconds - clipSeconds(before.file)) : 0;
|
|
1731
|
+
if (hold > 0) before.holdSec = hold;
|
|
1732
|
+
left.push(`${why} cutaway ${before.sceneIndex} plays on over it`);
|
|
1733
|
+
} else {
|
|
1734
|
+
left.push(`${why} the scene under it plays on`);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
timeline.cutaways = kept;
|
|
1738
|
+
return left;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
/** speedUpSlowBroll: the most a slow cutaway is sped up. */
|
|
1742
|
+
export const SLOW_SHOT_SPEED_MAX = 1.6;
|
|
1743
|
+
|
|
1744
|
+
/**
|
|
1745
|
+
* speedUpSlowBroll: every shot's motion is read off its clip before the render
|
|
1746
|
+
* (`motionOf(file, fromSec, seconds)`), and a cutaway that slowShots finds slow
|
|
1747
|
+
* plays its clip faster, at most SLOW_SHOT_SPEED_MAX, so it shows more of its
|
|
1748
|
+
* clip in the same time on screen. A cutaway whose clip is no longer than its
|
|
1749
|
+
* time on screen cannot be, and is noted. Returns a line for each slow cutaway.
|
|
1750
|
+
*/
|
|
1751
|
+
export function speedUpSlowBroll(timeline, motionOf, clipSeconds) {
|
|
1752
|
+
const shots = [
|
|
1753
|
+
...timeline.spine
|
|
1754
|
+
.filter((seg) => seg.source === "clip")
|
|
1755
|
+
.map((seg) => ({ n: seg.sceneIndex, role: roleOf(seg), file: seg.file, from: seg.inSec ?? 0, sec: seg.seconds - (seg.holdSec ?? 0) })),
|
|
1756
|
+
...timeline.cutaways
|
|
1757
|
+
.filter((c) => c.source === "clip")
|
|
1758
|
+
.map((c) => ({ n: c.sceneIndex, role: "b-roll", file: c.file, from: 0, sec: c.seconds, cutaway: c })),
|
|
1759
|
+
].filter((s) => s.sec > 0);
|
|
1760
|
+
const measured = shots.map((s) => ({ ...s, motion: motionOf(s.file, s.from, s.sec) }));
|
|
1761
|
+
const notes = [];
|
|
1762
|
+
for (const slow of slowShots(measured)) {
|
|
1763
|
+
const c = slow.cutaway;
|
|
1764
|
+
if (!c) continue;
|
|
1765
|
+
const have = clipSeconds(c.file);
|
|
1766
|
+
if (!(have > c.seconds + 0.05)) {
|
|
1767
|
+
notes.push(`cutaway ${c.sceneIndex} barely moves, but its clip (${have.toFixed(2)}s) is no longer than its time on screen (${c.seconds.toFixed(2)}s), so it plays as it is`);
|
|
1768
|
+
continue;
|
|
1769
|
+
}
|
|
1770
|
+
c.speed = roundMs(Math.min(have / c.seconds, SLOW_SHOT_SPEED_MAX));
|
|
1771
|
+
notes.push(`cutaway ${c.sceneIndex} barely moves, so it plays ${c.speed}x faster: ${(c.seconds * c.speed).toFixed(2)}s of its clip in ${c.seconds.toFixed(2)}s`);
|
|
1772
|
+
}
|
|
1773
|
+
return notes;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1681
1776
|
/** #3365: why the cut stopped on scenes with no clip, and the person's three ways on. */
|
|
1682
1777
|
function noClipRefusal(missing) {
|
|
1683
1778
|
const scenes = missing.map((m) => `scene ${m.n} (${m.status})`).join(", ");
|
|
@@ -1700,8 +1795,10 @@ function sec(n) {
|
|
|
1700
1795
|
* The render. `finish` (null: today's render) carries the finishing settings'
|
|
1701
1796
|
* part of it: levelSegments false leaves each segment's sound as it is for the
|
|
1702
1797
|
* whole mix's loudness pass, `ass` names the captions and cards file burned in
|
|
1703
|
-
* (read from the folder ffmpeg runs in),
|
|
1704
|
-
* cut, picture and sound, after the burn
|
|
1798
|
+
* (read from the folder ffmpeg runs in), `speed` over 1 speeds the whole
|
|
1799
|
+
* cut, picture and sound, after the burn, `clean` (cleanVoice) is the voice's
|
|
1800
|
+
* chain and the duck under it, and `meters` (cutChecks) names the two files
|
|
1801
|
+
* the voice and everything under it are also written to.
|
|
1705
1802
|
*/
|
|
1706
1803
|
export function buildFfmpegArgs(timeline, { resolve, music, out, finish = null, sound = null }) {
|
|
1707
1804
|
const level = finish && finish.levelSegments === false ? "anull" : LOUDNORM;
|
|
@@ -1813,8 +1910,11 @@ export function buildFfmpegArgs(timeline, { resolve, music, out, finish = null,
|
|
|
1813
1910
|
? addInput("-i", resolve(c.file))
|
|
1814
1911
|
: addInput("-loop", "1", "-t", String(c.seconds), "-i", resolve(c.file));
|
|
1815
1912
|
const end = c.startSec + c.seconds;
|
|
1913
|
+
// speedUpSlowBroll: a slow cutaway plays faster; brollMinSec: one that plays on past its clip holds its last frame.
|
|
1914
|
+
const faster = c.speed > 1 ? `,setpts=PTS/${c.speed}` : "";
|
|
1915
|
+
const hold = c.holdSec > 0 ? `,tpad=stop_mode=clone:stop_duration=${sec(c.holdSec)}` : "";
|
|
1816
1916
|
filters.push(
|
|
1817
|
-
`${norm(`${i}:v`)},trim=0:${sec(c.seconds)},setpts=PTS-STARTPTS+${sec(c.startSec)}/TB[cv${j}]`,
|
|
1917
|
+
`${norm(`${i}:v`)}${faster}${hold},trim=0:${sec(c.seconds)},setpts=PTS-STARTPTS+${sec(c.startSec)}/TB[cv${j}]`,
|
|
1818
1918
|
);
|
|
1819
1919
|
// eof_action=pass keeps the spine showing once the cutaway's frames end.
|
|
1820
1920
|
filters.push(
|
|
@@ -1867,9 +1967,10 @@ export function buildFfmpegArgs(timeline, { resolve, music, out, finish = null,
|
|
|
1867
1967
|
beds.push(`[sfx${j}]`);
|
|
1868
1968
|
});
|
|
1869
1969
|
let voice = "[voice]";
|
|
1970
|
+
const clean = finish?.clean ?? null;
|
|
1870
1971
|
if (music) {
|
|
1871
1972
|
const m = addInput("-stream_loop", "-1", "-i", music);
|
|
1872
|
-
const duck = sound?.music?.duck;
|
|
1973
|
+
const duck = clean ? null : sound?.music?.duck;
|
|
1873
1974
|
if (duck) {
|
|
1874
1975
|
filters.push("[voice]asplit=2[voiced][duckkey]");
|
|
1875
1976
|
filters.push(`[${m}:a]${stereo},atrim=0:${pictureSec.toFixed(6)},asetpts=PTS-STARTPTS,volume=${sound.music.gainDb}dB[bedraw]`);
|
|
@@ -1877,13 +1978,42 @@ export function buildFfmpegArgs(timeline, { resolve, music, out, finish = null,
|
|
|
1877
1978
|
`[bedraw][duckkey]sidechaincompress=threshold=${duck.threshold}:ratio=${duck.ratio}:attack=${duck.attack}:release=${duck.release}[bed]`,
|
|
1878
1979
|
);
|
|
1879
1980
|
voice = "[voiced]";
|
|
1981
|
+
} else if (clean && sound?.music) {
|
|
1982
|
+
filters.push(`[${m}:a]${stereo},atrim=0:${pictureSec.toFixed(6)},asetpts=PTS-STARTPTS,volume=${sound.music.gainDb}dB[bed]`);
|
|
1880
1983
|
} else {
|
|
1881
1984
|
filters.push(`[${m}:a]${stereo},volume=${MUSIC_VOLUME}[bed]`);
|
|
1882
1985
|
}
|
|
1883
1986
|
beds.push("[bed]");
|
|
1884
1987
|
}
|
|
1988
|
+
let under = beds;
|
|
1989
|
+
if (clean) {
|
|
1990
|
+
// Each bed is trimmed to the picture, then ducked on its own by the same key, which ducks their sum the same.
|
|
1991
|
+
const ducked = beds.filter((label) => !tails.includes(label));
|
|
1992
|
+
const u = clean.under;
|
|
1993
|
+
filters.push(`[voice]${clean.voice},asplit=${ducked.length + 1}[voiced]${ducked.map((_, j) => `[vkey${j}]`).join("")}`);
|
|
1994
|
+
ducked.forEach((label, j) => {
|
|
1995
|
+
filters.push(`${label}atrim=end=${pictureSec.toFixed(6)},highpass=f=${u.highpass},lowpass=f=${u.lowpass},volume=${u.db}dB[uc${j}]`);
|
|
1996
|
+
filters.push(
|
|
1997
|
+
`[uc${j}][vkey${j}]sidechaincompress=threshold=${u.duck.threshold}:ratio=${u.duck.ratio}:attack=${u.duck.attack}:release=${u.duck.release}[ud${j}]`,
|
|
1998
|
+
);
|
|
1999
|
+
});
|
|
2000
|
+
voice = "[voiced]";
|
|
2001
|
+
under = [...ducked.map((_, j) => `[ud${j}]`), ...tails];
|
|
2002
|
+
}
|
|
2003
|
+
if (finish?.meters) {
|
|
2004
|
+
// cutChecks: the voice, and everything under it mixed, each also written alone to be measured.
|
|
2005
|
+
filters.push(`${voice}asplit=2[metered][vmeter]`);
|
|
2006
|
+
voice = "[metered]";
|
|
2007
|
+
under = under.map((label, j) => {
|
|
2008
|
+
filters.push(`${label}asplit=2[mu${j}][mb${j}]`, `[mb${j}]atrim=end=${pictureSec.toFixed(6)}[mt${j}]`);
|
|
2009
|
+
return `[mu${j}]`;
|
|
2010
|
+
});
|
|
2011
|
+
filters.push(
|
|
2012
|
+
`${under.map((_, j) => `[mt${j}]`).join("")}amix=inputs=${under.length}:duration=longest:dropout_transition=0:normalize=0[bedmeter]`,
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
1885
2015
|
filters.push(
|
|
1886
|
-
`${voice}${
|
|
2016
|
+
`${voice}${under.join("")}amix=inputs=${under.length + 1}:duration=first:dropout_transition=0:normalize=0[mix]`,
|
|
1887
2017
|
);
|
|
1888
2018
|
let audioLabel = "mix";
|
|
1889
2019
|
if (speed) {
|
|
@@ -1900,6 +2030,9 @@ export function buildFfmpegArgs(timeline, { resolve, music, out, finish = null,
|
|
|
1900
2030
|
"-c:a", "aac", "-b:a", "192k",
|
|
1901
2031
|
"-movflags", "+faststart",
|
|
1902
2032
|
out,
|
|
2033
|
+
...(finish?.meters
|
|
2034
|
+
? ["-map", "[vmeter]", "-c:a", "pcm_s16le", finish.meters.voice, "-map", "[bedmeter]", "-c:a", "pcm_s16le", finish.meters.bed]
|
|
2035
|
+
: []),
|
|
1903
2036
|
];
|
|
1904
2037
|
}
|
|
1905
2038
|
|
|
@@ -2195,15 +2328,114 @@ export function captionScreens(words, cap = null) {
|
|
|
2195
2328
|
});
|
|
2196
2329
|
}
|
|
2197
2330
|
|
|
2331
|
+
/**
|
|
2332
|
+
* captionsByLine: a caption screen holds the words of one script line only, a
|
|
2333
|
+
* few a screen (`cap`, a source record's caption style, else 3), breaks on a
|
|
2334
|
+
* pause over CAPTION_LINE_GAP_SEC, stays up CAPTION_TAIL_SEC after its last
|
|
2335
|
+
* word at most and goes off CAPTION_CLEAR_SEC before the next comes on. A
|
|
2336
|
+
* screen shorter than CAPTION_MIN_SEC joins the next one of its line, else the
|
|
2337
|
+
* one before, one word over the few at most. `words`: [{ text, start, end, line }].
|
|
2338
|
+
*/
|
|
2339
|
+
export const CAPTION_LINE_GAP_SEC = 0.5;
|
|
2340
|
+
export const CAPTION_TAIL_SEC = 0.15;
|
|
2341
|
+
export const CAPTION_CLEAR_SEC = 0.02;
|
|
2342
|
+
export const CAPTION_MIN_SEC = 0.35;
|
|
2343
|
+
/** captionsByLine: the caption font is at most this share of the frame's height (69 px of 1920). */
|
|
2344
|
+
export const CAPTION_MAX_SHARE = 0.036;
|
|
2345
|
+
|
|
2346
|
+
export function lineCaptionScreens(words, cap = null) {
|
|
2347
|
+
const per = Math.max(1, Math.round(cap?.wordsPerLine?.median ?? 3));
|
|
2348
|
+
const caps = /all-caps|capitals|upper/i.test(cap?.style ?? "");
|
|
2349
|
+
let chunks = [];
|
|
2350
|
+
let cur = [];
|
|
2351
|
+
for (const w of words) {
|
|
2352
|
+
const last = cur.at(-1);
|
|
2353
|
+
// Script words timed by one heard word ("twenty five" for "25") stay on one screen.
|
|
2354
|
+
const oneHeard = last && w.line === last.line && w.start === last.start && w.end === last.end;
|
|
2355
|
+
if (last && !oneHeard && (cur.length >= per || w.line !== last.line || w.start - last.end > CAPTION_LINE_GAP_SEC)) {
|
|
2356
|
+
chunks.push(cur);
|
|
2357
|
+
cur = [];
|
|
2358
|
+
}
|
|
2359
|
+
cur.push(w);
|
|
2360
|
+
}
|
|
2361
|
+
if (cur.length) chunks.push(cur);
|
|
2362
|
+
for (let k = 0; k < chunks.length; k++) {
|
|
2363
|
+
const c = chunks[k];
|
|
2364
|
+
if (c.at(-1).end - c[0].start >= CAPTION_MIN_SEC) continue;
|
|
2365
|
+
const next = chunks[k + 1];
|
|
2366
|
+
const prev = chunks[k - 1];
|
|
2367
|
+
const joins = (a, b) => a && b && b[0].line === a[0].line && b[0].start - a.at(-1).end <= CAPTION_LINE_GAP_SEC && a.length + b.length <= per + 1;
|
|
2368
|
+
if (joins(c, next)) {
|
|
2369
|
+
chunks[k + 1] = [...c, ...next];
|
|
2370
|
+
chunks[k] = null;
|
|
2371
|
+
} else if (joins(prev, c)) {
|
|
2372
|
+
chunks[k - 1] = [...prev, ...c];
|
|
2373
|
+
chunks[k] = null;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
chunks = chunks.filter(Boolean);
|
|
2377
|
+
return chunks.map((ws, k) => {
|
|
2378
|
+
const next = chunks[k + 1]?.[0];
|
|
2379
|
+
const text = ws.map((w) => assText(w.text)).join(" ").replace(/[.,;:]+$/, "");
|
|
2380
|
+
const off = next ? next.start - CAPTION_CLEAR_SEC : Infinity;
|
|
2381
|
+
const e = Math.min(Math.max(ws[0].start + 0.12, ws.at(-1).end + CAPTION_TAIL_SEC), off);
|
|
2382
|
+
return { text: caps ? text.toUpperCase() : text, s: roundMs(ws[0].start), e: roundMs(e), line: ws[0].line };
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
/**
|
|
2387
|
+
* captionsByLine: the cut's words in its own time, each with the script line
|
|
2388
|
+
* it belongs to. Where a segment's script is heard in order (alignScript),
|
|
2389
|
+
* they are the script's words as written, each timed by the heard words that
|
|
2390
|
+
* say it; elsewhere they are the heard words, each on the line its place among
|
|
2391
|
+
* the script's words gives it, the way a cue line is found (lineInSegment).
|
|
2392
|
+
*/
|
|
2393
|
+
export function lineWords(timeline, storyboard) {
|
|
2394
|
+
const texts = new Map((storyboard?.script ?? []).map((line) => [line?.lineId, line?.text]));
|
|
2395
|
+
const counts = lineWordCounts(storyboard);
|
|
2396
|
+
const rows = [];
|
|
2397
|
+
for (const seg of timeline.spine) {
|
|
2398
|
+
const heard = seg.words ?? [];
|
|
2399
|
+
if (heard.length === 0) continue;
|
|
2400
|
+
const at = (t) => roundMs(seg.startSec + t);
|
|
2401
|
+
const lines = seg.lineIds.map((id) => scriptWords(texts.get(id)));
|
|
2402
|
+
const aligned = lines.some((l) => l.length > 0) ? alignScript(heard, lines.flat()) : null;
|
|
2403
|
+
if (aligned) {
|
|
2404
|
+
const lineOf = lines.flatMap((ws, j) => ws.map(() => seg.lineIds[j]));
|
|
2405
|
+
const { expected, heard: tokens, heardTokenOf } = aligned;
|
|
2406
|
+
lines.flat().forEach((text, i) => {
|
|
2407
|
+
const said = heardTokenOf.filter((_, e) => expected.sourceIndex[e] <= i && i <= expected.lastSourceIndex[e]);
|
|
2408
|
+
if (said.length === 0) return;
|
|
2409
|
+
const start = at(heard[tokens.sourceIndex[said[0]]].s);
|
|
2410
|
+
const end = at(heard[tokens.lastSourceIndex[said.at(-1)]].e);
|
|
2411
|
+
if (end > start) rows.push({ text, start, end, line: lineOf[i] });
|
|
2412
|
+
});
|
|
2413
|
+
continue;
|
|
2414
|
+
}
|
|
2415
|
+
const ends = [];
|
|
2416
|
+
let n = 0;
|
|
2417
|
+
for (const id of seg.lineIds) ends.push((n += counts.get(id) ?? 0));
|
|
2418
|
+
heard.forEach((w, i) => {
|
|
2419
|
+
const text = (w.w ?? "").trim();
|
|
2420
|
+
const start = at(w.s);
|
|
2421
|
+
const end = at(w.e);
|
|
2422
|
+
if (!text || end <= start) return;
|
|
2423
|
+
const j = ends.findIndex((last) => Math.min(i, n - 1) < last);
|
|
2424
|
+
rows.push({ text, start, end, line: seg.lineIds[j] ?? seg.lineIds.at(-1) ?? `scene ${seg.sceneIndex}` });
|
|
2425
|
+
});
|
|
2426
|
+
}
|
|
2427
|
+
return rows;
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2198
2430
|
/**
|
|
2199
2431
|
* One ASS file for the burn: the caption screens in their band, the cards in
|
|
2200
2432
|
* their boxes, the hook box and the end card. Boxes are [x0, y0, x1, y1] as
|
|
2201
2433
|
* shares of the frame. Every word on screen is the script's or the storyboard's.
|
|
2202
2434
|
*/
|
|
2203
|
-
export function editAss({ captions = [], cap = null, cards = [], hook = null, endCard = null }, W = WIDTH, H = HEIGHT) {
|
|
2435
|
+
export function editAss({ captions = [], cap = null, cards = [], hook = null, endCard = null, capMaxShare = null }, W = WIDTH, H = HEIGHT) {
|
|
2204
2436
|
const thick = /thick black outline/i.test(cap?.style ?? "");
|
|
2205
2437
|
const y = cap?.place ? Math.round(((cap.place[0] + cap.place[1]) / 2) * H) : Math.round(H * 0.7);
|
|
2206
|
-
const capSize = Math.round(H * (thick ? 0.05 : 0.034));
|
|
2438
|
+
const capSize = Math.min(Math.round(H * (thick ? 0.05 : 0.034)), capMaxShare ? Math.round(H * capMaxShare) : Infinity);
|
|
2207
2439
|
const box = (b) => `\\pos(${Math.round(((b[0] + b[2]) / 2) * W)},${Math.round(((b[1] + b[3]) / 2) * H)})`;
|
|
2208
2440
|
return [
|
|
2209
2441
|
"[Script Info]", "ScriptType: v4.00+", `PlayResX: ${W}`, `PlayResY: ${H}`, "WrapStyle: 0", "ScaledBorderAndShadow: yes", "",
|
|
@@ -2339,6 +2571,157 @@ export function voicePauses(rows) {
|
|
|
2339
2571
|
return pauses;
|
|
2340
2572
|
}
|
|
2341
2573
|
|
|
2574
|
+
// ---- cutChecks: the finished cut checked before anyone grades it ----
|
|
2575
|
+
|
|
2576
|
+
/**
|
|
2577
|
+
* The bars a checked cut is held to. voiceOverBedDb and the slow-shot ratio
|
|
2578
|
+
* are guesses, to be tuned against the graders' notes on the cuts they mark.
|
|
2579
|
+
*/
|
|
2580
|
+
export const CHECK_BARS = { voiceOverBedDb: 10, minBrollSec: 1.2, truePeak: -1.0, lufs: -14 };
|
|
2581
|
+
/** A shot is slow when it moves under this share of the cut's median motion, or under SLOW_SHOT_FLOOR. */
|
|
2582
|
+
const SLOW_SHOT_RATIO = 0.35;
|
|
2583
|
+
const SLOW_SHOT_FLOOR = 0.6;
|
|
2584
|
+
/** A phrase of this many words said again within REPEAT_WITHIN words is a repeat. */
|
|
2585
|
+
const REPEAT_WORDS = 3;
|
|
2586
|
+
const REPEAT_WITHIN = 14;
|
|
2587
|
+
const NUMBER_WORDS_AS_DIGITS = { zero: "0", one: "1", two: "2", three: "3", four: "4", five: "5", six: "6", seven: "7", eight: "8", nine: "9", ten: "10", twenty: "20", thirty: "30" };
|
|
2588
|
+
/** A heard word as the checks compare it: lower case, no punctuation, a number word as its digits. */
|
|
2589
|
+
export const checkWord = (s) => {
|
|
2590
|
+
const t = String(s).toLowerCase().replace(/[’']/g, "").replace(/[^a-z0-9%$]/g, "");
|
|
2591
|
+
return NUMBER_WORDS_AS_DIGITS[t] ?? t;
|
|
2592
|
+
};
|
|
2593
|
+
|
|
2594
|
+
/** Caption screens that hold words of two script lines. `words` carry their line (lineWords). */
|
|
2595
|
+
export function lineMixes(screens, words) {
|
|
2596
|
+
return screens
|
|
2597
|
+
.filter((c) => new Set(words.filter((w) => w.start >= c.s - 0.01 && w.start < c.e).map((w) => w.line)).size > 1)
|
|
2598
|
+
.map((c) => ({ s: c.s, text: c.text }));
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
/** A phrase of REPEAT_WORDS or more words said again within REPEAT_WITHIN words. `heard`: [{ w, s }]. */
|
|
2602
|
+
export function repeats(heard) {
|
|
2603
|
+
const t = heard.map((h) => checkWord(h.w));
|
|
2604
|
+
const out = [];
|
|
2605
|
+
for (let i = 0; i + REPEAT_WORDS <= t.length; i++) {
|
|
2606
|
+
const phrase = t.slice(i, i + REPEAT_WORDS).join(" ");
|
|
2607
|
+
for (let j = i + REPEAT_WORDS; j + REPEAT_WORDS <= Math.min(t.length, i + REPEAT_WORDS + REPEAT_WITHIN); j++) {
|
|
2608
|
+
if (t.slice(j, j + REPEAT_WORDS).join(" ") === phrase) {
|
|
2609
|
+
out.push({ phrase, firstAt: roundMs(heard[i].s), againAt: roundMs(heard[j].s) });
|
|
2610
|
+
i += REPEAT_WORDS - 1;
|
|
2611
|
+
break;
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
return out;
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
/** B-roll and narrated shots on screen for less than CHECK_BARS.minBrollSec. `shots`: [{ n, role, start, end }]. */
|
|
2619
|
+
export function shortShots(shots, minSec = CHECK_BARS.minBrollSec) {
|
|
2620
|
+
return shots
|
|
2621
|
+
.filter((s) => ["b-roll", "overlay", "vo-enactment"].includes(s.role) && s.end - s.start < minSec)
|
|
2622
|
+
.map((s) => ({ n: s.n, role: s.role, at: s.start, sec: roundMs(s.end - s.start) }));
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
/**
|
|
2626
|
+
* Shots whose motion is far under the cut's median. A shot of someone talking
|
|
2627
|
+
* to camera (a-roll) sits still at natural speed, so it is never slow here.
|
|
2628
|
+
* `motion`: [{ n, role, sec, motion }].
|
|
2629
|
+
*/
|
|
2630
|
+
export function slowShots(motion) {
|
|
2631
|
+
const values = motion.map((m) => m.motion).filter((x) => x != null).sort((a, b) => a - b);
|
|
2632
|
+
if (!values.length) return [];
|
|
2633
|
+
const median = values[Math.floor(values.length / 2)];
|
|
2634
|
+
return motion
|
|
2635
|
+
.filter((m) => m.role !== "a-roll" && m.motion != null && m.sec >= 1 && (m.motion < median * SLOW_SHOT_RATIO || m.motion < SLOW_SHOT_FLOOR))
|
|
2636
|
+
.map((m) => ({ ...m, median: roundMs(median) }));
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
/** The voice's loudness over the rest's, in dB; null when the voice is silent, 60 when the rest is. */
|
|
2640
|
+
export const voiceOverBed = (voiceLufs, bedLufs) =>
|
|
2641
|
+
voiceLufs == null || bedLufs == null || voiceLufs < -60 ? null : bedLufs < -60 ? 60 : roundMs(voiceLufs - bedLufs);
|
|
2642
|
+
|
|
2643
|
+
/** What fails the bars, in words; the cut passes when nothing does. */
|
|
2644
|
+
export function checkVerdict(c, bars = CHECK_BARS) {
|
|
2645
|
+
const fails = [];
|
|
2646
|
+
if (c.lineMixes?.length) fails.push(`${c.lineMixes.length} caption screens mix two lines`);
|
|
2647
|
+
if (c.voiceOverBedDb != null && c.voiceOverBedDb < bars.voiceOverBedDb) fails.push(`voice ${c.voiceOverBedDb} dB over the bed (bar ${bars.voiceOverBedDb})`);
|
|
2648
|
+
if (c.repeats?.length) fails.push(`${c.repeats.length} phrase(s) said twice`);
|
|
2649
|
+
if (c.shortShots?.length) fails.push(`${c.shortShots.length} b-roll shot(s) under ${bars.minBrollSec} s`);
|
|
2650
|
+
if (c.slowShots === null) fails.push("shot motion could not be measured");
|
|
2651
|
+
else if (c.slowShots?.length) fails.push(`${c.slowShots.length} slow shot(s)`);
|
|
2652
|
+
if (c.truePeak != null && c.truePeak > bars.truePeak) fails.push(`true peak ${c.truePeak} dBTP (bar ${bars.truePeak})`);
|
|
2653
|
+
if (c.lufs != null && Math.abs(c.lufs - bars.lufs) > 1) fails.push(`loudness ${c.lufs} LUFS (bar ${bars.lufs} ± 1)`);
|
|
2654
|
+
return { pass: !fails.length, fails };
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
/** Frame-to-frame change of a file's picture, on a 90 px wide copy, printed per frame. `from`/`seconds` read a stretch. */
|
|
2658
|
+
export function motionArgs(file, from = null, seconds = null) {
|
|
2659
|
+
return [
|
|
2660
|
+
"-hide_banner", "-nostats",
|
|
2661
|
+
...(from !== null ? ["-ss", sec(from)] : []), ...(seconds !== null ? ["-t", sec(seconds)] : []),
|
|
2662
|
+
"-i", file, "-an",
|
|
2663
|
+
"-vf", "scale=90:-2,tblend=all_mode=difference,signalstats,metadata=print:key=lavfi.signalstats.YAVG:file=-",
|
|
2664
|
+
"-f", "null", "-",
|
|
2665
|
+
];
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
/** motionArgs' printout as [{ t, y }]: each frame's time and its mean change. */
|
|
2669
|
+
export function readMotion(stdout) {
|
|
2670
|
+
const rows = [];
|
|
2671
|
+
let t = null;
|
|
2672
|
+
for (const line of String(stdout ?? "").split("\n")) {
|
|
2673
|
+
const time = line.match(/pts_time:([\d.]+)/);
|
|
2674
|
+
if (time) {
|
|
2675
|
+
t = Number(time[1]);
|
|
2676
|
+
continue;
|
|
2677
|
+
}
|
|
2678
|
+
const y = line.match(/YAVG=([\d.]+)/);
|
|
2679
|
+
if (y && t !== null) rows.push({ t, y: Number(y[1]) });
|
|
2680
|
+
}
|
|
2681
|
+
return rows;
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2684
|
+
/** Each shot's mean motion, its first and last 0.1 s left out so a cut is not counted as motion. */
|
|
2685
|
+
export function motionByShot(rows, shots) {
|
|
2686
|
+
return shots.map((s) => {
|
|
2687
|
+
const v = rows.filter((r) => r.t > s.start + 0.1 && r.t < s.end - 0.1).map((r) => r.y);
|
|
2688
|
+
return { n: s.n, role: s.role, at: roundMs(s.start), sec: roundMs(s.end - s.start), motion: v.length ? roundMs(v.reduce((x, y) => x + y, 0) / v.length) : null };
|
|
2689
|
+
});
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
/** The part a spine segment plays on screen, as the checks read shots: a scene speaking its own lines (or a reaction) is a-roll. */
|
|
2693
|
+
const roleOf = (seg) => (seg.reaction || seg.audio === "clip" ? "a-roll" : seg.audio === "narration" ? "vo-enactment" : "b-roll");
|
|
2694
|
+
|
|
2695
|
+
/**
|
|
2696
|
+
* cutChecks: the finished cut against CHECK_BARS. `screens` are the caption
|
|
2697
|
+
* screens burned in (null for none), `rows` and `scenes` the cut's words and
|
|
2698
|
+
* shots as written beside it, `levels` the voice's and the bed's loudness from
|
|
2699
|
+
* the render. Caption sync is not checked: it needs a transcription of the
|
|
2700
|
+
* finished cut of its own, and the cut's words are the ones its captions came from.
|
|
2701
|
+
*/
|
|
2702
|
+
function checkCut({ timeline, storyboard, screens, rows, scenes, out, loudness, levels }) {
|
|
2703
|
+
const roles = new Map(timeline.spine.map((seg) => [seg.sceneIndex, roleOf(seg)]));
|
|
2704
|
+
for (const c of timeline.cutaways) roles.set(c.sceneIndex, "b-roll");
|
|
2705
|
+
const shots = scenes.map((p) => ({ n: p.scene, role: roles.get(p.scene) ?? "b-roll", start: p.startSec, end: roundMs(p.startSec + p.seconds) }));
|
|
2706
|
+
const read = spawnSync("ffmpeg", motionArgs(out), { encoding: "utf8", maxBuffer: 1 << 28 });
|
|
2707
|
+
const motion = read.status === 0 ? readMotion(read.stdout) : [];
|
|
2708
|
+
const finished = loudness ? { i: loudness.lufs, tp: loudness.truePeak } : measureLoudness(out);
|
|
2709
|
+
const checks = {
|
|
2710
|
+
lineMixes: screens ? lineMixes(screens, lineWords(timeline, storyboard)) : null,
|
|
2711
|
+
// A song laid whole is the voice and the music at once, so it has no level over a bed.
|
|
2712
|
+
voiceOverBedDb: timeline.wholeVoice ? null : voiceOverBed(levels.voiceLufs, levels.bedLufs),
|
|
2713
|
+
voiceLufs: levels.voiceLufs,
|
|
2714
|
+
bedLufs: levels.bedLufs,
|
|
2715
|
+
repeats: repeats(rows.map((r) => ({ w: r.text, s: r.start }))),
|
|
2716
|
+
shortShots: shortShots(shots),
|
|
2717
|
+
// null: ffmpeg could not read the motion, so no shot was checked.
|
|
2718
|
+
slowShots: motion.length ? slowShots(motionByShot(motion, shots)) : null,
|
|
2719
|
+
lufs: finished ? round2(finished.i) : null,
|
|
2720
|
+
truePeak: finished ? round2(finished.tp) : null,
|
|
2721
|
+
};
|
|
2722
|
+
return { ...checks, verdict: checkVerdict(checks) };
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2342
2725
|
const LOUDNORM_TARGET = `I=${FINISH_LUFS}:TP=${FINISH_TRUE_PEAK}:LRA=${FINISH_LRA}`;
|
|
2343
2726
|
|
|
2344
2727
|
/** finishLoudness, pass one: measure a file's sound. Its numbers come back on stderr as JSON. */
|
|
@@ -2366,9 +2749,10 @@ export function readLoudness(stderr) {
|
|
|
2366
2749
|
/**
|
|
2367
2750
|
* finishLoudness, pass two: the whole mix normalized with pass one's numbers,
|
|
2368
2751
|
* the picture copied as it is. Without them (pass one could not read the
|
|
2369
|
-
* sound) loudnorm runs on its own, in one pass.
|
|
2752
|
+
* sound) loudnorm runs on its own, in one pass. `limiter` (limitPeaks) runs
|
|
2753
|
+
* after it.
|
|
2370
2754
|
*/
|
|
2371
|
-
export function loudnessApplyArgs(mix, measured, out) {
|
|
2755
|
+
export function loudnessApplyArgs(mix, measured, out, limiter = null) {
|
|
2372
2756
|
const second = measured
|
|
2373
2757
|
? `:measured_I=${measured.i}:measured_TP=${measured.tp}:measured_LRA=${measured.lra}` +
|
|
2374
2758
|
`:measured_thresh=${measured.thresh}:offset=${measured.offset}:linear=true`
|
|
@@ -2376,7 +2760,7 @@ export function loudnessApplyArgs(mix, measured, out) {
|
|
|
2376
2760
|
return [
|
|
2377
2761
|
"-y", "-hide_banner", "-loglevel", "error", "-i", mix,
|
|
2378
2762
|
"-map", "0:v:0", "-map", "0:a:0", "-c:v", "copy",
|
|
2379
|
-
"-af", `loudnorm=${LOUDNORM_TARGET}${second},aresample=48000`,
|
|
2763
|
+
"-af", `loudnorm=${LOUDNORM_TARGET}${second}${limiter ? `,${limiter}` : ""},aresample=48000`,
|
|
2380
2764
|
"-c:a", "aac", "-b:a", "192k", "-movflags", "+faststart", out,
|
|
2381
2765
|
];
|
|
2382
2766
|
}
|
|
@@ -2405,9 +2789,9 @@ function measureLufs(file) {
|
|
|
2405
2789
|
}
|
|
2406
2790
|
|
|
2407
2791
|
/** Both passes on the rendered mix, then the finished cut measured again; throws LoudnessRefusal over the limit. */
|
|
2408
|
-
export function finishLoudnessPass(mix, out) {
|
|
2792
|
+
export function finishLoudnessPass(mix, out, limiter = null) {
|
|
2409
2793
|
const measured = measureLoudness(mix);
|
|
2410
|
-
const args = loudnessApplyArgs(mix, measured, out);
|
|
2794
|
+
const args = loudnessApplyArgs(mix, measured, out, limiter);
|
|
2411
2795
|
const res = spawnSync("ffmpeg", args, { stdio: "inherit" });
|
|
2412
2796
|
if (res.status !== 0) {
|
|
2413
2797
|
const quoted = args.map((a) => (/[\s\[\];]/.test(a) ? `'${a}'` : a)).join(" ");
|
|
@@ -2416,16 +2800,24 @@ export function finishLoudnessPass(mix, out) {
|
|
|
2416
2800
|
const finished = measureLoudness(out);
|
|
2417
2801
|
const refusal = truePeakRefusal(finished);
|
|
2418
2802
|
if (refusal) throw new LoudnessRefusal(refusal, finished);
|
|
2419
|
-
return { lufs: round2(finished.i), truePeak: round2(finished.tp), passes: measured ? 2 : 1 };
|
|
2803
|
+
return { lufs: round2(finished.i), truePeak: round2(finished.tp), passes: measured ? 2 : 1, ...(limiter ? { limited: true } : {}) };
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
/** The filters of `names` this ffmpeg does not have. */
|
|
2807
|
+
function missingFilters(names) {
|
|
2808
|
+
const listed = spawnSync("ffmpeg", ["-hide_banner", "-filters"]).stdout?.toString() ?? "";
|
|
2809
|
+
return names.filter((name) => !new RegExp(`^\\s*\\S+\\s+${name}\\s`, "m").test(listed));
|
|
2420
2810
|
}
|
|
2421
2811
|
|
|
2422
2812
|
/** Whether this ffmpeg has a filter (the captions and cards need `subtitles`, which needs libass). */
|
|
2423
2813
|
function hasFilter(name) {
|
|
2424
|
-
|
|
2425
|
-
return new RegExp(`^\\s*\\S+\\s+${name}\\s`, "m").test(listed);
|
|
2814
|
+
return missingFilters([name]).length === 0;
|
|
2426
2815
|
}
|
|
2427
2816
|
|
|
2428
|
-
/**
|
|
2817
|
+
/**
|
|
2818
|
+
* The files the finishing settings write beside the cut: the pace record, the
|
|
2819
|
+
* mix before the loudness pass, and the voice and bed cutChecks measures.
|
|
2820
|
+
*/
|
|
2429
2821
|
export function finishPaths(outPath) {
|
|
2430
2822
|
const dir = path.dirname(outPath);
|
|
2431
2823
|
const base = path.basename(outPath, path.extname(outPath));
|
|
@@ -2434,6 +2826,8 @@ export function finishPaths(outPath) {
|
|
|
2434
2826
|
mix: path.join(dir, `${base}.mix${path.extname(outPath)}`),
|
|
2435
2827
|
sound: path.join(dir, `${base}.sound.json`),
|
|
2436
2828
|
master: path.join(dir, `${base}.music-only${path.extname(outPath)}`),
|
|
2829
|
+
voice: path.join(dir, `${base}.voice.wav`),
|
|
2830
|
+
bed: path.join(dir, `${base}.bed.wav`),
|
|
2437
2831
|
};
|
|
2438
2832
|
}
|
|
2439
2833
|
|
|
@@ -2560,7 +2954,22 @@ export function firstCut({ dir, out: outOpt, skip = new Set(), music: musicOn =
|
|
|
2560
2954
|
const pictureSec = timeline.spine.reduce((sum, seg) => sum + seg.seconds, 0);
|
|
2561
2955
|
// A voice laid whole is a song: it is never sped up.
|
|
2562
2956
|
const speed = finish?.cutPace && !timeline.wholeVoice ? speedFor(pictureSec, finish.targetSeconds) : 1;
|
|
2957
|
+
if (finish?.brollMinSec) {
|
|
2958
|
+
const held = holdBroll(timeline, finish.brollMinSec, speed, (file) => probe(file).seconds);
|
|
2959
|
+
timeline.left.push(...held);
|
|
2960
|
+
notes.push(...held);
|
|
2961
|
+
}
|
|
2962
|
+
if (finish?.speedUpSlowBroll && timeline.cutaways.length > 0) {
|
|
2963
|
+
const motionOf = (file, from, seconds) => {
|
|
2964
|
+
const res = spawnSync("ffmpeg", motionArgs(here(file), from, seconds), { encoding: "utf8", maxBuffer: 1 << 28 });
|
|
2965
|
+
if (res.status !== 0) return null;
|
|
2966
|
+
return motionByShot(readMotion(res.stdout), [{ n: 0, role: null, start: 0, end: seconds }])[0].motion;
|
|
2967
|
+
};
|
|
2968
|
+
notes.push(...speedUpSlowBroll(timeline, motionOf, (file) => probe(file).seconds));
|
|
2969
|
+
}
|
|
2563
2970
|
let ass = null;
|
|
2971
|
+
// The caption screens burned in, which cutChecks reads.
|
|
2972
|
+
let burned = null;
|
|
2564
2973
|
// A copied ad: its words in the record's boxes and its product photos from the product sheet.
|
|
2565
2974
|
const copied = sourceAd && finish?.cards ? sourceAdEdit(storyboard, sourceAd, timeline.sourceGroups ?? []) : null;
|
|
2566
2975
|
if (copied) notes.push(...copied.notes);
|
|
@@ -2580,9 +2989,16 @@ export function firstCut({ dir, out: outOpt, skip = new Set(), music: musicOn =
|
|
|
2580
2989
|
if (hasFilter("subtitles")) {
|
|
2581
2990
|
ass = "edit.ass";
|
|
2582
2991
|
const cap = sourceAd?.captions ?? null;
|
|
2992
|
+
const screens = !finish.captions
|
|
2993
|
+
? []
|
|
2994
|
+
: finish.captionsByLine
|
|
2995
|
+
? lineCaptionScreens(lineWords(timeline, storyboard), cap)
|
|
2996
|
+
: captionScreens(wordRows(timeline), cap);
|
|
2997
|
+
if (finish.captions) burned = screens;
|
|
2583
2998
|
writeFileSync(here(ass), editAss({
|
|
2584
|
-
captions:
|
|
2999
|
+
captions: screens,
|
|
2585
3000
|
cap,
|
|
3001
|
+
...(finish.captionsByLine ? { capMaxShare: CAPTION_MAX_SHARE } : {}),
|
|
2586
3002
|
cards: finish.cards ? (copied ? copied.cards : storyboardCards(storyboard, timeline)) : [],
|
|
2587
3003
|
hook: copied?.hook ?? null,
|
|
2588
3004
|
// A copied ad has an end card only where its source does.
|
|
@@ -2592,8 +3008,22 @@ export function firstCut({ dir, out: outOpt, skip = new Set(), music: musicOn =
|
|
|
2592
3008
|
notes.push("this ffmpeg has no subtitles filter (libass), so the captions and cards were not burned in");
|
|
2593
3009
|
}
|
|
2594
3010
|
}
|
|
3011
|
+
// cleanVoice, where this ffmpeg has the filters. A voice laid whole is a song, kept as it is.
|
|
3012
|
+
let clean = null;
|
|
3013
|
+
if (finish?.cleanVoice) {
|
|
3014
|
+
const missing = timeline.wholeVoice ? [] : missingFilters(CLEAN_FILTERS);
|
|
3015
|
+
if (timeline.wholeVoice) notes.push("the voice is a song laid whole, so it was kept as it is, not cleaned");
|
|
3016
|
+
else if (missing.length > 0) notes.push(`this ffmpeg has no ${missing.join(", ")} filter, so the voice was not cleaned`);
|
|
3017
|
+
else clean = { voice: VOICE_CLEAN, under: UNDER_VOICE };
|
|
3018
|
+
}
|
|
3019
|
+
let limiter = null;
|
|
3020
|
+
if (finish?.limitPeaks) {
|
|
3021
|
+
if (hasFilter("alimiter")) limiter = PEAK_LIMITER;
|
|
3022
|
+
else notes.push("this ffmpeg has no alimiter filter, so the loudness pass ran without the limiter");
|
|
3023
|
+
}
|
|
2595
3024
|
const paths = finishPaths(out);
|
|
2596
3025
|
const rendered = finish?.finishLoudness ? paths.mix : out;
|
|
3026
|
+
const meters = finish?.cutChecks ? { voice: paths.voice, bed: paths.bed } : null;
|
|
2597
3027
|
// The burn reads its file from the folder ffmpeg runs in, so every path is absolute then.
|
|
2598
3028
|
const at = ass ? (file) => path.resolve(dir, file) : here;
|
|
2599
3029
|
|
|
@@ -2621,7 +3051,14 @@ export function firstCut({ dir, out: outOpt, skip = new Set(), music: musicOn =
|
|
|
2621
3051
|
resolve: at,
|
|
2622
3052
|
music: music ? at(music) : null,
|
|
2623
3053
|
out: rendered,
|
|
2624
|
-
...(finish
|
|
3054
|
+
...(finish
|
|
3055
|
+
? {
|
|
3056
|
+
finish: {
|
|
3057
|
+
levelSegments: !finish.finishLoudness, ass, speed,
|
|
3058
|
+
...(pictures.length ? { pictures } : {}), ...(clean ? { clean } : {}), ...(meters ? { meters } : {}),
|
|
3059
|
+
},
|
|
3060
|
+
}
|
|
3061
|
+
: {}),
|
|
2625
3062
|
...(mixSound ? { sound: mixSound } : {}),
|
|
2626
3063
|
});
|
|
2627
3064
|
const res = spawnSync("ffmpeg", ffmpegArgs, { stdio: "inherit", ...(ass ? { cwd: path.resolve(dir) } : {}) });
|
|
@@ -2629,10 +3066,16 @@ export function firstCut({ dir, out: outOpt, skip = new Set(), music: musicOn =
|
|
|
2629
3066
|
const quoted = ffmpegArgs.map((a) => (/[\s\[\];]/.test(a) ? `'${a}'` : a)).join(" ");
|
|
2630
3067
|
throw new FirstCutError(1, `ffmpeg failed. The command it ran:\n ffmpeg ${quoted}`);
|
|
2631
3068
|
}
|
|
3069
|
+
let meterLevels = null;
|
|
3070
|
+
if (meters) {
|
|
3071
|
+
meterLevels = { voiceLufs: measureLufs(meters.voice), bedLufs: measureLufs(meters.bed) };
|
|
3072
|
+
rmSync(meters.voice, { force: true });
|
|
3073
|
+
rmSync(meters.bed, { force: true });
|
|
3074
|
+
}
|
|
2632
3075
|
let loudness = null;
|
|
2633
3076
|
if (finish?.finishLoudness) {
|
|
2634
3077
|
try {
|
|
2635
|
-
loudness = finishLoudnessPass(rendered, out);
|
|
3078
|
+
loudness = finishLoudnessPass(rendered, out, limiter);
|
|
2636
3079
|
} finally {
|
|
2637
3080
|
rmSync(rendered, { force: true });
|
|
2638
3081
|
}
|
|
@@ -2686,8 +3129,11 @@ export function firstCut({ dir, out: outOpt, skip = new Set(), music: musicOn =
|
|
|
2686
3129
|
const withSound = (cut) => (soundRecord ? { ...cut, sound: soundRecord, ...(soundRecord.master ? { musicOnlyMaster: paths.master } : {}) } : cut);
|
|
2687
3130
|
if (!finish) return withSound({ out, durationSec, manifest, timeline, music, rows, sidecars });
|
|
2688
3131
|
|
|
3132
|
+
const checks = finish.cutChecks
|
|
3133
|
+
? checkCut({ timeline, storyboard, screens: burned, rows, scenes, out, loudness, levels: meterLevels })
|
|
3134
|
+
: null;
|
|
2689
3135
|
// The pace record: the cut's own numbers, the settings it was cut with (so
|
|
2690
|
-
// a redo of the run matches),
|
|
3136
|
+
// a redo of the run matches), its loudness once the pass ran, and its checks.
|
|
2691
3137
|
const pace = {
|
|
2692
3138
|
...paceReport({
|
|
2693
3139
|
ourShots: scenes.map((p) => ({ start: p.startSec, end: roundMs(p.startSec + p.seconds) })),
|
|
@@ -2699,6 +3145,7 @@ export function firstCut({ dir, out: outOpt, skip = new Set(), music: musicOn =
|
|
|
2699
3145
|
}),
|
|
2700
3146
|
finishing: finish,
|
|
2701
3147
|
...(loudness ? { loudness } : {}),
|
|
3148
|
+
...(checks ? { checks } : {}),
|
|
2702
3149
|
...(notes.length > 0 ? { notes } : {}),
|
|
2703
3150
|
};
|
|
2704
3151
|
writeFileSync(paths.pace, `${JSON.stringify(pace, null, 2)}\n`);
|