@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,129 @@
1
+ import { z } from 'zod';
2
+ export declare const professionalMixSchema: z.ZodObject<{
3
+ preset: z.ZodEnum<{
4
+ "natural-cinematic": "natural-cinematic";
5
+ "clear-voiceover": "clear-voiceover";
6
+ }>;
7
+ enabled: z.ZodOptional<z.ZodBoolean>;
8
+ cleanup: z.ZodOptional<z.ZodNumber>;
9
+ warmth: z.ZodOptional<z.ZodNumber>;
10
+ clarity: z.ZodOptional<z.ZodNumber>;
11
+ consistency: z.ZodOptional<z.ZodNumber>;
12
+ dialogueLufs: z.ZodOptional<z.ZodNumber>;
13
+ highPassHz: z.ZodOptional<z.ZodNumber>;
14
+ eq: z.ZodOptional<z.ZodArray<z.ZodObject<{
15
+ frequency: z.ZodNumber;
16
+ q: z.ZodNumber;
17
+ db: z.ZodNumber;
18
+ }, z.core.$strict>>>;
19
+ deEsser: z.ZodOptional<z.ZodNumber>;
20
+ compressor: z.ZodOptional<z.ZodObject<{
21
+ thresholdDb: z.ZodNumber;
22
+ ratio: z.ZodNumber;
23
+ attackMs: z.ZodNumber;
24
+ releaseMs: z.ZodNumber;
25
+ }, z.core.$strict>>;
26
+ ai: z.ZodOptional<z.ZodLiteral<"deepfilternet">>;
27
+ dereverb: z.ZodOptional<z.ZodNumber>;
28
+ matching: z.ZodOptional<z.ZodObject<{
29
+ amount: z.ZodNumber;
30
+ referenceClip: z.ZodOptional<z.ZodString>;
31
+ }, z.core.$strict>>;
32
+ crossfadeMs: z.ZodOptional<z.ZodNumber>;
33
+ ducking: z.ZodOptional<z.ZodObject<{
34
+ depthDb: z.ZodOptional<z.ZodNumber>;
35
+ attackMs: z.ZodOptional<z.ZodNumber>;
36
+ holdMs: z.ZodOptional<z.ZodNumber>;
37
+ releaseMs: z.ZodOptional<z.ZodNumber>;
38
+ }, z.core.$strict>>;
39
+ delivery: z.ZodOptional<z.ZodObject<{
40
+ preset: z.ZodEnum<{
41
+ web: "web";
42
+ broadcast: "broadcast";
43
+ film: "film";
44
+ }>;
45
+ integratedLufs: z.ZodOptional<z.ZodNumber>;
46
+ truePeakDbtp: z.ZodOptional<z.ZodNumber>;
47
+ loudnessRange: z.ZodOptional<z.ZodNumber>;
48
+ }, z.core.$strict>>;
49
+ automation: z.ZodOptional<z.ZodObject<{
50
+ dialogue: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
51
+ sample: z.ZodInt;
52
+ db: z.ZodNumber;
53
+ }, z.core.$strict>>>>;
54
+ music: z.ZodOptional<z.ZodArray<z.ZodObject<{
55
+ sample: z.ZodInt;
56
+ db: z.ZodNumber;
57
+ }, z.core.$strict>>>;
58
+ }, z.core.$strict>>;
59
+ }, z.core.$strict>;
60
+ export declare const audioRoleSchema: z.ZodEnum<{
61
+ dialogue: "dialogue";
62
+ music: "music";
63
+ other: "other";
64
+ }>;
65
+ export declare const videoMixEditSchema: z.ZodObject<{
66
+ mix: z.ZodNullable<z.ZodObject<{
67
+ preset: z.ZodEnum<{
68
+ "natural-cinematic": "natural-cinematic";
69
+ "clear-voiceover": "clear-voiceover";
70
+ }>;
71
+ enabled: z.ZodOptional<z.ZodBoolean>;
72
+ cleanup: z.ZodOptional<z.ZodNumber>;
73
+ warmth: z.ZodOptional<z.ZodNumber>;
74
+ clarity: z.ZodOptional<z.ZodNumber>;
75
+ consistency: z.ZodOptional<z.ZodNumber>;
76
+ dialogueLufs: z.ZodOptional<z.ZodNumber>;
77
+ highPassHz: z.ZodOptional<z.ZodNumber>;
78
+ eq: z.ZodOptional<z.ZodArray<z.ZodObject<{
79
+ frequency: z.ZodNumber;
80
+ q: z.ZodNumber;
81
+ db: z.ZodNumber;
82
+ }, z.core.$strict>>>;
83
+ deEsser: z.ZodOptional<z.ZodNumber>;
84
+ compressor: z.ZodOptional<z.ZodObject<{
85
+ thresholdDb: z.ZodNumber;
86
+ ratio: z.ZodNumber;
87
+ attackMs: z.ZodNumber;
88
+ releaseMs: z.ZodNumber;
89
+ }, z.core.$strict>>;
90
+ ai: z.ZodOptional<z.ZodLiteral<"deepfilternet">>;
91
+ dereverb: z.ZodOptional<z.ZodNumber>;
92
+ matching: z.ZodOptional<z.ZodObject<{
93
+ amount: z.ZodNumber;
94
+ referenceClip: z.ZodOptional<z.ZodString>;
95
+ }, z.core.$strict>>;
96
+ crossfadeMs: z.ZodOptional<z.ZodNumber>;
97
+ ducking: z.ZodOptional<z.ZodObject<{
98
+ depthDb: z.ZodOptional<z.ZodNumber>;
99
+ attackMs: z.ZodOptional<z.ZodNumber>;
100
+ holdMs: z.ZodOptional<z.ZodNumber>;
101
+ releaseMs: z.ZodOptional<z.ZodNumber>;
102
+ }, z.core.$strict>>;
103
+ delivery: z.ZodOptional<z.ZodObject<{
104
+ preset: z.ZodEnum<{
105
+ web: "web";
106
+ broadcast: "broadcast";
107
+ film: "film";
108
+ }>;
109
+ integratedLufs: z.ZodOptional<z.ZodNumber>;
110
+ truePeakDbtp: z.ZodOptional<z.ZodNumber>;
111
+ loudnessRange: z.ZodOptional<z.ZodNumber>;
112
+ }, z.core.$strict>>;
113
+ automation: z.ZodOptional<z.ZodObject<{
114
+ dialogue: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
115
+ sample: z.ZodInt;
116
+ db: z.ZodNumber;
117
+ }, z.core.$strict>>>>;
118
+ music: z.ZodOptional<z.ZodArray<z.ZodObject<{
119
+ sample: z.ZodInt;
120
+ db: z.ZodNumber;
121
+ }, z.core.$strict>>>;
122
+ }, z.core.$strict>>;
123
+ }, z.core.$strict>>;
124
+ roles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
125
+ dialogue: "dialogue";
126
+ music: "music";
127
+ other: "other";
128
+ }>>>;
129
+ }, z.core.$strict>;
@@ -0,0 +1,70 @@
1
+ import { audioRoles, deliveryPresets, dialoguePresets } from '@opencut/shared';
2
+ import { z } from 'zod';
3
+ const amount = z.number().min(0).max(1);
4
+ const id = z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/);
5
+ const curve = z
6
+ .array(z.strictObject({
7
+ sample: z.int().min(0).max(28_800_000),
8
+ db: z.number().min(-60).max(24),
9
+ }))
10
+ .max(12000)
11
+ .refine((keys) => keys.every((key, i) => i === 0 || key.sample > keys[i - 1].sample), 'Mix automation samples must strictly increase.');
12
+ export const professionalMixSchema = z.strictObject({
13
+ preset: z.enum(dialoguePresets),
14
+ enabled: z.boolean().optional(),
15
+ cleanup: amount.optional(),
16
+ warmth: amount.optional(),
17
+ clarity: amount.optional(),
18
+ consistency: amount.optional(),
19
+ dialogueLufs: z.number().min(-40).max(-10).optional(),
20
+ highPassHz: z.number().min(0).max(250).optional(),
21
+ eq: z
22
+ .array(z.strictObject({
23
+ frequency: z.number().min(40).max(16000),
24
+ q: z.number().min(0.2).max(12),
25
+ db: z.number().min(-18).max(18),
26
+ }))
27
+ .max(8)
28
+ .optional(),
29
+ deEsser: amount.optional(),
30
+ compressor: z
31
+ .strictObject({
32
+ thresholdDb: z.number().min(-50).max(0),
33
+ ratio: z.number().min(1).max(8),
34
+ attackMs: z.number().min(1).max(200),
35
+ releaseMs: z.number().min(5).max(2000),
36
+ })
37
+ .optional(),
38
+ ai: z.literal('deepfilternet').optional(),
39
+ dereverb: amount.optional(),
40
+ matching: z.strictObject({ amount, referenceClip: id.optional() }).optional(),
41
+ crossfadeMs: z.number().min(0).max(250).optional(),
42
+ ducking: z
43
+ .strictObject({
44
+ depthDb: z.number().min(0).max(36).optional(),
45
+ attackMs: z.number().min(20).max(2000).optional(),
46
+ holdMs: z.number().min(0).max(5000).optional(),
47
+ releaseMs: z.number().min(50).max(5000).optional(),
48
+ })
49
+ .optional(),
50
+ delivery: z
51
+ .strictObject({
52
+ preset: z.enum(deliveryPresets),
53
+ integratedLufs: z.number().min(-40).max(-8).optional(),
54
+ truePeakDbtp: z.number().min(-8).max(-0.1).optional(),
55
+ loudnessRange: z.number().min(1).max(50).optional(),
56
+ })
57
+ .optional(),
58
+ automation: z
59
+ .strictObject({
60
+ dialogue: z.record(id, curve).optional(),
61
+ music: curve.optional(),
62
+ })
63
+ .optional(),
64
+ });
65
+ export const audioRoleSchema = z.enum(audioRoles);
66
+ export const videoMixEditSchema = z.strictObject({
67
+ mix: professionalMixSchema.nullable(),
68
+ roles: z.record(id, audioRoleSchema).optional(),
69
+ });
70
+ //# sourceMappingURL=professional-mix.js.map
@@ -63,6 +63,11 @@ export declare const assetSchema: z.ZodObject<{
63
63
  }, z.core.$strict>>;
