1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
use std::path::PathBuf;
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use continuator::{
ContinueVideoRequest, CreateVideoRequest, ProviderKind, SoraConfig, VideoManager, VideoVariant,
};
use tracing::info;
use tracing_subscriber::EnvFilter;
#[derive(Parser, Debug)]
#[command(author, version, about = "Generate and extend Continuator video slices via the CLI", long_about = None)]
struct Cli {
/// Video generation backend (sora or veo).
#[arg(long, global = true, value_enum)]
provider: Option<ProviderKind>,
/// Override the OpenAI API key. Defaults to the OPENAI_API_KEY environment variable.
#[arg(long, global = true)]
api_key: Option<String>,
/// Default Sora model (e.g., sora-2 or sora-2-pro).
#[arg(long, global = true)]
model: Option<String>,
/// Default output size (e.g., 1280x720).
#[arg(long, global = true)]
size: Option<String>,
/// Default clip length in seconds.
#[arg(long, global = true)]
seconds: Option<u32>,
/// Directory for storing videos and metadata (defaults to ./videos).
#[arg(long, global = true)]
data_dir: Option<PathBuf>,
/// Poll interval in milliseconds when waiting for renders.
#[arg(long, global = true)]
poll_interval_ms: Option<u64>,
/// Google Cloud project id for Veo.
#[arg(long, global = true)]
gcp_project: Option<String>,
/// Google Cloud location for Veo (for example, us-central1).
#[arg(long, global = true)]
gcp_location: Option<String>,
/// Pre-fetched Google Cloud access token for Veo requests.
#[arg(long, global = true)]
gcp_access_token: Option<String>,
/// Cloud Storage URI to store Veo outputs instead of returning bytes.
#[arg(long, global = true)]
gcp_storage_uri: Option<String>,
/// Whether Veo should generate audio (defaults to true).
#[arg(long, global = true)]
gcp_generate_audio: Option<bool>,
/// Preferred Veo resolution (720p or 1080p).
#[arg(long, global = true)]
gcp_resolution: Option<String>,
/// Whether Veo should let Gemini enhance prompts (defaults to true).
#[arg(long, global = true)]
gcp_enhance_prompt: Option<bool>,
#[command(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
/// Create a brand-new clip.
Create {
/// Local identifier used for filenames (e.g., intro-001).
#[arg(long)]
id: String,
/// Prompt describing the clip.
#[arg(long)]
prompt: String,
/// Override the model for this clip.
#[arg(long)]
model: Option<String>,
/// Override the size for this clip.
#[arg(long)]
size: Option<String>,
/// Override the duration in seconds.
#[arg(long)]
seconds: Option<u32>,
},
/// Generate a sequence of clips from multiple prompts and stitch them.
Flow {
/// Base identifier used for generated clip filenames and final stitch.
#[arg(long)]
id: String,
/// Optional starting clip to continue from.
#[arg(long)]
start_from: Option<String>,
/// Override the model for generated clips.
#[arg(long)]
model: Option<String>,
/// Override the size for generated clips.
#[arg(long)]
size: Option<String>,
/// Override the duration in seconds for generated clips.
#[arg(long)]
seconds: Option<u32>,
/// One or more prompts describing each beat of the flow.
#[arg(required = true)]
prompts: Vec<String>,
},
/// Generate a continuation clip using the last frame of an existing video.
Continue {
/// Local identifier of the clip to extend.
#[arg(long = "from")]
parent_id: String,
/// Local identifier to assign to the new clip.
#[arg(long)]
id: String,
/// Prompt defining the next beat of the scene.
#[arg(long)]
prompt: String,
/// Override the model for this clip.
#[arg(long)]
model: Option<String>,
/// Override the size for this clip.
#[arg(long)]
size: Option<String>,
/// Override the duration in seconds.
#[arg(long)]
seconds: Option<u32>,
},
/// List locally stored clips and continuations.
List,
/// Download alternate assets (thumbnail or spritesheet) for a clip.
Download {
/// Local identifier of the clip.
#[arg(long)]
id: String,
/// Asset variant to download.
#[arg(long, value_enum)]
variant: AssetVariant,
/// Output path for the asset.
#[arg(long)]
output: PathBuf,
},
/// Concatenate local clips into a single output MP4.
Stitch {
/// Local identifier to assign to the stitched clip output file.
#[arg(long)]
id: String,
/// One or more clip identifiers to concatenate (positional arguments).
#[arg(required = true)]
clips: Vec<String>,
},
}
#[derive(Debug, Clone, clap::ValueEnum)]
enum AssetVariant {
Video,
Thumbnail,
Spritesheet,
}
#[tokio::main]
async fn main() -> Result<()> {
setup_tracing();
let cli = Cli::parse();
let config = SoraConfig {
provider: cli.provider,
api_key: cli.api_key,
model: cli.model,
size: cli.size,
seconds: cli.seconds,
data_dir: cli.data_dir,
poll_interval_ms: cli.poll_interval_ms,
gcp_project: cli.gcp_project,
gcp_location: cli.gcp_location,
gcp_access_token: cli.gcp_access_token,
gcp_storage_uri: cli.gcp_storage_uri,
gcp_generate_audio: cli.gcp_generate_audio,
gcp_resolution: cli.gcp_resolution,
gcp_enhance_prompt: cli.gcp_enhance_prompt,
};
let manager = VideoManager::new(config).context("failed to construct video manager")?;
match cli.command {
Command::Create {
id,
prompt,
model,
size,
seconds,
} => {
let metadata = manager
.create_video(CreateVideoRequest {
local_id: id.clone(),
prompt,
model,
size,
seconds,
})
.await?;
print_metadata(&metadata);
}
Command::Continue {
parent_id,
id,
prompt,
model,
size,
seconds,
} => {
let metadata = manager
.continue_video(ContinueVideoRequest {
parent_local_id: parent_id,
local_id: id.clone(),
prompt,
model,
size,
seconds,
})
.await?;
print_metadata(&metadata);
}
Command::Flow {
id,
start_from,
model,
size,
seconds,
prompts,
} => {
if prompts.is_empty() {
anyhow::bail!("flow requires at least one prompt");
}
let start_clip = start_from.clone();
let mut previous = start_from;
let mut generated_ids = Vec::new();
for (index, prompt) in prompts.into_iter().enumerate() {
let clip_local_id = format!("{}-{:02}", id, index + 1);
let metadata = if let Some(parent_id) = previous.clone() {
manager
.continue_video(ContinueVideoRequest {
parent_local_id: parent_id,
local_id: clip_local_id.clone(),
prompt,
model: model.clone(),
size: size.clone(),
seconds,
})
.await?
} else {
manager
.create_video(CreateVideoRequest {
local_id: clip_local_id.clone(),
prompt,
model: model.clone(),
size: size.clone(),
seconds,
})
.await?
};
print_metadata(&metadata);
previous = Some(metadata.local_id.clone());
generated_ids.push(metadata.local_id);
}
let mut clips_for_stitch = Vec::new();
if let Some(start) = start_clip {
clips_for_stitch.push(start);
}
clips_for_stitch.extend(generated_ids);
let stitched_path = manager
.stitch_videos(&id, &clips_for_stitch)
.await
.context("failed to stitch flow clips")?;
println!("flow stitched {} -> {}", id, stitched_path.display());
}
Command::List => {
let videos = manager.list_videos().await?;
if videos.is_empty() {
println!("(no clips recorded)");
} else {
for video in videos {
print_metadata(&video);
}
}
}
Command::Download {
id,
variant,
output,
} => {
let variant = match variant {
AssetVariant::Video => VideoVariant::Video,
AssetVariant::Thumbnail => VideoVariant::Thumbnail,
AssetVariant::Spritesheet => VideoVariant::Spritesheet,
};
manager
.download_asset(&id, variant, &output)
.await
.context("failed to download asset")?;
info!(path = %output.display(), "downloaded asset");
}
Command::Stitch { id, clips } => {
let path = manager
.stitch_videos(&id, &clips)
.await
.context("failed to stitch clips")?;
println!("stitched {} -> {}", id, path.display());
}
}
Ok(())
}
fn setup_tracing() {
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
let _ = tracing_subscriber::fmt()
.with_env_filter(filter)
.with_target(false)
.compact()
.try_init();
}
fn print_metadata(metadata: &continuator::VideoMetadata) {
println!("id: {}", metadata.local_id);
println!("remote_id: {}", metadata.remote_id);
println!("backend: {:?}", metadata.backend);
println!("model: {}", metadata.model);
println!("seconds: {}", metadata.seconds);
println!("size: {}", metadata.size);
if let Some(parent) = &metadata.parent {
println!("parent: {}", parent);
}
if let Some(created_at) = metadata.created_at {
println!("created_at: {}", created_at);
}
println!("file: {}", metadata.file_path.display());
println!("prompt: {}", metadata.prompt);
println!();
}