@dantea/opencut 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/commands.d.ts +8 -1
  2. package/dist/commands.js +30 -5
  3. package/dist/index.js +1 -0
  4. package/dist/inspection.js +5 -0
  5. package/dist/mix-options.d.ts +59 -0
  6. package/dist/mix-options.js +23 -0
  7. package/dist/system-probe +0 -0
  8. package/dist/video.d.ts +1 -1
  9. package/dist/video.js +21 -3
  10. package/docs/AUDIO_MIX.md +132 -0
  11. package/docs/CLI.md +6 -0
  12. package/docs/INSTALL.md +1 -1
  13. package/docs/SDK.md +4 -0
  14. package/docs/VIDEO_DEFINITIONS.md +4 -0
  15. package/node_modules/@opencut/core/dist/index.d.ts +1 -0
  16. package/node_modules/@opencut/core/dist/index.js +1 -0
  17. package/node_modules/@opencut/core/dist/inspection.d.ts +115 -0
  18. package/node_modules/@opencut/core/dist/professional-mix.d.ts +129 -0
  19. package/node_modules/@opencut/core/dist/professional-mix.js +70 -0
  20. package/node_modules/@opencut/core/dist/project.d.ts +68 -0
  21. package/node_modules/@opencut/core/dist/project.js +15 -0
  22. package/node_modules/@opencut/core/dist/render-plan.d.ts +4 -1
  23. package/node_modules/@opencut/core/dist/render-plan.js +6 -0
  24. package/node_modules/@opencut/core/dist/render-sources.d.ts +3 -0
  25. package/node_modules/@opencut/core/dist/timeline-view.d.ts +1 -0
  26. package/node_modules/@opencut/core/dist/video-audio-mix.d.ts +25 -0
  27. package/node_modules/@opencut/core/dist/video-audio-mix.js +36 -0
  28. package/node_modules/@opencut/core/dist/video-compiler.d.ts +3 -0
  29. package/node_modules/@opencut/core/dist/video-compiler.js +20 -1
  30. package/node_modules/@opencut/core/dist/video-definition.d.ts +121 -0
  31. package/node_modules/@opencut/core/dist/video-definition.js +6 -1
  32. package/node_modules/@opencut/core/dist/video-files.d.ts +55 -0
  33. package/node_modules/@opencut/core/dist/video-package-format.d.ts +53 -0
  34. package/node_modules/@opencut/core/dist/video-preview.d.ts +56 -1
  35. package/node_modules/@opencut/core/dist/video-preview.js +7 -2
  36. package/node_modules/@opencut/core/dist/video-render.d.ts +11 -4
  37. package/node_modules/@opencut/core/dist/video-render.js +16 -3
  38. package/node_modules/@opencut/core/dist/video-watch.d.ts +5 -0
  39. package/node_modules/@opencut/core/dist/video-watch.js +18 -2
  40. package/node_modules/@opencut/core/dist/video.d.ts +5 -0
  41. package/node_modules/@opencut/core/dist/video.js +2 -0
  42. package/node_modules/@opencut/core/package.json +3 -3
  43. package/node_modules/@opencut/media/dist/audio-graph.d.ts +88 -0
  44. package/node_modules/@opencut/media/dist/audio-graph.js +292 -0
  45. package/node_modules/@opencut/media/dist/audio-mastering.d.ts +29 -0
  46. package/node_modules/@opencut/media/dist/audio-mastering.js +205 -0
  47. package/node_modules/@opencut/media/dist/deepfilter.d.ts +4 -0
  48. package/node_modules/@opencut/media/dist/deepfilter.js +76 -0
  49. package/node_modules/@opencut/media/dist/dialogue-analysis.d.ts +32 -0
  50. package/node_modules/@opencut/media/dist/dialogue-analysis.js +214 -0
  51. package/node_modules/@opencut/media/dist/index.d.ts +3 -1
  52. package/node_modules/@opencut/media/dist/index.js +1 -1
  53. package/node_modules/@opencut/media/dist/process-memory +0 -0
  54. package/node_modules/@opencut/media/dist/process.d.ts +2 -1
  55. package/node_modules/@opencut/media/dist/process.js +13 -4
  56. package/node_modules/@opencut/media/dist/professional-mix.d.ts +34 -0
  57. package/node_modules/@opencut/media/dist/professional-mix.js +411 -0
  58. package/node_modules/@opencut/media/dist/render-budget.d.ts +1 -1
  59. package/node_modules/@opencut/media/dist/render-budget.js +7 -5
  60. package/node_modules/@opencut/media/dist/render.d.ts +28 -46
  61. package/node_modules/@opencut/media/dist/render.js +78 -224
  62. package/node_modules/@opencut/media/dist/video-enhance +0 -0
  63. package/node_modules/@opencut/media/dist/video-interpolate +0 -0
  64. package/node_modules/@opencut/media/package.json +2 -2
  65. package/node_modules/@opencut/sdk/dist/index.d.ts +2 -2
  66. package/node_modules/@opencut/sdk/dist/index.js +1 -1
  67. package/node_modules/@opencut/sdk/package.json +3 -3
  68. package/node_modules/@opencut/shared/dist/index.d.ts +1 -0
  69. package/node_modules/@opencut/shared/dist/index.js +1 -0
  70. package/node_modules/@opencut/shared/dist/professional-mix.d.ts +98 -0
  71. package/node_modules/@opencut/shared/dist/professional-mix.js +30 -0
  72. package/node_modules/@opencut/shared/package.json +1 -1
  73. package/package.json +5 -5
  74. package/skills/video-editor/SKILL.md +6 -0
  75. package/skills/video-editor/references/cli.md +7 -0
  76. package/skills/video-editor/references/sdk.md +4 -0