64
64
  }, z.core.$strict>;
65
65
  export declare const trackSchema: z.ZodObject<{
66
+ audioRole: z.ZodOptional<z.ZodEnum<{
67
+ dialogue: "dialogue";
68
+ music: "music";
69
+ other: "other";
70
+ }>>;
66
71
  volume: z.ZodOptional<z.ZodNumber>;
67
72
  muted: z.ZodOptional<z.ZodBoolean>;
68
73
  id: z.ZodString;
@@ -389,6 +394,11 @@ export declare const snapshotSchema: z.ZodObject<{
389
394
  }, z.core.$strict>>;
390
395
  }, z.core.$strict>>;
391
396
  tracks: z.ZodArray<z.ZodObject<{
397
+ audioRole: z.ZodOptional<z.ZodEnum<{
398
+ dialogue: "dialogue";
399
+ music: "music";
400
+ other: "other";
401
+ }>>;
392
402
  volume: z.ZodOptional<z.ZodNumber>;
393
403
  muted: z.ZodOptional<z.ZodBoolean>;
394
404
  id: z.ZodString;
@@ -687,6 +697,64 @@ export declare const snapshotSchema: z.ZodObject<{
687
697
  frame: z.ZodInt;
688
698
  name: z.ZodString;
689
699
  }, z.core.$strict>>>;
700
+ professionalMix: z.ZodOptional<z.ZodObject<{
701
+ preset: z.ZodEnum<{
702
+ "natural-cinematic": "natural-cinematic";
703
+ "clear-voiceover": "clear-voiceover";
704
+ }>;
705
+ enabled: z.ZodOptional<z.ZodBoolean>;
706
+ cleanup: z.ZodOptional<z.ZodNumber>;
707
+ warmth: z.ZodOptional<z.ZodNumber>;
708
+ clarity: z.ZodOptional<z.ZodNumber>;
709
+ consistency: z.ZodOptional<z.ZodNumber>;
710
+ dialogueLufs: z.ZodOptional<z.ZodNumber>;
711
+ highPassHz: z.ZodOptional<z.ZodNumber>;
712
+ eq: z.ZodOptional<z.ZodArray<z.ZodObject<{
713
+ frequency: z.ZodNumber;
714
+ q: z.ZodNumber;
715
+ db: z.ZodNumber;
716
+ }, z.core.$strict>>>;
717
+ deEsser: z.ZodOptional<z.ZodNumber>;
718
+ compressor: z.ZodOptional<z.ZodObject<{
719
+ thresholdDb: z.ZodNumber;
720
+ ratio: z.ZodNumber;
721
+ attackMs: z.ZodNumber;
722
+ releaseMs: z.ZodNumber;
723
+ }, z.core.$strict>>;
724
+ ai: z.ZodOptional<z.ZodLiteral<"deepfilternet">>;
725
+ dereverb: z.ZodOptional<z.ZodNumber>;
726
+ matching: z.ZodOptional<z.ZodObject<{
727
+ amount: z.ZodNumber;
728
+ referenceClip: z.ZodOptional<z.ZodString>;
729
+ }, z.core.$strict>>;
730
+ crossfadeMs: z.ZodOptional<z.ZodNumber>;
731
+ ducking: z.ZodOptional<z.ZodObject<{
732
+ depthDb: z.ZodOptional<z.ZodNumber>;
733
+ attackMs: z.ZodOptional<z.ZodNumber>;
734
+ holdMs: z.ZodOptional<z.ZodNumber>;
735
+ releaseMs: z.ZodOptional<z.ZodNumber>;
736
+ }, z.core.$strict>>;
737
+ delivery: z.ZodOptional<z.ZodObject<{
738
+ preset: z.ZodEnum<{
739
+ web: "web";
740
+ broadcast: "broadcast";
741
+ film: "film";
742
+ }>;
743
+ integratedLufs: z.ZodOptional<z.ZodNumber>;
744
+ truePeakDbtp: z.ZodOptional<z.ZodNumber>;
745
+ loudnessRange: z.ZodOptional<z.ZodNumber>;
746
+ }, z.core.$strict>>;
747
+ automation: z.ZodOptional<z.ZodObject<{
748
+ dialogue: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
749
+ sample: z.ZodInt;
750
+ db: z.ZodNumber;
751
+ }, z.core.$strict>>>>;
752
+ music: z.ZodOptional<z.ZodArray<z.ZodObject<{
753
+ sample: z.ZodInt;
754
+ db: z.ZodNumber;
755
+ }, z.core.$strict>>>;
756
+ }, z.core.$strict>>;
757
+ }, z.core.$strict>>;
690
758
  }, z.core.$strict>;
