Composite Image + Video Generation → Final Merge
Three phases: composite scene images → video clips → merged final animation.
All shots are processed concurrently — for 15 shots the total runtime is roughly the time for one composite + one video, not 15× that.
Setup: .env
Same .env as Step 3. Only KIE_API_TOKEN is used here.
If no .env is present, the script auto-creates a template and exits:
KIE_API_TOKEN=your_kie_api_key_here
IMGBB_API_KEY=your_imgbb_api_key_here
Prerequisites
shots.jsonmust exist (from Skill 4)characters.jsonandbackgrounds.jsonmust haveimage_urlfields.envin project directory withKIE_API_TOKENfilled inpip install requests- FFmpeg installed and in PATH (for merge step)
- Windows:
winget install ffmpeg - Mac:
brew install ffmpeg - Linux:
sudo apt install ffmpeg
- Windows:
Running the Script
Per-shot mode (recommended — approve each clip before the next)
python scripts/generate_videos.py --shot shot_001
python scripts/generate_videos.py --shot shot_002
# ... etc.
Bulk mode (generate all shots at once)
cd /path/to/your/project
python scripts/generate_videos.py
What the Script Does
Phase 1 — Composite images (parallel, flux-2/pro-image-to-image)
input_urls= [backgroundimage_url, characterimage_url(s)]prompt= shotaction+ "Pixar-style 3D animation, cinematic 16:9 composition"- Polls until
state: success→ downloads to./composites/{shot_id}.png - Download result is verified (empty file = failure, retried)
Phase 2 — Video clips (parallel, grok-imagine/image-to-video)
image_urls= [composite URL from Phase 1]prompt=veo_promptfield fromshots.json- Downloads to
./clips/{shot_id}.mp4
Phase 3 — Merge clips (FFmpeg)
python scripts/merge_clips.py
- Reads shot order from
shots.json - Attempts stream copy first (fast) → auto-fallbacks to H.264 re-encode if codecs mismatch
- Output:
./final_animation.mp4
Configurable Settings (top of generate_videos.py)
| Setting | Default | Description |
|---|---|---|
COMPOSITE_MAX_WORKERS | 5 | Max parallel composite jobs |
VIDEO_MAX_WORKERS | 5 | Max parallel video jobs |
VIDEO_ASPECT_RATIO | "16:9" | "16:9", "9:16", "1:1" |
VIDEO_DURATION | 8 | Clip length in seconds (6–30) |
VIDEO_RESOLUTION | "720p" | "480p" or "720p" |
VIDEO_MODE | "normal" | "fun", "normal", or "spicy" |
MAX_RETRIES | 3 | Retry attempts on API errors |
POLL_INTERVAL | 5 | Seconds between status polls |
MAX_POLLS | 120 | Max polls per task (10 min timeout) |
These param names match the current
grok-imagine/image-to-videoAPI on kie.ai (duration/resolution/mode— NOT the oldern_frames/remove_watermark). Windows note: the script forces UTF-8 stdout so progress prints don't crash.
Transient errors — expect and retry
Grok Imagine intermittently returns Internal Error, Please try again later. on a few
shots in a large batch — this is a server-side hiccup, not a prompt or param problem.
The composites are already saved, so simply re-run the script: it skips finished
clips and regenerates only the failed ones. A single stubborn shot may need 2–3 retries.
Budget for this — a 12-shot project often costs ~20–30% more than the clip count alone
due to retries.
Regenerating Failed or Rejected Shots
- Delete
./composites/{shot_id}.pngand./clips/{shot_id}.mp4 - Optionally update
veo_promptinshots.json - Re-run the script — existing clips are skipped automatically
Review Gate (MANDATORY)
Per-shot mode — after EACH shot
🎬 Shot [shot_XXX] ready!
- Composite : ./composites/shot_XXX.png
- Video clip: ./clips/shot_XXX.mp4
- Run time : [X min]
👉 Please review this clip. You can:
- Approve → say "ok" or "next" to generate the next shot
- Redo → say "redo" (deletes composite + clip, re-runs same shot)
- Adjust → edit veo_prompt in shots.json, then say "redo"
⏸️ Waiting for your approval before generating shot_[next].
Bulk mode — after ALL shots
✅ Composite + Video Generation complete!
📋 Summary:
- Composite images: [X] → ./composites/
- Video clips: [X] → ./clips/
- Failed: [X] (list any failures)
- Total run time: [X min]
👉 Approve all → say "approved" or "merge" to proceed to final merge
Regenerate specific shots → e.g., "redo shot_003"
⏸️ Waiting for your approval before merging.
After merge
🎬 Final animation ready!
- Output : ./final_animation.mp4
- Size : [X] MB
- Clips : [X] merged in shot order
⏸️ The Story-to-Animation pipeline is complete.
NEVER mark the pipeline as complete without explicit user approval.