@morshoto/framekit 0.1.13 → 0.1.16
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-package/adapters/final-cut/typescript/src/background-materialization.js +28 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical.js +144 -35
- package/dist-package/adapters/final-cut/typescript/src/disposable-native.js +36 -7
- package/dist-package/adapters/final-cut/typescript/src/index.js +2 -0
- package/dist-package/adapters/final-cut/typescript/src/live.js +56 -1
- package/dist-package/adapters/final-cut/typescript/src/native.js +311 -20
- package/dist-package/adapters/final-cut/typescript/src/pasteboard-snapshot.js +312 -0
- package/dist-package/adapters/final-cut/typescript/src/publisher.js +68 -8
- package/dist-package/adapters/final-cut/typescript/src/sqlite-wal-observation.js +263 -0
- package/dist-package/adapters/final-cut/typescript/src/timeline-ir-fcpxml.js +75 -3
- package/dist-package/adapters/headless/typescript/src/ffmpeg-media-probe.js +62 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-renderer.js +443 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-verifier.js +181 -0
- package/dist-package/adapters/headless/typescript/src/index.js +3 -0
- package/dist-package/apps/mcp-server/src/headless-projects.js +139 -0
- package/dist-package/apps/mcp-server/src/headless-sessions.js +3 -0
- package/dist-package/apps/mcp-server/src/main.js +22 -1
- package/dist-package/apps/mcp-server/src/materialization-jobs.js +233 -4
- package/dist-package/apps/mcp-server/src/readback-policy.js +26 -0
- package/dist-package/apps/mcp-server/src/routing.js +134 -5
- package/dist-package/apps/mcp-server/src/server.js +214 -31
- package/dist-package/packages/runtime/src/application/local-media.js +157 -0
- package/dist-package/packages/runtime/src/application/project-store.js +234 -0
- package/dist-package/packages/runtime/src/application/project-transactions.js +227 -0
- package/dist-package/packages/runtime/src/index.js +6 -0
- package/dist-package/packages/runtime/src/render/render-and-verify.js +126 -0
- package/dist-package/packages/runtime/src/render/render-contract.js +143 -0
- package/dist-package/packages/runtime/src/timeline/editing-session.js +277 -9
- package/dist-package/packages/runtime/src/timeline/fast-observation.js +141 -0
- package/package.json +2 -1
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile as readFileCallback, stat as statCallback } from "node:fs";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { normalizeFastTimelineObservation, } from "../../../../packages/runtime/src/index.js";
|
|
5
|
+
import { FinalCutSqliteInspectionProvider, } from "./sqlite-inspection.js";
|
|
6
|
+
const readFile = promisify(readFileCallback);
|
|
7
|
+
const stat = promisify(statCallback);
|
|
8
|
+
export const FINAL_CUT_SQLITE_WAL_BACKEND = "final-cut-sqlite-wal-read-only";
|
|
9
|
+
export const FINAL_CUT_SQLITE_WAL_SCHEMA_VERSION = 1;
|
|
10
|
+
/** Read-only DB/WAL/SHM observation. This provider never opens a writable SQLite handle. */
|
|
11
|
+
export class FinalCutSqliteWalObservationProvider {
|
|
12
|
+
inspectionProvider;
|
|
13
|
+
readFile;
|
|
14
|
+
statFile;
|
|
15
|
+
timestamp;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.inspectionProvider = options.inspectionProvider ?? new FinalCutSqliteInspectionProvider();
|
|
18
|
+
this.readFile = options.readFile ?? (async (path) => readFile(path));
|
|
19
|
+
this.statFile = options.statFile ?? (async (path) => {
|
|
20
|
+
const result = await stat(path);
|
|
21
|
+
return { size: result.size, mtimeMs: result.mtimeMs };
|
|
22
|
+
});
|
|
23
|
+
this.timestamp = options.timestamp ?? (() => new Date().toISOString());
|
|
24
|
+
}
|
|
25
|
+
async capture(request) {
|
|
26
|
+
try {
|
|
27
|
+
const target = parseTarget(request.target);
|
|
28
|
+
const provenance = parseProvenance(request.provenance, target);
|
|
29
|
+
const finalCutVersion = nonEmpty(request.finalCutVersion, "finalCutVersion");
|
|
30
|
+
const databasePath = nonEmpty(request.databasePath, "databasePath");
|
|
31
|
+
const inspection = await this.inspectionProvider.inspect(databasePath);
|
|
32
|
+
if (inspection.status !== "partial")
|
|
33
|
+
return inspectionFailure(inspection);
|
|
34
|
+
const storage = await Promise.all([
|
|
35
|
+
this.fingerprint(databasePath, true),
|
|
36
|
+
this.fingerprint(request.walPath ?? `${databasePath}-wal`, false),
|
|
37
|
+
this.fingerprint(request.shmPath ?? `${databasePath}-shm`, false),
|
|
38
|
+
]);
|
|
39
|
+
const observation = {
|
|
40
|
+
schemaVersion: FINAL_CUT_SQLITE_WAL_SCHEMA_VERSION,
|
|
41
|
+
backend: FINAL_CUT_SQLITE_WAL_BACKEND,
|
|
42
|
+
canonical: false,
|
|
43
|
+
target,
|
|
44
|
+
provenance,
|
|
45
|
+
finalCutVersion,
|
|
46
|
+
database: inspection.observation,
|
|
47
|
+
storage: {
|
|
48
|
+
database: storage[0],
|
|
49
|
+
wal: storage[1],
|
|
50
|
+
shm: storage[2],
|
|
51
|
+
capturedAt: this.timestamp(),
|
|
52
|
+
freshness: "storage-observed",
|
|
53
|
+
},
|
|
54
|
+
coverage: {
|
|
55
|
+
storage: "observed",
|
|
56
|
+
structuralRows: "partial",
|
|
57
|
+
archivedPayloads: "opaque",
|
|
58
|
+
semanticOperation: "not-observable",
|
|
59
|
+
editorFreshness: "unknown",
|
|
60
|
+
canonicalTimeline: "unavailable",
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
status: "observed",
|
|
65
|
+
observation,
|
|
66
|
+
issues: [
|
|
67
|
+
"SQLite/WAL/SHM state proves storage observation only; it does not prove the latest in-memory Final Cut edit was flushed.",
|
|
68
|
+
"Undocumented archived payloads remain opaque and are not promoted to Timeline IR or canonicalDocument.read.",
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return { status: "unavailable", error: unavailable(error) };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async fingerprint(path, required) {
|
|
77
|
+
try {
|
|
78
|
+
const [bytes, metadata] = await Promise.all([this.readFile(path), this.statFile(path)]);
|
|
79
|
+
return {
|
|
80
|
+
path,
|
|
81
|
+
present: true,
|
|
82
|
+
bytes: metadata.size,
|
|
83
|
+
digest: createHash("sha256").update(bytes).digest("hex"),
|
|
84
|
+
modifiedAt: new Date(metadata.mtimeMs).toISOString(),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (!required && isMissingFile(error))
|
|
89
|
+
return { path, present: false };
|
|
90
|
+
throw new Error(`FINAL_CUT_SQLITE_STORAGE_UNAVAILABLE: ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function diffFinalCutSqliteWalObservations(previous, current) {
|
|
95
|
+
const reasons = [];
|
|
96
|
+
const targetMatches = sameTarget(previous.target, current.target)
|
|
97
|
+
&& sameTarget(previous.provenance.target, current.provenance.target);
|
|
98
|
+
if (!targetMatches)
|
|
99
|
+
reasons.push("target identity changed between SQLite observations");
|
|
100
|
+
const provenanceMatches = sameRevision(previous.provenance.framekitRevision, current.provenance.framekitRevision)
|
|
101
|
+
&& previous.provenance.artifactDigest === current.provenance.artifactDigest;
|
|
102
|
+
if (!provenanceMatches)
|
|
103
|
+
reasons.push("Framekit materialization provenance changed between SQLite observations");
|
|
104
|
+
if (previous.finalCutVersion !== current.finalCutVersion)
|
|
105
|
+
reasons.push("Final Cut version changed");
|
|
106
|
+
if (previous.database.schemaVersion !== current.database.schemaVersion)
|
|
107
|
+
reasons.push("SQLite schema version changed");
|
|
108
|
+
if (previous.database.sourcePath !== current.database.sourcePath)
|
|
109
|
+
reasons.push("SQLite source path changed");
|
|
110
|
+
const collections = diffRows(previous.database.collectionRows, current.database.collectionRows);
|
|
111
|
+
const metadata = diffRows(previous.database.metadataRows, current.database.metadataRows);
|
|
112
|
+
if (collections.added.length || collections.removed.length || collections.modified.length)
|
|
113
|
+
reasons.push("structural collection rows changed");
|
|
114
|
+
if (metadata.added.length || metadata.removed.length || metadata.modified.length)
|
|
115
|
+
reasons.push("metadata rows changed");
|
|
116
|
+
const storage = {
|
|
117
|
+
database: fingerprintChange(previous.storage.database, current.storage.database),
|
|
118
|
+
wal: optionalFingerprintChange(previous.storage.wal, current.storage.wal),
|
|
119
|
+
shm: optionalFingerprintChange(previous.storage.shm, current.storage.shm),
|
|
120
|
+
};
|
|
121
|
+
if (storage.database === "changed")
|
|
122
|
+
reasons.push("SQLite database bytes changed");
|
|
123
|
+
if (storage.wal === "changed")
|
|
124
|
+
reasons.push("SQLite WAL bytes changed");
|
|
125
|
+
if (storage.shm === "changed")
|
|
126
|
+
reasons.push("SQLite SHM bytes changed");
|
|
127
|
+
const changed = reasons.length > 0;
|
|
128
|
+
const ambiguous = !targetMatches || !provenanceMatches || previous.finalCutVersion !== current.finalCutVersion;
|
|
129
|
+
return {
|
|
130
|
+
schemaVersion: FINAL_CUT_SQLITE_WAL_SCHEMA_VERSION,
|
|
131
|
+
status: ambiguous ? "ambiguous" : changed ? "changed" : "unchanged",
|
|
132
|
+
canonical: false,
|
|
133
|
+
target: current.target,
|
|
134
|
+
from: { revision: previous.database.revision, storage: previous.storage },
|
|
135
|
+
to: { revision: current.database.revision, storage: current.storage },
|
|
136
|
+
collections,
|
|
137
|
+
metadata,
|
|
138
|
+
storage,
|
|
139
|
+
coverage: {
|
|
140
|
+
...current.coverage,
|
|
141
|
+
semanticOperation: ambiguous || changed ? "ambiguous" : "not-observable",
|
|
142
|
+
},
|
|
143
|
+
recommendation: changed || ambiguous ? "canonical-resync-required" : "no-change-observed",
|
|
144
|
+
reasons: reasons.length > 0 ? reasons : ["no SQLite/WAL/SHM change observed"],
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Convert SQLite/WAL evidence into the provider-neutral envelope without inventing Timeline IR. */
|
|
148
|
+
export function normalizeFinalCutSqliteWalObservation(observation) {
|
|
149
|
+
return normalizeFastTimelineObservation({
|
|
150
|
+
schemaVersion: 1,
|
|
151
|
+
provider: "final-cut",
|
|
152
|
+
sourceType: "sqlite-wal",
|
|
153
|
+
canonical: false,
|
|
154
|
+
target: structuredClone(observation.target),
|
|
155
|
+
provenance: structuredClone(observation.provenance),
|
|
156
|
+
observedAt: observation.storage.capturedAt,
|
|
157
|
+
trust: "structural",
|
|
158
|
+
freshness: "storage-observed",
|
|
159
|
+
revision: structuredClone(observation.database.revision),
|
|
160
|
+
observationDigest: observation.database.digest,
|
|
161
|
+
coverage: {
|
|
162
|
+
occurrences: "partial",
|
|
163
|
+
resources: "partial",
|
|
164
|
+
timing: "unknown",
|
|
165
|
+
roles: "unknown",
|
|
166
|
+
storylineRelationships: "unknown",
|
|
167
|
+
markersCaptions: "unknown",
|
|
168
|
+
},
|
|
169
|
+
unknowns: [
|
|
170
|
+
"timeline.semanticOperation",
|
|
171
|
+
"timeline.editorFreshness",
|
|
172
|
+
"timeline.canonicalTimeline",
|
|
173
|
+
"archivedPayloads",
|
|
174
|
+
],
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/** The initial safe matrix intentionally exposes no unproven semantic mappings. */
|
|
178
|
+
const FINAL_CUT_SQLITE_CONTROLLED_OPERATIONS = [
|
|
179
|
+
"trim-start", "trim-end", "move", "delete", "reorder", "add-existing-source",
|
|
180
|
+
"repeated-occurrence", "connected-clip", "marker", "project-rename",
|
|
181
|
+
];
|
|
182
|
+
export const FINAL_CUT_SQLITE_OPERATION_MATRIX = [
|
|
183
|
+
...FINAL_CUT_SQLITE_CONTROLLED_OPERATIONS,
|
|
184
|
+
].map((operation) => ({
|
|
185
|
+
operation,
|
|
186
|
+
coverage: "not-observable",
|
|
187
|
+
evidence: "fixture-matrix",
|
|
188
|
+
canonical: false,
|
|
189
|
+
reason: "No target-version repeated native before/after corpus has proven a semantic SQLite/WAL mapping",
|
|
190
|
+
}));
|
|
191
|
+
function diffRows(before, after) {
|
|
192
|
+
const beforeMap = new Map(before.map((row) => [row.primaryKey, row]));
|
|
193
|
+
const afterMap = new Map(after.map((row) => [row.primaryKey, row]));
|
|
194
|
+
const added = [];
|
|
195
|
+
const removed = [];
|
|
196
|
+
const modified = [];
|
|
197
|
+
for (const [key, row] of afterMap) {
|
|
198
|
+
const old = beforeMap.get(key);
|
|
199
|
+
if (!old)
|
|
200
|
+
added.push(row);
|
|
201
|
+
else if (JSON.stringify(old) !== JSON.stringify(row))
|
|
202
|
+
modified.push({ before: old, after: row });
|
|
203
|
+
}
|
|
204
|
+
for (const [key, row] of beforeMap)
|
|
205
|
+
if (!afterMap.has(key))
|
|
206
|
+
removed.push(row);
|
|
207
|
+
return { added, removed, modified };
|
|
208
|
+
}
|
|
209
|
+
function fingerprintChange(before, after) {
|
|
210
|
+
return before.present === after.present && before.digest === after.digest ? "unchanged" : "changed";
|
|
211
|
+
}
|
|
212
|
+
function optionalFingerprintChange(before, after) {
|
|
213
|
+
if (!before.present && !after.present)
|
|
214
|
+
return "absent";
|
|
215
|
+
return fingerprintChange(before, after);
|
|
216
|
+
}
|
|
217
|
+
function parseTarget(value) {
|
|
218
|
+
return {
|
|
219
|
+
projectId: nonEmpty(value?.projectId, "target.projectId"),
|
|
220
|
+
sequenceId: nonEmpty(value?.sequenceId, "target.sequenceId"),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function parseProvenance(value, target) {
|
|
224
|
+
const artifactDigest = nonEmpty(value?.artifactDigest, "provenance.artifactDigest");
|
|
225
|
+
if (!value?.framekitRevision || typeof value.framekitRevision.id !== "string"
|
|
226
|
+
|| !Number.isSafeInteger(value.framekitRevision.sequence) || typeof value.framekitRevision.timestamp !== "string") {
|
|
227
|
+
throw new Error("FINAL_CUT_SQLITE_PROVENANCE_INVALID: framekit revision is incomplete");
|
|
228
|
+
}
|
|
229
|
+
const provenanceTarget = parseTarget(value.target);
|
|
230
|
+
if (!sameTarget(target, provenanceTarget)) {
|
|
231
|
+
throw new Error("FINAL_CUT_SQLITE_TARGET_MISMATCH: capture target and provenance target differ");
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
framekitRevision: { ...value.framekitRevision },
|
|
235
|
+
artifactDigest,
|
|
236
|
+
target: provenanceTarget,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function inspectionFailure(inspection) {
|
|
240
|
+
return { status: inspection.status, error: inspection.error };
|
|
241
|
+
}
|
|
242
|
+
function unavailable(error) {
|
|
243
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
244
|
+
return {
|
|
245
|
+
code: "FINAL_CUT_SQLITE_WAL_UNAVAILABLE",
|
|
246
|
+
message,
|
|
247
|
+
retryable: /busy|locked|timed out|timeout|temporar|unavailable/i.test(message),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function isMissingFile(error) {
|
|
251
|
+
return Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
|
|
252
|
+
}
|
|
253
|
+
function nonEmpty(value, name) {
|
|
254
|
+
if (typeof value !== "string" || !value.trim())
|
|
255
|
+
throw new Error(`FINAL_CUT_SQLITE_INPUT_INVALID: ${name} is required`);
|
|
256
|
+
return value.trim();
|
|
257
|
+
}
|
|
258
|
+
function sameTarget(left, right) {
|
|
259
|
+
return left.projectId === right.projectId && left.sequenceId === right.sequenceId;
|
|
260
|
+
}
|
|
261
|
+
function sameRevision(left, right) {
|
|
262
|
+
return left.id === right.id && left.sequence === right.sequence && left.timestamp === right.timestamp;
|
|
263
|
+
}
|
|
@@ -15,6 +15,10 @@ export function compileTimelineIrToFcpxml(timeline, options) {
|
|
|
15
15
|
throw new Error(`FCPXML_VERSION_UNSUPPORTED: ${String(version)}`);
|
|
16
16
|
}
|
|
17
17
|
validateTarget(options.target);
|
|
18
|
+
const unsupported = unsupportedFeatures(timeline);
|
|
19
|
+
if (unsupported.length > 0) {
|
|
20
|
+
throw new Error(`FCPXML_UNSUPPORTED_TIMELINE_FEATURE: ${unsupported.join(", ")}`);
|
|
21
|
+
}
|
|
18
22
|
const destination = resolveDestination(timeline, options.target);
|
|
19
23
|
const resourceIds = createResourceIds(timeline);
|
|
20
24
|
const resourceNames = uniqueResourceNames(timeline);
|
|
@@ -62,6 +66,7 @@ export function compileTimelineIrToFcpxml(timeline, options) {
|
|
|
62
66
|
"",
|
|
63
67
|
];
|
|
64
68
|
const xml = lines.join("\n");
|
|
69
|
+
const timelineDigest = timelineIrDigest(timeline);
|
|
65
70
|
return {
|
|
66
71
|
format: "fcpxml",
|
|
67
72
|
version: FRAMEKIT_FCPXML_VERSION,
|
|
@@ -70,8 +75,74 @@ export function compileTimelineIrToFcpxml(timeline, options) {
|
|
|
70
75
|
target: structuredClone(options.target),
|
|
71
76
|
destination,
|
|
72
77
|
resourceIds: Object.fromEntries([...resourceIds.entries()].sort(([left], [right]) => left.localeCompare(right))),
|
|
78
|
+
coverage: materializationCoverage(timeline, destination.mode),
|
|
79
|
+
provenance: {
|
|
80
|
+
source: "framekit-timeline-ir",
|
|
81
|
+
schemaVersion: 1,
|
|
82
|
+
projectId: timeline.project.id,
|
|
83
|
+
sequenceId: timeline.sequence.id,
|
|
84
|
+
revision: structuredClone(timeline.revision),
|
|
85
|
+
timelineDigest,
|
|
86
|
+
target: {
|
|
87
|
+
libraryUid: options.target.libraryUid,
|
|
88
|
+
eventUid: options.target.eventUid,
|
|
89
|
+
projectUid: options.target.projectUid,
|
|
90
|
+
sequenceUid: options.target.sequenceUid,
|
|
91
|
+
},
|
|
92
|
+
destination: {
|
|
93
|
+
projectUid: destination.projectUid,
|
|
94
|
+
sequenceUid: destination.sequenceUid,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
73
97
|
};
|
|
74
98
|
}
|
|
99
|
+
function unsupportedFeatures(timeline) {
|
|
100
|
+
const unsupported = new Set();
|
|
101
|
+
if (timeline.sequence.titles?.length)
|
|
102
|
+
unsupported.add("titles");
|
|
103
|
+
if (timeline.sequence.transitions?.length)
|
|
104
|
+
unsupported.add("transitions");
|
|
105
|
+
for (const occurrence of timeline.sequence.occurrences) {
|
|
106
|
+
if (occurrence.transform !== undefined)
|
|
107
|
+
unsupported.add("transforms");
|
|
108
|
+
if (occurrence.fadeIn !== undefined || occurrence.fadeOut !== undefined)
|
|
109
|
+
unsupported.add("audio-fades");
|
|
110
|
+
if (occurrence.role === "title")
|
|
111
|
+
unsupported.add("title-occurrences");
|
|
112
|
+
}
|
|
113
|
+
for (const element of timeline.sequence.storyElements) {
|
|
114
|
+
if (element.kind !== "gap")
|
|
115
|
+
unsupported.add(`story-element:${element.kind}`);
|
|
116
|
+
}
|
|
117
|
+
return [...unsupported].sort((left, right) => left.localeCompare(right));
|
|
118
|
+
}
|
|
119
|
+
function materializationCoverage(timeline, destinationMode) {
|
|
120
|
+
const exact = new Set([
|
|
121
|
+
"artifact",
|
|
122
|
+
"project",
|
|
123
|
+
"sequence",
|
|
124
|
+
"resources",
|
|
125
|
+
"source-ranges",
|
|
126
|
+
"primary-storyline-order",
|
|
127
|
+
"provenance",
|
|
128
|
+
]);
|
|
129
|
+
if (timeline.sequence.occurrences.some(({ attachedTo }) => attachedTo !== undefined)
|
|
130
|
+
|| timeline.sequence.storyElements.some(({ attachedTo }) => attachedTo !== undefined))
|
|
131
|
+
exact.add("connected-elements");
|
|
132
|
+
if (timeline.sequence.occurrences.some(({ role }) => role !== undefined))
|
|
133
|
+
exact.add("roles");
|
|
134
|
+
if (timeline.sequence.occurrences.some(({ gainDb }) => gainDb !== undefined))
|
|
135
|
+
exact.add("gain");
|
|
136
|
+
if (timeline.sequence.occurrences.some(({ enabled }) => enabled !== undefined))
|
|
137
|
+
exact.add("enabled");
|
|
138
|
+
if (destinationMode === "versioned")
|
|
139
|
+
exact.add("versioned-destination");
|
|
140
|
+
if (timeline.sequence.markers.length > 0)
|
|
141
|
+
exact.add("markers");
|
|
142
|
+
if (timeline.sequence.captions.length > 0)
|
|
143
|
+
exact.add("captions");
|
|
144
|
+
return { exact: [...exact].sort(), degraded: [], unsupported: [] };
|
|
145
|
+
}
|
|
75
146
|
function validateTarget(target) {
|
|
76
147
|
if (!target || target.provider !== "final-cut")
|
|
77
148
|
throw new Error("FCPXML_TARGET_BINDING_INVALID: provider must be final-cut");
|
|
@@ -95,13 +166,14 @@ function resolveDestination(timeline, target) {
|
|
|
95
166
|
sequenceName: timeline.sequence.name,
|
|
96
167
|
};
|
|
97
168
|
}
|
|
98
|
-
const revisionKey = shortHash(`${timeline.project.id}:${timeline.sequence.id}:${timelineIrDigest(timeline)}`);
|
|
169
|
+
const revisionKey = shortHash(`${timeline.project.id}:${timeline.sequence.id}:${timeline.revision.id}:${timeline.revision.sequence}:${timeline.revision.timestamp}:${timelineIrDigest(timeline)}`);
|
|
170
|
+
const revisionName = `${safeId(timeline.revision.id)}-${timeline.revision.sequence}`;
|
|
99
171
|
return {
|
|
100
172
|
mode: "versioned",
|
|
101
173
|
projectUid: `${safeId(target.projectUid)}-framekit-${revisionKey}`,
|
|
102
174
|
sequenceUid: `${safeId(target.sequenceUid)}-framekit-${revisionKey}`,
|
|
103
|
-
projectName: `${timeline.project.name} (Framekit ${revisionKey})`,
|
|
104
|
-
sequenceName: `${timeline.sequence.name} (Framekit ${revisionKey})`,
|
|
175
|
+
projectName: `${timeline.project.name} (Framekit ${revisionName}-${revisionKey})`,
|
|
176
|
+
sequenceName: `${timeline.sequence.name} (Framekit ${revisionName}-${revisionKey})`,
|
|
105
177
|
};
|
|
106
178
|
}
|
|
107
179
|
function createResourceIds(timeline) {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { lstat } from "node:fs/promises";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
const execFileAsync = promisify(execFile);
|
|
5
|
+
export class FfmpegMediaMetadataProbe {
|
|
6
|
+
ffprobePath;
|
|
7
|
+
environment;
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.ffprobePath = options.ffprobePath ?? process.env.FFPROBE_BIN ?? "ffprobe";
|
|
10
|
+
this.environment = { ...process.env, ...options.env };
|
|
11
|
+
}
|
|
12
|
+
async probe(sourcePath) {
|
|
13
|
+
const details = await lstat(sourcePath);
|
|
14
|
+
if (!details.isFile() || details.isSymbolicLink())
|
|
15
|
+
throw new Error(`HEADLESS_MEDIA_INVALID: source is not a regular file: ${sourcePath}`);
|
|
16
|
+
const result = await execFileAsync(this.ffprobePath, [
|
|
17
|
+
"-v", "error",
|
|
18
|
+
"-show_entries", "stream=codec_type,codec_name,width,height,r_frame_rate,sample_rate,channels",
|
|
19
|
+
"-show_entries", "format=duration",
|
|
20
|
+
"-of", "json",
|
|
21
|
+
sourcePath,
|
|
22
|
+
], { env: this.environment, maxBuffer: 2 * 1024 * 1024 });
|
|
23
|
+
const parsed = JSON.parse(result.stdout);
|
|
24
|
+
const duration = decimalToRational(Number(parsed.format?.duration));
|
|
25
|
+
if (!parsed.streams || !duration)
|
|
26
|
+
throw new Error("HEADLESS_MEDIA_INVALID: ffprobe returned incomplete metadata");
|
|
27
|
+
const streams = parsed.streams.flatMap((stream) => {
|
|
28
|
+
if (stream.codec_type !== "video" && stream.codec_type !== "audio")
|
|
29
|
+
return [];
|
|
30
|
+
return [{
|
|
31
|
+
kind: stream.codec_type,
|
|
32
|
+
...(stream.codec_name ? { codec: stream.codec_name } : {}),
|
|
33
|
+
...(stream.width !== undefined ? { width: stream.width } : {}),
|
|
34
|
+
...(stream.height !== undefined ? { height: stream.height } : {}),
|
|
35
|
+
...(stream.r_frame_rate ? { frameRate: parseRate(stream.r_frame_rate) } : {}),
|
|
36
|
+
...(stream.sample_rate ? { sampleRate: Number(stream.sample_rate) } : {}),
|
|
37
|
+
...(stream.channels !== undefined ? { channels: stream.channels } : {}),
|
|
38
|
+
}];
|
|
39
|
+
});
|
|
40
|
+
return { durationTime: duration, streams };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function parseRate(value) {
|
|
44
|
+
const [numerator, denominator] = value.split("/").map(BigInt);
|
|
45
|
+
const divisor = gcd(numerator, denominator);
|
|
46
|
+
return { value: String(numerator / divisor), timescale: String(denominator / divisor) };
|
|
47
|
+
}
|
|
48
|
+
function decimalToRational(value) {
|
|
49
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
50
|
+
return undefined;
|
|
51
|
+
const scaled = Math.round(value * 1_000_000);
|
|
52
|
+
const divisor = gcd(BigInt(scaled), 1000000n);
|
|
53
|
+
return { value: String(BigInt(scaled) / divisor), timescale: String(1000000n / divisor) };
|
|
54
|
+
}
|
|
55
|
+
function gcd(left, right) {
|
|
56
|
+
while (right !== 0n) {
|
|
57
|
+
const remainder = left % right;
|
|
58
|
+
left = right;
|
|
59
|
+
right = remainder;
|
|
60
|
+
}
|
|
61
|
+
return left || 1n;
|
|
62
|
+
}
|