@@ -0,0 +1,411 @@
1
+ import { masterAudioMix, renderAudioFile } from './audio-mastering.js';
2
+ import { localEnhancer } from './deepfilter.js';
3
+ import { createHash } from 'node:crypto';
4
+ import { mkdir, writeFile } from 'node:fs/promises';
5
+ import { join } from 'node:path';
6
+ import { dialoguePresetControls } from '@opencut/shared';
7
+ import { audioClipSample, audioSourceSamples, buildAudioGraph, groupAudioRuns, } from './audio-graph.js';
8
+ import { clamp, detectDialogue, dialogueCurve, musicCurve, profileDialogue, } from './dialogue-analysis.js';
9
+ import { audioSourceDuration, probeMedia } from './probe.js';
10
+ import { checkRenderSignal, MediaError, runMediaTool, sourceFileStamp, } from './process.js';
11
+ const dbGain = (db) => 10 ** (db / 20);
12
+ const fixed = (n) => Number(n.toFixed(5));
13
+ const digest = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
14
+ function presetSettings(mix) {
15
+ const preset = dialoguePresetControls[mix.preset];
16
+ return {
17
+ cleanup: mix.cleanup ?? preset.cleanup,
18
+ warmth: mix.warmth ?? preset.warmth,
19
+ clarity: mix.clarity ?? preset.clarity,
20
+ consistency: mix.consistency ?? preset.consistency,
21
+ dialogueLufs: mix.dialogueLufs ?? preset.dialogueLufs,
22
+ ducking: {
23
+ depthDb: mix.ducking?.depthDb ?? preset.duckingDepth,
24
+ attackMs: mix.ducking?.attackMs ?? 180,
25
+ holdMs: mix.ducking?.holdMs ?? 340,
26
+ releaseMs: mix.ducking?.releaseMs ?? 620,
27
+ },
28
+ };
29
+ }
30
+ async function renderGraph(path, script, options, readSource, samples, mode, sampleRate, channels) {
31
+ const args = [];
32
+ const filters = [];
33
+ let index = 0;
34
+ await buildAudioGraph(options, {
35
+ filters,
36
+ readSource,
37
+ inputPathFor: (source) => options.snapshotSource?.(source) ?? source,
38
+ openInput: (_clip, input) => {
39
+ args.push('-protocol_whitelist', 'file', '-threads', '1', '-i', input);
40
+ return index++;
41
+ },
42
+ }, { total: samples, from: 0, to: samples }, mode);
43
+ await writeFile(script, filters.join(';'), {
44
+ flag: 'wx',
45
+ signal: options.signal,
46
+ });
47
+ await renderAudioFile([
48
+ ...args,
49
+ '-filter_complex_threads',
50
+ '1',
51
+ '-/filter_complex',
52
+ script,
53
+ '-map',
54
+ '[audio]',
55
+ '-map_metadata',
56
+ '-1',
57
+ '-ar',
58
+ String(sampleRate),
59
+ '-ac',
60
+ String(channels),
61
+ '-c:a',
62
+ 'pcm_f32le',
63
+ ], path, options.signal);
64
+ }
65
+ function crossfadePlacements(clips, sources, rate, maximum) {
66
+ const placements = new Map(clips.map((clip) => [clip.clipId, { pre: 0, post: 0 }]));
67
+ const tracks = new Map();
68
+ for (const clip of clips) {
69
+ if (!clip.trackId)
70
+ continue;
71
+ const track = tracks.get(clip.trackId) ?? [];
72
+ track.push(clip);
73
+ tracks.set(clip.trackId, track);
74
+ }
75
+ const start = (clip) => audioClipSample(rate, clip, 'start');
76
+ const end = (clip) => audioClipSample(rate, clip, 'end');
77
+ const unity = (clip) => !clip.retiming ||
78
+ clip.retiming.speed.numerator === clip.retiming.speed.denominator;
79
+ for (const track of tracks.values()) {
80
+ track.sort((a, b) => start(a) - start(b));
81
+ for (let i = 1; i < track.length; i++) {
82
+ const a = track[i - 1];
83
+ const b = track[i];
84
+ if (end(a) !== start(b) || a.fadeOut || b.fadeIn)
85
+ continue;
86
+ const previous = placements.get(a.clipId);
87
+ const next = placements.get(b.clipId);
88
+ const sourceA = audioSourceSamples(a, rate);
89
+ const sourceB = audioSourceSamples(b, rate);
90
+ const lengthA = end(a) - start(a);
91
+ const lengthB = end(b) - start(b);
92
+ if (a.path === b.path && sourceA.end === sourceB.start)
93
+ continue;
94
+ const length = Math.floor(Math.min(maximum, lengthA / 4, lengthB / 4));
95
+ if (!length)
96
+ continue;
97
+ const mediaB = sources.get(b.clipId);
98
+ const audioOffset = (mediaB.audio?.startTimeSeconds ?? 0) -
99
+ (mediaB.video?.startTimeSeconds ?? mediaB.audio?.startTimeSeconds ?? 0);
100
+ const incoming = unity(b) &&
101
+ sourceB.start - Math.max(0, Math.ceil(audioOffset * 48000)) >= length;
102
+ const duration = audioSourceDuration(sources.get(a.clipId)) ?? 0;
103
+ const outgoing = unity(a) && Math.floor(duration * 48000) - sourceA.end >= length;
104
+ if (incoming) {
105
+ next.pre = length;
106
+ next.fadeIn = { offset: 0, length };
107
+ previous.fadeOut = { offset: previous.pre + lengthA - length, length };
108
+ }
109
+ else if (outgoing) {
110
+ previous.post = length;
111
+ previous.fadeOut = { offset: previous.pre + lengthA, length };
112
+ next.fadeIn = { offset: 0, length };
113
+ }
114
+ else {
115
+ const edge = Math.min(length, 240);
116
+ previous.fadeOut = {
117
+ offset: previous.pre + lengthA - edge,
118
+ length: edge,
119
+ };
120
+ next.fadeIn = { offset: 0, length: edge };
121
+ }
122
+ }
123
+ }
124
+ return placements;
125
+ }
126
+ function processingFilters(mix, settings, floor, noisy, noiseLeadSeconds) {
127
+ const chain = [];
128
+ const pass = mix.highPassHz ??
129
+ (mix.preset === 'clear-voiceover' ? (noisy ? 75 : 45) : noisy ? 62 : 25);
130
+ if (pass)
131
+ chain.push(`highpass=f=${pass}:p=1`);
132
+ if (settings.cleanup && noisy && !mix.ai) {
133
+ // afftdn delays its audio by two 600-sample hops at 48 kHz.
134
+ const attenuation = fixed(Math.max(0.01, settings.cleanup * (noiseLeadSeconds ? 27 : 17)));
135
+ chain.push('apad=pad_len=1200', ...(noiseLeadSeconds
136
+ ? [
137
+ 'asendcmd=0 afftdn sn start',
138
+ `asendcmd=${noiseLeadSeconds} afftdn sn stop`,
139
+ ]
140
+ : []), `afftdn=nr=${attenuation}:nf=${fixed(clamp(floor - 5, -72, -22))}:tn=1:ad=0.8:gs=5:nl=average`, 'atrim=start_sample=1200', 'asettb=1/48000', 'asetpts=N');
141
+ }
142
+ if (settings.warmth)
143
+ chain.push(`lowshelf=f=240:g=${fixed(settings.warmth * 3)}`);
144
+ if (settings.clarity)
145
+ chain.push(`equalizer=f=2800:width_type=q:w=0.8:g=${fixed(settings.clarity * 4)}`);
146
+ for (const eq of mix.eq ?? [])
147
+ chain.push(`equalizer=f=${eq.frequency}:width_type=q:w=${eq.q}:g=${eq.db}`);
148
+ const deEsser = mix.deEsser ?? (mix.preset === 'clear-voiceover' ? 0.24 : 0.15);
149
+ if (deEsser)
150
+ chain.push(`deesser=i=${deEsser}:m=0.35:f=0.5`);
151
+ const tail = mix.dereverb ?? 0;
152
+ const reduction = (noisy ? settings.cleanup * 4 : 0) + tail * 6;
153
+ if (reduction) {
154
+ chain.push(`agate=threshold=${dbGain(clamp(floor + 2 + tail * 6, -66, -40))}:range=${dbGain(-reduction)}:ratio=1.6:attack=10:release=240:link=maximum`);
155
+ }
156
+ const compressor = mix.compressor ??
157
+ (mix.preset === 'clear-voiceover'
158
+ ? { thresholdDb: -21, ratio: 1.8, attackMs: 16, releaseMs: 210 }
159
+ : { thresholdDb: -17, ratio: 1.35, attackMs: 25, releaseMs: 270 });
160
+ if (compressor.ratio > 1)
161
+ chain.push(`acompressor=threshold=${dbGain(compressor.thresholdDb)}:ratio=${compressor.ratio}:attack=${compressor.attackMs}:release=${compressor.releaseMs}:link=maximum`);
162
+ chain.push('alimiter=limit=0.95:level=0:latency=1');
163
+ return chain;
164
+ }
165
+ function authoredGain(clip, rate) {
166
+ const start = audioClipSample(rate, clip, 'start');
167
+ const end = audioClipSample(rate, clip, 'end');
168
+ const fadeIn = clip.fadeIn;
169
+ const fadeOut = clip.fadeOut;
170
+ const attack = fadeIn
171
+ ? audioClipSample(rate, clip, 'start', fadeIn.duration) - start
172
+ : 0;
173
+ const release = fadeOut
174
+ ? audioClipSample(rate, clip, 'end', fadeOut.duration) - start
175
+ : Infinity;
176
+ const keys = clip.gainKeys?.map(({ time, value }) => ({
177
+ sample: audioClipSample(rate, clip, 'start', time) - start,
178
+ value,
179
+ }));
180
+ const lerp = (a, b, fraction) => a + (b - a) * fraction;
181
+ let index = 0;
182
+ return (sample) => {
183
+ let gain = clip.volume;
184
+ if (fadeIn && sample < attack)
185
+ gain *= lerp(fadeIn.from, fadeIn.to, sample / attack);
186
+ if (fadeOut && sample > release)
187
+ gain *= lerp(fadeOut.from, fadeOut.to, (sample - release) / (end - start - release));
188
+ if (keys?.length) {
189
+ // Profile and phrase scans can revisit earlier samples.
190
+ while (index && keys[index - 1].sample >= sample)
191
+ index--;
192
+ while (index < keys.length - 1 && keys[index].sample < sample)
193
+ index++;
194
+ const current = keys[index];
195
+ const previous = keys[index - 1];
196
+ gain *=
197
+ previous && sample < current.sample
198
+ ? lerp(previous.value, current.value, (sample - previous.sample) / (current.sample - previous.sample))
199
+ : current.value;
200
+ }
201
+ return gain;
202
+ };
203
+ }
204
+ async function stageDialogue(options, mix, readSource, folder, baseSamples) {
205
+ const settings = presetSettings(mix);
206
+ const backend = (await runMediaTool('ffmpeg', ['-version'], undefined, undefined, {
207
+ signal: options.signal,
208
+ })).toString();
209
+ const { frameRate, signal } = options;
210
+ const candidates = (options.audioClips ?? []).filter((clip) => clip.role === 'dialogue' &&
211
+ !clip.muted &&
212
+ clip.volume > 0 &&
213
+ audioClipSample(frameRate, clip, 'end') >
214
+ audioClipSample(frameRate, clip, 'start'));
215
+ const sources = new Map();
216
+ for (const clip of candidates) {
217
+ const source = await readSource(clip);
218
+ if (source.audio)
219
+ sources.set(clip.clipId, source);
220
+ }
221
+ const clips = candidates.filter((clip) => sources.has(clip.clipId));
222
+ const crossfades = crossfadePlacements(clips, sources, frameRate, Math.round((mix.crossfadeMs ?? 22) * 48));
223
+ const ai = mix.ai && clips.length ? await localEnhancer(signal) : undefined;
224
+ const dialogue = new Map();
225
+ const sample = (clip, edge) => audioClipSample(frameRate, clip, edge);
226
+ const runs = new Map();
227
+ for (const run of groupAudioRuns(options.audioClips ?? [], (a, b) => a.role === b.role)) {
228
+ const first = run[0];
229
+ const speed = first.retiming?.speed;
230
+ if (run.length < 2 ||
231
+ first.role !== 'dialogue' ||
232
+ !speed ||
233
+ speed.numerator === speed.denominator)
234
+ continue;
235
+ const start = run.find((clip) => sample(clip, 'end') > sample(clip, 'start'));
236
+ if (!start)
237
+ continue;
238
+ const last = run.at(-1);
239
+ const origin = sample(start, 'start');
240
+ const shared = {
241
+ clips: run,
242
+ start: origin,
243
+ samples: sample(last, 'end') - origin,
244
+ sourceIn: audioSourceSamples(first, frameRate).start,
245
+ sourceOut: audioSourceSamples(last, frameRate).end,
246
+ };
247
+ for (const clip of run)
248
+ runs.set(clip.clipId, shared);
249
+ }
250
+ const analyses = [];
251
+ for (const [index, clip] of clips.entries()) {
252
+ checkRenderSignal(signal);
253
+ const start = sample(clip, 'start');
254
+ const length = sample(clip, 'end') - start;
255
+ const placement = crossfades.get(clip.clipId);
256
+ const { pre, post, fadeIn, fadeOut } = placement;
257
+ const samples = pre + length + post;
258
+ const directory = join(folder, `dialogue-${index}`);
259
+ await mkdir(directory);
260
+ const raw = join(directory, 'raw.wav');
261
+ const stamp = await sourceFileStamp(clip.path);
262
+ const bound = await (options.snapshotSource?.(clip.path) ?? clip.path);
263
+ if (stamp !== (await sourceFileStamp(clip.path)))
264
+ throw new MediaError('Dialogue source changed while being read.');
265
+ const source = sources.get(clip.clipId);
266
+ const run = runs.get(clip.clipId);
267
+ const key = digest([
268
+ 'dialogue-v1',
269
+ backend,
270
+ stamp,
271
+ source.audio.index,
272
+ source.audio.startTimeSeconds,
273
+ source.video?.startTimeSeconds,
274
+ source.startTimeSeconds,
275
+ audioSourceSamples(clip, frameRate),
276
+ clip.retiming?.speed,
277
+ samples,
278
+ pre,
279
+ post,
280
+ clip.effects,
281
+ ...(run
282
+ ? [[run.sourceIn, run.sourceOut, run.samples, start - run.start]]
283
+ : []),
284
+ ]);
285
+ const isolate = (output, audioClips, count, handles) => renderGraph(output, output + '.ffscript', {
286
+ ...options,
287
+ audioClips,
288
+ snapshotSource: async () => bound,
289
+ }, readSource, count, { isolate: handles }, 48000, 2);
290
+ if (run) {
291
+ // Drain the tempo filter once at the end of the contiguous source range.
292
+ if (!run.raw) {
293
+ const shared = join(directory, 'run.wav');
294
+ await isolate(shared, run.clips, run.samples, { pre: 0, post: 0 });
295
+ run.raw = shared;
296
+ }
297
+ const from = start - run.start;
298
+ await renderAudioFile([
299
+ '-i',
300
+ run.raw,
301
+ '-af',
302
+ `atrim=start_sample=${from}:end_sample=${from + length},asetpts=PTS-STARTPTS`,
303
+ '-c:a',
304
+ 'pcm_f32le',
305
+ ], raw, signal);
306
+ }
307
+ else {
308
+ await isolate(raw, [clip], samples, placement);
309
+ }
310
+ const rawProfile = await profileDialogue(raw, key, signal);
311
+ const gainAt = authoredGain(clip, frameRate);
312
+ const rawActivity = detectDialogue(rawProfile, pre, length, () => 1);
313
+ const contrast = rawActivity.level - rawProfile.floor;
314
+ const noisy = rawProfile.floor > -56 &&
315
+ (contrast < 18 || (rawProfile.floor > -46 && contrast < 31));
316
+ const lead = ((rawActivity.phrases[0]?.from ?? 0) + pre) / 48000 - 0.065;
317
+ const noiseLeadSeconds = lead >= 0.2 ? fixed(Math.min(0.45, lead)) : 0;
318
+ const chain = processingFilters(mix, settings, rawProfile.floor, noisy, noiseLeadSeconds);
319
+ const wetKey = digest([key, chain, ai?.key]);
320
+ const encode = async (destination) => {
321
+ const enhanced = ai
322
+ ? await ai.enhance(raw, directory, join(directory, 'enhanced'))
323
+ : raw;
324
+ if (ai) {
325
+ const info = await probeMedia(enhanced, signal);
326
+ if (info.audio?.sampleRate !== 48000 ||
327
+ info.audio.channels !== 2 ||
328
+ !info.audio.durationSeconds ||
329
+ info.audio.durationSeconds * 48000 < samples - 1)
330
+ throw new MediaError('DeepFilterNet returned audio outside the original sample grid.');
331
+ }
332
+ await renderAudioFile([
333
+ '-i',
334
+ enhanced,
335
+ '-map',
336
+ '0:a:0',
337
+ '-af',
338
+ [
339
+ ...chain,
340
+ `apad,atrim=end_sample=${samples},asettb=1/48000,asetpts=N`,
341
+ ].join(','),
342
+ '-c:a',
343
+ 'pcm_f32le',
344
+ ], destination, signal);
345
+ return probeMedia(destination, signal);
346
+ };
347
+ let wet = join(directory, 'processed.wav');
348
+ if (ai && options.audioMixCache)
349
+ wet = await options.audioMixCache.materialize(wetKey, encode);
350
+ else
351
+ await encode(wet);
352
+ const profile = await profileDialogue(wet, wetKey, signal);
353
+ const activity = detectDialogue(profile, pre, length, gainAt);
354
+ dialogue.set(clip.clipId, {
355
+ path: wet,
356
+ pre,
357
+ fadeIn,
358
+ fadeOut,
359
+ gain: [],
360
+ toneDb: 0,
361
+ });
362
+ analyses.push({ clip, start, activity, profile, pre, length, gainAt });
363
+ }
364
+ const matching = mix.matching ?? { amount: 0.4 };
365
+ const usable = analyses.filter(({ activity }) => Number.isFinite(activity.level));
366
+ const tones = usable
367
+ .map(({ activity }) => activity.tone)
368
+ .sort((a, b) => a - b);
369
+ const reference = usable.find(({ clip }) => clip.clipId === matching.referenceClip)?.activity;
370
+ const anchor = reference?.tone ??
371
+ (matching.referenceClip ? undefined : tones[Math.floor(tones.length / 2)]);
372
+ const warnings = [];
373
+ if (matching.referenceClip && !reference && matching.amount)
374
+ warnings.push(`Reference clip '${matching.referenceClip}' has no active dialogue for matching.`);
375
+ const target = mix.dialogueLufs ??
376
+ (reference
377
+ ? settings.dialogueLufs +
378
+ clamp(reference.level - settings.dialogueLufs, -10, 10) *
379
+ matching.amount
380
+ : settings.dialogueLufs);
381
+ const stored = mix.automation?.dialogue;
382
+ for (const { clip, activity, profile, pre, length, gainAt } of analyses) {
383
+ const staged = dialogue.get(clip.clipId);
384
+ if (anchor !== undefined && Number.isFinite(activity.level))
385
+ staged.toneDb = fixed(clamp(anchor - activity.tone, -5, 5) * matching.amount);
386
+ staged.gain =
387
+ stored && Object.hasOwn(stored, clip.clipId)
388
+ ? stored[clip.clipId]
389
+ : dialogueCurve(profile, activity, target, settings.consistency, pre, length, gainAt);
390
+ if (staged.gain.some(({ sample }) => sample > length))
391
+ throw new MediaError(`Mix automation for '${clip.clipId}' extends beyond its clip.`);
392
+ }
393
+ const music = mix.automation?.music ??
394
+ musicCurve(analyses.flatMap(({ start, activity }) => activity.phrases.map(({ from, to }) => ({
395
+ from: start + from,
396
+ to: start + to,
397
+ }))), settings.ducking, baseSamples);
398
+ if (music.some(({ sample }) => sample > baseSamples))
399
+ throw new MediaError('Music automation extends beyond the project.');
400
+ return { dialogue, music, warnings };
401
+ }
402
+ export async function prepareProfessionalMix(options, mix, folder, readSource, { base, from, to }) {
403
+ const { dialogue, music, warnings } = await stageDialogue(options, mix, readSource, folder, base);
404
+ const { path, report } = await masterAudioMix(options, mix.delivery, folder, { base, from, to }, warnings, (path, kind, rate, channels) => renderGraph(path, join(folder, kind + '.ffscript'), options, readSource, base, kind === 'wet' ? { dialogue, music } : {}, rate, channels));
405
+ const automation = {
406
+ dialogue: Object.fromEntries([...dialogue].map(([id, { gain }]) => [id, gain])),
407
+ music,
408
+ };
409
+ return { path, report: { ...report, automation } };
410
+ }
411
+ //# sourceMappingURL=professional-mix.js.map
@@ -8,7 +8,7 @@ export declare function accountRenderBytes(bytes: number): void;
8
8
  export declare function accountRenderFile(file: string): Promise<void>;