691
759
  export type MediaReference = z.infer<typeof mediaReferenceSchema>;
692
760
  export type MediaAsset = z.infer<typeof assetSchema>;
@@ -5,6 +5,7 @@ import { textLayerSchema } from './text-style.js';
5
5
  import { subtitleTrackSchema, validSubtitleWords } from './subtitles.js';
6
6
  import { visualKeyframesSchema, visualValueSchema } from './keyframes.js';
7
7
  import { clipDuration, clipSpeedSchema } from './clip-timing.js';
8
+ import { audioRoleSchema, professionalMixSchema } from './professional-mix.js';
8
9
  import { clipAudioShape, resolveAudioFade, trackAudioShape } from './audio.js';
9
10
  import { addTimes, compareTimes, frameRateSchema, frameTime, subtractTimes, timeSchema, } from './time.js';
10
11
  export const entityIdSchema = z
@@ -73,6 +74,7 @@ export const trackSchema = z.strictObject({
73
74
  name: entityNameSchema,
74
75
  type: mediaType,
75
76
  ...trackAudioShape,
77
+ audioRole: audioRoleSchema.optional(),
76
78
  });
77
79
  export const clipVisualSchema = z.strictObject({
78
80
  crop: z
@@ -156,6 +158,7 @@ export const snapshotSchema = z.strictObject({
156
158
  subtitles: subtitleTrackSchema.optional(),
157
159
  transitions: z.array(transitionSchema).optional(),
158
160
  markers: z.array(markerSchema).optional(),
161
+ professionalMix: professionalMixSchema.optional(),
159
162
  });
160
163
  export class ProjectFormatError extends Error {
161
164
  issues;
@@ -234,6 +237,18 @@ function collectSemanticIssues(project) {
234
237
  }
235
238
  const assets = new Map(project.assets.map((asset) => [asset.id, asset]));
236
239
  const tracks = new Map(project.tracks.map((track) => [track.id, track]));
240
+ const mix = project.professionalMix;
241
+ const references = new Set(Object.keys(mix?.automation?.dialogue ?? {}));
242
+ const reference = mix?.matching?.referenceClip;
243
+ if (reference)
244
+ references.add(reference);
245
+ for (const id of references) {
246
+ const clip = project.clips.find((clip) => clip.id === id);
247
+ if (!clip ||
248
+ tracks.get(clip.trackId)?.audioRole !== 'dialogue' ||
249
+ clip.text)
250
+ add('/professionalMix', 'invalid_audio_reference', `Mix clip '${id}' must belong to a dialogue track.`);
251
+ }
237
252
  project.assets.forEach((asset, index) => {
238
253
  if (asset.freezeFrame &&
239
254
  (asset.metadata?.kind !== 'image' ||
@@ -1,4 +1,4 @@
1
- import type { RenderTimeMapping, TransitionRamp, VisualAnimation } from '@opencut/shared';
1
+ import type { AudioRole, ProfessionalMix, RenderTimeMapping, TransitionRamp, VisualAnimation } from '@opencut/shared';
2
2
  import type { Project, TimelineClip } from './project.js';
3
3
  import { resolveAudioFade } from './audio.js';
4
4
  import type { FrameRate, RationalTime } from './time.js';
@@ -44,6 +44,7 @@ export interface ProjectRenderPlan {
44
44
  /** Bottom to top, by track array order, then timeline start. */
45
45
  visualClips: VisualRenderClip[];
46
46
  audioClips: AudioRenderClip[];
47
+ professionalMix?: ProfessionalMix;
47
48
  visualTransitions?: Array<{
48
49
  afterClipId: string;
49
50
  layers: Array<Extract<VisualRenderClip, {
@@ -54,6 +55,8 @@ export interface ProjectRenderPlan {
54
55
  }>;
55
56
  }
56
57
  export interface AudioRenderClip {
58
+ trackId?: string;
59
+ role?: AudioRole;
57
60
  clipId: string;
58
61
  assetId: string;
59
62
  timelineStartFrame: number;
@@ -58,6 +58,7 @@ export function planProjectRender(project, { burnSubtitles = true } = {}) {
58
58
  throw new RenderError('Rendering requires an FFmpeg-compatible rational frame rate between 1 and 120 fps. Update project settings.');
59
59
  const visualClips = [];
60
60
  const audioClips = [];
61
+ const roles = new Map(project.tracks.map((track) => [track.id, track.audioRole]));
61
62
  if (compareTimes(timeline.duration, { numerator: 600, denominator: 1 }) > 0)
62
63
  throw new RenderError('Rendering supports at most 600 seconds. Shorten the timeline.');
63
64
  const sampledFrame = (time) => {
@@ -130,7 +131,9 @@ export function planProjectRender(project, { burnSubtitles = true } = {}) {
130
131
  ? undefined
131
132
  : clip.id;
132
133
  previousMedia = clip;
134
+ const role = roles.get(clip.trackId);
133
135
  audioClips.push({
136
+ ...(role && { role, trackId: clip.trackId }),
134
137
  clipId: clip.id,
135
138
  assetId: clip.assetId,
136
139
  timelineStartFrame: start,
@@ -223,6 +226,9 @@ export function planProjectRender(project, { burnSubtitles = true } = {}) {
223
226
  backgroundColor: project.settings.backgroundColor ?? '#000000',
224
227
  visualClips,
225
228
  audioClips,
229
+ ...(project.professionalMix && {
230
+ professionalMix: project.professionalMix,
231
+ }),
226
232
  ...(visualTransitions.length && { visualTransitions }),
227
233
  };
228
234
  }
@@ -37,6 +37,8 @@ export declare function bindRenderSources({ visualClips, audioClips, visualTrans
37
37
  visualClips: VisualTimelineClip[];
38
38
  audioClips: {
39
39
  path: string;
40
+ trackId?: string;
41
+ role?: import("@opencut/shared").AudioRole;
40
42
  clipId: string;
41
43
  assetId: string;
42
44
  timelineStartFrame: number;
@@ -58,5 +60,6 @@ export declare function bindRenderSources({ visualClips, audioClips, visualTrans
58
60
  backgroundColor: string;
59
61
  frameRate: import("./time.js").FrameRate;
60
62
  frameCount: number;
63
+ professionalMix?: import("@opencut/shared").ProfessionalMix;
61
64
  };
62
65
  export {};
@@ -274,6 +274,7 @@ export declare function listTimeline(project: Project): {
274
274
  id: string;
275
275
  name: string;
276
276
  type: "video" | "audio";
277
+ audioRole?: "dialogue" | "music" | "other" | undefined;
277
278
  volume?: number | undefined;
278
279
  muted?: boolean | undefined;
279
280
  }[];
@@ -0,0 +1,25 @@
1
+ import type { AudioMixCache, RenderControls } from '@opencut/media';
2
+ import type { CompiledVideo } from './video-compiler.js';
3
+ export declare function openAudioMixCache(directory: string | undefined, signal?: AbortSignal): Promise<AudioMixCache | undefined>;
4
+ export type AudioMixAnalysisOptions = Pick<RenderControls, 'signal' | 'audioSampleRate' | 'audioChannels' | 'audioBitrateKbps' | 'audioComparison'> & {
5
+ audioMixCacheDirectory?: string | undefined;
6
+ };
7
+ /** Analyze the exact PCM mix and decoded AAC without composing the picture. */
8
+ export declare function analyzeVideoMix(video: CompiledVideo, { audioMixCacheDirectory, ...settings }?: AudioMixAnalysisOptions): Promise<{
9
+ automation: {
10
+ dialogue: {
11
+ [k: string]: import("@opencut/shared").MixGainPoint[];
12
+ };
13
+ music: import("@opencut/shared").MixGainPoint[];
14
+ };
15
+ target: {
16
+ integratedLufs: number;
17
+ truePeakDbtp: number;
18
+ loudnessRange: number;
19
+ };
20
+ input: import("@opencut/media").LoudnessMeasurement;
21
+ output: import("@opencut/media").LoudnessMeasurement;
22
+ comparison: "after" | "before";
23
+ normalization: "linear" | "dynamic" | "none";
24
+ warnings: string[];
25
+ }>;
@@ -0,0 +1,36 @@
1
+ import { mkdir, realpath } from 'node:fs/promises';
2
+ import { tmpdir } from 'node:os';
3
+ import { join, resolve } from 'node:path';
4
+ import { analyzeTimelineAudioMix, MediaError } from '@opencut/media';
5
+ import { materializeMediaEntry } from './video-media-cache.js';
6
+ import { withRenderSources } from './render-sources.js';
7
+ export async function openAudioMixCache(directory, signal = new AbortController().signal) {
8
+ if (directory === undefined)
9
+ return;
10
+ if (!directory.trim())
11
+ throw new MediaError('Choose an audio mix cache directory.');
12
+ const root = resolve(directory, 'audio-mix-v1');
13
+ await mkdir(root, { recursive: true, mode: 0o700 });
14
+ const cache = await realpath(root);
15
+ return {
16
+ async materialize(key, encode) {
17
+ const { entry } = await materializeMediaEntry(cache, key, 'wav', signal, encode);
18
+ return entry.metadata.path;
19
+ },
20
+ };
21
+ }
22
+ /** Analyze the exact PCM mix and decoded AAC without composing the picture. */
23
+ export async function analyzeVideoMix(video, { audioMixCacheDirectory, ...settings } = {}) {
24
+ const { signal } = settings;
25
+ return withRenderSources(video, signal, async (plan) => {
26
+ const audioMixCache = await openAudioMixCache(audioMixCacheDirectory, signal);
27
+ return analyzeTimelineAudioMix({
28
+ ...plan,
29
+ ...settings,
30
+ ...(audioMixCache && { audioMixCache }),
31
+ output: join(tmpdir(), 'mix.mp4'),
32
+ scratchDirectory: tmpdir(),
33
+ });
34
+ });
35
+ }
36
+ //# sourceMappingURL=video-audio-mix.js.map
@@ -1,3 +1,4 @@
1
+ import type { VideoMixEdit } from '@opencut/shared';
1
2
  import type { MediaMetadata, RenderQuality } from '@opencut/media';
2
3
  import type { VideoAssetOptions } from './video-assets.js';
3
4
  import type { Project } from './project.js';
@@ -8,6 +9,7 @@ import type { VideoRecipeInspection } from './video-recipe.js';
8
9
  type BoundRenderPlan = ReturnType<typeof bindRenderSources>;
9
10
  export type CompilationOptions = VideoAssetOptions & {
10
11
  preview?: boolean;
12
+ audioMixEdit?: VideoMixEdit | undefined;
11
13
  };
12
14
  export interface CompiledVideo {
13
15
  readonly path: string;
@@ -16,6 +18,7 @@ export interface CompiledVideo {
16
18
  readonly project: Project;
17
19
  readonly frameCount: number;
18
20
  readonly recipes: readonly VideoRecipeInspection[];
21
+ readonly audioMixEdit?: VideoMixEdit;
19
22
  forQuality(quality: RenderQuality, preview: boolean, signal?: AbortSignal): Promise<CompiledVideo>;
20
23
  /** Media identity recorded before probing, keyed by the bound source path. */
21
24
  sourceIdentity(path: string): string | undefined;
@@ -1,3 +1,4 @@
1
+ import { videoMixEditSchema } from './professional-mix.js';
1
2
  import { createHash } from 'node:crypto';
2
3
  import { dirname, resolve } from 'node:path';
3
4
  import { audioSourceDuration, videoSourceDuration, validateEmbeddedFont, validateSubtitleBurnIn, renderQualities, } from '@opencut/media';
@@ -35,6 +36,9 @@ export async function compileDefinition(path, value, options = {}, getBuild) {
35
36
  if (!renderQualities.includes(quality))
36
37
  throw new VideoDefinitionError('Choose fast, quality, or maximum render quality.');
37
38
  const definition = freeze(parseVideoDefinition(value));
39
+ const audioMixEdit = options.audioMixEdit === undefined
40
+ ? undefined
41
+ : freeze(videoMixEditSchema.parse(options.audioMixEdit));
38
42
  const recipeSteps = [];
39
43
  const { processing, probes = new Map() } = options;
40
44
  const authoredFiles = [
@@ -54,6 +58,7 @@ export async function compileDefinition(path, value, options = {}, getBuild) {
54
58
  const { project, assets, recipes, qualitySensitive } = await buildProject(path, definition, {
55
59
  ...options,
56
60
  quality,
61
+ audioMixEdit,
57
62
  probes,
58
63
  ...(getBuild && {
59
64
  processing: {
@@ -103,6 +108,7 @@ export async function compileDefinition(path, value, options = {}, getBuild) {
103
108
  path,
104
109
  ...(build && { build: freeze(build) }),
105
110
  project: freeze(project),
111
+ ...(audioMixEdit && { audioMixEdit }),
106
112
  frameCount: renderPlan.frameCount,
107
113
  recipes: freeze(recipes),
108
114
  async forQuality(next, preview, signal) {
@@ -120,6 +126,7 @@ export async function compileDefinition(path, value, options = {}, getBuild) {
120
126
  processing,
121
127
  probes,
122
128
  pinnedSources,
129
+ audioMixEdit,
123
130
  ...(recovery && { recovery }),
124
131
  }, getBuild);
125
132
  checkInputs(next);
@@ -137,8 +144,11 @@ export async function compileDefinition(path, value, options = {}, getBuild) {
137
144
  return compiled;
138
145
  }
139
146
  async function buildProject(path, definition, options) {
140
- const { signal, inputs } = options;
147
+ const { signal, inputs, audioMixEdit } = options;
141
148
  const { canvas, assets = {}, tracks, name = 'Untitled video', id = stableId('video', name), createdAt = epoch, updatedAt = createdAt, transitions, markers, } = definition;
149
+ const professionalMix = audioMixEdit
150
+ ? audioMixEdit.mix
151
+ : definition.professionalMix;
142
152
  const { frameRate: authoredRate, ...settings } = canvas;
143
153
  const frameRate = typeof authoredRate === 'number'
144
154
  ? { numerator: authoredRate, denominator: 1 }
@@ -151,6 +161,7 @@ async function buildProject(path, definition, options) {
151
161
  clips: [],
152
162
  transitions,
153
163
  markers,
164
+ ...(professionalMix && { professionalMix }),
154
165
  };
155
166
  const resolveFont = await loadFonts(path, definition.fonts, signal, inputs?.record, options.pinnedSources);
156
167
  const { subtitles } = definition;
@@ -173,8 +184,13 @@ async function buildProject(path, definition, options) {
173
184
  for (const [trackIndex, track] of tracks.entries()) {
174
185
  const { id, name, type, clips, ...properties } = track;
175
186
  const trackId = id ?? generatedTrackId(track, occurrences);
187
+ const roles = audioMixEdit?.roles;
188
+ const role = roles && Object.hasOwn(roles, trackId) ? roles[trackId] : undefined;
189
+ if (role && type !== 'audio' && type !== 'video')
190
+ throw new VideoDefinitionError(`Track '${trackId}' does not support audio routing.`);
176
191
  project.tracks.push({
177
192
  ...properties,
193
+ ...(role && { audioRole: role }),
178
194
  id: trackId,
179
195
  name: name ?? type,
180
196
  type: type === 'audio' ? 'audio' : 'video',
@@ -194,6 +210,9 @@ async function buildProject(path, definition, options) {
194
210
  project.clips.push(await compileClip(clip, frameRate, trackId, location, resolveFont, 'text' in clip || asset?.kind === 'image'));
195
211
  }
196
212
  }
213
+ for (const id of Object.keys(audioMixEdit?.roles ?? {}))
214
+ if (!project.tracks.some((track) => track.id === id))
215
+ throw new VideoDefinitionError(`Unknown audio track '${id}'.`);
197
216
  const clipAssets = new Set(project.clips.flatMap(({ assetId }) => (assetId ? [assetId] : [])));
198
217
  const compiled = await compileVideoAssets(dirname(path), assets, clipAssets, options);
199
218
  project.assets = [...compiled.assets.values()].map(({ asset }) => asset);