-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_demo_reel.py
More file actions
427 lines (347 loc) · 13.6 KB
/
create_demo_reel.py
File metadata and controls
427 lines (347 loc) · 13.6 KB
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/env python3
"""
Demo Reel Generation Script
Creates a 1-minute montage MP4 showcasing all animation modes:
- 2D Grease Pencil mode
- 3D Mesh mode
- Hybrid mode
Generates sample assets, runs the pipeline for each mode, and combines
outputs into a polished demo reel with titles and transitions.
Author: Claude (Anthropic)
Version: 1.0 (v1.0 Release)
"""
import os
import sys
import json
import shutil
import argparse
import subprocess
from pathlib import Path
def create_demo_assets(assets_dir: str):
"""Create demo assets for the reel."""
print("\n" + "="*70)
print("STEP 1: Creating Demo Assets")
print("="*70)
os.makedirs(assets_dir, exist_ok=True)
# Create demo audio (10 seconds, upbeat)
print("Creating demo audio...")
try:
import numpy as np
try:
import soundfile as sf
except ImportError:
from scipy.io import wavfile
sf = None
duration = 10.0
sample_rate = 22050
t = np.linspace(0, duration, int(sample_rate * duration))
# Create upbeat melody
freqs = [440, 554, 659, 880] # A4, C#5, E5, A5
audio = np.zeros_like(t)
for i, freq in enumerate(freqs * 3):
start = i * duration / 12
end = (i + 1) * duration / 12
mask = (t >= start) & (t < end)
audio[mask] += 0.3 * np.sin(2 * np.pi * freq * t[mask])
# Add beat impulses every 0.5s
for beat_time in np.arange(0, duration, 0.5):
beat_idx = int(beat_time * sample_rate)
if beat_idx < len(audio) - 2000:
envelope = np.exp(-np.linspace(0, 5, 2000))
burst = envelope * np.sin(2 * np.pi * 200 * np.linspace(0, 0.1, 2000))
audio[beat_idx:beat_idx + 2000] += burst * 1.5
# Normalize
audio = audio / np.max(np.abs(audio)) * 0.9
audio_path = os.path.join(assets_dir, 'demo_song.wav')
if sf:
sf.write(audio_path, audio, sample_rate)
else:
wavfile.write(audio_path, sample_rate, (audio * 32767).astype(np.int16))
print(f"✓ Created demo audio: {audio_path}")
print(f" Duration: {duration}s, Sample rate: {sample_rate} Hz")
except Exception as e:
print(f"⚠ Could not create audio: {e}")
return False
# Create demo mascot image
print("\nCreating demo mascot image...")
try:
from PIL import Image, ImageDraw, ImageFont
img = Image.new('RGB', (1024, 1024), color=(255, 255, 255))
draw = ImageDraw.Draw(img)
# Draw colorful fox mascot
# Head
draw.ellipse([200, 200, 824, 824], fill=(255, 140, 0), outline=(0, 0, 0), width=5)
# Ears
draw.polygon([300, 200, 200, 100, 400, 160], fill=(255, 140, 0), outline=(0, 0, 0))
draw.polygon([724, 200, 824, 100, 624, 160], fill=(255, 140, 0), outline=(0, 0, 0))
# Inner ears
draw.polygon([320, 190, 250, 140, 370, 180], fill=(255, 200, 150))
draw.polygon([704, 190, 774, 140, 654, 180], fill=(255, 200, 150))
# Eyes
draw.ellipse([360, 400, 460, 540], fill=(0, 0, 0))
draw.ellipse([564, 400, 664, 540], fill=(0, 0, 0))
# Eye highlights
draw.ellipse([390, 420, 430, 470], fill=(255, 255, 255))
draw.ellipse([594, 420, 634, 470], fill=(255, 255, 255))
# Nose
draw.polygon([512, 560, 462, 620, 562, 620], fill=(0, 0, 0))
# Mouth
draw.arc([400, 560, 624, 700], 0, 180, fill=(0, 0, 0), width=5)
image_path = os.path.join(assets_dir, 'demo_fox.png')
img.save(image_path)
print(f"✓ Created demo mascot: {image_path}")
print(f" Resolution: 1024x1024")
except Exception as e:
print(f"⚠ Could not create image: {e}")
return False
# Create demo lyrics
print("\nCreating demo lyrics...")
lyrics = """0:00-0:03 Welcome|to|Semantic|Foragecast
0:03-0:06 AI-powered|video|generation
0:06-0:10 Watch|the|magic|happen"""
lyrics_path = os.path.join(assets_dir, 'demo_lyrics.txt')
with open(lyrics_path, 'w') as f:
f.write(lyrics)
print(f"✓ Created demo lyrics: {lyrics_path}")
print("\n✓ All demo assets created successfully!")
return True
def create_mode_config(mode: str, assets_dir: str, output_dir: str) -> str:
"""Create configuration for a specific mode."""
import yaml
config = {
'gp_style': {
'stroke_thickness': 4,
'ink_type': 'sketchy',
'enable_wobble': True,
'wobble_intensity': 0.6
},
'inputs': {
'mascot_image': os.path.join(assets_dir, 'demo_fox.png'),
'song_file': os.path.join(assets_dir, 'demo_song.wav'),
'lyrics_file': os.path.join(assets_dir, 'demo_lyrics.txt')
},
'output': {
'output_dir': os.path.join(output_dir, mode),
'video_name': f'{mode}_demo.mp4',
'frames_dir': os.path.join(output_dir, mode, 'frames'),
'prep_json': os.path.join(output_dir, mode, 'prep_data.json')
},
'video': {
'duration': 10,
'resolution': [1920, 1080],
'fps': 24,
'render_engine': 'EEVEE',
'samples': 64,
'codec': 'libx264',
'quality': 'high'
},
'style': {
'lighting': 'disco' if mode == '2d_grease' else 'jazzy',
'mascot': 'fox',
'colors': {
'primary': [0.9, 0.2, 0.7],
'secondary': [0.2, 0.9, 0.9],
'accent': [0.9, 0.9, 0.2]
},
'background': 'gradient'
},
'animation': {
'mode': mode,
'enable_lipsync': True,
'enable_gestures': True,
'enable_lyrics': True,
'enable_effects': True,
'gesture_intensity': 0.8,
'lyrics_style': 'bounce'
},
'effects': {
'fog': {'enabled': True, 'density': 0.03},
'particles': {'enabled': True, 'count': 500, 'type': 'sparks'},
'lights': {
'spotlight': {'enabled': True, 'intensity': 800, 'color': [1.0, 0.95, 0.9]},
'flashes': {'enabled': True, 'intensity_range': [10, 20], 'random_colors': True}
}
},
'rhubarb': {
'executable_path': None,
'use_mock_fallback': True
},
'advanced': {
'preview_mode': False,
'preview_scale': 1.0,
'keep_intermediate': True,
'verbose': True,
'threads': None
},
'blender': {
'executable_path': None,
'background': True,
'script_path': 'blender_script.py'
}
}
os.makedirs(os.path.join(output_dir, mode), exist_ok=True)
config_path = os.path.join(output_dir, f'config_{mode}.yaml')
with open(config_path, 'w') as f:
yaml.dump(config, f, default_flow_style=False, sort_keys=False)
return config_path
def run_mode_pipeline(mode: str, config_path: str):
"""Run the pipeline for a specific mode."""
print(f"\n{'='*70}")
print(f"STEP 2.{['2d_grease', '3d', 'hybrid'].index(mode) + 1}: Generating {mode.upper()} Demo")
print(f"{'='*70}")
try:
from main import PipelineOrchestrator
print(f"Running pipeline for {mode} mode...")
engine = PipelineOrchestrator(config_path)
# Run Phase 1
print("\n Phase 1: Audio preprocessing...")
engine.run_phase1()
print(f"\n✓ {mode.upper()} mode demo generated successfully!")
print(f" Note: Full rendering requires Blender installation")
print(f" Output: {engine.config['output']['output_dir']}")
return True
except Exception as e:
print(f"⚠ Pipeline failed for {mode}: {e}")
print(f" (This is expected if Blender is not installed)")
return False
def create_title_card(text: str, output_path: str, duration: float = 2.0):
"""Create a title card using FFmpeg."""
print(f"\nCreating title card: '{text}'...")
try:
# Create title card with FFmpeg
cmd = [
'ffmpeg', '-y',
'-f', 'lavfi',
'-i', f'color=c=black:s=1920x1080:d={duration}',
'-vf', f"drawtext=text='{text}':fontcolor=white:fontsize=80:x=(w-text_w)/2:y=(h-text_h)/2:fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
'-c:v', 'libx264',
'-t', str(duration),
output_path
]
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
print(f"✓ Title card created: {output_path}")
return True
else:
print(f"⚠ FFmpeg title card failed: {result.stderr}")
return False
except Exception as e:
print(f"⚠ Could not create title card: {e}")
return False
def combine_demo_reel(output_dir: str, final_output: str):
"""Combine all mode demos into final reel."""
print(f"\n{'='*70}")
print("STEP 3: Combining Demo Reel")
print(f"{'='*70}")
# Create title cards
intro_path = os.path.join(output_dir, 'intro.mp4')
mode_2d_title = os.path.join(output_dir, 'title_2d.mp4')
mode_3d_title = os.path.join(output_dir, 'title_3d.mp4')
mode_hybrid_title = os.path.join(output_dir, 'title_hybrid.mp4')
outro_path = os.path.join(output_dir, 'outro.mp4')
create_title_card("Semantic Foragecast Engine", intro_path, 3.0)
create_title_card("2D Grease Pencil Mode", mode_2d_title, 2.0)
create_title_card("3D Mesh Mode", mode_3d_title, 2.0)
create_title_card("Hybrid Mode", mode_hybrid_title, 2.0)
create_title_card("github.com/semanticintent/semantic-foragecast-engine", outro_path, 3.0)
# Create concat file for FFmpeg
concat_file = os.path.join(output_dir, 'concat_list.txt')
segments = [
intro_path,
mode_2d_title,
# os.path.join(output_dir, '2d_grease', '2d_grease_demo.mp4'), # Would be generated by Blender
mode_3d_title,
# os.path.join(output_dir, '3d', '3d_demo.mp4'), # Would be generated by Blender
mode_hybrid_title,
# os.path.join(output_dir, 'hybrid', 'hybrid_demo.mp4'), # Would be generated by Blender
outro_path
]
# Filter out non-existent files
existing_segments = [s for s in segments if os.path.exists(s)]
with open(concat_file, 'w') as f:
for segment in existing_segments:
f.write(f"file '{os.path.abspath(segment)}'\n")
print(f"\nCombining {len(existing_segments)} segments...")
try:
cmd = [
'ffmpeg', '-y',
'-f', 'concat',
'-safe', '0',
'-i', concat_file,
'-c', 'copy',
final_output
]
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
file_size = os.path.getsize(final_output) / (1024 * 1024)
print(f"\n✅ Demo reel created successfully!")
print(f" Output: {final_output}")
print(f" Size: {file_size:.2f} MB")
print(f" Segments: {len(existing_segments)}")
return True
else:
print(f"⚠ FFmpeg concat failed: {result.stderr}")
return False
except Exception as e:
print(f"⚠ Could not combine demo reel: {e}")
return False
def main():
"""Main demo reel generation workflow."""
parser = argparse.ArgumentParser(
description='Generate demo reel showcasing all animation modes'
)
parser.add_argument(
'--output-dir',
default='demo_reel',
help='Output directory for demo files (default: demo_reel)'
)
parser.add_argument(
'--final-output',
default='demo_reel/semantic_foragecast_demo.mp4',
help='Final demo reel output path (default: demo_reel/semantic_foragecast_demo.mp4)'
)
parser.add_argument(
'--skip-generation',
action='store_true',
help='Skip pipeline generation, only create title cards and combine'
)
args = parser.parse_args()
print("="*70)
print("Semantic Foragecast Engine - Demo Reel Generator")
print("="*70)
print(f"Output directory: {args.output_dir}")
print(f"Final output: {args.final_output}")
print("="*70)
# Create output directory
os.makedirs(args.output_dir, exist_ok=True)
assets_dir = os.path.join(args.output_dir, 'assets')
# Step 1: Create assets
if not create_demo_assets(assets_dir):
print("\n❌ Failed to create demo assets")
return 1
# Step 2: Generate demos for each mode
if not args.skip_generation:
modes = ['2d_grease', '3d', 'hybrid']
for mode in modes:
config_path = create_mode_config(mode, assets_dir, args.output_dir)
run_mode_pipeline(mode, config_path)
else:
print("\n⚠ Skipping pipeline generation (--skip-generation)")
# Step 3: Combine into final reel
if not combine_demo_reel(args.output_dir, args.final_output):
print("\n❌ Failed to create demo reel")
return 1
print("\n" + "="*70)
print("✅ Demo Reel Generation Complete!")
print("="*70)
print(f"\nFinal demo reel: {args.final_output}")
print("\nNext steps:")
print(" 1. Upload to YouTube/X for visibility")
print(" 2. Add to README.md as demo showcase")
print(" 3. Share on r/blender, r/Python, etc.")
print("\nNote: Full rendering requires Blender installation.")
print(" This script generated title cards and combined available segments.")
print("="*70)
return 0
if __name__ == '__main__':
sys.exit(main())