Animate Lumi wing strokes and narrate the promo through OpenRouter
This commit is contained in:
1 parent
284282fc10
commit
883f0eff65
15 files changed
+304
-54
No files matched your search
@@ -1173,7 +1173,7 @@ social-post-dry-run:
|
||||
screenshot: $(TARGET)
|
||||
./scripts/generate-screenshots.sh "$(TARGET)"
|
||||
|
||||
.PHONY: screenshot-verify screenshot-review screenshot-export screenshot-source-check play-preflight lumi-promo
|
||||
.PHONY: screenshot-verify screenshot-review screenshot-export screenshot-source-check play-preflight lumi-promo lumi-narration
|
||||
screenshot-source-check: $(ZI2C_BIN) | build-laws
|
||||
@ZI_CHECK_DEFINES="$(ZI_NATIVE_DEFINES)" python3 scripts/check-zi-sources.py $(ZI2ZIR_BIN) $(KRYON_DIR)/src/ui $(ZIRAN_DIR)/std $(KSS_DIR)/src
|
||||
|
||||
@@ -1192,6 +1192,9 @@ play-preflight:
|
||||
lumi-promo:
|
||||
python3 scripts/render-lumi-promo.py
|
||||
|
||||
lumi-narration:
|
||||
python3 scripts/generate-lumi-narration.py
|
||||
|
||||
test-tui-screenshot test-termi-screenshot:
|
||||
@$(MAKE) --no-print-directory KRYON_BACKEND=termi test-termi-screenshot-direct
|
||||
|
||||
|
||||
@@ -115,9 +115,14 @@ and the existing release workflow, which builds and publishes the signed
|
||||
Google Play AAB and owns release tags. A local build or commit is not a Play
|
||||
deployment.
|
||||
|
||||
`make lumi-promo` renders a 30-second portrait review MP4 from the exact
|
||||
`make lumi-promo` renders a narrated portrait review MP4 from the exact
|
||||
reviewed phone captures and the generated artwork in `design/lumi-promo/`.
|
||||
Lumi flies between screens with light trails and original synthesized bells.
|
||||
Lumi uses eight generated wing-flapping frames, flies to each screen and settles
|
||||
while a narrator explains it. The audio contains speech only, without music or
|
||||
sound effects. Scene timings expand to fit the complete spoken lines.
|
||||
`make lumi-narration` generates the stored narrator clips through OpenRouter
|
||||
using a locally configured `OPENROUTER_API_KEY`; unchanged clips are reused.
|
||||
The voice, script and provider options are in `design/lumi-promo/narration.json`.
|
||||
The chat example runs real local theme actions; the surrounding forest and
|
||||
glow are marketing effects. Inspect `build/lumi-promo/storyboard.jpg` and
|
||||
`build/lumi-promo/inner-breeze-lumi-review.mp4` before using it publicly.
|
||||
|
||||
@@ -9,5 +9,13 @@
|
||||
"transparent": false,
|
||||
"prompt": "Use case: ads-marketing. Asset type: portrait background plate for an Inner Breeze wellness app promo guided by Lumi, a glowing golden firefly. Create an enchanting cinematic forest glade at twilight in a premium soft storybook painted 3D style with delicate watercolor texture. Deep sage, teal, moss and midnight green foliage framing only the extreme bottom and side edges, many tiny warm gold firefly lights at different depths, soft volumetric moonlight and gentle golden light trails like breath rising toward the center. Calm spacious central area with an uncluttered deep teal-to-sage atmospheric gradient, where readable app screens will be composited later. Magical intimate and inviting, lush organic detail, exquisite soft glowing bokeh, subtle painterly paper texture. Portrait 9:16 composition. No characters, no letters or typography, no phones, no UI, no logos or watermark."
|
||||
},
|
||||
"lumi-flight-cycle.png": {
|
||||
"reference": "lumi-flight.png",
|
||||
"transparent": true,
|
||||
"columns": 4,
|
||||
"rows": 2,
|
||||
"frames": 8,
|
||||
"prompt": "Use case: ads-marketing. Asset type: transparent 8-frame wing-flapping sprite sheet for an animated video. Input image 1 is the Lumi identity reference; input image 2 is the existing animation sheet to fix. Recreate image 2 as an evenly spaced 4-column by 2-row grid of exactly 8 full-body frames, same warm olive green firefly Lumi and same soft painted 3D texture. Critical correction: shrink EVERY character so its complete antenna glow, wings and feet occupy ONLY the central 60 percent of its cell, leaving an empty transparent margin of at least 18 percent along EVERY side. No character part or glow can touch a cell edge. Keep precisely the same head center and body size in all 8 cells. Body stable; wings do real full up/down strokes. Sequential wing positions left-to-right then second row: frame 1 wings up, frame 2 middle downward, frame 3 wings fully down, frame 4 middle upward, frame 5 wings up, frame 6 middle downward, frame 7 wings fully down, frame 8 middle upward. Clearly distinct full strokes, not duplicate wings. Both delicate wings attached at the back, correct anatomy. No whole-body rotation or sliding. Preserve face and hands identically so playback doesn't flicker. Tiny feet gently flex with the strokes. Big friendly brown eyes and inviting smile. Golden glows localized close to antenna bulbs and belly, no large halo clouds. True transparent alpha everywhere outside the character. No scenery, no grid lines, no text or labels. Wide canvas 2:1 aspect ratio, high resolution. Character always fully contained within its allotted cell with very generous empty alpha padding."
|
||||
},
|
||||
"status": "Review artwork for a promo; does not change the in-app mascot or claim new customization capabilities."
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"model": "microsoft/mai-voice-2.1",
|
||||
"voice": "en-US-Harper:MAI-Voice-2.1",
|
||||
"response_format": "mp3",
|
||||
"speed": 1.0,
|
||||
"provider": {"options": {"azure": {"style": "narrator", "styledegree": 1.0}}},
|
||||
"clips": [
|
||||
"Meet Lumi. Your little guide to Inner Breeze.",
|
||||
"A space for your apps, and your daily rhythm.",
|
||||
"Take a breath. Find your calm. Make time to move.",
|
||||
"Build little habits that make every day brighter.",
|
||||
"Keep your plans in Lists, and your thoughts in Diary.",
|
||||
"Make it yours. Ask Lumi for a forest theme, then switch to dark mode.",
|
||||
"Inner Breeze. A little space, made for you."
|
||||
],
|
||||
"documentation": "https://openrouter.ai/docs/guides/overview/multimodal/tts"
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"config_sha256": "a3f0fbaea5ab604d86f9117572956e0597f18d314660c16c836e38ed431e1c83",
|
||||
"provider": "OpenRouter",
|
||||
"model": "microsoft/mai-voice-2.1",
|
||||
"voice": "en-US-Harper:MAI-Voice-2.1",
|
||||
"clips": [
|
||||
{
|
||||
"file": "clip-00.mp3",
|
||||
"text": "Meet Lumi. Your little guide to Inner Breeze.",
|
||||
"seconds": 3.648,
|
||||
"sha256": "31777f316cb9f786ea69a051be06fd82ad4a8e7508a1f739a9b6faa8a3dd4734",
|
||||
"generation_id": "gen-tts-1791514279-Tg7LWgrcfvxt2OIWjuDj"
|
||||
},
|
||||
{
|
||||
"file": "clip-01.mp3",
|
||||
"text": "A space for your apps, and your daily rhythm.",
|
||||
"seconds": 2.952,
|
||||
"sha256": "766bdb7e9ca8c44b6690170ab20ac61ddfcca4934947d4f369d150ea2a6e7224",
|
||||
"generation_id": "gen-tts-1791514280-LacvzXxRZsGdXgjW1xmY"
|
||||
},
|
||||
{
|
||||
"file": "clip-02.mp3",
|
||||
"text": "Take a breath. Find your calm. Make time to move.",
|
||||
"seconds": 4.752,
|
||||
"sha256": "f2ed561fa0b3c77775b4cc3b3a4fb19fa1ea6cb23cc0bbc4c7216305edd12f4f",
|
||||
"generation_id": "gen-tts-1791514282-FVKXyQSwJ0oGJecZ9MPL"
|
||||
},
|
||||
{
|
||||
"file": "clip-03.mp3",
|
||||
"text": "Build little habits that make every day brighter.",
|
||||
"seconds": 2.784,
|
||||
"sha256": "3685d1e6ec34bd1c2bbd98db10b0fd3e0cc3313bb14dfd1ccae596289eea849b",
|
||||
"generation_id": "gen-tts-1791514283-tIeLAmKNQfvB5vqNpjLR"
|
||||
},
|
||||
{
|
||||
"file": "clip-04.mp3",
|
||||
"text": "Keep your plans in Lists, and your thoughts in Diary.",
|
||||
"seconds": 3.48,
|
||||
"sha256": "34db8fdb37793e22425867fc5123d0abdac4cf8fa515f373b1553e7c4d31bef0",
|
||||
"generation_id": "gen-tts-1791514286-Be2DMWRxLmqQHWnLy2WK"
|
||||
},
|
||||
{
|
||||
"file": "clip-05.mp3",
|
||||
"text": "Make it yours. Ask Lumi for a forest theme, then switch to dark mode.",
|
||||
"seconds": 5.088,
|
||||
"sha256": "3a9816c6484ee089bdfd36bc15b8efd8d925b79ad4477c8b3680a3918706e4c5",
|
||||
"generation_id": "gen-tts-1791514288-kfGqTRkfR6gYKGQzSzTH"
|
||||
},
|
||||
{
|
||||
"file": "clip-06.mp3",
|
||||
"text": "Inner Breeze. A little space, made for you.",
|
||||
"seconds": 4.056,
|
||||
"sha256": "55e9a0c3b19a8c5b6f9eaf23bb81b1b3cc67a0a6b864f3aa57ad3103ef0c3eaa",
|
||||
"generation_id": "gen-tts-1791514290-ttQk1lQ5H3modKGaq95J"
|
||||
}
|
||||
],
|
||||
"music": false,
|
||||
"documentation": "https://openrouter.ai/docs/guides/overview/multimodal/tts"
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate the promo's spoken narration through OpenRouter, without music."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
ASSETS = ROOT / "design/lumi-promo"
|
||||
ENDPOINT = "https://openrouter.ai/api/v1/audio/speech"
|
||||
|
||||
|
||||
def digest(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def duration(path):
|
||||
return float(subprocess.check_output([
|
||||
"ffprobe", "-v", "error", "-show_entries", "format=duration",
|
||||
"-of", "default=noprint_wrappers=1:nokey=1", str(path)], text=True))
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--regenerate", action="store_true")
|
||||
args = parser.parse_args()
|
||||
config_path = ASSETS / "narration.json"
|
||||
config = json.loads(config_path.read_text())
|
||||
output = ASSETS / "narration"
|
||||
output.mkdir(exist_ok=True)
|
||||
receipt_path = output / "receipt.json"
|
||||
if receipt_path.is_file() and not args.regenerate:
|
||||
receipt = json.loads(receipt_path.read_text())
|
||||
if receipt["config_sha256"] == digest(config_path) and all(
|
||||
(output / row["file"]).is_file() and
|
||||
digest(output / row["file"]) == row["sha256"]
|
||||
for row in receipt["clips"]):
|
||||
print("Using the existing verified OpenRouter narration.")
|
||||
return
|
||||
key = os.environ.get("OPENROUTER_API_KEY", "")
|
||||
if not key:
|
||||
raise SystemExit("Set OPENROUTER_API_KEY locally before generating narration.")
|
||||
models_url = "https://openrouter.ai/api/v1/models?output_modalities=speech"
|
||||
with urllib.request.urlopen(models_url, timeout=30) as response:
|
||||
models = json.load(response)["data"]
|
||||
model = next((item for item in models if item["id"] == config["model"]), None)
|
||||
if model is None or config["voice"] not in model.get("supported_voices", []):
|
||||
raise SystemExit("The configured narrator model or voice is not in OpenRouter's current catalog.")
|
||||
rows = []
|
||||
for index, text in enumerate(config["clips"]):
|
||||
body = {name: config[name] for name in (
|
||||
"model", "voice", "response_format", "speed", "provider")}
|
||||
body["input"] = text
|
||||
request = urllib.request.Request(ENDPOINT,
|
||||
data=json.dumps(body).encode(), headers={
|
||||
"Authorization": "Bearer " + key,
|
||||
"Content-Type": "application/json",
|
||||
"X-Title": "Inner Breeze Lumi promo narration"})
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=90) as response:
|
||||
mime = response.headers.get_content_type()
|
||||
if not mime.startswith("audio/"):
|
||||
raise ValueError("OpenRouter returned a non-audio response")
|
||||
audio = response.read()
|
||||
generation = response.headers.get("X-Generation-Id")
|
||||
except urllib.error.HTTPError as error:
|
||||
raise SystemExit(f"OpenRouter narration request failed (HTTP {error.code}); no audio was saved.") from None
|
||||
if len(audio) < 1024:
|
||||
raise ValueError("OpenRouter returned empty or truncated narration")
|
||||
destination = output / f"clip-{index:02}.mp3"
|
||||
with tempfile.NamedTemporaryFile(suffix=".mp3", dir=output, delete=False) as stream:
|
||||
stream.write(audio)
|
||||
temporary = Path(stream.name)
|
||||
try:
|
||||
seconds = duration(temporary)
|
||||
if not 0.3 <= seconds <= 20:
|
||||
raise ValueError("Narration clip duration is outside the expected range")
|
||||
subprocess.run(["ffmpeg", "-v", "error", "-i", str(temporary),
|
||||
"-f", "null", "-"], check=True, capture_output=True)
|
||||
temporary.replace(destination)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
rows.append(dict(file=destination.name, text=text, seconds=seconds,
|
||||
sha256=digest(destination), generation_id=generation))
|
||||
print(f"Generated narrator line {index + 1}/{len(config['clips'])}: {seconds:.2f} seconds", flush=True)
|
||||
receipt = dict(config_sha256=digest(config_path), provider="OpenRouter",
|
||||
model=config["model"], voice=config["voice"], clips=rows,
|
||||
music=False, documentation=config["documentation"])
|
||||
receipt_path.write_text(json.dumps(receipt, indent=2) + "\n")
|
||||
print("Saved all narrator clips and their generation record.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+110
-51
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Render a captioned Lumi tour using the exact visually reviewed captures."""
|
||||
import argparse
|
||||
from collections import deque
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
@@ -11,7 +12,7 @@ import subprocess
|
||||
import wave
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFilter, ImageFont
|
||||
from PIL import Image, ImageDraw, ImageFilter, ImageFont, ImageOps
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
ASSETS = ROOT / "design/lumi-promo"
|
||||
@@ -39,23 +40,82 @@ def ease(value):
|
||||
return value * value * (3 - 2 * value)
|
||||
|
||||
|
||||
def soundtrack(path, seconds):
|
||||
"""An original quiet bell bed, synthesized here; no licensed music."""
|
||||
def narrated_story(path):
|
||||
"""Leave each spoken line enough time; never trim speech to fit a card."""
|
||||
config_path = ASSETS / "narration.json"
|
||||
narration = json.loads((ASSETS / "narration/receipt.json").read_text())
|
||||
assert narration["config_sha256"] == hashlib.sha256(config_path.read_bytes()).hexdigest()
|
||||
assert len(narration["clips"]) == len(STORY)
|
||||
rate = 48000
|
||||
time = np.arange(seconds * rate) / rate
|
||||
sound = np.zeros_like(time)
|
||||
for at, frequency in [(0, 261.63), (4, 329.63), (8, 392), (12, 523.25), (16, 392), (20, 329.63), (23, 523.25), (26, 261.63), (27, 392)]:
|
||||
offset = time - at
|
||||
active = offset >= 0
|
||||
envelope = np.exp(-np.maximum(offset, 0) / 2.7) * np.minimum(np.maximum(offset, 0) * 12, 1)
|
||||
sound += active * envelope * (np.sin(2 * math.pi * frequency * offset) + .22 * np.sin(2 * math.pi * frequency * 2.01 * offset)) * .075
|
||||
sound *= np.minimum(time, 1) * np.minimum(np.maximum(seconds - time, 0), 1)
|
||||
stereo = np.stack([sound, sound * .94], axis=1)
|
||||
story = []
|
||||
clips = []
|
||||
start = 0.0
|
||||
for beat, row in zip(STORY, narration["clips"]):
|
||||
audio = ASSETS / "narration" / row["file"]
|
||||
assert hashlib.sha256(audio.read_bytes()).hexdigest() == row["sha256"], "Narration changed; regenerate its receipt"
|
||||
raw = subprocess.check_output([
|
||||
"ffmpeg", "-v", "error", "-i", str(audio), "-af",
|
||||
"loudnorm=I=-16:TP=-1.5:LRA=7", "-ar", str(rate), "-ac", "1",
|
||||
"-f", "f32le", "pipe:1"])
|
||||
samples = np.frombuffer(raw, dtype="<f4")
|
||||
end = start + max(beat[1] - beat[0], len(samples) / rate + .65)
|
||||
story.append((start, end, *beat[2:]))
|
||||
clips.append((round((start + .25) * rate), samples))
|
||||
start = end
|
||||
sound = np.zeros(math.ceil(start * rate), dtype=np.float32)
|
||||
for offset, samples in clips:
|
||||
sound[offset:offset + len(samples)] = samples
|
||||
with wave.open(str(path), "wb") as stream:
|
||||
stream.setnchannels(2)
|
||||
stream.setnchannels(1)
|
||||
stream.setsampwidth(2)
|
||||
stream.setframerate(rate)
|
||||
stream.writeframes((stereo * 32767).astype("<i2").tobytes())
|
||||
stream.writeframes((np.clip(sound, -1, 1) * 32767).astype("<i2").tobytes())
|
||||
return story, start, narration
|
||||
|
||||
|
||||
def animation_frames():
|
||||
"""Slice the generated cycle and align eyes to avoid registration jitter."""
|
||||
atlas = Image.open(ASSETS / "lumi-flight-cycle.png").convert("RGBA")
|
||||
assert atlas.getchannel("A").getextrema() == (0, 255), "Lumi needs true transparency"
|
||||
tiles = []
|
||||
anchors = []
|
||||
side = round(atlas.width / 4)
|
||||
for index in range(8):
|
||||
column, row = index % 4, index // 4
|
||||
box = (round(column * atlas.width / 4), round(row * atlas.height / 2),
|
||||
round((column + 1) * atlas.width / 4), round((row + 1) * atlas.height / 2))
|
||||
tile = atlas.crop(box).resize((side, side), Image.Resampling.LANCZOS)
|
||||
pixels = np.asarray(tile)
|
||||
eyes = ((pixels[:, :, 0] < 65) & (pixels[:, :, 1] < 65) &
|
||||
(pixels[:, :, 2] < 60) & (pixels[:, :, 3] > 220))
|
||||
eyes[:int(side * .28)] = False
|
||||
eyes[int(side * .66):] = False
|
||||
eyes[:, :int(side * .38)] = False
|
||||
eyes[:, int(side * .81):] = False
|
||||
ys, xs = np.nonzero(eyes)
|
||||
assert len(xs) > 100, "Animation frame has no stable eye anchor"
|
||||
anchors.append((float(xs.mean()), float(ys.mean())))
|
||||
tiles.append(tile)
|
||||
target = np.mean(anchors, axis=0)
|
||||
aligned = []
|
||||
for tile, anchor in zip(tiles, anchors):
|
||||
canvas = Image.new("RGBA", tile.size)
|
||||
canvas.alpha_composite(tile, (round(target[0] - anchor[0]), round(target[1] - anchor[1])))
|
||||
aligned.append(canvas)
|
||||
return aligned
|
||||
|
||||
|
||||
def flight_position(index, local, width, height):
|
||||
"""Fly to a destination, settle there, then move when the scene changes."""
|
||||
targets = [(.5, .48), (.85, .66), (.85, .54), (.85, .66),
|
||||
(.85, .58), (.85, .65), (.5, .48)]
|
||||
origin = (-.3, .58) if index == 0 else targets[index - 1]
|
||||
target = targets[index]
|
||||
progress = ease(local / 1.35)
|
||||
x = origin[0] + (target[0] - origin[0]) * progress
|
||||
y = origin[1] + (target[1] - origin[1]) * progress
|
||||
y -= math.sin(progress * math.pi) * .045
|
||||
return x * width, y * height, progress
|
||||
|
||||
|
||||
def main():
|
||||
@@ -74,12 +134,10 @@ def main():
|
||||
width, height = args.width, args.height
|
||||
scale = width / 1080
|
||||
background = Image.open(ASSETS / "forest.png").convert("RGB")
|
||||
from PIL import ImageOps
|
||||
background = ImageOps.fit(background, (width, height)).convert("RGBA")
|
||||
shade = Image.new("RGBA", (width, height), (3, 19, 20, 90))
|
||||
background = Image.alpha_composite(background, shade)
|
||||
lumi = Image.open(ASSETS / "lumi-flight.png").convert("RGBA")
|
||||
assert lumi.getchannel("A").getextrema() == (0, 255), "Lumi needs true transparency"
|
||||
sprites = animation_frames()
|
||||
title_font = ImageFont.truetype(BOLD, int(54 * scale))
|
||||
small_font = ImageFont.truetype(FONT, int(29 * scale))
|
||||
brand_font = ImageFont.truetype(FONT, int(23 * scale))
|
||||
@@ -94,17 +152,20 @@ def main():
|
||||
cards[name] = picture
|
||||
randomizer = random.Random(42)
|
||||
motes = [(randomizer.random(), randomizer.random(), randomizer.uniform(.4, 1.4), randomizer.random() * math.tau) for _ in range(70)]
|
||||
audio = OUTPUT / "lumi-bells.wav"
|
||||
soundtrack(audio, 30)
|
||||
audio = OUTPUT / "lumi-narration.wav"
|
||||
story, seconds, narration = narrated_story(audio)
|
||||
destination = OUTPUT / "inner-breeze-lumi-review.mp4"
|
||||
command = ["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-f", "rawvideo", "-pixel_format", "rgb24", "-video_size", f"{width}x{height}", "-framerate", str(args.fps), "-i", "pipe:0", "-i", str(audio), "-c:v", "libx264", "-preset", "fast", "-crf", "19", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "160k", "-movflags", "+faststart", "-shortest", str(destination)]
|
||||
staged = OUTPUT / "inner-breeze-lumi-rendering.mp4"
|
||||
command = ["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-f", "rawvideo", "-pixel_format", "rgb24", "-video_size", f"{width}x{height}", "-framerate", str(args.fps), "-i", "pipe:0", "-i", str(audio), "-c:v", "libx264", "-preset", "fast", "-crf", "19", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "160k", "-movflags", "+faststart", "-shortest", str(staged)]
|
||||
review_frames = []
|
||||
trail = deque(maxlen=24)
|
||||
with (OUTPUT / "render.log").open("w") as log:
|
||||
encoder = subprocess.Popen(command, stdin=subprocess.PIPE, stderr=log)
|
||||
try:
|
||||
for frame in range(30 * args.fps):
|
||||
for frame in range(math.ceil(seconds * args.fps)):
|
||||
time = frame / args.fps
|
||||
start, end, title, subtitle, scene = next(beat for beat in STORY if beat[0] <= time < beat[1])
|
||||
index, beat = next((i, beat) for i, beat in enumerate(story) if beat[0] <= time < beat[1])
|
||||
start, end, title, subtitle, scene = beat
|
||||
local = time - start
|
||||
canvas = background.copy()
|
||||
draw = ImageDraw.Draw(canvas, "RGBA")
|
||||
@@ -119,70 +180,67 @@ def main():
|
||||
text_center(draw, subtitle, int(290 * scale), small_font, "#dfe9d8", width)
|
||||
if scene:
|
||||
card = cards[scene]
|
||||
if start == 20:
|
||||
card = Image.blend(cards["09-lumi-light"], cards[scene], ease((local - 2.5) / .8))
|
||||
if index == 5:
|
||||
card = Image.blend(cards["09-lumi-light"], cards[scene], ease((local / (end - start) - .43) / .14))
|
||||
left = (width - card_width) // 2
|
||||
top = int(410 * scale + 12 * scale * math.sin(time * .8))
|
||||
top = int(410 * scale)
|
||||
top += int((1 - ease(local / .7)) * 130 * scale)
|
||||
shadow = Image.new("RGBA", canvas.size)
|
||||
ImageDraw.Draw(shadow).rounded_rectangle((left - 12, top - 12, left + card_width + 12, top + card_height + 12), radius=int(48 * scale), fill=(193, 218, 150, 115))
|
||||
canvas = Image.alpha_composite(canvas, shadow.filter(ImageFilter.GaussianBlur(int(22 * scale))))
|
||||
canvas.alpha_composite(card, (left, top))
|
||||
# An orbiting guide and a glowing trail reveal each screen.
|
||||
progress = min(local / (end - start), 1)
|
||||
center_x = width * (.79 - .13 * math.sin(progress * math.pi))
|
||||
center_y = height * (.72 - .37 * progress)
|
||||
character_size = int(260 * scale)
|
||||
else:
|
||||
center_x = width * .5 + width * .13 * math.sin(local * 1.05)
|
||||
center_y = height * (.48 + .025 * math.sin(time * 2.2))
|
||||
character_size = int((570 if start == 0 else 500) * scale)
|
||||
center_x, center_y, progress = flight_position(index, local, width, height)
|
||||
previous_size = 570 if index <= 1 else 285
|
||||
target_size = 570 if index in (0, 6) else 285
|
||||
character_size = int((previous_size + (target_size - previous_size) * progress) * scale)
|
||||
draw = ImageDraw.Draw(canvas, "RGBA")
|
||||
for tail in range(32, 0, -1):
|
||||
px = center_x - tail * 5 * scale
|
||||
py = center_y + math.sin(time * 4 - tail * .14) * 18 * scale + tail * scale
|
||||
radius = (4 - tail / 12) * scale
|
||||
draw.ellipse((px - radius, py - radius, px + radius, py + radius), fill=(255, 222, 122, int(120 * (1 - tail / 33))))
|
||||
character = lumi.resize((character_size, character_size), Image.Resampling.LANCZOS)
|
||||
character = character.rotate(5 * math.sin(time * 3), resample=Image.Resampling.BICUBIC, expand=True)
|
||||
trail.append((center_x, center_y))
|
||||
for age, (px, py) in enumerate(trail):
|
||||
if math.hypot(px - center_x, py - center_y) > 8 * scale:
|
||||
radius = (1 + age / len(trail) * 2) * scale
|
||||
draw.ellipse((px - radius, py - radius, px + radius, py + radius), fill=(255, 222, 122, int(100 * age / len(trail))))
|
||||
phase = (time * 12) % len(sprites)
|
||||
pose = int(phase)
|
||||
character = Image.blend(sprites[pose], sprites[(pose + 1) % len(sprites)], ease(phase - pose))
|
||||
character = character.resize((character_size, character_size), Image.Resampling.LANCZOS)
|
||||
glow = Image.new("RGBA", canvas.size)
|
||||
glow_draw = ImageDraw.Draw(glow)
|
||||
radius = character_size * .31
|
||||
glow_draw.ellipse((center_x - radius, center_y - radius, center_x + radius, center_y + radius), fill=(255, 212, 105, 75))
|
||||
canvas = Image.alpha_composite(canvas, glow.filter(ImageFilter.GaussianBlur(int(42 * scale))))
|
||||
canvas.alpha_composite(character, (int(center_x - character.width / 2), int(center_y - character.height / 2)))
|
||||
if start == 16 and local < 1.6:
|
||||
if index == 4 and local < 1.6:
|
||||
thumbnail = cards["06-lists"].resize((int(width * .33), int(height * .33)), Image.Resampling.LANCZOS)
|
||||
canvas.alpha_composite(thumbnail, (int(width * .03), int(height * .5)))
|
||||
if start == 20:
|
||||
if index == 5:
|
||||
draw = ImageDraw.Draw(canvas, "RGBA")
|
||||
pill = "theme forest" if local < 3 else "/dark"
|
||||
pill = "theme forest" if local / (end - start) < .5 else "/dark"
|
||||
label_font = ImageFont.truetype(BOLD, int(32 * scale))
|
||||
pill_width = int(draw.textlength(pill, font=label_font) + 70 * scale)
|
||||
left = (width - pill_width) // 2
|
||||
draw.rounded_rectangle((left, int(1670 * scale), left + pill_width, int(1760 * scale)), radius=int(35 * scale), fill=(231, 239, 210, 245))
|
||||
text_center(draw, pill, int(1693 * scale), label_font, "#214332", width)
|
||||
if start == 26:
|
||||
if index == 6:
|
||||
draw = ImageDraw.Draw(canvas, "RGBA")
|
||||
text_center(draw, "Breathe · Grow · Make it yours", int(1390 * scale), small_font, "#fff0c2", width)
|
||||
fade = min(ease(time / .5), ease((30 - time) / .8))
|
||||
fade = min(ease(time / .5), ease((seconds - time) / .8))
|
||||
if fade < 1:
|
||||
canvas = Image.blend(Image.new("RGBA", canvas.size, "#071c1b"), canvas, fade)
|
||||
if abs(local - 1.5) < .5 / args.fps:
|
||||
path = OUTPUT / f"review-{start:02}.jpg"
|
||||
path = OUTPUT / f"review-{index:02}.jpg"
|
||||
canvas.convert("RGB").save(path, quality=93)
|
||||
review_frames.append(path)
|
||||
encoder.stdin.write(canvas.convert("RGB").tobytes())
|
||||
if frame % (args.fps * 4) == 0:
|
||||
print(f"Rendered {time:.0f}/30 seconds", flush=True)
|
||||
print(f"Rendered {time:.0f}/{seconds:.1f} seconds", flush=True)
|
||||
finally:
|
||||
encoder.stdin.close()
|
||||
assert encoder.wait() == 0, "video encoding failed; inspect render.log"
|
||||
harness.verify(reviewed=True, current=False)
|
||||
probe = json.loads(subprocess.check_output(["ffprobe", "-v", "error", "-show_streams", "-show_format", "-of", "json", str(destination)], text=True))
|
||||
probe = json.loads(subprocess.check_output(["ffprobe", "-v", "error", "-show_streams", "-show_format", "-of", "json", str(staged)], text=True))
|
||||
video = next(stream for stream in probe["streams"] if stream["codec_type"] == "video")
|
||||
assert (video["width"], video["height"]) == (width, height) and video["codec_name"] == "h264"
|
||||
assert abs(float(probe["format"]["duration"]) - 30) < .2
|
||||
assert abs(float(probe["format"]["duration"]) - seconds) < .2
|
||||
assert any(stream["codec_type"] == "audio" for stream in probe["streams"])
|
||||
sheet = Image.new("RGB", (280 * len(review_frames), 500), "#09221d")
|
||||
for index, path in enumerate(review_frames):
|
||||
@@ -190,7 +248,8 @@ def main():
|
||||
picture.thumbnail((280, 500))
|
||||
sheet.paste(picture, (index * 280, 0))
|
||||
sheet.save(OUTPUT / "storyboard.jpg", quality=95)
|
||||
receipt = dict(capture_sha256=harness.digest(harness.OUTPUT / "capture.json"), artwork={name: harness.digest(ASSETS / name) for name in ("lumi-flight.png", "forest.png")}, video_sha256=harness.digest(destination), seconds=30, width=width, height=height, fps=args.fps, status="owner-review", soundtrack="original synthesized bells", story=STORY)
|
||||
staged.replace(destination)
|
||||
receipt = dict(capture_sha256=harness.digest(harness.OUTPUT / "capture.json"), artwork={name: harness.digest(ASSETS / name) for name in ("lumi-flight-cycle.png", "forest.png")}, video_sha256=harness.digest(destination), seconds=seconds, width=width, height=height, fps=args.fps, status="owner-review", soundtrack="OpenRouter narrator only; no music or sound effects", narration_sha256=harness.digest(ASSETS / "narration/receipt.json"), narrator=dict(provider=narration["provider"], model=narration["model"], voice=narration["voice"]), animation_frames=len(sprites), story=story)
|
||||
harness.write_json(OUTPUT / "render-receipt.json", receipt)
|
||||
audio.unlink()
|
||||
print(f"Review video saved: {destination}")
|
||||
|
||||
Reference in new issue
Block a user