@morshoto/framekit 0.1.4 → 0.1.6
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/README.md +2 -2
- package/dist-package/adapters/final-cut/typescript/src/analyzers.js +29 -2
- package/dist-package/adapters/final-cut/typescript/src/assets.js +89 -3
- package/dist-package/adapters/final-cut/typescript/src/canonical.js +431 -0
- package/dist-package/adapters/final-cut/typescript/src/connection.js +19 -4
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +212 -13
- package/dist-package/adapters/final-cut/typescript/src/index.js +1 -0
- package/dist-package/adapters/final-cut/typescript/src/native.js +1026 -7
- package/dist-package/adapters/final-cut/typescript/src/publisher.js +207 -30
- package/dist-package/adapters/final-cut/typescript/src/session.js +69 -8
- package/dist-package/apps/mcp-server/src/main.js +49 -11
- package/dist-package/apps/mcp-server/src/routing.js +15 -0
- package/dist-package/apps/mcp-server/src/server.js +289 -68
- package/dist-package/apps/mcp-server/src/version.js +34 -0
- package/dist-package/packages/runtime/src/application/media-analysis-service.js +119 -15
- package/dist-package/packages/runtime/src/application/project-service.js +21 -2
- package/dist-package/packages/runtime/src/audio/dialogue-normalization.js +9 -0
- package/dist-package/packages/runtime/src/capabilities.js +90 -10
- package/dist-package/packages/runtime/src/context/context-engine.js +10 -1
- package/dist-package/packages/runtime/src/domain/editing.js +27 -1
- package/dist-package/packages/runtime/src/domain/media.js +1 -0
- package/dist-package/packages/runtime/src/domain/skills.js +2 -0
- package/dist-package/packages/runtime/src/editing/edit-service.js +82 -4
- package/dist-package/packages/runtime/src/editing/filler-removal-service.js +31 -7
- package/dist-package/packages/runtime/src/index.js +2 -0
- package/dist-package/packages/runtime/src/planning/rough-cut.js +9 -3
- package/dist-package/packages/runtime/src/runtime.js +2 -2
- package/dist-package/packages/runtime/src/skills/builtin.js +314 -39
- package/dist-package/packages/runtime/src/skills/requirements.js +1 -0
- package/dist-package/packages/runtime/src/skills/runtime.js +33 -8
- package/dist-package/packages/runtime/src/speech/analysis.js +301 -0
- package/dist-package/packages/runtime/src/speech/mapping.js +227 -0
- package/dist-package/packages/runtime/src/timeline/rational-time.js +5 -0
- package/dist-package/packages/runtime/src/verification/verification.js +81 -4
- package/dist-package/packages/testkit/src/fixture-analyzers.js +1 -0
- package/dist-package/packages/testkit/src/in-memory-editor.js +126 -0
- package/package.json +8 -2
|
@@ -7,6 +7,11 @@ import { dirname, join, resolve } from "node:path";
|
|
|
7
7
|
import { withCapabilityFamilies } from "../../../../packages/runtime/src/index.js";
|
|
8
8
|
import { createFinalCutLiveAdapter, DEFAULT_FINAL_CUT_LIVE_SOCKET } from "./live.js";
|
|
9
9
|
const execFile = promisify(execFileCallback);
|
|
10
|
+
export function assertCanonicalProviderConfiguration(options) {
|
|
11
|
+
if (options.required && options.fcpxmlPath?.trim()) {
|
|
12
|
+
throw new Error("FINAL_CUT_CANONICAL_FALLBACK_CONFLICT: canonical provider mode cannot use FRAMEKIT_FCPXML_PATH");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
10
15
|
const DEFAULT_EXTENSION_NAME = "FramekitFinalCutWorkflow.app";
|
|
11
16
|
/**
|
|
12
17
|
* Owns the user-facing lifecycle around the native Workflow Extension.
|
|
@@ -16,6 +21,7 @@ const DEFAULT_EXTENSION_NAME = "FramekitFinalCutWorkflow.app";
|
|
|
16
21
|
export class FinalCutConnectionManager {
|
|
17
22
|
socketPath;
|
|
18
23
|
headless;
|
|
24
|
+
canonicalProviderRequired;
|
|
19
25
|
extensionSourcePath;
|
|
20
26
|
extensionInstallPath;
|
|
21
27
|
finalCutApp;
|
|
@@ -38,6 +44,8 @@ export class FinalCutConnectionManager {
|
|
|
38
44
|
constructor(options = {}) {
|
|
39
45
|
this.socketPath = options.socketPath ?? process.env.FRAMEKIT_FINAL_CUT_SOCKET ?? DEFAULT_FINAL_CUT_LIVE_SOCKET;
|
|
40
46
|
this.headless = options.headless ?? process.env.FRAMEKIT_FINAL_CUT_HEADLESS === "1";
|
|
47
|
+
this.canonicalProviderRequired = options.canonicalProviderRequired
|
|
48
|
+
?? process.env.FRAMEKIT_FINAL_CUT_CANONICAL_REQUIRED === "1";
|
|
41
49
|
this.extensionInstallPath = options.extensionInstallPath
|
|
42
50
|
?? process.env.FRAMEKIT_EXTENSION_INSTALL_PATH
|
|
43
51
|
?? join(homedir(), "Applications", DEFAULT_EXTENSION_NAME);
|
|
@@ -98,6 +106,9 @@ export class FinalCutConnectionManager {
|
|
|
98
106
|
const existing = await this.tryProbe();
|
|
99
107
|
if (existing)
|
|
100
108
|
return this.ready(existing);
|
|
109
|
+
if (this.canonicalProviderRequired) {
|
|
110
|
+
return this.fail("FINAL_CUT_CANONICAL_PROVIDER_UNAVAILABLE", `Canonical live provider is unavailable at ${this.socketPath}; metadata-only fallback is disabled`, "needs-user-action");
|
|
111
|
+
}
|
|
101
112
|
if (this.headless) {
|
|
102
113
|
return this.fail("FINAL_CUT_HEADLESS_SOCKET_UNAVAILABLE", `Headless mode only probes the existing Workflow Extension socket at ${this.socketPath}; it does not launch or activate Final Cut Pro`, "unavailable");
|
|
103
114
|
}
|
|
@@ -182,15 +193,19 @@ export class FinalCutConnectionManager {
|
|
|
182
193
|
}
|
|
183
194
|
}
|
|
184
195
|
ready(result) {
|
|
196
|
+
const capabilities = withCapabilityFamilies(result.capabilities, {
|
|
197
|
+
backend: result.identity.backend,
|
|
198
|
+
connectionBackend: result.identity.backend,
|
|
199
|
+
});
|
|
200
|
+
if (this.canonicalProviderRequired && capabilities.editor.canonicalTimelineMode !== "canonical-write") {
|
|
201
|
+
return this.fail("FINAL_CUT_CANONICAL_PROVIDER_REQUIRED", `Canonical live provider at ${this.socketPath} reports ${capabilities.editor.canonicalTimelineMode}; canonical-write is required`, "needs-user-action");
|
|
202
|
+
}
|
|
185
203
|
this.update({
|
|
186
204
|
state: "ready",
|
|
187
205
|
editorDetected: true,
|
|
188
206
|
extensionInstalled: true,
|
|
189
207
|
identity: result.identity,
|
|
190
|
-
capabilities
|
|
191
|
-
backend: result.identity.backend,
|
|
192
|
-
connectionBackend: result.identity.backend,
|
|
193
|
-
}),
|
|
208
|
+
capabilities,
|
|
194
209
|
lastError: undefined,
|
|
195
210
|
});
|
|
196
211
|
return this.getStatus();
|
|
@@ -66,7 +66,8 @@ export class FcpxmlDocumentAdapter {
|
|
|
66
66
|
projectCatalogRead: true,
|
|
67
67
|
projectSelection: true,
|
|
68
68
|
compositeTransactions: true,
|
|
69
|
-
|
|
69
|
+
pictureInPicture: true,
|
|
70
|
+
semanticOperations: { "add-marker": true, "set-gain": true, "timeline.picture-in-picture.add": true },
|
|
70
71
|
},
|
|
71
72
|
analyzers: emptyAnalyzerCapabilities(),
|
|
72
73
|
}, { backend: "fcpxml-document" });
|
|
@@ -95,6 +96,7 @@ export class FcpxmlDocumentAdapter {
|
|
|
95
96
|
const clips = elements
|
|
96
97
|
.filter(({ kind }) => CLIP_KINDS.has(kind))
|
|
97
98
|
.map((entry) => this.clipFromXml(entry, timelineId));
|
|
99
|
+
const frameDuration = sequenceFrameDuration(sequence, this.xml ?? []);
|
|
98
100
|
const durationValue = attribute(sequence, "duration")
|
|
99
101
|
?? formatSeconds(Math.max(0, ...storyElements.map((element) => element.start + element.duration)));
|
|
100
102
|
return {
|
|
@@ -105,6 +107,7 @@ export class FcpxmlDocumentAdapter {
|
|
|
105
107
|
name: sequenceName,
|
|
106
108
|
duration: parseSeconds(durationValue),
|
|
107
109
|
durationTime: parseRational(durationValue),
|
|
110
|
+
...(frameDuration ? { frameDuration } : {}),
|
|
108
111
|
clips,
|
|
109
112
|
storyElements,
|
|
110
113
|
markers: this.markersFromXml(elements),
|
|
@@ -166,12 +169,14 @@ export class FcpxmlDocumentAdapter {
|
|
|
166
169
|
const originalSignature = this.fileSignature;
|
|
167
170
|
try {
|
|
168
171
|
for (const operation of operations) {
|
|
169
|
-
if (operation.type === "media.import"
|
|
172
|
+
if (operation.type === "media.import"
|
|
173
|
+
|| operation.type.startsWith("timeline.") && operation.type !== "timeline.picture-in-picture.add") {
|
|
170
174
|
throw new Error(`CAPABILITY_UNAVAILABLE: FCPXML preview does not support ${operation.type}`);
|
|
171
175
|
}
|
|
172
176
|
this.applyOperation(operation);
|
|
173
177
|
}
|
|
174
|
-
|
|
178
|
+
const preview = await this.readProject();
|
|
179
|
+
return preview;
|
|
175
180
|
}
|
|
176
181
|
finally {
|
|
177
182
|
this.xml = originalXml;
|
|
@@ -184,15 +189,27 @@ export class FcpxmlDocumentAdapter {
|
|
|
184
189
|
if (!sameRevision(expectedRevision, this.revision())) {
|
|
185
190
|
throw new Error("STALE_CONTEXT: FCPXML document changed before transaction");
|
|
186
191
|
}
|
|
192
|
+
const originalXml = structuredClone(this.xml);
|
|
193
|
+
const originalSequence = this.sequence;
|
|
194
|
+
const originalSignature = this.fileSignature;
|
|
187
195
|
this.history.set(expectedRevision.id, structuredClone(this.xml));
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
196
|
+
try {
|
|
197
|
+
for (const operation of operations) {
|
|
198
|
+
if (operation.type === "media.import"
|
|
199
|
+
|| operation.type.startsWith("timeline.") && operation.type !== "timeline.picture-in-picture.add") {
|
|
200
|
+
throw new Error(`CAPABILITY_UNAVAILABLE: FCPXML transaction does not support ${operation.type}`);
|
|
201
|
+
}
|
|
202
|
+
this.applyOperation(operation);
|
|
191
203
|
}
|
|
192
|
-
this.
|
|
204
|
+
this.sequence += 1;
|
|
205
|
+
await this.persist();
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
this.xml = originalXml;
|
|
209
|
+
this.sequence = originalSequence;
|
|
210
|
+
this.fileSignature = originalSignature;
|
|
211
|
+
throw error;
|
|
193
212
|
}
|
|
194
|
-
this.sequence += 1;
|
|
195
|
-
await this.persist();
|
|
196
213
|
}
|
|
197
214
|
applyOperation(operation) {
|
|
198
215
|
const project = this.projectNode();
|
|
@@ -200,6 +217,11 @@ export class FcpxmlDocumentAdapter {
|
|
|
200
217
|
const sequence = sequenceNode ?? {};
|
|
201
218
|
const spine = findElement(sequence, "spine") ?? {};
|
|
202
219
|
const timelineId = stableTimelineId(project, sequenceNode);
|
|
220
|
+
if (operation.type === "timeline.picture-in-picture.add") {
|
|
221
|
+
this.applyPictureInPicture(spine, timelineId, operation);
|
|
222
|
+
this.updateSequenceDuration(sequence, spine);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
203
225
|
switch (operation.type) {
|
|
204
226
|
case "rename-clip": {
|
|
205
227
|
const node = this.findClipNode(spine, operation.clipId, timelineId);
|
|
@@ -248,6 +270,69 @@ export class FcpxmlDocumentAdapter {
|
|
|
248
270
|
}
|
|
249
271
|
this.updateSequenceDuration(sequence, spine);
|
|
250
272
|
}
|
|
273
|
+
applyPictureInPicture(spine, timelineId, operation) {
|
|
274
|
+
const media = this.mediaFromResources().find((candidate) => candidate.mediaId === operation.mediaId);
|
|
275
|
+
if (!media)
|
|
276
|
+
throw new Error(`MEDIA_NOT_FOUND: ${operation.mediaId}`);
|
|
277
|
+
if (media.mediaKind !== undefined && media.mediaKind !== "video") {
|
|
278
|
+
throw new Error(`MEDIA_KIND_MISMATCH: ${operation.mediaId}`);
|
|
279
|
+
}
|
|
280
|
+
if (this.findClipNode(spine, operation.occurrenceId, timelineId)) {
|
|
281
|
+
throw new Error(`OCCURRENCE_ALREADY_EXISTS: ${operation.occurrenceId}`);
|
|
282
|
+
}
|
|
283
|
+
const anchorEntry = timelineEntries(spine)
|
|
284
|
+
.find(({ kind, node, path }) => CLIP_KINDS.has(kind)
|
|
285
|
+
&& this.instanceId(node, kind, path, timelineId) === operation.attachedTo);
|
|
286
|
+
if (!anchorEntry)
|
|
287
|
+
throw new Error(`CLIP_NOT_FOUND: ${operation.attachedTo}`);
|
|
288
|
+
if (anchorEntry.kind !== "asset-clip" && anchorEntry.kind !== "clip"
|
|
289
|
+
&& anchorEntry.kind !== "ref-clip" && anchorEntry.kind !== "sync-clip"
|
|
290
|
+
&& anchorEntry.kind !== "mc-clip") {
|
|
291
|
+
throw new Error("INVALID_OPERATION: PIP anchor must be a video occurrence");
|
|
292
|
+
}
|
|
293
|
+
if (operation.frame) {
|
|
294
|
+
throw new Error("CAPABILITY_UNAVAILABLE: FCPXML picture-in-picture frame requires the native Final Cut provider");
|
|
295
|
+
}
|
|
296
|
+
validatePictureInPictureOperation(operation, anchorEntry.startTime, anchorEntry.durationTime, media.duration);
|
|
297
|
+
const connected = {
|
|
298
|
+
"asset-clip": [],
|
|
299
|
+
":@": {
|
|
300
|
+
"@_id": operation.occurrenceId,
|
|
301
|
+
"@_name": media.source.split("/").pop() || operation.mediaId,
|
|
302
|
+
"@_ref": operation.mediaId,
|
|
303
|
+
"@_offset": formatSeconds(operation.start - rationalSeconds(anchorEntry.startTime)),
|
|
304
|
+
"@_start": "0s",
|
|
305
|
+
"@_duration": formatSeconds(operation.duration),
|
|
306
|
+
"@_lane": String(operation.targetLane),
|
|
307
|
+
"@_framekit-attached-to": operation.attachedTo,
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
appendChild(anchorEntry.node, "asset-clip", connected);
|
|
311
|
+
appendChild(connected, "adjust-transform", {
|
|
312
|
+
":@": {
|
|
313
|
+
"@_position": `${operation.position.x} ${operation.position.y}`,
|
|
314
|
+
"@_scale": `${operation.scale * 100} ${operation.scale * 100}`,
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
if (operation.crop) {
|
|
318
|
+
appendChild(connected, "adjust-crop", {
|
|
319
|
+
":@": {
|
|
320
|
+
"@_mode": "crop",
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
const crop = firstChild(connected, "adjust-crop");
|
|
324
|
+
if (!crop)
|
|
325
|
+
throw new Error("FCPXML_INVALID_PIP: crop adjustment could not be created");
|
|
326
|
+
appendChild(crop, "crop-rect", {
|
|
327
|
+
":@": {
|
|
328
|
+
"@_top": formatPictureInPicturePercentage(operation.crop.top),
|
|
329
|
+
"@_right": formatPictureInPicturePercentage(operation.crop.right),
|
|
330
|
+
"@_bottom": formatPictureInPicturePercentage(operation.crop.bottom),
|
|
331
|
+
"@_left": formatPictureInPicturePercentage(operation.crop.left),
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
251
336
|
async restore(snapshot, expectedRevision) {
|
|
252
337
|
await this.ensureLoaded();
|
|
253
338
|
if (!sameRevision(expectedRevision, this.revision())) {
|
|
@@ -280,6 +365,7 @@ export class FcpxmlDocumentAdapter {
|
|
|
280
365
|
}
|
|
281
366
|
storyElementFromXml(entry, timelineId) {
|
|
282
367
|
const { node, kind, path, startTime, durationTime } = entry;
|
|
368
|
+
const visual = pictureInPictureProperties(node);
|
|
283
369
|
return {
|
|
284
370
|
id: this.instanceId(node, kind, path, timelineId),
|
|
285
371
|
kind,
|
|
@@ -289,21 +375,32 @@ export class FcpxmlDocumentAdapter {
|
|
|
289
375
|
durationTime,
|
|
290
376
|
...(attribute(node, "lane") !== undefined ? { lane: Number(attribute(node, "lane")) } : {}),
|
|
291
377
|
...(attribute(node, "ref") !== undefined ? { mediaId: String(attribute(node, "ref")) } : {}),
|
|
378
|
+
...(attribute(node, "framekit-attached-to") !== undefined ? { attachedTo: String(attribute(node, "framekit-attached-to")) } : {}),
|
|
379
|
+
...visual,
|
|
292
380
|
};
|
|
293
381
|
}
|
|
294
382
|
clipFromXml(entry, timelineId) {
|
|
295
383
|
const { node, kind, path, startTime, durationTime } = entry;
|
|
296
384
|
const gain = firstChild(node, "adjust-volume");
|
|
385
|
+
const visual = pictureInPictureProperties(node);
|
|
386
|
+
const sourceStartValue = attribute(node, "start");
|
|
387
|
+
const sourceStartTime = sourceStartValue === undefined ? undefined : parseRational(sourceStartValue);
|
|
388
|
+
const sourceStart = sourceStartTime === undefined ? undefined : rationalSeconds(sourceStartTime);
|
|
389
|
+
if (sourceStart !== undefined && sourceStart < 0)
|
|
390
|
+
throw new Error("FCPXML_INVALID_TIME: source clip start cannot be negative");
|
|
297
391
|
return {
|
|
298
392
|
id: this.instanceId(node, kind, path, timelineId),
|
|
299
393
|
mediaId: attribute(node, "ref") === undefined ? undefined : String(attribute(node, "ref")),
|
|
300
394
|
name: String(attribute(node, "name") ?? attribute(node, "ref") ?? `Clip ${path.includes(".") ? path : path + 1}`),
|
|
301
395
|
start: rationalSeconds(startTime),
|
|
302
396
|
duration: rationalSeconds(durationTime),
|
|
397
|
+
...(sourceStart !== undefined ? { sourceStart, sourceStartTime } : {}),
|
|
303
398
|
track: Number(attribute(node, "lane") ?? 0),
|
|
399
|
+
...(attribute(node, "framekit-attached-to") !== undefined ? { attachedTo: String(attribute(node, "framekit-attached-to")) } : {}),
|
|
304
400
|
startTime,
|
|
305
401
|
durationTime,
|
|
306
402
|
...(gain ? { gainDb: parseDb(attribute(gain, "amount") ?? "0dB") } : {}),
|
|
403
|
+
...visual,
|
|
307
404
|
};
|
|
308
405
|
}
|
|
309
406
|
instanceId(node, kind, path, timelineId) {
|
|
@@ -362,10 +459,16 @@ export class FcpxmlDocumentAdapter {
|
|
|
362
459
|
const resources = findElement(this.xml ?? [], "resources");
|
|
363
460
|
return storyEntries(resources ?? {})
|
|
364
461
|
.filter(({ kind }) => kind === "asset" || kind === "media" || kind === "effect")
|
|
365
|
-
.map(({ node }) =>
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
462
|
+
.map(({ node }) => {
|
|
463
|
+
const durationValue = attribute(node, "duration");
|
|
464
|
+
const mediaKind = mediaKindFromResource(node);
|
|
465
|
+
return {
|
|
466
|
+
mediaId: String(attribute(node, "id") ?? ""),
|
|
467
|
+
source: resolveMediaSource(String(attribute(node, "src") ?? attribute(node, "name") ?? attribute(node, "id") ?? ""), this.filePath),
|
|
468
|
+
...(mediaKind ? { mediaKind } : {}),
|
|
469
|
+
...(durationValue !== undefined ? { duration: parseSeconds(durationValue) } : {}),
|
|
470
|
+
};
|
|
471
|
+
})
|
|
369
472
|
.filter((media) => media.mediaId.length > 0);
|
|
370
473
|
}
|
|
371
474
|
revision() {
|
|
@@ -446,6 +549,15 @@ function attributes(node) {
|
|
|
446
549
|
function attribute(node, name) {
|
|
447
550
|
return attributes(node)[`@_${name}`];
|
|
448
551
|
}
|
|
552
|
+
function sequenceFrameDuration(sequence, document) {
|
|
553
|
+
const formatId = attribute(sequence, "format");
|
|
554
|
+
if (formatId === undefined)
|
|
555
|
+
return undefined;
|
|
556
|
+
const resources = findElement(document, "resources");
|
|
557
|
+
const format = storyEntries(resources ?? {}).find((entry) => entry.kind === "format" && attribute(entry.node, "id") === String(formatId))?.node;
|
|
558
|
+
const value = attribute(format ?? {}, "frameDuration");
|
|
559
|
+
return value === undefined ? undefined : parseRational(value);
|
|
560
|
+
}
|
|
449
561
|
function setAttribute(node, name, value) {
|
|
450
562
|
node[":@"] = { ...attributes(node), [`@_${name}`]: value };
|
|
451
563
|
}
|
|
@@ -525,6 +637,93 @@ function decimalToRational(value) {
|
|
|
525
637
|
function formatDb(value) {
|
|
526
638
|
return `${value}dB`;
|
|
527
639
|
}
|
|
640
|
+
function mediaKindFromResource(node) {
|
|
641
|
+
const hasVideo = attribute(node, "hasVideo");
|
|
642
|
+
const hasAudio = attribute(node, "hasAudio");
|
|
643
|
+
if (hasVideo === "1" || hasVideo === "true")
|
|
644
|
+
return "video";
|
|
645
|
+
if ((hasVideo === "0" || hasVideo === "false") && (hasAudio === "1" || hasAudio === "true"))
|
|
646
|
+
return "audio";
|
|
647
|
+
return undefined;
|
|
648
|
+
}
|
|
649
|
+
function validatePictureInPictureOperation(operation, anchorStartTime, anchorDurationTime, mediaDuration) {
|
|
650
|
+
const anchorStart = rationalSeconds(anchorStartTime);
|
|
651
|
+
const anchorEnd = anchorStart + rationalSeconds(anchorDurationTime);
|
|
652
|
+
if (!Number.isFinite(operation.start) || !Number.isFinite(operation.duration)
|
|
653
|
+
|| operation.start < anchorStart
|
|
654
|
+
|| operation.duration <= 0
|
|
655
|
+
|| operation.start + operation.duration > anchorEnd
|
|
656
|
+
|| !Number.isInteger(operation.targetLane)
|
|
657
|
+
|| operation.targetLane === 0
|
|
658
|
+
|| !Number.isFinite(operation.position.x)
|
|
659
|
+
|| !Number.isFinite(operation.position.y)
|
|
660
|
+
|| !Number.isFinite(operation.scale)
|
|
661
|
+
|| operation.scale <= 0
|
|
662
|
+
|| mediaDuration !== undefined && operation.duration > mediaDuration) {
|
|
663
|
+
throw new Error("INVALID_OPERATION: PIP timing, connected lane, position, and scale are invalid");
|
|
664
|
+
}
|
|
665
|
+
if (operation.crop)
|
|
666
|
+
validatePictureInPictureCrop(operation.crop);
|
|
667
|
+
}
|
|
668
|
+
function validatePictureInPictureCrop(crop) {
|
|
669
|
+
const values = [crop.top, crop.right, crop.bottom, crop.left];
|
|
670
|
+
if (!values.every((value) => Number.isFinite(value) && value >= 0 && value < 1)
|
|
671
|
+
|| crop.left + crop.right >= 1
|
|
672
|
+
|| crop.top + crop.bottom >= 1) {
|
|
673
|
+
throw new Error("INVALID_OPERATION: PIP crop must leave a positive source rectangle");
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function pictureInPictureProperties(node) {
|
|
677
|
+
const transform = firstChild(node, "adjust-transform");
|
|
678
|
+
const crop = firstChild(node, "adjust-crop");
|
|
679
|
+
const positionValue = transform ? attribute(transform, "position") : undefined;
|
|
680
|
+
const scaleValue = transform ? attribute(transform, "scale") : undefined;
|
|
681
|
+
const position = positionValue === undefined ? undefined : parsePictureInPicturePosition(positionValue);
|
|
682
|
+
const scale = scaleValue === undefined ? undefined : parsePictureInPictureScale(scaleValue);
|
|
683
|
+
const cropRect = crop ? firstChild(crop, "crop-rect") : undefined;
|
|
684
|
+
const cropKeys = ["top", "right", "bottom", "left"];
|
|
685
|
+
const hasCrop = cropRect !== undefined && cropKeys.some((key) => attribute(cropRect, key) !== undefined);
|
|
686
|
+
const parsedCrop = hasCrop
|
|
687
|
+
? {
|
|
688
|
+
top: parsePictureInPictureNumber(cropRect && attribute(cropRect, "top"), "top crop"),
|
|
689
|
+
right: parsePictureInPictureNumber(cropRect && attribute(cropRect, "right"), "right crop"),
|
|
690
|
+
bottom: parsePictureInPictureNumber(cropRect && attribute(cropRect, "bottom"), "bottom crop"),
|
|
691
|
+
left: parsePictureInPictureNumber(cropRect && attribute(cropRect, "left"), "left crop"),
|
|
692
|
+
}
|
|
693
|
+
: undefined;
|
|
694
|
+
if (parsedCrop)
|
|
695
|
+
validatePictureInPictureCrop(parsedCrop);
|
|
696
|
+
return {
|
|
697
|
+
...(position ? { position } : {}),
|
|
698
|
+
...(scale !== undefined ? { scale } : {}),
|
|
699
|
+
...(parsedCrop ? { crop: parsedCrop } : {}),
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
function parsePictureInPicturePosition(value) {
|
|
703
|
+
const values = String(value).trim().split(/\s+/).map(Number);
|
|
704
|
+
if (values.length !== 2 || !values.every(Number.isFinite)) {
|
|
705
|
+
throw new Error(`FCPXML_INVALID_PIP: position ${String(value)} is not a finite pair`);
|
|
706
|
+
}
|
|
707
|
+
return { x: values[0], y: values[1] };
|
|
708
|
+
}
|
|
709
|
+
function parsePictureInPictureScale(value) {
|
|
710
|
+
const values = String(value).trim().split(/\s+/).map(Number);
|
|
711
|
+
if (values.length !== 2 || !values.every((candidate) => Number.isFinite(candidate) && candidate > 0)
|
|
712
|
+
|| values[0] !== values[1]) {
|
|
713
|
+
throw new Error(`FCPXML_INVALID_PIP: scale ${String(value)} is not a positive uniform pair`);
|
|
714
|
+
}
|
|
715
|
+
return values[0] / 100;
|
|
716
|
+
}
|
|
717
|
+
function parsePictureInPictureNumber(value, label) {
|
|
718
|
+
const text = String(value ?? "").trim();
|
|
719
|
+
const parsed = Number(text.replace(/%$/, ""));
|
|
720
|
+
if (!Number.isFinite(parsed))
|
|
721
|
+
throw new Error(`FCPXML_INVALID_PIP: ${label} is not finite`);
|
|
722
|
+
return text.endsWith("%") ? parsed / 100 : parsed;
|
|
723
|
+
}
|
|
724
|
+
function formatPictureInPicturePercentage(value) {
|
|
725
|
+
return `${value * 100}%`;
|
|
726
|
+
}
|
|
528
727
|
function emptyAnalyzerCapabilities() {
|
|
529
728
|
return { speechTranscribe: false, speechVad: false, audioLoudness: false, visualTrack: false };
|
|
530
729
|
}
|