@sogni-ai/sogni-creative-agent-skill 3.12.0 β 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/SKILL.md +2 -2
- package/desktop-extension/README.md +21 -0
- package/desktop-extension/manifest.json +1 -1
- package/desktop-extension/server/import-media.mjs +113 -0
- package/desktop-extension/server/index.mjs +13 -0
- package/desktop-extension/server/tools.mjs +33 -5
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/references/video-editing.md +23 -0
- package/sogni-agent.mjs +565 -1
- package/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [3.14.0](https://github.com/Sogni-AI/sogni-creative-agent-skill/compare/v3.13.0...v3.14.0) (2026-07-05)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **desktop:** add import_media tool bridging chat attachments to local files ([a259bcf](https://github.com/Sogni-AI/sogni-creative-agent-skill/commit/a259bcf36d4a747bb2cbe9d71ff8ec9da9e6c1c9))
|
|
7
|
+
|
|
8
|
+
# [3.13.0](https://github.com/Sogni-AI/sogni-creative-agent-skill/compare/v3.12.0...v3.13.0) (2026-07-05)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **cli:** port SourceReel folder-to-video reels from recovered branch ([0e61830](https://github.com/Sogni-AI/sogni-creative-agent-skill/commit/0e6183090a0e1af698bce5de112246bcd44d5eac))
|
|
14
|
+
|
|
1
15
|
# [3.12.0](https://github.com/Sogni-AI/sogni-creative-agent-skill/compare/v3.11.1...v3.12.0) (2026-07-05)
|
|
2
16
|
|
|
3
17
|
|
package/SKILL.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: sogni-creative-agent-skill
|
|
3
3
|
description: "Sogni Creative Agent Skill: agent skill and CLI for image, video, and music generation using Sogni AI's decentralized GPU network. Supports personas (named people with saved reference photos and voice clips), persistent memories, custom personality, style transfer, angle synthesis, Seedance/HappyHorse/LTX/WAN video, music/lyrics, hosted chat, durable workflows, replay records, and multi-step creative workflows. Ask the agent to \"draw\", \"generate\", \"create an image\", \"make a video/animate\", \"make music\", \"apply a style\", or \"generate me as a superhero\"."
|
|
4
4
|
metadata:
|
|
5
|
-
version: "3.
|
|
5
|
+
version: "3.13.0"
|
|
6
6
|
homepage: https://sogni.ai
|
|
7
7
|
openclaw:
|
|
8
8
|
emoji: "π¨"
|
|
@@ -222,7 +222,7 @@ For "4k" / "uhd" requests where the user accepts the Premium Spark vendor path o
|
|
|
222
222
|
|
|
223
223
|
### Video editing, stitching, 360 turnarounds
|
|
224
224
|
|
|
225
|
-
Trigger patterns β "animate/morph image A to image B" (`--ref A --ref-end B`; on LTX-2.3 i2v this is a single render β the transition/morph LoRA auto-applies, no bridge clip), "continue this video" (extract last frame β i2v β concat), "transition between two videos" (bridge clip between two *finished videos*), "360 video" (`--angles-360 --angles-360-video`), "add/replace the soundtrack" (`--concat-audio` / `--remix-audio`). **Read [`references/video-editing.md`](./references/video-editing.md) for the step-by-step recipes.**
|
|
225
|
+
Trigger patterns β "animate/morph image A to image B" (`--ref A --ref-end B`; on LTX-2.3 i2v this is a single render β the transition/morph LoRA auto-applies, no bridge clip), "continue this video" (extract last frame β i2v β concat), "transition between two videos" (bridge clip between two *finished videos*), "make a reel/slideshow from these images" or "animate this folder of images" (`--source-reel <dir>`; plan first with the free `--reel-plan-only`; options: `--reel-image-seconds`, `--reel-transition-seconds`, `--reel-loop`/`--no-reel-loop`, `--reel-image-prompt`, `--reel-transition-prompt`), "360 video" (`--angles-360 --angles-360-video`), "add/replace the soundtrack" (`--concat-audio` / `--remix-audio`). **Read [`references/video-editing.md`](./references/video-editing.md) for the step-by-step recipes.**
|
|
226
226
|
|
|
227
227
|
**Security: never run raw shell commands (`ffmpeg`, `ls`, `cp`, etc.) for file operations or video/audio manipulation.** Always use the CLI's built-in safe wrappers: `--extract-first-frame`, `--extract-last-frame`, `--concat-videos`, `--remix-audio`, `--list-media`, `--video-start`, `--audio-start`, `--audio-duration`, `--looping`.
|
|
228
228
|
|
|
@@ -9,6 +9,27 @@ A dependency-free MCP stdio server that wraps the globally installed
|
|
|
9
9
|
- `server/tools.mjs` β tool schemas + pure argv builders
|
|
10
10
|
- `server/resolve.mjs` β absolute-path resolution (agent, ffmpeg, child env);
|
|
11
11
|
Claude Desktop's GUI environment has a minimal PATH, so nothing here relies on PATH lookup
|
|
12
|
+
- `server/import-media.mjs` β local handler for `import_media` (see below); the
|
|
13
|
+
only tool that runs inside the server instead of spawning the CLI
|
|
14
|
+
|
|
15
|
+
## Chat attachments and import_media
|
|
16
|
+
|
|
17
|
+
Files attached to a chat never reach this server: Claude Desktop keeps
|
|
18
|
+
attachments in its remote sandbox, and MCP has no clientβserver file
|
|
19
|
+
transfer. Every media input (`ref`, `context_images`, β¦) therefore only
|
|
20
|
+
accepts paths on this machine or URLs β the tool descriptions say so, and
|
|
21
|
+
point the model at the bridge:
|
|
22
|
+
|
|
23
|
+
`import_media` accepts base64-encoded bytes and writes them into the Sogni
|
|
24
|
+
media inbox (`SOGNI_MEDIA_INBOUND_DIR`, default `~/.openclaw/media/inbound/`
|
|
25
|
+
β the same directory `list_media` reads), returning the absolute path to feed
|
|
26
|
+
into the generation tools. Large files arrive in chunks: first call passes
|
|
27
|
+
`filename`, later calls pass `append_to_path` from the previous result.
|
|
28
|
+
Guardrails: media-only extensions, filenames reduced to their basename,
|
|
29
|
+
existing files never overwritten (suffixed instead), appends confined to the
|
|
30
|
+
inbox, 2MB per chunk / 25MB per file. In practice the model reads the
|
|
31
|
+
attachment in its code-execution sandbox, downscales images to ~1024px JPEG,
|
|
32
|
+
and relays the base64 β token-expensive, so previews beat full-res originals.
|
|
12
33
|
|
|
13
34
|
## Inline images
|
|
14
35
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifest_version": "0.3",
|
|
3
3
|
"name": "sogni-creative-agent",
|
|
4
4
|
"display_name": "Sogni Creative Agent",
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.13.0",
|
|
6
6
|
"description": "Generate images, video, and music on Sogni AI's decentralized GPU network β with personas, memories, and safe video editing tools.",
|
|
7
7
|
"author": { "name": "Sogni AI", "url": "https://sogni.ai" },
|
|
8
8
|
"homepage": "https://sogni.ai",
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// desktop-extension/server/import-media.mjs
|
|
2
|
+
// Local handler for the import_media tool: decodes base64 chunks sent by the
|
|
3
|
+
// model and writes them into the Sogni media inbox, returning the absolute
|
|
4
|
+
// path the generation tools can consume. This exists because chat clients
|
|
5
|
+
// (e.g. Claude Desktop) cannot hand attachment bytes to a local MCP server β
|
|
6
|
+
// the model relays them as base64 instead, chunked for anything beyond one
|
|
7
|
+
// tool call's worth of output. Runs entirely locally: no CLI spawn, no network.
|
|
8
|
+
import { appendFileSync, existsSync, mkdirSync, statSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
import { basename, extname, join, resolve, sep } from 'node:path';
|
|
11
|
+
|
|
12
|
+
// Decoded-bytes ceilings. A chunk is one tool call's `data` payload; the total
|
|
13
|
+
// bounds the finished file so a runaway chunk loop can't fill the disk.
|
|
14
|
+
const MAX_CHUNK_BYTES = 2 * 1024 * 1024;
|
|
15
|
+
const MAX_TOTAL_BYTES = 25 * 1024 * 1024;
|
|
16
|
+
|
|
17
|
+
// Media-only allowlist: this tool imports generation inputs, not arbitrary
|
|
18
|
+
// files, so executable/document extensions are rejected outright.
|
|
19
|
+
const ALLOWED_EXTENSIONS = new Set([
|
|
20
|
+
'.png', '.jpg', '.jpeg', '.webp', '.gif',
|
|
21
|
+
'.mp3', '.wav', '.flac', '.m4a', '.ogg',
|
|
22
|
+
'.mp4', '.mov', '.webm',
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
// Mirrors the CLI's inbound-dir resolution (sogni-agent.mjs): env override
|
|
26
|
+
// first, then the OpenClaw inbox with a legacy clawdbot-era fallback. Keeping
|
|
27
|
+
// the same directory means --list-media sees imported files immediately.
|
|
28
|
+
function resolveInboundDir(env, home) {
|
|
29
|
+
if (env.SOGNI_MEDIA_INBOUND_DIR) return env.SOGNI_MEDIA_INBOUND_DIR;
|
|
30
|
+
const openclaw = join(home, '.openclaw', 'media', 'inbound');
|
|
31
|
+
const legacy = join(home, '.clawdbot', 'media', 'inbound');
|
|
32
|
+
return !existsSync(openclaw) && existsSync(legacy) ? legacy : openclaw;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function decodeChunk(data, maxChunkBytes) {
|
|
36
|
+
if (typeof data !== 'string' || data === '') {
|
|
37
|
+
throw new Error('data is required β the base64-encoded bytes of this chunk.');
|
|
38
|
+
}
|
|
39
|
+
const compact = data.replace(/\s+/g, '');
|
|
40
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(compact) || compact.length % 4 !== 0) {
|
|
41
|
+
throw new Error('data is not valid base64.');
|
|
42
|
+
}
|
|
43
|
+
const bytes = Buffer.from(compact, 'base64');
|
|
44
|
+
if (bytes.length > maxChunkBytes) {
|
|
45
|
+
throw new Error(`Chunk too large: ${bytes.length} bytes decoded (max ${maxChunkBytes}). Send smaller chunks.`);
|
|
46
|
+
}
|
|
47
|
+
return bytes;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// New imports never clobber: pixel.png β pixel-2.png β pixel-3.png β¦
|
|
51
|
+
function uniquePath(dir, filename) {
|
|
52
|
+
const ext = extname(filename);
|
|
53
|
+
const stem = filename.slice(0, filename.length - ext.length);
|
|
54
|
+
let candidate = join(dir, filename);
|
|
55
|
+
for (let n = 2; existsSync(candidate); n += 1) {
|
|
56
|
+
candidate = join(dir, `${stem}-${n}${ext}`);
|
|
57
|
+
}
|
|
58
|
+
return candidate;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function importMedia(input, {
|
|
62
|
+
env = process.env,
|
|
63
|
+
home = homedir(),
|
|
64
|
+
maxChunkBytes = MAX_CHUNK_BYTES,
|
|
65
|
+
maxTotalBytes = MAX_TOTAL_BYTES,
|
|
66
|
+
} = {}) {
|
|
67
|
+
const bytes = decodeChunk(input.data, maxChunkBytes);
|
|
68
|
+
const dir = resolveInboundDir(env, home);
|
|
69
|
+
|
|
70
|
+
if (input.append_to_path) {
|
|
71
|
+
const target = resolve(String(input.append_to_path));
|
|
72
|
+
if (!target.startsWith(resolve(dir) + sep)) {
|
|
73
|
+
throw new Error('append_to_path must be a path inside the Sogni media inbox returned by a previous import_media call.');
|
|
74
|
+
}
|
|
75
|
+
if (!existsSync(target)) {
|
|
76
|
+
throw new Error('append_to_path does not exist β start the import with a filename first.');
|
|
77
|
+
}
|
|
78
|
+
const existing = statSync(target).size;
|
|
79
|
+
if (existing + bytes.length > maxTotalBytes) {
|
|
80
|
+
throw new Error(`Import would exceed the total size cap (${maxTotalBytes} bytes).`);
|
|
81
|
+
}
|
|
82
|
+
appendFileSync(target, bytes);
|
|
83
|
+
return { path: target, bytes: existing + bytes.length };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const filename = basename(String(input.filename ?? ''));
|
|
87
|
+
if (!filename || filename === '.' || filename === sep) {
|
|
88
|
+
throw new Error('filename is required for a new import, e.g. "photo.jpg".');
|
|
89
|
+
}
|
|
90
|
+
const ext = extname(filename).toLowerCase();
|
|
91
|
+
if (!ALLOWED_EXTENSIONS.has(ext)) {
|
|
92
|
+
throw new Error(`Unsupported extension "${ext || '(none)'}" β allowed: ${[...ALLOWED_EXTENSIONS].join(', ')}.`);
|
|
93
|
+
}
|
|
94
|
+
if (bytes.length > maxTotalBytes) {
|
|
95
|
+
throw new Error(`Import would exceed the total size cap (${maxTotalBytes} bytes).`);
|
|
96
|
+
}
|
|
97
|
+
mkdirSync(dir, { recursive: true });
|
|
98
|
+
const target = uniquePath(dir, filename);
|
|
99
|
+
writeFileSync(target, bytes);
|
|
100
|
+
return { path: target, bytes: bytes.length };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Tool-call entry point used by index.mjs: wraps the core in the JSON shape
|
|
104
|
+
// the model reads back, including where to point the generation tools next.
|
|
105
|
+
export async function runImportMedia(input) {
|
|
106
|
+
const { path, bytes } = await importMedia(input ?? {});
|
|
107
|
+
return JSON.stringify({
|
|
108
|
+
path,
|
|
109
|
+
bytes,
|
|
110
|
+
note: 'Saved locally. To add more chunks, call import_media again with append_to_path set to this path. '
|
|
111
|
+
+ 'When complete, pass this path as generate_video.ref, generate_image.context_images, photobooth.ref, or a persona ref.',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -11,6 +11,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
11
11
|
import { TOOLS, getTool } from './tools.mjs';
|
|
12
12
|
import { buildChildEnv, resolveAgentPath, resolveFfmpegPath } from './resolve.mjs';
|
|
13
13
|
import { collectInlineImages } from './inline-images.mjs';
|
|
14
|
+
import { runImportMedia } from './import-media.mjs';
|
|
14
15
|
|
|
15
16
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
16
17
|
const PROTOCOL_FALLBACK = '2025-06-18';
|
|
@@ -33,10 +34,22 @@ function textResult(text, isError = false) {
|
|
|
33
34
|
return { content: [{ type: 'text', text }], isError };
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
// Tools marked local in the registry run inside this process and must work
|
|
38
|
+
// even when the sogni-agent CLI is not installed yet.
|
|
39
|
+
const LOCAL_HANDLERS = { import_media: runImportMedia };
|
|
40
|
+
|
|
36
41
|
async function callTool(name, input, progressToken) {
|
|
37
42
|
const tool = getTool(name);
|
|
38
43
|
if (!tool) return textResult(`Unknown tool: ${name}`, true);
|
|
39
44
|
|
|
45
|
+
if (tool.local) {
|
|
46
|
+
try {
|
|
47
|
+
return textResult(await LOCAL_HANDLERS[name](input ?? {}));
|
|
48
|
+
} catch (err) {
|
|
49
|
+
return textResult(err.message, true);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
40
53
|
const agentPath = resolveAgentPath();
|
|
41
54
|
if (!agentPath) {
|
|
42
55
|
return textResult(
|
|
@@ -20,6 +20,13 @@ function required(input, field, hint) {
|
|
|
20
20
|
const str = (description) => ({ type: 'string', description });
|
|
21
21
|
const num = (description) => ({ type: 'number', description });
|
|
22
22
|
|
|
23
|
+
// Chat clients (Claude Desktop etc.) never expose chat-attached files to this
|
|
24
|
+
// server's filesystem; without this warning the model wastes turns discovering
|
|
25
|
+
// that boundary by trial and error.
|
|
26
|
+
const CHAT_ATTACHMENT_NOTE =
|
|
27
|
+
'Files attached to the chat are NOT visible to Sogni tools β import them with import_media first ' +
|
|
28
|
+
'(returns a local path), or pass a local absolute path, URL, or saved persona.';
|
|
29
|
+
|
|
23
30
|
export const TOOLS = [
|
|
24
31
|
{
|
|
25
32
|
name: 'generate_image',
|
|
@@ -27,7 +34,7 @@ export const TOOLS = [
|
|
|
27
34
|
'Generate one or more images from a text prompt on the Sogni GPU network. ' +
|
|
28
35
|
'Pass output_path (absolute, .png/.jpg) to save locally; otherwise a hosted URL is returned. ' +
|
|
29
36
|
'Use context_images for image editing ("make the background a beach") and persona to include a saved person. ' +
|
|
30
|
-
'Image results are attached inline in the tool result.',
|
|
37
|
+
'Image results are attached inline in the tool result. ' + CHAT_ATTACHMENT_NOTE,
|
|
31
38
|
inputSchema: {
|
|
32
39
|
type: 'object',
|
|
33
40
|
properties: {
|
|
@@ -67,7 +74,7 @@ export const TOOLS = [
|
|
|
67
74
|
description:
|
|
68
75
|
'Generate a video from a text prompt, optionally driven by reference media. ' +
|
|
69
76
|
'ref = start frame image, ref_end = end frame, ref_audio = soundtrack/lip-sync audio, ref_video = motion reference. ' +
|
|
70
|
-
'Rendering takes minutes; prefer output_path (absolute .mp4).',
|
|
77
|
+
'Rendering takes minutes; prefer output_path (absolute .mp4). ' + CHAT_ATTACHMENT_NOTE,
|
|
71
78
|
inputSchema: {
|
|
72
79
|
type: 'object',
|
|
73
80
|
properties: {
|
|
@@ -144,7 +151,7 @@ export const TOOLS = [
|
|
|
144
151
|
description:
|
|
145
152
|
'Face-transfer portrait generation: renders the person in the ref photo into a new scene ' +
|
|
146
153
|
'(e.g. "LinkedIn professional headshot", "80s fashion portrait"). ' +
|
|
147
|
-
'Image results are attached inline in the tool result.',
|
|
154
|
+
'Image results are attached inline in the tool result. ' + CHAT_ATTACHMENT_NOTE,
|
|
148
155
|
inputSchema: {
|
|
149
156
|
type: 'object',
|
|
150
157
|
properties: {
|
|
@@ -210,9 +217,30 @@ export const TOOLS = [
|
|
|
210
217
|
throw new Error(`Unknown action "${action}".`);
|
|
211
218
|
},
|
|
212
219
|
},
|
|
220
|
+
{
|
|
221
|
+
name: 'import_media',
|
|
222
|
+
description:
|
|
223
|
+
'Save base64-encoded media bytes to the local Sogni media inbox and return the absolute file path, ' +
|
|
224
|
+
'ready to pass as ref / context_images / persona ref. Use this to hand chat-attached files to the ' +
|
|
225
|
+
'generation tools: read the attachment bytes (e.g. via code execution), downscale large images to ' +
|
|
226
|
+
'~1024px JPEG first, base64-encode, and send. For anything over ~40KB, send multiple calls: the first ' +
|
|
227
|
+
'with filename, each following chunk with append_to_path set to the returned path.',
|
|
228
|
+
inputSchema: {
|
|
229
|
+
type: 'object',
|
|
230
|
+
properties: {
|
|
231
|
+
data: str('Base64-encoded file bytes for this chunk (keep each chunk under ~64KB of base64)'),
|
|
232
|
+
filename: str('Filename with a media extension for a NEW import, e.g. "photo.jpg"'),
|
|
233
|
+
append_to_path: str('Path returned by the previous call β appends this chunk to that file instead of creating a new one'),
|
|
234
|
+
},
|
|
235
|
+
required: ['data'],
|
|
236
|
+
},
|
|
237
|
+
local: true, // handled inside the server (import-media.mjs); never spawns the CLI
|
|
238
|
+
},
|
|
213
239
|
{
|
|
214
240
|
name: 'list_media',
|
|
215
|
-
description:
|
|
241
|
+
description:
|
|
242
|
+
'List recent files in the Sogni media inbox: media the user sent via connected messaging apps ' +
|
|
243
|
+
'plus files saved by import_media. Chat attachments do NOT appear here unless imported first.',
|
|
216
244
|
inputSchema: {
|
|
217
245
|
type: 'object',
|
|
218
246
|
properties: { type: { type: 'string', enum: ['images', 'audio', 'all'] } },
|
|
@@ -225,7 +253,7 @@ export const TOOLS = [
|
|
|
225
253
|
name: 'manage_personas',
|
|
226
254
|
description:
|
|
227
255
|
'Manage saved personas (named people with reference photos and optional voice clips). ' +
|
|
228
|
-
'Actions: list, add (needs name + ref photo), remove, resolve (show details).',
|
|
256
|
+
'Actions: list, add (needs name + ref photo), remove, resolve (show details). ' + CHAT_ATTACHMENT_NOTE,
|
|
229
257
|
inputSchema: {
|
|
230
258
|
type: 'object',
|
|
231
259
|
properties: {
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "sogni-creative-agent-skill",
|
|
3
3
|
"name": "Sogni Creative Agent Skill β Image, Video & Music Generation",
|
|
4
4
|
"description": "Agent skill and CLI for Sogni AI image, video, and music generation.",
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.13.0",
|
|
6
6
|
"skills": [
|
|
7
7
|
"."
|
|
8
8
|
],
|
package/package.json
CHANGED
|
@@ -83,6 +83,29 @@ To **create a transition between two existing videos** (A β B), bridge them wi
|
|
|
83
83
|
|
|
84
84
|
> **i2v clips are silent and use the model's own frame rate** (often not 24). `--concat-videos` normalizes fps/size and fills silent audio automatically, so mismatched clips stitch correctly β but passing `--fps` to the transition generation keeps things clean from the start. Use `--concat-fps <n>` to force a specific output frame rate.
|
|
85
85
|
|
|
86
|
+
## SourceReel: Folder of Images β Loopable Video
|
|
87
|
+
|
|
88
|
+
Turn a folder of images into one stitched video: each image becomes an animated
|
|
89
|
+
clip, consecutive images are bridged by generated transition clips, and the
|
|
90
|
+
whole set is concatenated into a single mp4 (a single image renders one clip with
|
|
91
|
+
no transitions). **Always plan first β `--reel-plan-only` prints the planned
|
|
92
|
+
clips/transitions for free without rendering.** The render populates a working
|
|
93
|
+
folder (`<source>/sogni-source-reel-*`, or `--reel-workdir <dir>`) that keeps
|
|
94
|
+
every intermediate ref, clip, and transition so reruns can reuse them; the final
|
|
95
|
+
stitch **requires ffmpeg**. Looping is on by default (a lastβfirst transition
|
|
96
|
+
closes the loop) β pass `--no-reel-loop` for a one-way reel.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# 1. Plan the reel for free (no rendering)
|
|
100
|
+
sogni-agent --source-reel ./images --reel-plan-only
|
|
101
|
+
|
|
102
|
+
# 2. Render clips + transitions and stitch (loop on by default)
|
|
103
|
+
sogni-agent --source-reel ./images \
|
|
104
|
+
--reel-image-seconds 3 --reel-transition-seconds 3 \
|
|
105
|
+
--reel-image-prompt "friendly camera-ready motion" \
|
|
106
|
+
--reel-output ./reel.mp4
|
|
107
|
+
```
|
|
108
|
+
|
|
86
109
|
## Segment a Longer Reference Video
|
|
87
110
|
|
|
88
111
|
For local stitched workflows that only need part of a source video:
|
package/sogni-agent.mjs
CHANGED
|
@@ -1866,6 +1866,19 @@ const options = {
|
|
|
1866
1866
|
concatFps: null, // --concat-fps <n>: override target fps for concat normalization
|
|
1867
1867
|
extractFirstFrame: null, // --extract-first-frame <video> <image>
|
|
1868
1868
|
extractFirstFrameOutput: null,
|
|
1869
|
+
sourceReelDir: null, // --source-reel <image-folder>: animate folder images into a stitched video
|
|
1870
|
+
sourceReelImageSeconds: 3,
|
|
1871
|
+
sourceReelTransitionSeconds: 3,
|
|
1872
|
+
sourceReelLoop: true,
|
|
1873
|
+
sourceReelWorkdir: null,
|
|
1874
|
+
sourceReelOutput: null,
|
|
1875
|
+
sourceReelImagePrompt: null,
|
|
1876
|
+
sourceReelTransitionPrompt: null,
|
|
1877
|
+
sourceReelTransitionPrompts: null,
|
|
1878
|
+
sourceReelPlanOnly: false,
|
|
1879
|
+
sourceReelConcurrency: 2,
|
|
1880
|
+
sourceReelModel: null,
|
|
1881
|
+
sourceReelTargetResolution: 768,
|
|
1869
1882
|
// Audio remix (--remix-audio <in_video> <out_video>): loop/fade/mix without re-encoding video
|
|
1870
1883
|
remixAudio: null,
|
|
1871
1884
|
remixAudioOutput: null,
|
|
@@ -2450,6 +2463,56 @@ for (let i = 0; i < args.length; i++) {
|
|
|
2450
2463
|
i++;
|
|
2451
2464
|
options.extractFirstFrame = videoArg;
|
|
2452
2465
|
options.extractFirstFrameOutput = imageArg;
|
|
2466
|
+
} else if (arg === '--source-reel' || arg === '--image-reel') {
|
|
2467
|
+
const raw = expandHomePath(requireFlagValue(args, i, arg));
|
|
2468
|
+
i++;
|
|
2469
|
+
options.sourceReelDir = raw;
|
|
2470
|
+
} else if (arg === '--reel-image-seconds' || arg === '--reel-clip-seconds') {
|
|
2471
|
+
const raw = requireFlagValue(args, i, arg);
|
|
2472
|
+
i++;
|
|
2473
|
+
options.sourceReelImageSeconds = parsePositiveIntegerValue(raw, arg);
|
|
2474
|
+
} else if (arg === '--reel-transition-seconds') {
|
|
2475
|
+
const raw = requireFlagValue(args, i, arg);
|
|
2476
|
+
i++;
|
|
2477
|
+
options.sourceReelTransitionSeconds = parsePositiveIntegerValue(raw, arg);
|
|
2478
|
+
} else if (arg === '--reel-loop') {
|
|
2479
|
+
options.sourceReelLoop = true;
|
|
2480
|
+
} else if (arg === '--no-reel-loop') {
|
|
2481
|
+
options.sourceReelLoop = false;
|
|
2482
|
+
} else if (arg === '--reel-workdir') {
|
|
2483
|
+
const raw = expandHomePath(requireFlagValue(args, i, arg));
|
|
2484
|
+
i++;
|
|
2485
|
+
options.sourceReelWorkdir = raw;
|
|
2486
|
+
} else if (arg === '--reel-output') {
|
|
2487
|
+
const raw = expandHomePath(requireFlagValue(args, i, arg));
|
|
2488
|
+
i++;
|
|
2489
|
+
options.sourceReelOutput = raw;
|
|
2490
|
+
} else if (arg === '--reel-image-prompt') {
|
|
2491
|
+
const raw = requireFlagValue(args, i, arg);
|
|
2492
|
+
i++;
|
|
2493
|
+
options.sourceReelImagePrompt = raw;
|
|
2494
|
+
} else if (arg === '--reel-transition-prompt') {
|
|
2495
|
+
const raw = requireFlagValue(args, i, arg);
|
|
2496
|
+
i++;
|
|
2497
|
+
options.sourceReelTransitionPrompt = raw;
|
|
2498
|
+
} else if (arg === '--reel-transition-prompts') {
|
|
2499
|
+
const raw = requireFlagValue(args, i, arg);
|
|
2500
|
+
i++;
|
|
2501
|
+
options.sourceReelTransitionPrompts = raw;
|
|
2502
|
+
} else if (arg === '--reel-plan-only' || arg === '--reel-dry-run') {
|
|
2503
|
+
options.sourceReelPlanOnly = true;
|
|
2504
|
+
} else if (arg === '--reel-concurrency') {
|
|
2505
|
+
const raw = requireFlagValue(args, i, arg);
|
|
2506
|
+
i++;
|
|
2507
|
+
options.sourceReelConcurrency = parsePositiveIntegerValue(raw, arg, 1, 8);
|
|
2508
|
+
} else if (arg === '--reel-model') {
|
|
2509
|
+
const raw = requireFlagValue(args, i, arg);
|
|
2510
|
+
i++;
|
|
2511
|
+
options.sourceReelModel = raw;
|
|
2512
|
+
} else if (arg === '--reel-target-resolution') {
|
|
2513
|
+
const raw = requireFlagValue(args, i, arg);
|
|
2514
|
+
i++;
|
|
2515
|
+
options.sourceReelTargetResolution = parsePositiveIntegerValue(raw, arg, 480, 1536);
|
|
2453
2516
|
} else if (arg === '--remix-audio') {
|
|
2454
2517
|
const inArg = requireFlagValue(args, i, arg + ' (input video)');
|
|
2455
2518
|
i++;
|
|
@@ -2906,6 +2969,21 @@ Seedance Reference Modes (mutually exclusive on seedance2 / seedance2-mini / see
|
|
|
2906
2969
|
--looping, --loop Create seamless loop (i2v only): AβBβA
|
|
2907
2970
|
--last-image Use last generated image as reference
|
|
2908
2971
|
|
|
2972
|
+
SourceReel (folder of images β loopable video):
|
|
2973
|
+
--source-reel <dir> Build a video reel from images in a folder (alias: --image-reel)
|
|
2974
|
+
--reel-plan-only Print the planned clips/transitions without rendering
|
|
2975
|
+
--reel-image-seconds <sec> Seconds per animated image clip (default: 3)
|
|
2976
|
+
--reel-transition-seconds <sec> Seconds per bridge transition (default: 3)
|
|
2977
|
+
--reel-loop / --no-reel-loop Include final lastβfirst transition (default: loop)
|
|
2978
|
+
--reel-image-prompt <text> Motion prompt for each source image
|
|
2979
|
+
--reel-transition-prompt <text> Default transition style between images
|
|
2980
|
+
--reel-transition-prompts <json|@file> Per-transition prompt array/object
|
|
2981
|
+
--reel-workdir <dir> Use/create one working folder (default: <source>/sogni-source-reel-*)
|
|
2982
|
+
--reel-output <path> Final merged mp4 path (default: inside working folder)
|
|
2983
|
+
--reel-model <id> Video model for clips/transitions (default: WAN i2v lightx2v)
|
|
2984
|
+
--reel-concurrency <n> Parallel render jobs, 1-8 (default: 2)
|
|
2985
|
+
--reel-target-resolution <px> Inferred short side when -w/-h omitted (default: 768)
|
|
2986
|
+
|
|
2909
2987
|
Hosted API Modes:
|
|
2910
2988
|
--api-chat Use /v1/chat/completions with Sogni creative-agent tools
|
|
2911
2989
|
--durable-chat Like --api-chat but routes through durable /v1/chat/runs + SSE
|
|
@@ -3066,6 +3144,8 @@ Examples:
|
|
|
3066
3144
|
sogni-agent --video --ref cat.jpg --ref-audio speech.m4a -m wan_v2.2-14b-fp8_s2v_lightx2v "lip sync"
|
|
3067
3145
|
sogni-agent --video --ref cover.jpg --ref-audio song.mp3 "music video"
|
|
3068
3146
|
sogni-agent --video --ref-audio song.mp3 "abstract music visualizer"
|
|
3147
|
+
sogni-agent --source-reel ./images --reel-plan-only
|
|
3148
|
+
sogni-agent --source-reel ./images --reel-image-seconds 3 --reel-transition-seconds 3 --reel-image-prompt "friendly camera-ready motion"
|
|
3069
3149
|
sogni-agent --music --duration 30 "uplifting cinematic synthwave theme for a product launch"
|
|
3070
3150
|
sogni-agent --music --lyrics "Rise with the morning light" --bpm 128 --keyscale "C major" --output-format mp3 "bright indie pop chorus"
|
|
3071
3151
|
sogni-agent --video --reference-audio-identity voice.webm 'NARRATOR: "This is my voice."'
|
|
@@ -3756,6 +3836,7 @@ const commandUsesGenerationSeed = !options.apiChat &&
|
|
|
3756
3836
|
!options.extractLastFrame &&
|
|
3757
3837
|
!options.extractFirstFrame &&
|
|
3758
3838
|
!options.concatVideos &&
|
|
3839
|
+
!options.sourceReelDir &&
|
|
3759
3840
|
!options.remixAudio &&
|
|
3760
3841
|
!options.listMedia &&
|
|
3761
3842
|
!options.memoryAction &&
|
|
@@ -3772,7 +3853,7 @@ if (apiWorkflowStartAction && apiWorkflowTemplate === 'storyboard_video' && !opt
|
|
|
3772
3853
|
if (typeof options.prompt === 'string' && options.prompt.trim() === '') {
|
|
3773
3854
|
options.prompt = '';
|
|
3774
3855
|
}
|
|
3775
|
-
if (!options.prompt && !options.apiChat && !apiWorkflowUtilityAction && !apiWorkflowStartAction && !apiModelUtilityAction && !apiReplayUtilityAction && !contractUtilityAction && !storyboardPlanUtilityAction && !options.estimateVideoCost && !options.multiAngle && !options.showBalance && !options.showVersion && !options.doctor && !options.extractLastFrame && !options.extractFirstFrame && !options.concatVideos && !options.remixAudio && !options.listMedia && !options.memoryAction && !options.personalityAction && !personaUtilityAction) {
|
|
3856
|
+
if (!options.prompt && !options.apiChat && !apiWorkflowUtilityAction && !apiWorkflowStartAction && !apiModelUtilityAction && !apiReplayUtilityAction && !contractUtilityAction && !storyboardPlanUtilityAction && !options.estimateVideoCost && !options.multiAngle && !options.showBalance && !options.showVersion && !options.doctor && !options.extractLastFrame && !options.extractFirstFrame && !options.concatVideos && !options.sourceReelDir && !options.remixAudio && !options.listMedia && !options.memoryAction && !options.personalityAction && !personaUtilityAction) {
|
|
3776
3857
|
fatalCliError('No prompt provided. Use --help for usage.', { code: 'INVALID_ARGUMENT' });
|
|
3777
3858
|
}
|
|
3778
3859
|
|
|
@@ -7543,6 +7624,484 @@ async function remixVideoAudio(inputVideo, outputVideo, opts = {}) {
|
|
|
7543
7624
|
}
|
|
7544
7625
|
}
|
|
7545
7626
|
|
|
7627
|
+
const SOURCE_REEL_IMAGE_EXTS = new Set(['.jpg', '.jpeg', '.png', '.webp']);
|
|
7628
|
+
const SOURCE_REEL_DEFAULT_MODEL = 'wan_v2.2-14b-fp8_i2v_lightx2v';
|
|
7629
|
+
const SOURCE_REEL_DEFAULT_IMAGE_PROMPT =
|
|
7630
|
+
'A polished camera-ready photo moment: the subject or scene comes gently to life with restrained natural motion, soft breathing or environmental movement, subtle parallax, stable lighting, and a smooth steady camera. Preserve the source image identity, composition, style, and important details.';
|
|
7631
|
+
const SOURCE_REEL_DEFAULT_TRANSITION_PROMPT =
|
|
7632
|
+
'Create a seamless, well-designed transition between the two shots with continuous camera motion, natural subject movement where appropriate, consistent lighting, and a clean landing into the next frame. Avoid a simple fade; make the bridge feel intentional and cinematic.';
|
|
7633
|
+
|
|
7634
|
+
function sourceReelTimestamp() {
|
|
7635
|
+
return new Date().toISOString().replace(/[-:]/g, '').replace(/\.\d+Z$/, 'Z');
|
|
7636
|
+
}
|
|
7637
|
+
|
|
7638
|
+
function sourceReelSlug(value, fallback = 'item') {
|
|
7639
|
+
const slug = String(value || '')
|
|
7640
|
+
.toLowerCase()
|
|
7641
|
+
.replace(/\.[^.]+$/, '')
|
|
7642
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
7643
|
+
.replace(/^-+|-+$/g, '')
|
|
7644
|
+
.slice(0, 64);
|
|
7645
|
+
return slug || fallback;
|
|
7646
|
+
}
|
|
7647
|
+
|
|
7648
|
+
function roundToMultiple(value, multiple) {
|
|
7649
|
+
return Math.max(multiple, Math.round(value / multiple) * multiple);
|
|
7650
|
+
}
|
|
7651
|
+
|
|
7652
|
+
function inferSourceReelDimensions(metadata, targetShortSide) {
|
|
7653
|
+
const rawWidth = Number(metadata?.width) || targetShortSide;
|
|
7654
|
+
const rawHeight = Number(metadata?.height) || targetShortSide;
|
|
7655
|
+
const aspect = rawWidth > 0 && rawHeight > 0 ? rawWidth / rawHeight : 1;
|
|
7656
|
+
let width;
|
|
7657
|
+
let height;
|
|
7658
|
+
if (aspect >= 1) {
|
|
7659
|
+
height = targetShortSide;
|
|
7660
|
+
width = targetShortSide * aspect;
|
|
7661
|
+
} else {
|
|
7662
|
+
width = targetShortSide;
|
|
7663
|
+
height = targetShortSide / aspect;
|
|
7664
|
+
}
|
|
7665
|
+
|
|
7666
|
+
const maxSide = Math.max(width, height);
|
|
7667
|
+
if (maxSide > 1536) {
|
|
7668
|
+
const scale = 1536 / maxSide;
|
|
7669
|
+
width *= scale;
|
|
7670
|
+
height *= scale;
|
|
7671
|
+
}
|
|
7672
|
+
const minSide = Math.min(width, height);
|
|
7673
|
+
if (minSide < 480) {
|
|
7674
|
+
const scale = 480 / minSide;
|
|
7675
|
+
width *= scale;
|
|
7676
|
+
height *= scale;
|
|
7677
|
+
}
|
|
7678
|
+
|
|
7679
|
+
return {
|
|
7680
|
+
width: roundToMultiple(width, 16),
|
|
7681
|
+
height: roundToMultiple(height, 16)
|
|
7682
|
+
};
|
|
7683
|
+
}
|
|
7684
|
+
|
|
7685
|
+
function uniqueSourceReelWorkdir(sourceDir) {
|
|
7686
|
+
const base = join(sourceDir, `sogni-source-reel-${sourceReelTimestamp()}`);
|
|
7687
|
+
if (!existsSync(base)) return base;
|
|
7688
|
+
for (let i = 2; i < 100; i++) {
|
|
7689
|
+
const candidate = `${base}-${i}`;
|
|
7690
|
+
if (!existsSync(candidate)) return candidate;
|
|
7691
|
+
}
|
|
7692
|
+
return mkdtempSync(`${base}-`);
|
|
7693
|
+
}
|
|
7694
|
+
|
|
7695
|
+
function loadSourceReelImages(sourceDir) {
|
|
7696
|
+
const dir = sanitizePath(sourceDir, '--source-reel');
|
|
7697
|
+
if (!existsSync(dir)) {
|
|
7698
|
+
const err = new Error(`SourceReel image folder not found: ${dir}`);
|
|
7699
|
+
err.code = 'FILE_NOT_FOUND';
|
|
7700
|
+
throw err;
|
|
7701
|
+
}
|
|
7702
|
+
const lstats = lstatSync(dir);
|
|
7703
|
+
if (!lstats.isDirectory() || lstats.isSymbolicLink()) {
|
|
7704
|
+
const err = new Error(`SourceReel path must be a real directory: ${dir}`);
|
|
7705
|
+
err.code = 'INVALID_PATH';
|
|
7706
|
+
throw err;
|
|
7707
|
+
}
|
|
7708
|
+
|
|
7709
|
+
const entries = readdirSync(dir);
|
|
7710
|
+
const images = [];
|
|
7711
|
+
for (const entry of entries) {
|
|
7712
|
+
const ext = extname(entry).toLowerCase();
|
|
7713
|
+
if (!SOURCE_REEL_IMAGE_EXTS.has(ext)) continue;
|
|
7714
|
+
const fullPath = join(dir, entry);
|
|
7715
|
+
const fileStats = lstatSync(fullPath);
|
|
7716
|
+
if (fileStats.isSymbolicLink() || !fileStats.isFile()) continue;
|
|
7717
|
+
images.push({
|
|
7718
|
+
path: fullPath,
|
|
7719
|
+
name: entry,
|
|
7720
|
+
base: basename(entry, ext),
|
|
7721
|
+
slug: sourceReelSlug(entry, `image-${images.length + 1}`)
|
|
7722
|
+
});
|
|
7723
|
+
}
|
|
7724
|
+
images.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
|
|
7725
|
+
images.forEach((image, idx) => {
|
|
7726
|
+
image.index = idx + 1;
|
|
7727
|
+
image.id = String(idx + 1).padStart(2, '0');
|
|
7728
|
+
});
|
|
7729
|
+
return images;
|
|
7730
|
+
}
|
|
7731
|
+
|
|
7732
|
+
function loadSourceReelTransitionPromptOverrides(raw) {
|
|
7733
|
+
if (!raw) return null;
|
|
7734
|
+
const parsed = parseJsonArgument(raw, '--reel-transition-prompts', 'INVALID_REEL_PROMPTS');
|
|
7735
|
+
if (Array.isArray(parsed)) return parsed;
|
|
7736
|
+
if (parsed && typeof parsed === 'object') return parsed;
|
|
7737
|
+
fatalCliError('--reel-transition-prompts must be a JSON array or object, or @path to one.', {
|
|
7738
|
+
code: 'INVALID_REEL_PROMPTS'
|
|
7739
|
+
});
|
|
7740
|
+
}
|
|
7741
|
+
|
|
7742
|
+
function sourceReelTransitionOverride(overrides, index, from, to) {
|
|
7743
|
+
if (!overrides) return null;
|
|
7744
|
+
if (Array.isArray(overrides)) {
|
|
7745
|
+
return typeof overrides[index] === 'string' ? overrides[index] : null;
|
|
7746
|
+
}
|
|
7747
|
+
const keys = [
|
|
7748
|
+
`${from.id}-to-${to.id}`,
|
|
7749
|
+
`${from.index}-to-${to.index}`,
|
|
7750
|
+
`${from.slug}-to-${to.slug}`,
|
|
7751
|
+
`${from.base}-to-${to.base}`,
|
|
7752
|
+
];
|
|
7753
|
+
for (const key of keys) {
|
|
7754
|
+
if (typeof overrides[key] === 'string') return overrides[key];
|
|
7755
|
+
}
|
|
7756
|
+
return typeof overrides.default === 'string' ? overrides.default : null;
|
|
7757
|
+
}
|
|
7758
|
+
|
|
7759
|
+
function buildSourceReelPlan() {
|
|
7760
|
+
const sourceDir = resolve(sanitizePath(options.sourceReelDir, '--source-reel'));
|
|
7761
|
+
const images = loadSourceReelImages(sourceDir);
|
|
7762
|
+
if (images.length === 0) {
|
|
7763
|
+
fatalCliError(`No source images found in ${sourceDir}. Supported: jpg, jpeg, png, webp.`, {
|
|
7764
|
+
code: 'NO_SOURCE_IMAGES',
|
|
7765
|
+
details: { sourceDir }
|
|
7766
|
+
});
|
|
7767
|
+
}
|
|
7768
|
+
|
|
7769
|
+
let dimensions = null;
|
|
7770
|
+
if (cliSet.width || cliSet.height) {
|
|
7771
|
+
if (!cliSet.width || !cliSet.height) {
|
|
7772
|
+
fatalCliError('SourceReel requires both -w and -h when overriding dimensions.', {
|
|
7773
|
+
code: 'INVALID_ARGUMENT'
|
|
7774
|
+
});
|
|
7775
|
+
}
|
|
7776
|
+
dimensions = {
|
|
7777
|
+
width: roundToMultiple(options.width, 16),
|
|
7778
|
+
height: roundToMultiple(options.height, 16)
|
|
7779
|
+
};
|
|
7780
|
+
}
|
|
7781
|
+
|
|
7782
|
+
const workdir = resolve(options.sourceReelWorkdir
|
|
7783
|
+
? sanitizePath(options.sourceReelWorkdir, '--reel-workdir')
|
|
7784
|
+
: uniqueSourceReelWorkdir(sourceDir));
|
|
7785
|
+
const outputPath = resolve(options.sourceReelOutput
|
|
7786
|
+
? sanitizePath(options.sourceReelOutput, '--reel-output')
|
|
7787
|
+
: join(workdir, options.sourceReelLoop ? 'source-reel-loop.mp4' : 'source-reel.mp4'));
|
|
7788
|
+
|
|
7789
|
+
const imagePrompt = options.sourceReelImagePrompt || options.prompt || SOURCE_REEL_DEFAULT_IMAGE_PROMPT;
|
|
7790
|
+
const transitionBasePrompt = options.sourceReelTransitionPrompt || SOURCE_REEL_DEFAULT_TRANSITION_PROMPT;
|
|
7791
|
+
const promptOverrides = loadSourceReelTransitionPromptOverrides(options.sourceReelTransitionPrompts);
|
|
7792
|
+
const model = options.sourceReelModel || (cliSet.model ? options.model : null) || SOURCE_REEL_DEFAULT_MODEL;
|
|
7793
|
+
const fps = cliSet.fps ? options.fps : 32;
|
|
7794
|
+
const concurrency = options.sourceReelConcurrency || 2;
|
|
7795
|
+
|
|
7796
|
+
const clips = images.map((image) => ({
|
|
7797
|
+
...image,
|
|
7798
|
+
refPath: join(workdir, 'refs', `${image.id}-${image.slug}.jpg`),
|
|
7799
|
+
clipPath: join(workdir, 'clips', `${image.id}-${image.slug}.mp4`),
|
|
7800
|
+
logPath: join(workdir, 'logs', 'clips', `${image.id}-${image.slug}.log`),
|
|
7801
|
+
prompt: imagePrompt
|
|
7802
|
+
}));
|
|
7803
|
+
|
|
7804
|
+
const transitionCount = images.length > 1
|
|
7805
|
+
? (options.sourceReelLoop ? images.length : images.length - 1)
|
|
7806
|
+
: 0;
|
|
7807
|
+
const transitions = [];
|
|
7808
|
+
for (let i = 0; i < transitionCount; i++) {
|
|
7809
|
+
const from = clips[i];
|
|
7810
|
+
const to = clips[(i + 1) % clips.length];
|
|
7811
|
+
const key = `${from.id}-to-${to.id}`;
|
|
7812
|
+
const override = sourceReelTransitionOverride(promptOverrides, i, from, to);
|
|
7813
|
+
const body = override || transitionBasePrompt;
|
|
7814
|
+
const prompt =
|
|
7815
|
+
`Start exactly on the first reference frame and end exactly on the second reference frame. ` +
|
|
7816
|
+
`${body}`;
|
|
7817
|
+
transitions.push({
|
|
7818
|
+
key,
|
|
7819
|
+
from: from.id,
|
|
7820
|
+
to: to.id,
|
|
7821
|
+
lastFramePath: join(workdir, 'frames', `${from.id}-${from.slug}-last.png`),
|
|
7822
|
+
firstFramePath: join(workdir, 'frames', `${to.id}-${to.slug}-first.png`),
|
|
7823
|
+
clipPath: join(workdir, 'transitions', `${key}.mp4`),
|
|
7824
|
+
logPath: join(workdir, 'logs', 'transitions', `${key}.log`),
|
|
7825
|
+
prompt
|
|
7826
|
+
});
|
|
7827
|
+
}
|
|
7828
|
+
|
|
7829
|
+
return {
|
|
7830
|
+
type: 'source-reel',
|
|
7831
|
+
sourceDir,
|
|
7832
|
+
workdir,
|
|
7833
|
+
outputPath,
|
|
7834
|
+
model,
|
|
7835
|
+
fps,
|
|
7836
|
+
dimensions,
|
|
7837
|
+
targetResolution: options.sourceReelTargetResolution,
|
|
7838
|
+
imageSeconds: options.sourceReelImageSeconds,
|
|
7839
|
+
transitionSeconds: options.sourceReelTransitionSeconds,
|
|
7840
|
+
loop: Boolean(options.sourceReelLoop),
|
|
7841
|
+
concurrency,
|
|
7842
|
+
imagePrompt,
|
|
7843
|
+
transitionBasePrompt,
|
|
7844
|
+
clips,
|
|
7845
|
+
transitions
|
|
7846
|
+
};
|
|
7847
|
+
}
|
|
7848
|
+
|
|
7849
|
+
function printSourceReelPlan(plan) {
|
|
7850
|
+
console.log('SourceReel plan');
|
|
7851
|
+
console.log(` Source folder: ${plan.sourceDir}`);
|
|
7852
|
+
console.log(` Working folder: ${plan.workdir}`);
|
|
7853
|
+
console.log(` Final output: ${plan.outputPath}`);
|
|
7854
|
+
console.log(` Images: ${plan.clips.length}`);
|
|
7855
|
+
console.log(` Clip seconds: ${plan.imageSeconds}`);
|
|
7856
|
+
console.log(` Transition seconds: ${plan.transitionSeconds}`);
|
|
7857
|
+
console.log(` Loop lastβfirst: ${plan.loop ? 'yes' : 'no'}`);
|
|
7858
|
+
console.log(` Model: ${plan.model}`);
|
|
7859
|
+
console.log(` FPS: ${plan.fps}`);
|
|
7860
|
+
if (plan.dimensions) {
|
|
7861
|
+
console.log(` Size: ${plan.dimensions.width}x${plan.dimensions.height}`);
|
|
7862
|
+
} else {
|
|
7863
|
+
console.log(` Size: infer from first image, short side ${plan.targetResolution}px`);
|
|
7864
|
+
}
|
|
7865
|
+
console.log('');
|
|
7866
|
+
console.log('Clip prompt:');
|
|
7867
|
+
console.log(` ${plan.imagePrompt}`);
|
|
7868
|
+
console.log('');
|
|
7869
|
+
console.log('Default transition prompt:');
|
|
7870
|
+
console.log(` ${plan.transitionBasePrompt}`);
|
|
7871
|
+
console.log('');
|
|
7872
|
+
console.log('Images:');
|
|
7873
|
+
for (const clip of plan.clips) {
|
|
7874
|
+
console.log(` ${clip.id}. ${clip.name}`);
|
|
7875
|
+
}
|
|
7876
|
+
if (plan.transitions.length > 0) {
|
|
7877
|
+
console.log('');
|
|
7878
|
+
console.log('Transitions:');
|
|
7879
|
+
for (const transition of plan.transitions) {
|
|
7880
|
+
console.log(` ${transition.key}: ${transition.prompt}`);
|
|
7881
|
+
}
|
|
7882
|
+
}
|
|
7883
|
+
console.log('');
|
|
7884
|
+
console.log('Run the same command without --reel-plan-only to render.');
|
|
7885
|
+
}
|
|
7886
|
+
|
|
7887
|
+
async function prepareSourceReelReferenceImages(plan, log) {
|
|
7888
|
+
const refsDir = join(plan.workdir, 'refs');
|
|
7889
|
+
mkdirSync(refsDir, { recursive: true });
|
|
7890
|
+
|
|
7891
|
+
let dimensions = plan.dimensions;
|
|
7892
|
+
if (!dimensions) {
|
|
7893
|
+
const metadata = await sharp(plan.clips[0].path).rotate().metadata();
|
|
7894
|
+
dimensions = inferSourceReelDimensions(metadata, plan.targetResolution);
|
|
7895
|
+
plan.dimensions = dimensions;
|
|
7896
|
+
}
|
|
7897
|
+
|
|
7898
|
+
for (const clip of plan.clips) {
|
|
7899
|
+
if (isNonEmptyFile(clip.refPath)) {
|
|
7900
|
+
log(`SKIP ref ${clip.refPath}`);
|
|
7901
|
+
continue;
|
|
7902
|
+
}
|
|
7903
|
+
const background = await sharp(clip.path)
|
|
7904
|
+
.rotate()
|
|
7905
|
+
.resize(dimensions.width, dimensions.height, { fit: 'cover' })
|
|
7906
|
+
.blur(28)
|
|
7907
|
+
.modulate({ brightness: 0.72, saturation: 0.9 })
|
|
7908
|
+
.jpeg({ quality: 90 })
|
|
7909
|
+
.toBuffer();
|
|
7910
|
+
const foreground = await sharp(clip.path)
|
|
7911
|
+
.rotate()
|
|
7912
|
+
.resize(dimensions.width, dimensions.height, {
|
|
7913
|
+
fit: 'contain',
|
|
7914
|
+
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
7915
|
+
})
|
|
7916
|
+
.png()
|
|
7917
|
+
.toBuffer();
|
|
7918
|
+
await sharp(background)
|
|
7919
|
+
.composite([{ input: foreground, gravity: 'center' }])
|
|
7920
|
+
.jpeg({ quality: 95 })
|
|
7921
|
+
.toFile(clip.refPath);
|
|
7922
|
+
log(`REF ${clip.name} -> ${clip.refPath}`);
|
|
7923
|
+
}
|
|
7924
|
+
}
|
|
7925
|
+
|
|
7926
|
+
async function runSourceReelPool(items, concurrency, worker) {
|
|
7927
|
+
let next = 0;
|
|
7928
|
+
const workers = Array.from({ length: Math.min(concurrency, items.length) }, async () => {
|
|
7929
|
+
while (next < items.length) {
|
|
7930
|
+
const index = next++;
|
|
7931
|
+
await worker(items[index], index);
|
|
7932
|
+
}
|
|
7933
|
+
});
|
|
7934
|
+
await Promise.all(workers);
|
|
7935
|
+
}
|
|
7936
|
+
|
|
7937
|
+
function sourceReelChildArgs(baseArgs, outputPath, prompt, plan, duration) {
|
|
7938
|
+
const args = [
|
|
7939
|
+
fileURLToPath(import.meta.url),
|
|
7940
|
+
'--no-update-check',
|
|
7941
|
+
'-q',
|
|
7942
|
+
'--json',
|
|
7943
|
+
'--video',
|
|
7944
|
+
'-m', plan.model,
|
|
7945
|
+
'--duration', String(duration),
|
|
7946
|
+
'--fps', String(plan.fps),
|
|
7947
|
+
'-w', String(plan.dimensions.width),
|
|
7948
|
+
'-h', String(plan.dimensions.height),
|
|
7949
|
+
'-o', outputPath,
|
|
7950
|
+
...baseArgs
|
|
7951
|
+
];
|
|
7952
|
+
if (options.tokenType) args.push('--token-type', options.tokenType);
|
|
7953
|
+
if (options.steps !== null && options.steps !== undefined) args.push('--steps', String(options.steps));
|
|
7954
|
+
if (options.guidance !== null && options.guidance !== undefined) args.push('--guidance', String(options.guidance));
|
|
7955
|
+
if (options.noFilter) args.push('--no-filter');
|
|
7956
|
+
if (options.strictSize) args.push('--strict-size');
|
|
7957
|
+
if (cliSet.timeout) args.push('-t', String(Math.ceil(options.timeout / 1000)));
|
|
7958
|
+
args.push(prompt);
|
|
7959
|
+
return args;
|
|
7960
|
+
}
|
|
7961
|
+
|
|
7962
|
+
function parseSourceReelChildJson(stdout) {
|
|
7963
|
+
const text = String(stdout || '').trim();
|
|
7964
|
+
if (!text) return null;
|
|
7965
|
+
try {
|
|
7966
|
+
return JSON.parse(text);
|
|
7967
|
+
} catch {
|
|
7968
|
+
const lastLine = text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).pop();
|
|
7969
|
+
if (!lastLine) return null;
|
|
7970
|
+
try { return JSON.parse(lastLine); } catch { return null; }
|
|
7971
|
+
}
|
|
7972
|
+
}
|
|
7973
|
+
|
|
7974
|
+
async function runSourceReelChild(label, args, logPath, outputPath) {
|
|
7975
|
+
const result = await runCommand(process.execPath, args, { captureOutput: true });
|
|
7976
|
+
const parsed = parseSourceReelChildJson(result.stdout);
|
|
7977
|
+
const logBody = [
|
|
7978
|
+
`label=${label}`,
|
|
7979
|
+
`command=${process.execPath} ${args.map((x) => JSON.stringify(x)).join(' ')}`,
|
|
7980
|
+
'',
|
|
7981
|
+
'stdout:',
|
|
7982
|
+
result.stdout || '',
|
|
7983
|
+
'',
|
|
7984
|
+
'stderr:',
|
|
7985
|
+
result.stderr || ''
|
|
7986
|
+
].join('\n');
|
|
7987
|
+
writeOutputFileSafe(logPath, Buffer.from(logBody), 'SourceReel render log');
|
|
7988
|
+
if (result.error || result.status !== 0 || !parsed?.success || !isNonEmptyFile(outputPath)) {
|
|
7989
|
+
const err = new Error(`SourceReel render failed: ${label}`);
|
|
7990
|
+
err.code = parsed?.errorCode || parsed?.code || 'SOURCE_REEL_RENDER_FAILED';
|
|
7991
|
+
err.hint = parsed?.hint || `See log: ${logPath}`;
|
|
7992
|
+
err.details = { label, outputPath, logPath, status: result.status, child: parsed || null };
|
|
7993
|
+
throw err;
|
|
7994
|
+
}
|
|
7995
|
+
return parsed;
|
|
7996
|
+
}
|
|
7997
|
+
|
|
7998
|
+
async function runSourceReel(log) {
|
|
7999
|
+
const plan = buildSourceReelPlan();
|
|
8000
|
+
if (options.sourceReelPlanOnly) {
|
|
8001
|
+
if (options.json || JSON_ERROR_MODE) {
|
|
8002
|
+
console.log(JSON.stringify({ success: true, ...plan, timestamp: new Date().toISOString() }));
|
|
8003
|
+
} else {
|
|
8004
|
+
printSourceReelPlan(plan);
|
|
8005
|
+
}
|
|
8006
|
+
return;
|
|
8007
|
+
}
|
|
8008
|
+
|
|
8009
|
+
mkdirSync(plan.workdir, { recursive: true });
|
|
8010
|
+
mkdirSync(join(plan.workdir, 'clips'), { recursive: true });
|
|
8011
|
+
mkdirSync(join(plan.workdir, 'transitions'), { recursive: true });
|
|
8012
|
+
mkdirSync(join(plan.workdir, 'frames'), { recursive: true });
|
|
8013
|
+
mkdirSync(join(plan.workdir, 'logs', 'clips'), { recursive: true });
|
|
8014
|
+
mkdirSync(join(plan.workdir, 'logs', 'transitions'), { recursive: true });
|
|
8015
|
+
|
|
8016
|
+
await prepareSourceReelReferenceImages(plan, log);
|
|
8017
|
+
writeOutputFileSafe(join(plan.workdir, 'plan.json'), Buffer.from(JSON.stringify(plan, null, 2)), 'SourceReel plan');
|
|
8018
|
+
|
|
8019
|
+
log(`SourceReel rendering ${plan.clips.length} clips (${plan.imageSeconds}s each)...`);
|
|
8020
|
+
await runSourceReelPool(plan.clips, plan.concurrency, async (clip) => {
|
|
8021
|
+
if (isNonEmptyFile(clip.clipPath)) {
|
|
8022
|
+
log(`SKIP clip ${clip.clipPath}`);
|
|
8023
|
+
return;
|
|
8024
|
+
}
|
|
8025
|
+
log(`START clip ${clip.id} ${clip.name}`);
|
|
8026
|
+
const args = sourceReelChildArgs(['--ref', clip.refPath], clip.clipPath, clip.prompt, plan, plan.imageSeconds);
|
|
8027
|
+
await runSourceReelChild(`clip ${clip.id}`, args, clip.logPath, clip.clipPath);
|
|
8028
|
+
log(`DONE clip ${clip.id} -> ${clip.clipPath}`);
|
|
8029
|
+
});
|
|
8030
|
+
|
|
8031
|
+
for (const transition of plan.transitions) {
|
|
8032
|
+
const fromClip = plan.clips.find((clip) => clip.id === transition.from);
|
|
8033
|
+
const toClip = plan.clips.find((clip) => clip.id === transition.to);
|
|
8034
|
+
if (!isNonEmptyFile(transition.lastFramePath)) {
|
|
8035
|
+
log(`FRAME last ${fromClip.clipPath} -> ${transition.lastFramePath}`);
|
|
8036
|
+
await extractLastFrameFromVideo(fromClip.clipPath, transition.lastFramePath);
|
|
8037
|
+
}
|
|
8038
|
+
if (!isNonEmptyFile(transition.firstFramePath)) {
|
|
8039
|
+
log(`FRAME first ${toClip.clipPath} -> ${transition.firstFramePath}`);
|
|
8040
|
+
await extractFirstFrameFromVideo(toClip.clipPath, transition.firstFramePath);
|
|
8041
|
+
}
|
|
8042
|
+
}
|
|
8043
|
+
|
|
8044
|
+
if (plan.transitions.length > 0) {
|
|
8045
|
+
log(`SourceReel rendering ${plan.transitions.length} transitions (${plan.transitionSeconds}s each)...`);
|
|
8046
|
+
await runSourceReelPool(plan.transitions, plan.concurrency, async (transition) => {
|
|
8047
|
+
if (isNonEmptyFile(transition.clipPath)) {
|
|
8048
|
+
log(`SKIP transition ${transition.clipPath}`);
|
|
8049
|
+
return;
|
|
8050
|
+
}
|
|
8051
|
+
log(`START transition ${transition.key}`);
|
|
8052
|
+
const args = sourceReelChildArgs(
|
|
8053
|
+
['--ref', transition.lastFramePath, '--ref-end', transition.firstFramePath],
|
|
8054
|
+
transition.clipPath,
|
|
8055
|
+
transition.prompt,
|
|
8056
|
+
plan,
|
|
8057
|
+
plan.transitionSeconds
|
|
8058
|
+
);
|
|
8059
|
+
await runSourceReelChild(`transition ${transition.key}`, args, transition.logPath, transition.clipPath);
|
|
8060
|
+
log(`DONE transition ${transition.key} -> ${transition.clipPath}`);
|
|
8061
|
+
});
|
|
8062
|
+
}
|
|
8063
|
+
|
|
8064
|
+
const concatParts = [];
|
|
8065
|
+
for (const clip of plan.clips) {
|
|
8066
|
+
concatParts.push(clip.clipPath);
|
|
8067
|
+
const transition = plan.transitions.find((item) => item.from === clip.id);
|
|
8068
|
+
if (transition) concatParts.push(transition.clipPath);
|
|
8069
|
+
}
|
|
8070
|
+
|
|
8071
|
+
if (concatParts.length === 1) {
|
|
8072
|
+
// Single-image reels have no bridge clips. Normalize through concat anyway
|
|
8073
|
+
// would require two inputs, so preserve the generated clip as the final.
|
|
8074
|
+
const buffer = readFileSync(concatParts[0]);
|
|
8075
|
+
writeOutputFileSafe(plan.outputPath, buffer, 'SourceReel final video');
|
|
8076
|
+
} else {
|
|
8077
|
+
log(`SourceReel stitching ${concatParts.length} clips -> ${plan.outputPath}`);
|
|
8078
|
+
await buildConcatVideoFromClips(plan.outputPath, concatParts, { targetFps: plan.fps });
|
|
8079
|
+
}
|
|
8080
|
+
|
|
8081
|
+
if (options.json || JSON_ERROR_MODE) {
|
|
8082
|
+
console.log(JSON.stringify({
|
|
8083
|
+
success: true,
|
|
8084
|
+
type: 'source-reel',
|
|
8085
|
+
sourceDir: plan.sourceDir,
|
|
8086
|
+
workdir: plan.workdir,
|
|
8087
|
+
outputPath: plan.outputPath,
|
|
8088
|
+
imageCount: plan.clips.length,
|
|
8089
|
+
transitionCount: plan.transitions.length,
|
|
8090
|
+
imageSeconds: plan.imageSeconds,
|
|
8091
|
+
transitionSeconds: plan.transitionSeconds,
|
|
8092
|
+
loop: plan.loop,
|
|
8093
|
+
model: plan.model,
|
|
8094
|
+
fps: plan.fps,
|
|
8095
|
+
width: plan.dimensions.width,
|
|
8096
|
+
height: plan.dimensions.height,
|
|
8097
|
+
timestamp: new Date().toISOString()
|
|
8098
|
+
}));
|
|
8099
|
+
} else {
|
|
8100
|
+
console.log(`SourceReel complete: ${plan.outputPath}`);
|
|
8101
|
+
console.log(`Working folder: ${plan.workdir}`);
|
|
8102
|
+
}
|
|
8103
|
+
}
|
|
8104
|
+
|
|
7546
8105
|
async function runImageEditProjectWithEvents(client, editConfig, expectedCount, log, timeoutMs, label) {
|
|
7547
8106
|
const results = [];
|
|
7548
8107
|
let completed = 0;
|
|
@@ -8479,6 +9038,11 @@ async function main() {
|
|
|
8479
9038
|
return;
|
|
8480
9039
|
}
|
|
8481
9040
|
|
|
9041
|
+
if (options.sourceReelDir) {
|
|
9042
|
+
await runSourceReel(log);
|
|
9043
|
+
return;
|
|
9044
|
+
}
|
|
9045
|
+
|
|
8482
9046
|
if (options.remixAudio) {
|
|
8483
9047
|
const inputVideo = sanitizePath(options.remixAudio, '--remix-audio input');
|
|
8484
9048
|
const outputVideo = sanitizePath(options.remixAudioOutput, '--remix-audio output');
|
package/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = '3.
|
|
1
|
+
export const PACKAGE_VERSION = '3.13.0';
|