@vivix-labs/media-tools 0.0.0-stage → 1.0.0-beta
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 +129 -2
- package/dist/Inter-LICENSE.txt +93 -0
- package/dist/UI-LICENSE.txt +21 -0
- package/dist/assets/35a50-G5EJUNOC.svg +6 -0
- package/dist/assets/369ca-BISNKZ3M.svg +6 -0
- package/dist/assets/441bc-BCMNQ72W.svg +6 -0
- package/dist/assets/483f0-T6ZAGTDG.svg +6 -0
- package/dist/assets/6911b-ESLYKSC6.svg +6 -0
- package/dist/assets/Inter-LICENSE.txt +93 -0
- package/dist/assets/UI-system-LICENSE.txt +21 -0
- package/dist/assets/add-JY533O73.svg +5 -0
- package/dist/assets/area-P2WOMBT5.svg +9 -0
- package/dist/assets/b70bb-BTTOKPOH.svg +6 -0
- package/dist/assets/b9919-3S3O6YOT.svg +6 -0
- package/dist/assets/calendar-JI6USFRJ.svg +1 -0
- package/dist/assets/check-JSRRIXN5.svg +5 -0
- package/dist/assets/check-on-content-FQUVG3IZ.svg +5 -0
- package/dist/assets/chevron-down-K7YKS2EY.svg +5 -0
- package/dist/assets/chevron-left-JQCLK2WZ.svg +3 -0
- package/dist/assets/chevron-right-TNE35DBJ.svg +3 -0
- package/dist/assets/chevron-up-VBHYAJVB.svg +5 -0
- package/dist/assets/clear-XNEZJKFC.svg +5 -0
- package/dist/assets/close-GO5F7YFS.svg +10 -0
- package/dist/assets/dccd4-CZJXWICW.svg +6 -0
- package/dist/assets/dd163-3S3O6YOT.svg +6 -0
- package/dist/assets/draw-FOFX5TOM.svg +6 -0
- package/dist/assets/e8aed-CZJXWICW.svg +6 -0
- package/dist/assets/ea990-CZJXWICW.svg +6 -0
- package/dist/assets/expand-IAV75AFA.svg +6 -0
- package/dist/assets/fullscreen-L2JCXIN2.svg +6 -0
- package/dist/assets/grid-TLG5JYWB.svg +8 -0
- package/dist/assets/import-AFBUV2VV.svg +4 -0
- package/dist/assets/inter-latin-400-normal-55WT6UWF.woff2 +0 -0
- package/dist/assets/inter-latin-500-normal-W62DVTXI.woff2 +0 -0
- package/dist/assets/inter-latin-600-normal-R6Y2SZCR.woff2 +0 -0
- package/dist/assets/list-5VUAOZUH.svg +9 -0
- package/dist/assets/magic-OMME7FOV.svg +9 -0
- package/dist/assets/more-AEJ5MHWV.svg +5 -0
- package/dist/assets/mute-SXOSCR2U.svg +6 -0
- package/dist/assets/pause-2E4UY4FW.svg +6 -0
- package/dist/assets/play-WIIT3XQK.svg +5 -0
- package/dist/assets/reset-JESMTEMV.svg +6 -0
- package/dist/assets/search-JUOSGQRM.svg +6 -0
- package/dist/assets/select-VU7WR7B4.svg +7 -0
- package/dist/assets/sound-file-YYY6VNYN.svg +3 -0
- package/dist/assets/volume-2TYGJL6F.svg +6 -0
- package/dist/client.bundle.js +1606 -0
- package/dist/client.css +2242 -0
- package/dist/client.d.ts +18 -0
- package/dist/client.js +3 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.js +1763 -0
- package/dist/shared.d.ts +664 -0
- package/dist/shared.js +217 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.js +189 -0
- package/package.json +42 -3
- package/skills/SKILL.md +49 -0
- package/skills/references/processing.md +32 -0
- package/studio-plugin.json +11 -0
package/dist/shared.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// packages/media-tools/src/shared.ts
|
|
2
|
+
import { z, PluginError } from "vivix-studio/sdk/shared";
|
|
3
|
+
var packageVersion = "0.1.22-ecommerce.20261110.1";
|
|
4
|
+
var Config = z.object({
|
|
5
|
+
dataInstance: z.string().min(1).default("user:data"),
|
|
6
|
+
studioInstance: z.string().min(1).default("studio"),
|
|
7
|
+
executionNamespace: z.string().regex(/^[a-zA-Z0-9_-]{1,64}$/).default("media"),
|
|
8
|
+
ffmpegPath: z.string().min(1).default("ffmpeg"),
|
|
9
|
+
ffprobePath: z.string().min(1).default("ffprobe")
|
|
10
|
+
}).strict();
|
|
11
|
+
var versionRef = z.object({ storeId: z.uuid(), objectId: z.uuid(), versionId: z.uuid() }).strict();
|
|
12
|
+
var videoFileRef = z.object({ source: versionRef, fileId: z.uuid() }).strict();
|
|
13
|
+
var sourceInput = z.object({ kind: z.literal("source"), file: videoFileRef }).strict();
|
|
14
|
+
var editInput = z.object({ kind: z.literal("edit"), editRef: versionRef }).strict();
|
|
15
|
+
var videoInput = z.discriminatedUnion("kind", [sourceInput, editInput]);
|
|
16
|
+
var sequenceVideoInput = z.discriminatedUnion("kind", [
|
|
17
|
+
sourceInput.extend({ trimEndMs: z.number().int().positive().optional() }),
|
|
18
|
+
editInput
|
|
19
|
+
]);
|
|
20
|
+
var recipe = z.object({
|
|
21
|
+
trim: z.object({ inMs: z.number().int().nonnegative(), outMs: z.number().int().positive() }).strict(),
|
|
22
|
+
crop: z.object({
|
|
23
|
+
x: z.number().finite().nonnegative(),
|
|
24
|
+
y: z.number().finite().nonnegative(),
|
|
25
|
+
width: z.number().finite().positive().max(1),
|
|
26
|
+
height: z.number().finite().positive().max(1)
|
|
27
|
+
}).strict()
|
|
28
|
+
}).strict().superRefine((v, c) => {
|
|
29
|
+
if (v.trim.inMs >= v.trim.outMs)
|
|
30
|
+
c.addIssue({ code: "custom", message: "The selected interval must have positive duration." });
|
|
31
|
+
if (v.crop.x + v.crop.width > 1 + 1e-9 || v.crop.y + v.crop.height > 1 + 1e-9)
|
|
32
|
+
c.addIssue({ code: "custom", message: "The crop must remain inside the source picture." });
|
|
33
|
+
});
|
|
34
|
+
var pixelRect = z.object({
|
|
35
|
+
x: z.number().int().nonnegative(),
|
|
36
|
+
y: z.number().int().nonnegative(),
|
|
37
|
+
width: z.number().int().positive(),
|
|
38
|
+
height: z.number().int().positive()
|
|
39
|
+
}).strict();
|
|
40
|
+
var geometry = z.object({
|
|
41
|
+
displayWidth: z.number().int().positive(),
|
|
42
|
+
displayHeight: z.number().int().positive(),
|
|
43
|
+
pixelRect
|
|
44
|
+
}).strict();
|
|
45
|
+
var metadata = z.object({
|
|
46
|
+
durationMs: z.number().int().positive(),
|
|
47
|
+
width: z.number().int().positive(),
|
|
48
|
+
height: z.number().int().positive(),
|
|
49
|
+
displayWidth: z.number().int().positive(),
|
|
50
|
+
displayHeight: z.number().int().positive(),
|
|
51
|
+
rotation: z.union([z.literal(0), z.literal(90), z.literal(180), z.literal(270)]),
|
|
52
|
+
frameRate: z.number().positive().max(60),
|
|
53
|
+
startTime: z.number().finite(),
|
|
54
|
+
hasAudio: z.boolean(),
|
|
55
|
+
audioSampleRate: z.number().int().nullable(),
|
|
56
|
+
audioChannels: z.number().int().nullable(),
|
|
57
|
+
audioStartTime: z.number().finite().nullable(),
|
|
58
|
+
sizeBytes: z.number().int().nonnegative(),
|
|
59
|
+
sha256: z.string().regex(/^[a-f0-9]{64}$/),
|
|
60
|
+
colorInterpretation: z.enum(["declared-bt709", "assumed-bt709"]).optional()
|
|
61
|
+
}).strict();
|
|
62
|
+
var editDescriptor = z.object({ format: z.literal(1), file: videoFileRef, recipe, geometry, metadata }).strict();
|
|
63
|
+
var saveEdit = z.object({
|
|
64
|
+
file: videoFileRef,
|
|
65
|
+
recipe,
|
|
66
|
+
editId: z.uuid().optional(),
|
|
67
|
+
expectedRevision: z.number().int().positive().optional()
|
|
68
|
+
}).strict().superRefine((v, c) => {
|
|
69
|
+
if (Boolean(v.editId) !== Boolean(v.expectedRevision))
|
|
70
|
+
c.addIssue({ code: "custom", message: "An edit update requires its revision." });
|
|
71
|
+
});
|
|
72
|
+
var outputName = z.string().trim().min(1).max(200);
|
|
73
|
+
var processVideo = z.object({ input: videoInput, outputName, retryOfJobId: z.uuid().optional() }).strict();
|
|
74
|
+
var canvas = z.object({ width: z.number().int().min(2).max(3840), height: z.number().int().min(2).max(3840) }).strict().refine(
|
|
75
|
+
(v) => v.width % 2 === 0 && v.height % 2 === 0 && Math.min(v.width, v.height) <= 2160,
|
|
76
|
+
"Canvas dimensions must be even and within 3840 by 2160."
|
|
77
|
+
);
|
|
78
|
+
var processSequence = z.object({
|
|
79
|
+
inputs: z.array(sequenceVideoInput).min(1).max(64),
|
|
80
|
+
outputName,
|
|
81
|
+
canvas,
|
|
82
|
+
retryOfJobId: z.uuid().optional()
|
|
83
|
+
}).strict();
|
|
84
|
+
var mediaRequest = z.discriminatedUnion("operation", [
|
|
85
|
+
z.object({ operation: z.literal("video.process"), input: processVideo }).strict(),
|
|
86
|
+
z.object({ operation: z.literal("sequence.process"), input: processSequence }).strict()
|
|
87
|
+
]);
|
|
88
|
+
var jobStates = [
|
|
89
|
+
"queued",
|
|
90
|
+
"running",
|
|
91
|
+
"saving",
|
|
92
|
+
"succeeded",
|
|
93
|
+
"failed",
|
|
94
|
+
"canceled",
|
|
95
|
+
"interrupted"
|
|
96
|
+
];
|
|
97
|
+
var jobsQuery = z.object({
|
|
98
|
+
limit: z.number().int().min(1).max(100).default(50),
|
|
99
|
+
offset: z.number().int().nonnegative().default(0),
|
|
100
|
+
request: z.object({
|
|
101
|
+
operation: z.enum(["video.process", "sequence.process"]),
|
|
102
|
+
requestKey: z.string().min(1).max(128),
|
|
103
|
+
intent: z.union([processVideo, processSequence])
|
|
104
|
+
}).strict().optional()
|
|
105
|
+
}).strict();
|
|
106
|
+
function mediaError(code, message) {
|
|
107
|
+
throw new PluginError(
|
|
108
|
+
code,
|
|
109
|
+
message,
|
|
110
|
+
"Review the fixed source, edit and current project, then retry explicitly."
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
function normalizeRecipe(raw, displayWidth, displayHeight, durationMs) {
|
|
114
|
+
const value = recipe.parse(raw);
|
|
115
|
+
if (![displayWidth, displayHeight, durationMs].every(Number.isSafeInteger) || displayWidth < 2 || displayHeight < 2 || durationMs < 1 || displayWidth % 2 !== 0 || displayHeight % 2 !== 0)
|
|
116
|
+
mediaError("UNSUPPORTED_GEOMETRY", "The source needs positive even display dimensions.");
|
|
117
|
+
if (value.trim.outMs > durationMs)
|
|
118
|
+
mediaError("INVALID_RECIPE", "The trim exceeds the fixed source duration.");
|
|
119
|
+
const edge = (fraction, size) => Math.round(fraction * size / 2) * 2;
|
|
120
|
+
const x = edge(value.crop.x, displayWidth);
|
|
121
|
+
const y = edge(value.crop.y, displayHeight);
|
|
122
|
+
const right = Math.min(displayWidth, edge(value.crop.x + value.crop.width, displayWidth));
|
|
123
|
+
const bottom = Math.min(displayHeight, edge(value.crop.y + value.crop.height, displayHeight));
|
|
124
|
+
if (right - x < 2 || bottom - y < 2)
|
|
125
|
+
mediaError("INVALID_RECIPE", "The crop must contain at least two pixels in each dimension.");
|
|
126
|
+
const pixelRect2 = { x, y, width: right - x, height: bottom - y };
|
|
127
|
+
return {
|
|
128
|
+
recipe: {
|
|
129
|
+
trim: { ...value.trim },
|
|
130
|
+
crop: {
|
|
131
|
+
x: x / displayWidth,
|
|
132
|
+
y: y / displayHeight,
|
|
133
|
+
width: pixelRect2.width / displayWidth,
|
|
134
|
+
height: pixelRect2.height / displayHeight
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
geometry: { displayWidth, displayHeight, pixelRect: pixelRect2 }
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function sameFile(a, b) {
|
|
141
|
+
return a.fileId === b.fileId && a.source.storeId === b.source.storeId && a.source.objectId === b.source.objectId && a.source.versionId === b.source.versionId;
|
|
142
|
+
}
|
|
143
|
+
function readSavedEdit(data, raw) {
|
|
144
|
+
const ref = versionRef.parse(raw);
|
|
145
|
+
if (data.scope.kind !== "project" || ref.storeId !== data.storeId)
|
|
146
|
+
mediaError("SCOPE_MISMATCH", "The edit is not in this project store.");
|
|
147
|
+
const object = data.get(ref.objectId, true);
|
|
148
|
+
if (object.typeId !== "media.edit" || object.schemaVersion !== 1 || object.scope.kind !== data.scope.kind || object.scope.id !== data.scope.id)
|
|
149
|
+
mediaError("EDIT_FORMAT_UNSUPPORTED", "A supported fixed media edit is required.");
|
|
150
|
+
const version = data.version(ref);
|
|
151
|
+
if (version.schemaVersion !== 1 || version.payload?.kind !== "media.edit")
|
|
152
|
+
mediaError("EDIT_FORMAT_UNSUPPORTED", "This edit descriptor format is unsupported.");
|
|
153
|
+
const parsed = editDescriptor.safeParse(version.payload.descriptor);
|
|
154
|
+
if (!parsed.success)
|
|
155
|
+
mediaError("EDIT_FORMAT_UNSUPPORTED", "The fixed edit descriptor is invalid.");
|
|
156
|
+
const value = parsed.data;
|
|
157
|
+
if (!sameFile(object.data.file, value.file))
|
|
158
|
+
mediaError("IMMUTABLE_FIELD", "The fixed edit version changed its original source.");
|
|
159
|
+
const canonical = normalizeRecipe(
|
|
160
|
+
value.recipe,
|
|
161
|
+
value.metadata.displayWidth,
|
|
162
|
+
value.metadata.displayHeight,
|
|
163
|
+
value.metadata.durationMs
|
|
164
|
+
);
|
|
165
|
+
if (JSON.stringify(canonical.recipe) !== JSON.stringify(value.recipe) || JSON.stringify(canonical.geometry) !== JSON.stringify(value.geometry))
|
|
166
|
+
mediaError("EDIT_FORMAT_UNSUPPORTED", "The stored edit geometry is not canonical.");
|
|
167
|
+
if (value.file.source.storeId !== data.storeId)
|
|
168
|
+
mediaError("SCOPE_MISMATCH", "The edit source belongs to another store.");
|
|
169
|
+
const original = data.get(value.file.source.objectId, true);
|
|
170
|
+
if (original.typeId !== "studio.asset" || original.data.kind !== "video")
|
|
171
|
+
mediaError("SOURCE_NOT_VIDEO", "The edit source is not a project video.");
|
|
172
|
+
const sourceVersion = data.version(value.file.source), files = data.files(value.file.source);
|
|
173
|
+
if (sourceVersion.payload.kind !== "video" || !files.some(
|
|
174
|
+
(f) => f.fileId === value.file.fileId && f.mimeType === "video/mp4" && f.sha256 === value.metadata.sha256
|
|
175
|
+
))
|
|
176
|
+
mediaError(
|
|
177
|
+
"INVALID_REFERENCE",
|
|
178
|
+
"The saved video file is not part of its fixed source version."
|
|
179
|
+
);
|
|
180
|
+
const ownFiles = data.files(ref);
|
|
181
|
+
if (!ownFiles.some(
|
|
182
|
+
(f) => f.fileId === version.payload.primaryFileId && f.role === "primary" && f.mimeType.startsWith("text/plain")
|
|
183
|
+
))
|
|
184
|
+
mediaError("EDIT_FORMAT_UNSUPPORTED", "The edit is missing its authored descriptor file.");
|
|
185
|
+
if (value.recipe.trim.outMs > value.metadata.durationMs)
|
|
186
|
+
mediaError("INVALID_RECIPE", "The saved trim exceeds the fixed source.");
|
|
187
|
+
return {
|
|
188
|
+
editRef: ref,
|
|
189
|
+
revision: object.revision,
|
|
190
|
+
file: value.file,
|
|
191
|
+
recipe: value.recipe,
|
|
192
|
+
geometry: value.geometry,
|
|
193
|
+
effectiveDurationMs: value.recipe.trim.outMs - value.recipe.trim.inMs
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export {
|
|
197
|
+
Config,
|
|
198
|
+
canvas,
|
|
199
|
+
editDescriptor,
|
|
200
|
+
geometry,
|
|
201
|
+
jobStates,
|
|
202
|
+
jobsQuery,
|
|
203
|
+
mediaError,
|
|
204
|
+
mediaRequest,
|
|
205
|
+
metadata,
|
|
206
|
+
normalizeRecipe,
|
|
207
|
+
packageVersion,
|
|
208
|
+
processSequence,
|
|
209
|
+
processVideo,
|
|
210
|
+
readSavedEdit,
|
|
211
|
+
recipe,
|
|
212
|
+
sameFile,
|
|
213
|
+
saveEdit,
|
|
214
|
+
versionRef,
|
|
215
|
+
videoFileRef,
|
|
216
|
+
videoInput
|
|
217
|
+
};
|
package/dist/worker.d.ts
ADDED
package/dist/worker.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// packages/media-tools/src/worker.ts
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import { mkdir, open, rename, stat } from "fs/promises";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
var child;
|
|
6
|
+
var disconnected = false;
|
|
7
|
+
var stopping = false;
|
|
8
|
+
var active;
|
|
9
|
+
var reason;
|
|
10
|
+
var term;
|
|
11
|
+
var deadline;
|
|
12
|
+
var send = (value) => {
|
|
13
|
+
if (process.connected) process.send?.(value);
|
|
14
|
+
};
|
|
15
|
+
async function record(name, value) {
|
|
16
|
+
if (!active) return;
|
|
17
|
+
const path = join(active.directory, name);
|
|
18
|
+
const temporary = path + ".tmp";
|
|
19
|
+
const file = await open(temporary, "w", 384);
|
|
20
|
+
try {
|
|
21
|
+
await file.writeFile(JSON.stringify(value));
|
|
22
|
+
await file.sync();
|
|
23
|
+
} finally {
|
|
24
|
+
await file.close();
|
|
25
|
+
}
|
|
26
|
+
await rename(temporary, path);
|
|
27
|
+
const directory = await open(active.directory, "r");
|
|
28
|
+
try {
|
|
29
|
+
await directory.sync();
|
|
30
|
+
} finally {
|
|
31
|
+
await directory.close();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function stop(code) {
|
|
35
|
+
reason ??= code;
|
|
36
|
+
if (stopping) return;
|
|
37
|
+
stopping = true;
|
|
38
|
+
if (!child) {
|
|
39
|
+
if (!active) process.exit(0);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
child.kill("SIGTERM");
|
|
43
|
+
term = setTimeout(() => {
|
|
44
|
+
if (child && child.exitCode === null && child.signalCode === null) child.kill("SIGKILL");
|
|
45
|
+
}, 2e3);
|
|
46
|
+
deadline = setTimeout(() => {
|
|
47
|
+
send({
|
|
48
|
+
type: "unconfirmed",
|
|
49
|
+
code: "PROCESS_STOP_UNCONFIRMED",
|
|
50
|
+
jobId: active?.jobId,
|
|
51
|
+
executionToken: active?.executionToken,
|
|
52
|
+
commandId: active?.id
|
|
53
|
+
});
|
|
54
|
+
}, 5e3);
|
|
55
|
+
}
|
|
56
|
+
process.on("disconnect", () => {
|
|
57
|
+
disconnected = true;
|
|
58
|
+
stop("PARENT_DISCONNECTED");
|
|
59
|
+
});
|
|
60
|
+
process.on("SIGTERM", () => stop("WORKER_STOPPED"));
|
|
61
|
+
process.on("SIGINT", () => stop("WORKER_STOPPED"));
|
|
62
|
+
process.on("message", async (message) => {
|
|
63
|
+
if (message?.type === "cancel") {
|
|
64
|
+
stop("PROCESS_CANCELED");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (message?.type !== "run" || active) return;
|
|
68
|
+
active = message.command;
|
|
69
|
+
const command = active;
|
|
70
|
+
let timeout, watcher;
|
|
71
|
+
let stdout = "", stderr = "", overflow = false;
|
|
72
|
+
try {
|
|
73
|
+
await mkdir(command.directory, { recursive: true });
|
|
74
|
+
await record("worker-start.json", {
|
|
75
|
+
jobId: command.jobId,
|
|
76
|
+
executionToken: command.executionToken,
|
|
77
|
+
commandId: command.id,
|
|
78
|
+
workerPid: process.pid
|
|
79
|
+
});
|
|
80
|
+
if (disconnected || !process.connected || stopping) {
|
|
81
|
+
const result = {
|
|
82
|
+
type: "result",
|
|
83
|
+
commandId: command.id,
|
|
84
|
+
jobId: command.jobId,
|
|
85
|
+
executionToken: command.executionToken,
|
|
86
|
+
closed: true,
|
|
87
|
+
exitCode: null,
|
|
88
|
+
signal: null,
|
|
89
|
+
code: reason || "PARENT_DISCONNECTED",
|
|
90
|
+
stdout: "",
|
|
91
|
+
stderr: ""
|
|
92
|
+
};
|
|
93
|
+
await record("worker-exit.json", result);
|
|
94
|
+
if (process.connected) process.send?.(result, () => process.exit(1));
|
|
95
|
+
else process.exit(1);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
child = spawn(command.command, command.args, {
|
|
99
|
+
shell: false,
|
|
100
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
101
|
+
windowsHide: true
|
|
102
|
+
});
|
|
103
|
+
child.once("spawn", () => {
|
|
104
|
+
void record("worker-start.json", {
|
|
105
|
+
jobId: command.jobId,
|
|
106
|
+
executionToken: command.executionToken,
|
|
107
|
+
commandId: command.id,
|
|
108
|
+
workerPid: process.pid,
|
|
109
|
+
mediaPid: child?.pid,
|
|
110
|
+
executable: command.command,
|
|
111
|
+
startedAt: Date.now()
|
|
112
|
+
}).catch(() => stop("PROCESS_RECORD_UNAVAILABLE"));
|
|
113
|
+
});
|
|
114
|
+
timeout = setTimeout(() => stop("PROCESS_TIMEOUT"), command.timeoutMs);
|
|
115
|
+
if (command.outputPath && command.maxOutputBytes)
|
|
116
|
+
watcher = setInterval(() => {
|
|
117
|
+
void stat(command.outputPath).then((s) => {
|
|
118
|
+
if (s.size > command.maxOutputBytes) stop("OUTPUT_TOO_LARGE");
|
|
119
|
+
}).catch((error) => {
|
|
120
|
+
if (error.code !== "ENOENT") stop("OUTPUT_UNREADABLE");
|
|
121
|
+
});
|
|
122
|
+
}, 250);
|
|
123
|
+
child.stdout.on("data", (chunk) => {
|
|
124
|
+
const text = chunk.toString();
|
|
125
|
+
if (Buffer.byteLength(stdout) + chunk.length > 1024 * 1024) {
|
|
126
|
+
overflow = true;
|
|
127
|
+
stop("PROCESS_OUTPUT_LIMIT");
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
stdout += text;
|
|
131
|
+
send({ type: "stdout", text });
|
|
132
|
+
});
|
|
133
|
+
child.stderr.on("data", (chunk) => {
|
|
134
|
+
stderr = (stderr + chunk.toString()).slice(-256 * 1024);
|
|
135
|
+
});
|
|
136
|
+
let spawnError;
|
|
137
|
+
child.on("error", (error) => {
|
|
138
|
+
spawnError = error.code === "ENOENT" ? "TOOL_UNAVAILABLE" : "PROCESS_START_FAILED";
|
|
139
|
+
});
|
|
140
|
+
child.on("close", async (code, signal) => {
|
|
141
|
+
clearTimeout(timeout);
|
|
142
|
+
clearTimeout(term);
|
|
143
|
+
clearTimeout(deadline);
|
|
144
|
+
clearInterval(watcher);
|
|
145
|
+
const result = {
|
|
146
|
+
type: "result",
|
|
147
|
+
workerPid: process.pid,
|
|
148
|
+
mediaPid: child?.pid,
|
|
149
|
+
executable: command.command,
|
|
150
|
+
commandId: command.id,
|
|
151
|
+
executionToken: command.executionToken,
|
|
152
|
+
jobId: command.jobId,
|
|
153
|
+
closed: true,
|
|
154
|
+
exitCode: code,
|
|
155
|
+
signal,
|
|
156
|
+
code: reason || spawnError || (overflow ? "PROCESS_OUTPUT_LIMIT" : code === 0 ? null : "MEDIA_PROCESS_FAILED"),
|
|
157
|
+
stdout,
|
|
158
|
+
stderr
|
|
159
|
+
};
|
|
160
|
+
try {
|
|
161
|
+
await record("worker-exit.json", result);
|
|
162
|
+
} catch {
|
|
163
|
+
send({ type: "record-error", code: "PROCESS_RECORD_UNAVAILABLE" });
|
|
164
|
+
}
|
|
165
|
+
if (process.connected)
|
|
166
|
+
process.send?.(result, () => process.exit(code === 0 && !reason ? 0 : 1));
|
|
167
|
+
else process.exit(code === 0 && !reason ? 0 : 1);
|
|
168
|
+
});
|
|
169
|
+
} catch {
|
|
170
|
+
const result = {
|
|
171
|
+
type: "result",
|
|
172
|
+
jobId: command.jobId,
|
|
173
|
+
executionToken: command.executionToken,
|
|
174
|
+
commandId: command.id,
|
|
175
|
+
closed: !child,
|
|
176
|
+
code: "PROCESS_START_FAILED",
|
|
177
|
+
stdout,
|
|
178
|
+
stderr
|
|
179
|
+
};
|
|
180
|
+
if (!child) {
|
|
181
|
+
try {
|
|
182
|
+
await record("worker-exit.json", result);
|
|
183
|
+
} catch {
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
send(result);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vivix-labs/media-tools",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0-beta",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org/",
|
|
8
|
+
"tag": "beta"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"studio-plugin.json",
|
|
14
|
+
"skills"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.12.0"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
"./studio-plugin.json": "./studio-plugin.json",
|
|
21
|
+
"./server": {
|
|
22
|
+
"types": "./dist/server.d.ts",
|
|
23
|
+
"import": "./dist/server.js"
|
|
24
|
+
},
|
|
25
|
+
"./shared": {
|
|
26
|
+
"types": "./dist/shared.d.ts",
|
|
27
|
+
"import": "./dist/shared.js"
|
|
28
|
+
},
|
|
29
|
+
"./client": {
|
|
30
|
+
"types": "./dist/client.d.ts",
|
|
31
|
+
"import": "./dist/client.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"vivix-studio": ">=2.1.0-0",
|
|
36
|
+
"react": "19.3.1",
|
|
37
|
+
"react-dom": "^19.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@vivix-labs/ui-system": "1.0.0-beta"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "node ../../scripts/build-product-packages.mjs media-tools"
|
|
44
|
+
}
|
|
6
45
|
}
|
package/skills/SKILL.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vivix-media-tools
|
|
3
|
+
description: Trim or crop fixed Studio video versions, compare candidates, and process or export video through the installed media-tools queue. Use for saved edit recipes, actual edited previews, sequence exports, and original-job recovery. Selection and storyboards remain with the calling project/workbench.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Edit, compare, and export Studio video
|
|
7
|
+
|
|
8
|
+
Discover the configured media instance through `plugin list` and `plugin describe`
|
|
9
|
+
for the actual project. Read the workspace Skill returned by `agent guide --json`
|
|
10
|
+
for page opening and chat presentation. Resolve exact saved source versions through
|
|
11
|
+
the calling project's operations. Instance IDs and candidate order are caller data.
|
|
12
|
+
|
|
13
|
+
## Save an edit and show its effect
|
|
14
|
+
|
|
15
|
+
Read the fixed source and any saved edit first. A Trim request changes the time
|
|
16
|
+
range and preserves an existing crop unless the user asks to change it. A Crop
|
|
17
|
+
request changes framing and preserves the existing time range. For "the first
|
|
18
|
+
8 seconds", use `[0,8000)` milliseconds when the source is long enough.
|
|
19
|
+
|
|
20
|
+
`edits.save` saves an immutable recipe; it does not encode a video or select a
|
|
21
|
+
candidate. Bind the returned edit through the caller's operation with its observed
|
|
22
|
+
revisions. A conflict retains the draft and saved edit. Reconcile the intended
|
|
23
|
+
source and current selection before another bind.
|
|
24
|
+
|
|
25
|
+
To deliver a playable edited result, use `video.process` or the caller's whole-film
|
|
26
|
+
export through `sequence.process`. Read the exact input/output schema. Save the
|
|
27
|
+
original intent and key, follow the accepted durable job, and present only its
|
|
28
|
+
actual succeeded result. Read [processing and recovery](references/processing.md)
|
|
29
|
+
for format, aspect, queue, cancellation, and uncertain-response details.
|
|
30
|
+
|
|
31
|
+
## Compare
|
|
32
|
+
|
|
33
|
+
Use two to four fixed candidate slots when the installed Compare component offers
|
|
34
|
+
that range. Preserve the caller's order, labels, and current choice. The workbench
|
|
35
|
+
may restrict slots to one clip. Compare itself does not generate, delete, or adopt
|
|
36
|
+
content. Adoption is a separate caller operation at the observed revision.
|
|
37
|
+
|
|
38
|
+
Open the actual Compare view for full interactions. Prefer real playable previews
|
|
39
|
+
in chat when supported; otherwise show ordered media and the workspace entry.
|
|
40
|
+
Close or replace players through the component's cleanup behavior. Details return
|
|
41
|
+
with the fixed slots paused; do not claim restoration of playback frames.
|
|
42
|
+
|
|
43
|
+
## Completion
|
|
44
|
+
|
|
45
|
+
A saved recipe, an accepted job, and a finished file are distinct states. Keep
|
|
46
|
+
original source bytes and earlier versions. Verify the actual saved selection/edit,
|
|
47
|
+
duration and geometry of the processed file when those are part of the request.
|
|
48
|
+
Use a returned fixed result reference to resolve/download it and display the real
|
|
49
|
+
media. Closing a page does not cancel a job.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Processing and original-job recovery
|
|
2
|
+
|
|
3
|
+
Use the actual installed operation schemas and capability errors. The current
|
|
4
|
+
media-tools queue accepts fixed `VideoInput` values, either a verified source file
|
|
5
|
+
reference or a saved edit reference. A sequence has an explicit ordered input list,
|
|
6
|
+
output name, and canvas. It does not add narration, music, captions, transitions,
|
|
7
|
+
or candidate selection.
|
|
8
|
+
|
|
9
|
+
The supported native path is MP4/H.264 8-bit SDR BT.709 with square pixels,
|
|
10
|
+
supported quarter-turn rotation, and no audio or supported mono/stereo AAC. Explicit
|
|
11
|
+
HDR or a different color declaration is refused. Missing/unknown declarations use
|
|
12
|
+
the existing recorded SDR BT.709 interpretation, which can affect apparent color.
|
|
13
|
+
Respect actual size, duration, queue, and disk-space refusals rather than converting
|
|
14
|
+
them into success. The output is re-encoded H.264/AAC, not lossless.
|
|
15
|
+
|
|
16
|
+
Each effective crop must exactly match the requested canvas aspect ratio. Preserve
|
|
17
|
+
framing unless the user requests or approves a crop change. An aspect mismatch is
|
|
18
|
+
a concrete refusal; do not silently stretch, pad, or crop to force an export.
|
|
19
|
+
Crop uses the canonical even-pixel rectangle returned by edits.save. Trim ranges
|
|
20
|
+
are `[inMs,outMs)` with source-frame boundary tolerance.
|
|
21
|
+
|
|
22
|
+
Keep original request input and key. `video.process` and `sequence.process` return
|
|
23
|
+
a durable job ID after acceptance. Poll `jobs.get` for that exact job. For a lost
|
|
24
|
+
response, query `jobs.list` with its request filter containing the original
|
|
25
|
+
operation, requestKey, and intent. A missing receipt does not establish rejection
|
|
26
|
+
and never triggers another submission. Changed input under the same key conflicts.
|
|
27
|
+
|
|
28
|
+
Cancel explicitly through `jobs.cancel` and inspect the actual result. A Host
|
|
29
|
+
restart marks unfinished work interrupted; an explicit retry uses a new key and
|
|
30
|
+
its saved immutable execution snapshot. Preserve failures and completed outputs.
|
|
31
|
+
The caller retains responsibility for binding edits and displaying the fixed
|
|
32
|
+
result in the correct project, version, and chat.
|