@dantea/opencut 0.1.0 → 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.
- package/dist/commands.d.ts +9 -1
- package/dist/commands.js +32 -5
- package/dist/index.js +1 -0
- package/dist/inspection.js +5 -0
- package/dist/mix-options.d.ts +59 -0
- package/dist/mix-options.js +23 -0
- package/dist/system-probe +0 -0
- package/dist/video.d.ts +1 -1
- package/dist/video.js +28 -3
- package/docs/AUDIO_MIX.md +132 -0
- package/docs/CLI.md +46 -6
- package/docs/INSTALL.md +13 -8
- package/docs/SDK.md +14 -3
- package/docs/VIDEO_DEFINITIONS.md +17 -8
- package/node_modules/@opencut/core/dist/index.d.ts +1 -0
- package/node_modules/@opencut/core/dist/index.js +1 -0
- package/node_modules/@opencut/core/dist/inspection.d.ts +115 -0
- package/node_modules/@opencut/core/dist/professional-mix.d.ts +129 -0
- package/node_modules/@opencut/core/dist/professional-mix.js +70 -0
- package/node_modules/@opencut/core/dist/project.d.ts +68 -0
- package/node_modules/@opencut/core/dist/project.js +15 -0
- package/node_modules/@opencut/core/dist/render-plan.d.ts +5 -1
- package/node_modules/@opencut/core/dist/render-plan.js +11 -4
- package/node_modules/@opencut/core/dist/render-sources.d.ts +4 -0
- package/node_modules/@opencut/core/dist/timeline-view.d.ts +1 -0
- package/node_modules/@opencut/core/dist/video-audio-mix.d.ts +25 -0
- package/node_modules/@opencut/core/dist/video-audio-mix.js +36 -0
- package/node_modules/@opencut/core/dist/video-build.js +2 -2
- package/node_modules/@opencut/core/dist/video-compiler.d.ts +3 -0
- package/node_modules/@opencut/core/dist/video-compiler.js +20 -1
- package/node_modules/@opencut/core/dist/video-definition.d.ts +121 -0
- package/node_modules/@opencut/core/dist/video-definition.js +6 -1
- package/node_modules/@opencut/core/dist/video-files.d.ts +55 -0
- package/node_modules/@opencut/core/dist/video-media-cache.d.ts +15 -0
- package/node_modules/@opencut/core/dist/{video-recipe-cache.js → video-media-cache.js} +7 -7
- package/node_modules/@opencut/core/dist/video-package-format.d.ts +53 -0
- package/node_modules/@opencut/core/dist/video-picture-cache.d.ts +3 -0
- package/node_modules/@opencut/core/dist/video-picture-cache.js +29 -0
- package/node_modules/@opencut/core/dist/video-preview.d.ts +56 -1
- package/node_modules/@opencut/core/dist/video-preview.js +7 -2
- package/node_modules/@opencut/core/dist/video-processing.js +2 -2
- package/node_modules/@opencut/core/dist/video-render.d.ts +14 -4
- package/node_modules/@opencut/core/dist/video-render.js +21 -3
- package/node_modules/@opencut/core/dist/video-watch.d.ts +5 -0
- package/node_modules/@opencut/core/dist/video-watch.js +18 -2
- package/node_modules/@opencut/core/dist/video.d.ts +5 -0
- package/node_modules/@opencut/core/dist/video.js +2 -0
- package/node_modules/@opencut/core/package.json +3 -3
- package/node_modules/@opencut/media/dist/audio-graph.d.ts +88 -0
- package/node_modules/@opencut/media/dist/audio-graph.js +292 -0
- package/node_modules/@opencut/media/dist/audio-mastering.d.ts +29 -0
- package/node_modules/@opencut/media/dist/audio-mastering.js +205 -0
- package/node_modules/@opencut/media/dist/deepfilter.d.ts +4 -0
- package/node_modules/@opencut/media/dist/deepfilter.js +76 -0
- package/node_modules/@opencut/media/dist/dialogue-analysis.d.ts +32 -0
- package/node_modules/@opencut/media/dist/dialogue-analysis.js +214 -0
- package/node_modules/@opencut/media/dist/enhance.js +11 -3
- package/node_modules/@opencut/media/dist/index.d.ts +4 -1
- package/node_modules/@opencut/media/dist/index.js +1 -1
- package/node_modules/@opencut/media/dist/picture-cache.d.ts +39 -0
- package/node_modules/@opencut/media/dist/picture-cache.js +169 -0
- package/node_modules/@opencut/media/dist/picture-seek.d.ts +4 -0
- package/node_modules/@opencut/media/dist/picture-seek.js +77 -0
- package/node_modules/@opencut/media/dist/process-memory +0 -0
- package/node_modules/@opencut/media/dist/process.d.ts +2 -1
- package/node_modules/@opencut/media/dist/process.js +13 -4
- package/node_modules/@opencut/media/dist/professional-mix.d.ts +34 -0
- package/node_modules/@opencut/media/dist/professional-mix.js +411 -0
- package/node_modules/@opencut/media/dist/render-budget.d.ts +1 -1
- package/node_modules/@opencut/media/dist/render-budget.js +7 -5
- package/node_modules/@opencut/media/dist/render.d.ts +33 -47
- package/node_modules/@opencut/media/dist/render.js +273 -333
- package/node_modules/@opencut/media/dist/transform-layer.d.ts +7 -1
- package/node_modules/@opencut/media/dist/transform-layer.js +32 -2
- package/node_modules/@opencut/media/dist/video-enhance +0 -0
- package/node_modules/@opencut/media/dist/video-filter.d.ts +2 -0
- package/node_modules/@opencut/media/dist/video-filter.js +4 -0
- package/node_modules/@opencut/media/dist/video-interpolate +0 -0
- package/node_modules/@opencut/media/package.json +2 -2
- package/node_modules/@opencut/sdk/dist/index.d.ts +2 -2
- package/node_modules/@opencut/sdk/dist/index.js +1 -1
- package/node_modules/@opencut/sdk/package.json +3 -3
- package/node_modules/@opencut/shared/dist/index.d.ts +1 -0
- package/node_modules/@opencut/shared/dist/index.js +1 -0
- package/node_modules/@opencut/shared/dist/professional-mix.d.ts +98 -0
- package/node_modules/@opencut/shared/dist/professional-mix.js +30 -0
- package/node_modules/@opencut/shared/package.json +1 -1
- package/package.json +5 -5
- package/skills/video-editor/SKILL.md +13 -1
- package/skills/video-editor/references/cli.md +14 -0
- package/skills/video-editor/references/sdk.md +9 -0
- package/skills/video-editor/references/video-definitions.md +7 -3
- package/node_modules/@opencut/core/dist/video-recipe-cache.d.ts +0 -16
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { runMediaTool } from './process.js';
|
|
2
|
+
const windowSize = 4800;
|
|
3
|
+
const rate = 12000;
|
|
4
|
+
const analysisCache = new Map();
|
|
5
|
+
export const clamp = (value, lo, hi) => Math.min(hi, Math.max(lo, value));
|
|
6
|
+
function percentile(values, q, fallback) {
|
|
7
|
+
if (!values.length)
|
|
8
|
+
return fallback;
|
|
9
|
+
return values.sort((a, b) => a - b)[Math.floor((values.length - 1) * q)];
|
|
10
|
+
}
|
|
11
|
+
/** K-weighted stereo energy and a coarse spectral tilt estimate in 100 ms windows. */
|
|
12
|
+
export async function profileDialogue(path, key, signal) {
|
|
13
|
+
const cached = analysisCache.get(key);
|
|
14
|
+
if (cached) {
|
|
15
|
+
analysisCache.delete(key);
|
|
16
|
+
analysisCache.set(key, cached);
|
|
17
|
+
return cached;
|
|
18
|
+
}
|
|
19
|
+
const windows = [];
|
|
20
|
+
let pending = Buffer.alloc(0);
|
|
21
|
+
let count = 0;
|
|
22
|
+
let energy = 0;
|
|
23
|
+
let bass = 0;
|
|
24
|
+
let high = 0;
|
|
25
|
+
let leftLow = 0;
|
|
26
|
+
let rightLow = 0;
|
|
27
|
+
let offset = 0;
|
|
28
|
+
const coefficient = 1 - Math.exp((-2 * Math.PI * 800) / rate);
|
|
29
|
+
function flush() {
|
|
30
|
+
if (!count)
|
|
31
|
+
return;
|
|
32
|
+
const end = offset + count * (48000 / rate);
|
|
33
|
+
windows.push({
|
|
34
|
+
from: offset,
|
|
35
|
+
to: end,
|
|
36
|
+
level: 10 * Math.log10(Math.max(1e-12, energy / count)) - 0.691,
|
|
37
|
+
tone: 10 * Math.log10((high + 1e-9) / (bass + 1e-9)),
|
|
38
|
+
});
|
|
39
|
+
offset = end;
|
|
40
|
+
count = energy = bass = high = 0;
|
|
41
|
+
}
|
|
42
|
+
await runMediaTool('ffmpeg', [
|
|
43
|
+
'-v',
|
|
44
|
+
'error',
|
|
45
|
+
'-nostdin',
|
|
46
|
+
'-xerror',
|
|
47
|
+
'-filter_threads',
|
|
48
|
+
'1',
|
|
49
|
+
'-i',
|
|
50
|
+
path,
|
|
51
|
+
'-map',
|
|
52
|
+
'0:a:0',
|
|
53
|
+
'-af',
|
|
54
|
+
'biquad=b0=1.53512485958697:b1=-2.69169618940638:b2=1.19839281085285:a1=-1.69065929318241:a2=0.73248077421585:precision=f64,biquad=b0=1:b1=-2:b2=1:a1=-1.99004745483398:a2=0.99007225036621:precision=f64',
|
|
55
|
+
'-ar',
|
|
56
|
+
String(rate),
|
|
57
|
+
'-ac',
|
|
58
|
+
'2',
|
|
59
|
+
'-c:a',
|
|
60
|
+
'pcm_f32le',
|
|
61
|
+
'-f',
|
|
62
|
+
'f32le',
|
|
63
|
+
'pipe:1',
|
|
64
|
+
], 64 * 1024 * 1024, 120_000, {
|
|
65
|
+
signal,
|
|
66
|
+
onStdout(chunk) {
|
|
67
|
+
if (pending.length)
|
|
68
|
+
chunk = Buffer.concat([pending, chunk]);
|
|
69
|
+
const end = chunk.length - (chunk.length % 8);
|
|
70
|
+
for (let i = 0; i < end; i += 8) {
|
|
71
|
+
const left = chunk.readFloatLE(i);
|
|
72
|
+
const right = chunk.readFloatLE(i + 4);
|
|
73
|
+
leftLow += coefficient * (left - leftLow);
|
|
74
|
+
rightLow += coefficient * (right - rightLow);
|
|
75
|
+
energy += left ** 2 + right ** 2;
|
|
76
|
+
bass += leftLow ** 2 + rightLow ** 2;
|
|
77
|
+
high += (left - leftLow) ** 2 + (right - rightLow) ** 2;
|
|
78
|
+
if (++count === windowSize / (48000 / rate))
|
|
79
|
+
flush();
|
|
80
|
+
}
|
|
81
|
+
pending = chunk.subarray(end);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
flush();
|
|
85
|
+
const profile = {
|
|
86
|
+
windows,
|
|
87
|
+
floor: percentile(windows.map((window) => window.level), 0.15, -90),
|
|
88
|
+
};
|
|
89
|
+
analysisCache.set(key, profile);
|
|
90
|
+
if (analysisCache.size > 96)
|
|
91
|
+
analysisCache.delete(analysisCache.keys().next().value);
|
|
92
|
+
return profile;
|
|
93
|
+
}
|
|
94
|
+
export function detectDialogue(profile, pre, length, gainAt) {
|
|
95
|
+
const windows = profile.windows
|
|
96
|
+
.filter((window) => window.to > pre && window.from < pre + length)
|
|
97
|
+
.map((window) => {
|
|
98
|
+
const from = Math.max(0, window.from - pre);
|
|
99
|
+
const to = Math.min(length, window.to - pre);
|
|
100
|
+
const gain = gainAt((from + to) / 2);
|
|
101
|
+
return {
|
|
102
|
+
from,
|
|
103
|
+
to,
|
|
104
|
+
tone: window.tone,
|
|
105
|
+
level: window.level + 20 * Math.log10(gain),
|
|
106
|
+
audible: gain > 0.015,
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
const levels = windows
|
|
110
|
+
.filter(({ audible }) => audible)
|
|
111
|
+
.map(({ level }) => level);
|
|
112
|
+
const upper = percentile(levels.slice(), 0.85, -90);
|
|
113
|
+
const floor = percentile(levels, 0.15, -90);
|
|
114
|
+
const stationary = windows.length >= 12 && upper - floor < 2.5 && upper < -27;
|
|
115
|
+
// A brief utterance may sit entirely above the percentile used for typical speech.
|
|
116
|
+
const threshold = Math.max(-64, upper - 27, stationary ? floor + 7 : Math.min(floor + 7, upper - 3));
|
|
117
|
+
const active = windows.filter(({ audible, level }) => audible && level >= threshold);
|
|
118
|
+
const phrases = [];
|
|
119
|
+
const voiced = [];
|
|
120
|
+
let start = 0;
|
|
121
|
+
while (start < active.length) {
|
|
122
|
+
let end = start + 1;
|
|
123
|
+
while (end < active.length &&
|
|
124
|
+
active[end].from - active[end - 1].to <= 9600)
|
|
125
|
+
end++;
|
|
126
|
+
const { from, level } = active[start];
|
|
127
|
+
const { to } = active[end - 1];
|
|
128
|
+
// Remove isolated low-level impacts while retaining strong one-window utterances.
|
|
129
|
+
if (to - from >= 7200 || level >= Math.max(-42, upper - 5)) {
|
|
130
|
+
phrases.push({ from, to });
|
|
131
|
+
voiced.push(...active.slice(start, end));
|
|
132
|
+
}
|
|
133
|
+
start = end;
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
phrases,
|
|
137
|
+
level: percentile(voiced.map(({ level }) => level), 0.65, -Infinity),
|
|
138
|
+
tone: percentile(voiced.map(({ tone }) => tone), 0.5, 0),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function point(keys, sample, db) {
|
|
142
|
+
const value = db === 0 ? 0 : db;
|
|
143
|
+
const last = keys.at(-1);
|
|
144
|
+
if (last?.sample === sample)
|
|
145
|
+
last.db = value;
|
|
146
|
+
else
|
|
147
|
+
keys.push({ sample, db: value });
|
|
148
|
+
}
|
|
149
|
+
export function dialogueCurve(profile, activity, target, intensity, pre, length, gainAt) {
|
|
150
|
+
if (!Number.isFinite(activity.level) || !intensity)
|
|
151
|
+
return [];
|
|
152
|
+
const keys = [];
|
|
153
|
+
const clipGain = clamp(target - activity.level, -15, 15) * intensity;
|
|
154
|
+
let first = 0;
|
|
155
|
+
for (const { from, to } of activity.phrases) {
|
|
156
|
+
while (profile.windows[first] && profile.windows[first].to - pre <= from)
|
|
157
|
+
first++;
|
|
158
|
+
const phraseLevels = [];
|
|
159
|
+
for (let i = first; i < profile.windows.length && profile.windows[i].from - pre < to; i++) {
|
|
160
|
+
const window = profile.windows[i];
|
|
161
|
+
phraseLevels.push(window.level +
|
|
162
|
+
20 *
|
|
163
|
+
Math.log10(gainAt(clamp((window.from + window.to) / 2 - pre, from, to))));
|
|
164
|
+
}
|
|
165
|
+
const difference = activity.level - percentile(phraseLevels, 0.65, activity.level);
|
|
166
|
+
// Quiet and loud expressive phrases retain their contrast.
|
|
167
|
+
const correction = Math.abs(difference) <= 9 ? clamp(difference * 0.45, -3, 3) : 0;
|
|
168
|
+
const value = Math.round((clipGain + correction * intensity) * 100) / 100;
|
|
169
|
+
if (!value)
|
|
170
|
+
continue;
|
|
171
|
+
const attack = Math.max(keys.at(-1)?.sample ?? 0, from - 2400);
|
|
172
|
+
const release = Math.min(length, to + 3600);
|
|
173
|
+
if (attack < from)
|
|
174
|
+
point(keys, attack, 0);
|
|
175
|
+
point(keys, from, value);
|
|
176
|
+
point(keys, to, value);
|
|
177
|
+
if (release > to)
|
|
178
|
+
point(keys, release, 0);
|
|
179
|
+
}
|
|
180
|
+
return keys;
|
|
181
|
+
}
|
|
182
|
+
export function musicCurve(activity, { depthDb, attackMs, holdMs, releaseMs, }, length) {
|
|
183
|
+
if (!depthDb)
|
|
184
|
+
return [];
|
|
185
|
+
const [attack, hold, release] = [attackMs, holdMs, releaseMs].map((ms) => Math.round(ms * 48));
|
|
186
|
+
const regions = [];
|
|
187
|
+
for (const span of activity
|
|
188
|
+
.slice()
|
|
189
|
+
.sort((a, b) => a.from - b.from || a.to - b.to)) {
|
|
190
|
+
const preceding = regions.at(-1);
|
|
191
|
+
if (preceding && span.from - attack <= preceding.to + hold + release)
|
|
192
|
+
preceding.to = Math.max(preceding.to, span.to);
|
|
193
|
+
else
|
|
194
|
+
regions.push({ ...span });
|
|
195
|
+
}
|
|
196
|
+
const keys = [];
|
|
197
|
+
for (const { from, to } of regions) {
|
|
198
|
+
if (from >= length)
|
|
199
|
+
break;
|
|
200
|
+
if (from > 0) {
|
|
201
|
+
const begin = Math.max(0, from - attack);
|
|
202
|
+
point(keys, begin, -depthDb * (1 - (from - begin) / attack));
|
|
203
|
+
}
|
|
204
|
+
point(keys, from, -depthDb);
|
|
205
|
+
const held = Math.min(length, to + hold);
|
|
206
|
+
point(keys, held, -depthDb);
|
|
207
|
+
if (held < length) {
|
|
208
|
+
const end = Math.min(length, held + release);
|
|
209
|
+
point(keys, end, -depthDb * (1 - (end - held) / release));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return keys;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=dialogue-analysis.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { release } from 'node:os';
|
|
1
|
+
import { availableParallelism, release } from 'node:os';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import { sourceColorMatrix } from '@opencut/shared';
|
|
4
4
|
import { interpolationTiming } from './interpolate.js';
|
|
@@ -6,13 +6,15 @@ import { recipeInputArguments, videoSourceDuration } from './probe.js';
|
|
|
6
6
|
import { MediaError } from './process.js';
|
|
7
7
|
import { nativeRecipeFingerprint, runRecipeProcess } from './recipe-process.js';
|
|
8
8
|
export const enhancementBackendId = 'videotoolbox-enhancement-v4';
|
|
9
|
+
// Encoder changes invalidate cached artifacts without changing the package contract.
|
|
10
|
+
const enhancementCacheVersion = `${enhancementBackendId}:encoder-v2`;
|
|
9
11
|
const worker = fileURLToPath(new URL('./video-enhance', import.meta.url));
|
|
10
12
|
export async function enhancementBackendVersion(signal) {
|
|
11
13
|
if (process.platform !== 'darwin' ||
|
|
12
14
|
process.arch !== 'arm64' ||
|
|
13
15
|
Number(release().split('.')[0]) < 25)
|
|
14
16
|
throw new MediaError('AI enhancement requires Apple Silicon and macOS 26 or later. Run opencut system inspect --json.');
|
|
15
|
-
return nativeRecipeFingerprint(worker,
|
|
17
|
+
return nativeRecipeFingerprint(worker, enhancementCacheVersion, 'enhancement', signal);
|
|
16
18
|
}
|
|
17
19
|
function enhancementTiming(input) {
|
|
18
20
|
const video = input.video;
|
|
@@ -178,6 +180,8 @@ export async function runEnhancement(input, operation, output, limits, signal, o
|
|
|
178
180
|
`settb=1/${scale}`,
|
|
179
181
|
`setpts=PTS+${offset}`,
|
|
180
182
|
];
|
|
183
|
+
// Keep the lossless encoder at zero frame delay while bounding CPU work.
|
|
184
|
+
const encodeThreads = String(Math.min(4, availableParallelism()));
|
|
181
185
|
const colors = [
|
|
182
186
|
'-color_range',
|
|
183
187
|
'tv',
|
|
@@ -255,6 +259,8 @@ export async function runEnhancement(input, operation, output, limits, signal, o
|
|
|
255
259
|
: []),
|
|
256
260
|
'-map',
|
|
257
261
|
'0:v:0',
|
|
262
|
+
'-filter_threads',
|
|
263
|
+
encodeThreads,
|
|
258
264
|
'-vf',
|
|
259
265
|
encodeFilters.join(','),
|
|
260
266
|
'-enc_time_base:v',
|
|
@@ -270,7 +276,9 @@ export async function runEnhancement(input, operation, output, limits, signal, o
|
|
|
270
276
|
'-qp',
|
|
271
277
|
'0',
|
|
272
278
|
'-threads:v',
|
|
273
|
-
|
|
279
|
+
encodeThreads,
|
|
280
|
+
'-thread_type:v',
|
|
281
|
+
'slice',
|
|
274
282
|
'-pix_fmt',
|
|
275
283
|
'yuv420p',
|
|
276
284
|
...colors,
|
|
@@ -7,10 +7,11 @@ export { separateDialogue } from './dialogue.js';
|
|
|
7
7
|
export { MediaError, RenderCancelledError } from './process.js';
|
|
8
8
|
export type { MediaMetadata, MediaStream } from './probe.js';
|
|
9
9
|
export type { FrameResult } from './frame.js';
|
|
10
|
-
export { renderVideoTimeline, renderTimelineFrame, validateVideoTimeline, validateSubtitleBurnIn, renderCodecs, renderResolutions, } from './render.js';
|
|
10
|
+
export { renderVideoTimeline, renderTimelineFrame, analyzeTimelineAudioMix, validateVideoTimeline, validateSubtitleBurnIn, renderCodecs, renderResolutions, } from './render.js';
|
|
11
11
|
export type { VisualTimelineClip, VideoTimelineOptions, VideoTimelineResult, RenderControls, RenderCodec, RenderResolution, } from './render.js';
|
|
12
12
|
export { renderQualities, renderQualityProfiles } from '@opencut/shared';
|
|
13
13
|
export type { RenderQuality } from '@opencut/shared';
|
|
14
|
+
export type { PictureCache, PictureRange } from './picture-cache.js';
|
|
14
15
|
export type { RenderProgress } from './render-progress.js';
|
|
15
16
|
export { renderContactSheet } from './contact-sheet.js';
|
|
16
17
|
export { rasterizeTextLayer, validateEmbeddedFont } from './text.js';
|
|
@@ -24,3 +25,5 @@ export { accountRenderFile, withRenderBudget, withDefaultRenderBudget, } from '.
|
|
|
24
25
|
export { hostRenderResources, sampleMemoryPressure } from './host-resources.js';
|
|
25
26
|
export { interpolationBackendId } from './interpolate.js';
|
|
26
27
|
export { enhancementBackendId } from './enhance.js';
|
|
28
|
+
export type { AudioMixReport, LoudnessMeasurement } from './audio-mastering.js';
|
|
29
|
+
export type { AudioMixCache } from './professional-mix.js';
|
|
@@ -5,7 +5,7 @@ export { inspectVideoToolboxWorkers } from './video-toolbox-workers.js';
|
|
|
5
5
|
export { inspectRenderMemory } from './process-memory.js';
|
|
6
6
|
export { separateDialogue } from './dialogue.js';
|
|
7
7
|
export { MediaError, RenderCancelledError } from './process.js';
|
|
8
|
-
export { renderVideoTimeline, renderTimelineFrame, validateVideoTimeline, validateSubtitleBurnIn, renderCodecs, renderResolutions, } from './render.js';
|
|
8
|
+
export { renderVideoTimeline, renderTimelineFrame, analyzeTimelineAudioMix, validateVideoTimeline, validateSubtitleBurnIn, renderCodecs, renderResolutions, } from './render.js';
|
|
9
9
|
export { renderQualities, renderQualityProfiles } from '@opencut/shared';
|
|
10
10
|
export { renderContactSheet } from './contact-sheet.js';
|
|
11
11
|
export { rasterizeTextLayer, validateEmbeddedFont } from './text.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TextLayer } from '@opencut/shared';
|
|
2
|
+
import type { MediaMetadata } from './probe.js';
|
|
3
|
+
import type { TextRaster } from './text.js';
|
|
4
|
+
import type { VideoTimelineOptions, VisualTimelineClip } from './render.js';
|
|
5
|
+
export interface PictureRange {
|
|
6
|
+
startFrame: number;
|
|
7
|
+
endFrame: number;
|
|
8
|
+
status: 'reused' | 'rendered';
|
|
9
|
+
}
|
|
10
|
+
export interface PictureCache {
|
|
11
|
+
backend: string;
|
|
12
|
+
sourceIdentity(path: string): string;
|
|
13
|
+
materialize(key: string, encode: (path: string) => Promise<MediaMetadata>): Promise<{
|
|
14
|
+
path: string;
|
|
15
|
+
reused: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
type Transition = NonNullable<VideoTimelineOptions['visualTransitions']>[number];
|
|
19
|
+
interface CachePlan {
|
|
20
|
+
options: VideoTimelineOptions;
|
|
21
|
+
cache: PictureCache;
|
|
22
|
+
visualClips: VisualTimelineClip[];
|
|
23
|
+
byOwner: ReadonlyMap<string, Transition[]>;
|
|
24
|
+
startFrame: number;
|
|
25
|
+
endFrame: number;
|
|
26
|
+
outputWidth: number;
|
|
27
|
+
outputHeight: number;
|
|
28
|
+
warnings: string[];
|
|
29
|
+
rasterize(clip: VisualTimelineClip & {
|
|
30
|
+
text: TextLayer;
|
|
31
|
+
}): Promise<TextRaster>;
|
|
32
|
+
encode(startFrame: number, endFrame: number, destination: string): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
/** Use render inputs and clip-local sample positions as the identity of a range. */
|
|
35
|
+
export declare function cachePicture({ options, cache, visualClips, byOwner, startFrame, endFrame, outputWidth, outputHeight, warnings, rasterize, encode, }: CachePlan): Promise<{
|
|
36
|
+
concat: string;
|
|
37
|
+
ranges: PictureRange[];
|
|
38
|
+
}>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { opaqueCanvasColor } from '@opencut/shared';
|
|
3
|
+
import { MediaError, checkRenderSignal, runMediaTool } from './process.js';
|
|
4
|
+
import { isStillImage, probeMedia } from './probe.js';
|
|
5
|
+
function digest(value) {
|
|
6
|
+
return createHash('sha256').update(value).digest('hex');
|
|
7
|
+
}
|
|
8
|
+
function relativeTime(time, frame, rate) {
|
|
9
|
+
const n = BigInt(time.numerator) * BigInt(rate.numerator) -
|
|
10
|
+
BigInt(frame) * BigInt(rate.denominator) * BigInt(time.denominator);
|
|
11
|
+
const d = BigInt(time.denominator) * BigInt(rate.numerator);
|
|
12
|
+
let a = n < 0n ? -n : n;
|
|
13
|
+
let b = d;
|
|
14
|
+
while (b)
|
|
15
|
+
[a, b] = [b, a % b];
|
|
16
|
+
return [(n / a).toString(), (d / a).toString()];
|
|
17
|
+
}
|
|
18
|
+
/** Use render inputs and clip-local sample positions as the identity of a range. */
|
|
19
|
+
export async function cachePicture({ options, cache, visualClips, byOwner, startFrame, endFrame, outputWidth, outputHeight, warnings, rasterize, encode, }) {
|
|
20
|
+
const { width, height, frameRate, signal } = options;
|
|
21
|
+
const boundaries = new Set([startFrame, endFrame]);
|
|
22
|
+
const include = (boundary) => {
|
|
23
|
+
if (boundary > startFrame && boundary < endFrame)
|
|
24
|
+
boundaries.add(boundary);
|
|
25
|
+
};
|
|
26
|
+
const sources = new Map(options.sourceMetadata);
|
|
27
|
+
const identities = new Map();
|
|
28
|
+
const layers = new Map();
|
|
29
|
+
const layerKey = async (clip, start) => {
|
|
30
|
+
let layer = layers.get(clip);
|
|
31
|
+
const { retiming, text, animation } = clip;
|
|
32
|
+
if (!layer) {
|
|
33
|
+
let sourceKey;
|
|
34
|
+
let still = !!text;
|
|
35
|
+
if (text) {
|
|
36
|
+
// Include the raster so font installation and fallback affect cache hits.
|
|
37
|
+
const { png, x, y, warning } = await rasterize(clip);
|
|
38
|
+
if (warning)
|
|
39
|
+
warnings.push(`Clip '${clip.clipId}': ${warning}`);
|
|
40
|
+
sourceKey = png && [digest(png), x, y];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
let identity = identities.get(clip.path);
|
|
44
|
+
if (!identity) {
|
|
45
|
+
identity = cache.sourceIdentity(clip.path);
|
|
46
|
+
identities.set(clip.path, identity);
|
|
47
|
+
}
|
|
48
|
+
let metadata = sources.get(clip.path);
|
|
49
|
+
if (!metadata) {
|
|
50
|
+
metadata = await probeMedia(clip.path, signal);
|
|
51
|
+
sources.set(clip.path, metadata);
|
|
52
|
+
}
|
|
53
|
+
const { freezeFrame } = clip;
|
|
54
|
+
still = !!freezeFrame || isStillImage(metadata);
|
|
55
|
+
sourceKey = [clip.path, identity, freezeFrame];
|
|
56
|
+
}
|
|
57
|
+
layer = {
|
|
58
|
+
still,
|
|
59
|
+
key: digest(JSON.stringify([
|
|
60
|
+
sourceKey,
|
|
61
|
+
clip.x,
|
|
62
|
+
clip.y,
|
|
63
|
+
clip.scale,
|
|
64
|
+
clip.opacity,
|
|
65
|
+
clip.rotation,
|
|
66
|
+
clip.fit,
|
|
67
|
+
clip.crop,
|
|
68
|
+
clip.grade,
|
|
69
|
+
animation?.keyframes,
|
|
70
|
+
])),
|
|
71
|
+
};
|
|
72
|
+
layers.set(clip, layer);
|
|
73
|
+
}
|
|
74
|
+
const offset = start - clip.timelineStartFrame;
|
|
75
|
+
return [
|
|
76
|
+
layer.key,
|
|
77
|
+
animation && relativeTime(animation.start, start, frameRate),
|
|
78
|
+
layer.still
|
|
79
|
+
? null
|
|
80
|
+
: retiming
|
|
81
|
+
? [
|
|
82
|
+
offset,
|
|
83
|
+
retiming.speed,
|
|
84
|
+
retiming.localSourceOriginNs ?? [
|
|
85
|
+
retiming.sourceOriginNs,
|
|
86
|
+
clip.timelineStartFrame,
|
|
87
|
+
],
|
|
88
|
+
]
|
|
89
|
+
: clip.sourceStartFrame + offset,
|
|
90
|
+
];
|
|
91
|
+
};
|
|
92
|
+
const active = (start, end, frame) => start <= frame && frame < end;
|
|
93
|
+
for (const clip of visualClips) {
|
|
94
|
+
include(clip.timelineStartFrame);
|
|
95
|
+
include(clip.timelineStartFrame + clip.frameCount);
|
|
96
|
+
for (const { layers } of byOwner.get(clip.clipId) ?? []) {
|
|
97
|
+
const { startFrame, endFrame } = layers[0].ramp;
|
|
98
|
+
include(startFrame);
|
|
99
|
+
include(endFrame);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const edges = [...boundaries].sort((a, b) => a - b);
|
|
103
|
+
let concat = '';
|
|
104
|
+
const ranges = [];
|
|
105
|
+
const settings = [
|
|
106
|
+
cache.backend,
|
|
107
|
+
width,
|
|
108
|
+
height,
|
|
109
|
+
frameRate,
|
|
110
|
+
outputWidth,
|
|
111
|
+
outputHeight,
|
|
112
|
+
opaqueCanvasColor(options.backgroundColor ?? '#000000'),
|
|
113
|
+
];
|
|
114
|
+
for (let i = 1; i < edges.length; i++) {
|
|
115
|
+
checkRenderSignal(signal);
|
|
116
|
+
const start = edges[i - 1];
|
|
117
|
+
const end = edges[i];
|
|
118
|
+
const count = end - start;
|
|
119
|
+
const composition = [];
|
|
120
|
+
for (const clip of visualClips) {
|
|
121
|
+
const at = clip.timelineStartFrame;
|
|
122
|
+
if (active(at, at + clip.frameCount, start))
|
|
123
|
+
composition.push(['layer', await layerKey(clip, start)]);
|
|
124
|
+
for (const { layers } of byOwner.get(clip.clipId) ?? []) {
|
|
125
|
+
const { startFrame, endFrame } = layers[0].ramp;
|
|
126
|
+
if (active(startFrame, endFrame, start))
|
|
127
|
+
composition.push([
|
|
128
|
+
'transition',
|
|
129
|
+
start - startFrame,
|
|
130
|
+
endFrame - startFrame,
|
|
131
|
+
await Promise.all(layers.map(async (layer) => [
|
|
132
|
+
layer.ramp.direction,
|
|
133
|
+
await layerKey(layer, start),
|
|
134
|
+
])),
|
|
135
|
+
]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const key = digest(JSON.stringify([settings, count, composition]));
|
|
139
|
+
const { path, reused } = await cache.materialize(key, async (destination) => {
|
|
140
|
+
await encode(start, end, destination);
|
|
141
|
+
const packets = await runMediaTool('ffprobe', [
|
|
142
|
+
'-v',
|
|
143
|
+
'error',
|
|
144
|
+
'-count_packets',
|
|
145
|
+
'-select_streams',
|
|
146
|
+
'v:0',
|
|
147
|
+
'-show_entries',
|
|
148
|
+
'stream=nb_read_packets',
|
|
149
|
+
'-of',
|
|
150
|
+
'csv=p=0',
|
|
151
|
+
destination,
|
|
152
|
+
], undefined, 600_000, { signal });
|
|
153
|
+
if (Number(packets.toString().trim()) !== count)
|
|
154
|
+
throw new MediaError(`Picture range [${start}, ${end}) has an unexpected frame count.`);
|
|
155
|
+
return probeMedia(destination, signal);
|
|
156
|
+
});
|
|
157
|
+
if (/[\r\n]/.test(path))
|
|
158
|
+
throw new MediaError('Picture cache paths cannot contain line breaks.');
|
|
159
|
+
const duration = (count * frameRate.denominator) / frameRate.numerator;
|
|
160
|
+
concat += `file '${path.replaceAll("'", "'\\''")}'\nduration ${duration.toFixed(6)}\n`;
|
|
161
|
+
ranges.push({
|
|
162
|
+
startFrame: start,
|
|
163
|
+
endFrame: end,
|
|
164
|
+
status: reused ? 'reused' : 'rendered',
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return { concat, ranges };
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=picture-cache.js.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { checkRenderSignal, runMediaTool } from './process.js';
|
|
2
|
+
import { indexedSeekArgs } from './video-filter.js';
|
|
3
|
+
async function firstPictureTimestamp(path, stream, seekSeconds, signal) {
|
|
4
|
+
try {
|
|
5
|
+
// Use the same decoder and input seek as the compositor. A packet's DTS
|
|
6
|
+
// can precede the target even when the first decoded picture's PTS does not.
|
|
7
|
+
const result = await runMediaTool('ffmpeg', [
|
|
8
|
+
'-v',
|
|
9
|
+
'error',
|
|
10
|
+
'-nostdin',
|
|
11
|
+
'-xerror',
|
|
12
|
+
'-copyts',
|
|
13
|
+
'-threads',
|
|
14
|
+
'1',
|
|
15
|
+
...indexedSeekArgs(seekSeconds),
|
|
16
|
+
'-i',
|
|
17
|
+
path,
|
|
18
|
+
'-map',
|
|
19
|
+
`0:${stream}`,
|
|
20
|
+
'-filter_threads',
|
|
21
|
+
'1',
|
|
22
|
+
'-vf',
|
|
23
|
+
'scale=2:2,format=yuv420p',
|
|
24
|
+
'-frames:v',
|
|
25
|
+
'1',
|
|
26
|
+
'-c:v',
|
|
27
|
+
'rawvideo',
|
|
28
|
+
'-threads',
|
|
29
|
+
'1',
|
|
30
|
+
'-fps_mode',
|
|
31
|
+
'passthrough',
|
|
32
|
+
'-enc_time_base:v',
|
|
33
|
+
'demux',
|
|
34
|
+
'-avoid_negative_ts',
|
|
35
|
+
'disabled',
|
|
36
|
+
'-f',
|
|
37
|
+
'framecrc',
|
|
38
|
+
'pipe:1',
|
|
39
|
+
], undefined, undefined, { signal });
|
|
40
|
+
const output = result.toString();
|
|
41
|
+
const timeBase = /^#tb 0: ([1-9]\d*)\/([1-9]\d*)$/m.exec(output);
|
|
42
|
+
const frame = /^0,\s*-?\d+,\s*(-?\d+),/m.exec(output);
|
|
43
|
+
if (timeBase && frame)
|
|
44
|
+
return {
|
|
45
|
+
pts: BigInt(frame[1]),
|
|
46
|
+
numerator: BigInt(timeBase[1]),
|
|
47
|
+
denominator: BigInt(timeBase[2]),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// If the probe is inconclusive, the normal sequential path owns decoding errors.
|
|
52
|
+
checkRenderSignal(signal);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function pictureSeekCheck(signal) {
|
|
56
|
+
const origins = new Map();
|
|
57
|
+
return async (path, stream, seekSeconds, firstFrame, rate) => {
|
|
58
|
+
const key = JSON.stringify([path, stream]);
|
|
59
|
+
let hasZeroOrigin = origins.get(key);
|
|
60
|
+
if (!hasZeroOrigin) {
|
|
61
|
+
// Sequential sampling rebases the first decoded frame. An indexed decode
|
|
62
|
+
// uses the original PTS, so both clocks must share an actual zero origin.
|
|
63
|
+
hasZeroOrigin = firstPictureTimestamp(path, stream, 0, signal).then((timestamp) => timestamp?.pts === 0n);
|
|
64
|
+
origins.set(key, hasZeroOrigin);
|
|
65
|
+
}
|
|
66
|
+
if (!(await hasZeroOrigin))
|
|
67
|
+
return false;
|
|
68
|
+
const first = await firstPictureTimestamp(path, stream, seekSeconds, signal);
|
|
69
|
+
// round=up must place the first decoded picture strictly before the first
|
|
70
|
+
// requested project tick. This retains its predecessor across VFR gaps.
|
|
71
|
+
return (!!first &&
|
|
72
|
+
first.pts > 0n &&
|
|
73
|
+
first.pts * first.numerator * BigInt(rate.numerator) <=
|
|
74
|
+
BigInt(firstFrame - 1) * BigInt(rate.denominator) * first.denominator);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=picture-seek.js.map
|
|
Binary file
|
|
@@ -10,7 +10,8 @@ export interface MediaToolControl {
|
|
|
10
10
|
signal?: AbortSignal | undefined;
|
|
11
11
|
onStdout?: (chunk: Buffer) => void;
|
|
12
12
|
writesFile?: boolean;
|
|
13
|
+
onDiagnostics?: (diagnostics: string) => void;
|
|
13
14
|
}
|
|
14
15
|
export declare function localFile(file: string): Promise<string>;
|
|
15
16
|
export declare function sourceFileStamp(path: string): Promise<string>;
|
|
16
|
-
export declare function runMediaTool(tool:
|
|
17
|
+
export declare function runMediaTool(tool: string, args: string[], maxBuffer?: number, timeoutMs?: number, control?: MediaToolControl): Promise<Buffer>;
|
|
@@ -35,7 +35,7 @@ export async function sourceFileStamp(path) {
|
|
|
35
35
|
return [info.dev, info.ino, info.size, info.mtimeNs, info.ctimeNs].join(':');
|
|
36
36
|
}
|
|
37
37
|
// execFile passes arguments directly, without shell expansion. Bound both runtime
|
|
38
|
-
// and buffered output
|
|
38
|
+
// and buffered output, and close stdin so tools cannot wait for user input.
|
|
39
39
|
export async function runMediaTool(tool, args, maxBuffer = 4 * 1024 * 1024, timeoutMs = 60_000, control) {
|
|
40
40
|
checkRenderSignal(control?.signal);
|
|
41
41
|
const command = renderToolCommand(tool, args, control?.writesFile);
|
|
@@ -79,7 +79,10 @@ export async function runMediaTool(tool, args, maxBuffer = 4 * 1024 * 1024, time
|
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
if (error && 'code' in error && error.code === 'ENOENT') {
|
|
82
|
-
reject(new MediaError(`Required executable '${tool}' was not found on PATH
|
|
82
|
+
reject(new MediaError(`Required executable '${tool}' was not found on PATH.` +
|
|
83
|
+
(tool === 'ffmpeg' || tool === 'ffprobe'
|
|
84
|
+
? ' Install FFmpeg/ffprobe manually to use media commands.'
|
|
85
|
+
: ''), { cause: error }));
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
85
88
|
const diagnostics = stderr.toString('utf8').trim();
|
|
@@ -90,11 +93,17 @@ export async function runMediaTool(tool, args, maxBuffer = 4 * 1024 * 1024, time
|
|
|
90
93
|
}));
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
|
-
if (error || diagnostics) {
|
|
96
|
+
if (error || (diagnostics && !control?.onDiagnostics)) {
|
|
94
97
|
reject(new MediaError(`${tool} failed: ${diagnostics || error?.message || 'unknown execution failure'}`, { cause: error }));
|
|
95
98
|
return;
|
|
96
99
|
}
|
|
97
|
-
|
|
100
|
+
try {
|
|
101
|
+
control?.onDiagnostics?.(diagnostics);
|
|
102
|
+
resolve(stdout);
|
|
103
|
+
}
|
|
104
|
+
catch (cause) {
|
|
105
|
+
reject(cause);
|
|
106
|
+
}
|
|
98
107
|
});
|
|
99
108
|
if (!closed)
|
|
100
109
|
untrack = trackRenderProcess(child.pid, (error) => {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ProfessionalMix } from '@opencut/shared';
|
|
2
|
+
import type { AudioRenderClip } from './audio-graph.js';
|
|
3
|
+
import type { MediaMetadata } from './probe.js';
|
|
4
|
+
import type { VideoTimelineOptions } from './render.js';
|
|
5
|
+
export interface AudioMixCache {
|
|
6
|
+
materialize(key: string, encode: (path: string) => Promise<MediaMetadata>): Promise<string>;
|
|
7
|
+
}
|
|
8
|
+
type SourceReader = (clip: AudioRenderClip) => Promise<MediaMetadata>;
|
|
9
|
+
export declare function prepareProfessionalMix(options: VideoTimelineOptions, mix: ProfessionalMix, folder: string, readSource: SourceReader, { base, from, to }: {
|
|
10
|
+
base: number;
|
|
11
|
+
from: number;
|
|
12
|
+
to: number;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
path: string;
|
|
15
|
+
report: {
|
|
16
|
+
automation: {
|
|
17
|
+
dialogue: {
|
|
18
|
+
[k: string]: import("@opencut/shared").MixGainPoint[];
|
|
19
|
+
};
|
|
20
|
+
music: import("@opencut/shared").MixGainPoint[];
|
|
21
|
+
};
|
|
22
|
+
target: {
|
|
23
|
+
integratedLufs: number;
|
|
24
|
+
truePeakDbtp: number;
|
|
25
|
+
loudnessRange: number;
|
|
26
|
+
};
|
|
27
|
+
input: import("./audio-mastering.js").LoudnessMeasurement;
|
|
28
|
+
output: import("./audio-mastering.js").LoudnessMeasurement;
|
|
29
|
+
comparison: "after" | "before";
|
|
30
|
+
normalization: "linear" | "dynamic" | "none";
|
|
31
|
+
warnings: string[];
|
|
32
|
+
};
|
|
33
|
+
}>;
|
|
34
|
+
export {};
|