9
9
  export declare function trackRenderProcess(pid: number | undefined, stop: (error: Error) => void): () => void;
10
10
  /** Bound individual writes at the OS level before charging the finished file. */
11
- export declare function renderToolCommand(tool: 'ffmpeg' | 'ffprobe', args: string[], writesFile?: boolean): {
11
+ export declare function renderToolCommand(tool: string, args: string[], writesFile?: boolean): {
12
12
  tool: string;
13
13
  args: string[];
14
14
  };
@@ -78,11 +78,13 @@ export function renderToolCommand(tool, args, writesFile = false) {
78
78
  return { tool, args };
79
79
  if (budget.samplerFailure)
80
80
  throw budget.samplerFailure;
81
- const bounded = [
82
- '-max_alloc',
83
- String(Math.min(budget.maxNativeBytes, 2_147_483_647)),
84
- ...args,
85
- ];
81
+ const bounded = tool === 'ffmpeg' || tool === 'ffprobe'
82
+ ? [
83
+ '-max_alloc',
84
+ String(Math.min(budget.maxNativeBytes, 2_147_483_647)),
85
+ ...args,
86
+ ]
87
+ : args;
86
88
  if (!writesFile || budget.remainingBytes === undefined)
87
89
  return { tool, args: bounded };
88
90
  if (budget.remainingBytes < 1024)
@@ -1,4 +1,7 @@
1
- import type { RenderTimeMapping, TextLayer, VisualAnimation, TransitionRamp } from '@opencut/shared';
1
+ import type { AudioMixCache } from './professional-mix.js';
2
+ import type { AudioMixReport } from './audio-mastering.js';
3
+ import type { AudioRenderClip } from './audio-graph.js';
4
+ import type { RenderTimeMapping, ProfessionalMix, TextLayer, VisualAnimation, TransitionRamp } from '@opencut/shared';
2
5
  import type { MediaMetadata } from './probe.js';
3
6
  import type { RenderQuality } from '@opencut/shared';
4
7
  import type { RenderProgress } from './render-progress.js';
@@ -72,18 +75,11 @@ export interface RenderControls {
72
75
  audioBitrateKbps?: number | undefined;
73
76
  audioSampleRate?: 44100 | 48000 | undefined;
74
77
  audioChannels?: 1 | 2 | undefined;
78
+ audioComparison?: 'before' | 'after' | undefined;
75
79
  overwrite?: boolean | undefined;
76
80
  signal?: AbortSignal | undefined;
77
81
  onProgress?: (progress: RenderProgress) => void;
78
82
  }
79
- interface RenderAudioFade {
80
- duration: {
81
- numerator: number;
82
- denominator: number;
83
- };
84
- from: number;
85
- to: number;
86
- }
87
83
  export interface VideoTimelineOptions extends RenderControls {
88
84
  /** Serialize build provenance in a custom MP4 format tag. */
89
85
  buildMetadata?: string;
@@ -119,43 +115,9 @@ export interface VideoTimelineOptions extends RenderControls {
119
115
  sourceStartFrame: number;
120
116
  frameCount: number;
121
117
  }>;
122
- audioClips?: Array<{
123
- clipId: string;
124
- path: string;
125
- timelineStartFrame: number;
126
- sourceStartFrame: number;
127
- frameCount: number;
128
- retiming?: RenderTimeMapping;
129
- tempoRunId?: string;
130
- volume: number;
131
- muted: boolean;
132
- fadeIn?: RenderAudioFade;
133
- fadeOut?: RenderAudioFade;
134
- gainKeys?: {
135
- time: Rational;
136
- value: number;
137
- }[];
138
- effects?: Array<{
139
- type: 'eq';
140
- frequency: number;
141
- db: number;
142
- } | {
143
- type: 'compressor';
144
- threshold: number;
145
- ratio: number;
146
- } | {
147
- type: 'limiter';
148
- ceiling: number;
149
- } | {
150
- type: 'de-esser';
151
- amount: number;
152
- } | {
153
- type: 'reverb';
154
- mix: number;
155
- }>;
156
- required: boolean;
157
- padAudio?: true;
158
- }>;
118
+ audioClips?: AudioRenderClip[];
119
+ professionalMix?: ProfessionalMix;
120
+ audioMixCache?: AudioMixCache;
159
121
  output: string;
160
122
  }
161
123
  export interface VideoTimelineResult {
@@ -174,6 +136,7 @@ export interface VideoTimelineResult {
174
136
  metadata: MediaMetadata;
175
137
  warnings?: string[];
176
138
  pictureRanges?: PictureRange[];
139
+ audioMix?: AudioMixReport;
177
140
  }
178
141
  type Rational = RenderTimeMapping['sourceIn'];
179
142
  export declare function validateSubtitleBurnIn(clips: readonly Pick<VisualTimelineClip, 'subtitle' | 'subtitleCueId' | 'clipId'>[]): void;
@@ -191,6 +154,25 @@ export declare function validateVideoTimeline(options: VideoTimelineOptions): Pr
191
154
  }>;
192
155
  /** Execute the shared headless pipeline and publish only a verified, complete file. */
193
156
  export declare function renderVideoTimeline(options: VideoTimelineOptions): Promise<VideoTimelineResult>;
157
+ /** Analyze and verify a mix without composing or encoding picture. */
158
+ export declare function analyzeTimelineAudioMix(options: VideoTimelineOptions): Promise<{
159
+ automation: {
160
+ dialogue: {
161
+ [k: string]: import("@opencut/shared").MixGainPoint[];
162
+ };
163
+ music: import("@opencut/shared").MixGainPoint[];
164
+ };
165
+ target: {
166
+ integratedLufs: number;
167
+ truePeakDbtp: number;
168
+ loudnessRange: number;
169
+ };
170
+ input: import("./audio-mastering.js").LoudnessMeasurement;
171
+ output: import("./audio-mastering.js").LoudnessMeasurement;
172
+ comparison: "after" | "before";
173
+ normalization: "linear" | "dynamic" | "none";
174
+ warnings: string[];
175
+ }>;
194
176
  /** Lossless frame output from the same RGB compositor used by video exports. */
195
177
  export declare function renderTimelineFrame(options: VideoTimelineOptions): Promise<{
196
178
  path: string;