diff --git a/.claude/launch.json b/.claude/launch.json deleted file mode 100644 index cdaf4ad..0000000 --- a/.claude/launch.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": "0.0.1", - "configurations": [ - { - "name": "site", - "runtimeExecutable": "python3", - "runtimeArgs": ["-m", "http.server", "8766", "--directory", "site"], - "port": 8766 - } - ] -} diff --git a/.gitignore b/.gitignore index b4e5e2f..bda9111 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ HypeBlock_Konzept.pdf # ElevenLabs API key for the trailer voice-over (secret) elevenlabs-api-key.txt + +# Local Claude Code settings (preview config etc.) +.claude/ diff --git a/CLAUDE.md b/CLAUDE.md index de65a3a..03b744a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -41,6 +41,10 @@ The user speaks German; answer in German. `build/trailer/HypeBlock-Trailer[-de].mp4`. VO lines and cue times: `script.py`; event times in the footage (door/bridge open): constants at the top of `render.py`. - ElevenLabs key: `elevenlabs-api-key.txt` in the repo root (git-ignored, starts with `sk_`). +- Promo pieces: `promo.py short --lang en|de` (YouTube Short 1080x1920 from the vertical shots, + `HYPEBLOCK_TRAILER_VERTICAL=1` → `shots-vertical/`, voice `voiceover.py --script short`, burned-in + captions; the portrait window caps the GUI scale, so the HUD tile is magnified in the edit), + `promo.py teaser` (X, 13 s, no voice), `promo.py gif` (push GIF 640x320), `thumbnail.py` (YouTube/site). ## HypeRate API key (secret) diff --git a/src/gametest/java/io/hyperate/hypeblock/gametest/TrailerRecorder.java b/src/gametest/java/io/hyperate/hypeblock/gametest/TrailerRecorder.java index 1e8ed78..d8b157b 100644 --- a/src/gametest/java/io/hyperate/hypeblock/gametest/TrailerRecorder.java +++ b/src/gametest/java/io/hyperate/hypeblock/gametest/TrailerRecorder.java @@ -45,7 +45,9 @@ */ public class TrailerRecorder implements FabricClientGameTest { private static final int FPS = 30; - private static final int W = 1920, H = 1080; + /** HYPEBLOCK_TRAILER_VERTICAL=1 records 1080x1920 for Shorts into shots-vertical/, with a wider FOV. */ + private static final boolean VERTICAL = "1".equals(System.getenv("HYPEBLOCK_TRAILER_VERTICAL")); + private static final int W = VERTICAL ? 1080 : 1920, H = VERTICAL ? 1920 : 1080; private static final int[] SX = SampleWorldBuilder.STATION_X; private final SampleWorldBuilder world = new SampleWorldBuilder(); @@ -59,7 +61,7 @@ public void runTest(ClientGameTestContext context) { String only = System.getenv("HYPEBLOCK_TRAILER_SHOTS"); Set wanted = only == null || only.isBlank() ? null : Arrays.stream(only.split(",")).map(String::trim).collect(Collectors.toSet()); - out = Path.of(System.getProperty("user.dir")).resolve("../trailer/shots").normalize(); + out = Path.of(System.getProperty("user.dir")).resolve(VERTICAL ? "../trailer/shots-vertical" : "../trailer/shots").normalize(); try { Files.createDirectories(out); } catch (IOException e) { @@ -69,7 +71,8 @@ public void runTest(ClientGameTestContext context) { context.getInput().resizeWindow(W, H); context.runOnClient(mc -> { mc.options.chatVisibility().set(ChatVisiblity.HIDDEN); - mc.options.fov().set(60); + mc.options.fov().set(VERTICAL ? 80 : 60); + if (VERTICAL) mc.options.guiScale().set(4); mc.options.bobView().set(false); }); diff --git a/tools/trailer/promo.py b/tools/trailer/promo.py new file mode 100644 index 0000000..b2390a3 --- /dev/null +++ b/tools/trailer/promo.py @@ -0,0 +1,394 @@ +"""Short promo pieces cut from the trailer shots: + + python tools/trailer/promo.py short [--lang en|de] YouTube Short, 1080x1920, ~38 s, voice + captions + python tools/trailer/promo.py teaser X teaser, 1920x1080, ~13 s, music, big texts (plays muted) + python tools/trailer/promo.py gif push GIF, 2:1 loop (heart lamps + beating HypeBlock) + +The Short uses the vertical shots (HYPEBLOCK_TRAILER=1 HYPEBLOCK_TRAILER_VERTICAL=1 runClientGameTest → +build/run/trailer/shots-vertical/), the teaser and the GIF the normal ones. Voice lines: script.SHORT_LINES, +recorded with `voiceover.py --script short`. Output: build/trailer/. +""" +import argparse +import os +import subprocess +import sys + +import numpy as np +from PIL import Image, ImageFilter +from scipy.io import wavfile + +sys.path.insert(0, os.path.dirname(__file__)) +import fx # noqa: E402 +import mc # noqa: E402 +import mix # noqa: E402 +import render # noqa: E402 +from render import T, cached, centered_text, fade_alpha, layout, run_edit, toast_at # noqa: E402 +from script import SHORT_LINES # noqa: E402 + +OUT = os.path.join(mc.ROOT, "build/trailer") +SHOTS_V = os.path.join(mc.ROOT, "build/run/trailer/shots-vertical") +SR = mix.SR +G = 0xAAAAAA + + +# ---------------------------------------------------------------- shared drawing + +def wrap(text, width_px, scale): + f = mc.font() + lines, line = [], "" + for word in text.split(): + test = (line + " " + word).strip() + if f.width(test, True) * scale > width_px and line: + lines.append(line) + line = word + else: + line = test + if line: + lines.append(line) + return lines + + +def caption(frame, text, y, scale, lt, t0, t1, color=0xFFFFFF, box=True): + """Centered, wrapped text in the game font on a dark box (subtitle style).""" + a = fade_alpha(lt, t0, t1, 0.15) + if a <= 0: + return + W = frame.shape[1] + lines = wrap(text, W * 0.86, scale) + lh = 11 * scale + if box: + h = lh * len(lines) + 4 * scale + widest = max(mc.font().width(l, True) for l in lines) * scale + 8 * scale + x0, y0 = int((W - widest) / 2), int(y - 2 * scale) + region = frame[max(0, y0):y0 + int(h), max(0, x0):x0 + int(widest)] + region[:] = (region.astype(np.float32) * (1 - 0.55 * a)).astype(np.uint8) + for i, l in enumerate(lines): + centered_text(frame, l, y + i * lh, scale, color, bold=True, alpha=a) + + +def label(frame, text, sub, y, S, lt, t0, t1, scale=5): + """A feature name as an item tooltip, centered.""" + lines = [(text, 0xFFFFFF)] + ([(sub, G)] if sub else []) + img = cached(("plabel", text, sub, scale), lambda: mc.tooltip(lines, scale)) + a = fade_alpha(lt, t0, t1, 0.2) + rise = int((1 - fx.ease_out(min(1, (lt - t0) / 0.3))) * 30) + fx.over(frame, img, (frame.shape[1] - img.width) // 2, int(y) + rise, a) + + +def bpm_counter(frame, lt, x_right, y, scale, schedule): + """Big BPM readout; schedule: list of (time, bpm).""" + bpm = schedule[0][1] + for t, v in schedule: + if lt >= t: + bpm = v + img = mc.text_image(f"{bpm} BPM", scale, 0xFF5555, bold=True) + fx.over(frame, img, x_right - img.width, y) + + +def magnify_hud(frame, lt, t0, t1, box=(10, 10, 196, 74), k=4, y=720): + """The real HUD tile from the corner, enlarged (the window caps the GUI scale in portrait).""" + a = fade_alpha(lt, t0, t1, 0.2) + if a <= 0: + return + x0, y0, x1, y1 = box + tile = Image.fromarray(frame[y0:y1, x0:x1].copy()) + s = k * (0.7 + 0.3 * fx.ease_out(min(1, (lt - t0) / 0.3))) + big = np.asarray(tile.resize((int(tile.width * s), int(tile.height * s)), Image.NEAREST)) + h, w = big.shape[:2] + border = np.zeros((h + 12, w + 12, 3), np.uint8) + border[:] = 255 + border[6:-6, 6:-6] = big + rgba = np.dstack([border, np.full(border.shape[:2], 255, np.uint8)]) + fx.over(frame, rgba, (frame.shape[1] - w) // 2 - 6, y - (h + 12) // 2, a) + + +def logo_card(lt, W, H, S, lines, logo_px, y_logo, title_scale, gap): + """Dirt background, the HypeBlock face falling in pixel by pixel, title and lines below.""" + f = cached(("dirt", W, H), lambda: mc.dirt_background(W, H, 8, 0.18)).copy() + L = cached(("logo_card", logo_px), lambda: fx.PixelLogo(logo_px, seed=11)) + beat = lt - 1.6 + pulse = max(0.0, 1 - (beat % 0.85) / 0.25) if beat > 0 else 0.0 + L.draw(f, (W - L.size) // 2, int(y_logo), lt + 0.3, build=0.9, pulse=pulse) + y = y_logo + L.size + gap + if lt > 0.8: + centered_text(f, "HYPEBLOCK", y, title_scale, bold=True, reveal=min(1.0, (lt - 0.8) / 0.6), seed=12) + y += title_scale * 12 + for i, (text, scale, color, bold) in enumerate(lines): + t0 = 1.4 + i * 0.35 + if lt > t0: + centered_text(f, text, y, scale, color, bold=bold, alpha=min(1.0, (lt - t0) / 0.4)) + y += scale * 14 + return f + + +# ---------------------------------------------------------------- audio + +def score(cl, total, hits, tense=None, intro_beats=3): + """Music + SFX for a short edit: heartbeats in the intro, groove, impacts on `hits`.""" + tr = mix.Track(total) + tl = {"clips": cl, "total": total, "events": {}} + # transition sounds, same as the trailer + for x in cl: + if not x["out"]: + continue + name, d = x["out"] + t0 = x["end"] - d + if name == "crack": + tr.add("sfx", t0 + d * 0.5, mix.crunch(0.7)) + tr.add("sfx", t0 + d * 0.5, mix.impact(0.5, 2.0)) + elif name == "punch": + tr.add("sfx", t0 + d * 0.5 - 0.02, mix.heartbeat(0.9)) + tr.add("sfx", t0 + d * 0.5, mix.impact(0.3, 1.6)) + elif name != "fade": + tr.add("sfx", t0, mix.whoosh(d + 0.2, 0.2)) + first = cl[0]["end"] - (cl[0]["out"][1] if cl[0]["out"] else 0) + for k in range(intro_beats): + tr.add("drums", 0.2 + k * 0.8, mix.heartbeat(0.7)) + tr.add("music", 0.0, mix.pad([mix.hz("D2"), mix.hz("A2")], first + 0.5, bright=500, gain=0.16)) + end = cl[-1] + t, bar = first, 0 + while t < end["start"]: + ch = mix.PROG[bar % 4] + notes, b = mix.CHORDS[ch] + is_tense = tense and tense[0] <= t < tense[1] + if is_tense: + tr.add("music", t, mix.pad([mix.hz("D3"), mix.hz("A3"), mix.hz("Eb4")], mix.BAR + 0.2, bright=1200, gain=0.12)) + for k in range(16): + tr.add("music", t + k * mix.BEAT / 4, mix.pluck(mix.hz("D5") if k % 4 else mix.hz("A5"), 0.3, 0.035)) + tr.add("drums", t, mix.kick(0.5)) + else: + tr.add("music", t, mix.pad([mix.hz(n) for n in notes[:5]], mix.BAR + 0.2, bright=2400, gain=0.13)) + arp = [notes[2], notes[3], notes[4], notes[3], notes[5], notes[4], notes[3], notes[4]] + for k in range(8): + tr.add("music", t + k * mix.BEAT / 2, mix.pluck(mix.hz(arp[k]), 0.9, 0.06, bright=0.8), pan=-0.4 if k % 2 else 0.4) + for k in range(4): + tr.add("music", t + k * mix.BEAT, mix.bass(mix.hz(b) * (2 if k == 3 else 1), mix.BEAT * 0.9, 0.22)) + if k in (0, 2): + tr.add("drums", t + k * mix.BEAT - 0.01, mix.heartbeat(0.55)) + tr.add("drums", t + k * mix.BEAT + mix.BEAT / 2, mix.hat(0.05)) + if k in (1, 3): + tr.add("drums", t + k * mix.BEAT, mix.snare(0.14)) + t += mix.BAR + bar += 1 + for h, g in hits: + tr.add("sfx", h - 1.6, mix.riser(1.6, 0.2)) + tr.add("sfx", h, mix.impact(g, 3.0)) + e0 = end["start"] + tr.add("sfx", e0 + 0.8, mix.impact(0.8, 3.5)) + tr.add("music", e0 + 0.8, mix.pad([mix.hz(n) for n in ["D2", "A2", "D3", "F3", "A3", "E4"]], 3.5, bright=1500, gain=0.18)) + for k in range(4): + tr.add("drums", e0 + 1.6 + k * 0.85 - 0.02, mix.heartbeat(0.55 * (1 - k / 5))) + return tr + + +def mixdown(tr, vo, total, wav): + for t, x in vo: + tr.add("vo", t, x, 1.0) + music = mix.reverb(tr.buses["music"], 3.0, 0.32, 1) + drums = mix.reverb(tr.buses["drums"], 1.2, 0.12, 2) + sfx = mix.reverb(tr.buses["sfx"], 2.0, 0.2, 3) + voice = tr.buses["vo"] + env = mix.lowpass(np.abs(voice[:, 0]), 6, 1) + env = np.convolve(env, np.ones(int(0.25 * SR)) / int(0.25 * SR), mode="same") + duck = 1 - 0.62 * np.clip(env / 0.03, 0, 1) + out = ((music + drums * 0.9) * duck[:, None] + sfx * (0.6 + 0.4 * duck[:, None])) * 0.75 + voice * 2.1 + n = int(total * SR) + out = out[:n] + fade = int(0.6 * SR) + out[-fade:] *= np.linspace(1, 0, fade)[:, None] + out = np.tanh(out / np.max(np.abs(out)) * 1.4) / np.tanh(1.4) * 0.92 + wavfile.write(wav, SR, (out * 32767).astype(np.int16)) + + +def mux(video, wav, final): + subprocess.run(["ffmpeg", "-y", "-loglevel", "error", "-i", video, "-i", wav, "-map", "0:v", "-map", "1:a", + "-c:v", "copy", "-c:a", "aac", "-b:a", "256k", "-shortest", "-movflags", "+faststart", final], check=True) + print("wrote", final) + + +def load_line(path): + raw = subprocess.run(["ffmpeg", "-loglevel", "error", "-i", path, "-f", "f32le", "-ac", "1", "-ar", str(SR), "-"], + capture_output=True, check=True).stdout + x = np.frombuffer(raw, np.float32).astype(np.float64) + nz = np.where(np.abs(x) > 0.01)[0] + return x[max(0, nz[0] - int(0.03 * SR)):nz[-1] + int(0.15 * SR)] if len(nz) else x + + +# ---------------------------------------------------------------- YouTube Short + +def short(lang): + render.LANG = lang + render.DE["YOUR HEART"] = "DEIN PULS" + W, H, S = 1080, 1920, 1.0 + D, B = render.DOOR_OPEN, render.BRIDGE_OPEN + cl = layout([ + dict(name="intro", gen="intro", dur=3.6, out=("punch", 0.5)), + dict(name="hud", src=2.0, dur=5.4, out=("block", 0.6), vignette=0.4), + dict(name="heartbeat", src=5.5, dur=3.4, out=("punch", 0.5), vignette=1.0, exposure=1.6), + dict(name="strength", src=4.0, dur=4.6, out=("redstone", 0.8)), + dict(name="calmdoor", src=3.0, dur=7.4, out=("crack", 1.0), vignette=0.5), + dict(name="bridge", src=1.5, dur=9.2, out=("mosaic", 0.6), vignette=0.6), + dict(name="finale", src=7.0, dur=4.5, out=("fade", 0.8), vignette=1.0, exposure=1.5), + dict(name="end", gen="end", dur=4.5, out=None), + ]) + total = cl[-1]["end"] + c = {x["name"]: x for x in cl} + door_local, bridge_local = D - 3.0, B - 1.5 + + # voice lines and their captions + vo, caps = [], {} + for lid, clip, at, en, de in SHORT_LINES: + path = os.path.join(OUT, "vo", f"short-{lang}", lid + ".mp3") + x = load_line(path) + t = c[clip]["start"] + at + vo.append((t, x)) + caps.setdefault(clip, []).append((at, at + len(x) / SR + 0.2, en if lang == "en" else de)) + + cap_y, cap_scale = 1380, 6 + + def captions(name): + return [(t0, t1, lambda f, lt, S, t0=t0, t1=t1, txt=txt: caption(f, txt, cap_y, cap_scale, lt, t0, t1)) + for t0, t1, txt in caps.get(name, [])] + + ovl = { + "intro": [(0.0, 3.6, lambda f, lt, S: ( + centered_text(f, T("YOUR HEART"), 640, 13, bold=True, alpha=fade_alpha(lt, 0.2, 3.6, 0.3), + reveal=min(1.0, (lt - 0.2) / 0.8), seed=4), + centered_text(f, "= REDSTONE", 800, 13, 0xFF5555, bold=True, alpha=fade_alpha(lt, 0.9, 3.6, 0.3), + reveal=min(1.0, (lt - 0.9) / 0.8), seed=5)))] + captions("intro"), + "hud": [(0.6, 5.0, lambda f, lt, S: (magnify_hud(f, lt, 0.6, 5.0), + label(f, T("Heart rate HUD"), T("Type /hr "), 300, S, lt, 0.6, 5.0)))] + captions("hud"), + "heartbeat": [(0.4, 3.2, lambda f, lt, S: label(f, T("Output: Heartbeat"), None, 300, S, lt, 0.4, 3.2))] + captions("heartbeat"), + "strength": [(0.4, 4.4, lambda f, lt, S: ( + label(f, T("Output: Signal strength"), None, 300, S, lt, 0.4, 4.4), + bpm_counter(f, lt, W - 60, 440, 9, [(0, 115)] + [(0.55 * i + 0.0, min(160, 115 + 5 * i)) for i in range(1, 10)])))] + captions("strength"), + "calmdoor": [(0.4, door_local, lambda f, lt, S: label(f, T("Trigger: below 80 BPM"), T("Hold it for 5 seconds"), 300, S, lt, 0.4, door_local)), + (door_local + 0.2, door_local + 2.8, lambda f, lt, S: toast_at(f, T("Advancement Made!"), T("Inner Peace"), 1.0, lt, door_local + 0.2, door_local + 2.8))] + + captions("calmdoor"), + "bridge": [(0.4, bridge_local - 0.2, lambda f, lt, S: label(f, T("Over 110 BPM"), T("Bridge: after 5 seconds"), 300, S, lt, 0.4, bridge_local - 0.2)), + (bridge_local + 0.3, bridge_local + 2.6, lambda f, lt, S: toast_at(f, T("Challenge Complete!"), T("Lava? No problem."), 1.0, lt, bridge_local + 0.3, bridge_local + 2.6, 0xFF55FF))] + + captions("bridge"), + "finale": [(0.2, 4.5, lambda f, lt, S: ( + centered_text(f, T("YOUR HEART IS"), 760, 8, bold=True, alpha=fade_alpha(lt, 0.2, 4.4, 0.3)), + centered_text(f, T("THE NEW REDSTONE."), 880, 8, 0xFF5555, bold=True, alpha=fade_alpha(lt, 0.5, 4.4, 0.3), + reveal=min(1.0, (lt - 0.5) / 0.8), seed=9)))], + "end": captions("end"), + } + + def gen_end(lt, W, H, S): + free = "Kostenlose Fabric-Mod" if lang == "de" else "Free Fabric mod" + return logo_card(lt, W, H, S, [ + (free + " - Minecraft Java 26.3", 3, 0xAAAAAA, False), + ("minecraft.hyperate.io", 5, 0xFFFF55, True), + ("Powered by HypeRate", 4, 0xFF5555, False), + ], logo_px=26, y_logo=360, title_scale=12, gap=50) + + video = os.path.join(OUT, f"short-video-{lang}.mp4") + run_edit(cl, ovl, {"intro": render.gen_intro, "end": gen_end}, W, H, S, video, shots=SHOTS_V, crf=18) + tr = score(cl, total, hits=[(c["calmdoor"]["start"] + door_local, 0.5), (c["bridge"]["start"] + bridge_local, 0.9), + (c["finale"]["start"] + 0.2, 0.8)], + tense=(c["bridge"]["start"], c["bridge"]["start"] + bridge_local)) + wav = os.path.join(OUT, f"short-audio-{lang}.wav") + mixdown(tr, vo, total, wav) + mux(video, wav, os.path.join(OUT, f"HypeBlock-Short{'' if lang == 'en' else '-de'}.mp4")) + + +# ---------------------------------------------------------------- X teaser + +def teaser(): + render.LANG = "en" + W, H, S = 1920, 1080, 1.0 + D, B = render.DOOR_OPEN, render.BRIDGE_OPEN + cl = layout([ + dict(name="intro", gen="intro", dur=2.0, out=("punch", 0.5)), + dict(name="hud", src=3.0, dur=2.4, out=("block", 0.6), vignette=0.4), + dict(name="heartbeat", src=6.5, dur=2.4, out=("punch", 0.5), vignette=1.0, exposure=1.6), + dict(name="calmdoor", src=7.3, dur=2.6, out=("crack", 1.0), vignette=0.5), + dict(name="bridge", src=6.4, dur=3.4, out=("mosaic", 0.6), vignette=0.6), + dict(name="end", gen="end", dur=3.6, out=None), + ]) + total = cl[-1]["end"] + c = {x["name"]: x for x in cl} + door_local, bridge_local = D - 7.3, B - 6.4 + + def big(text, color=0xFFFFFF, t0=0.15): + def draw(f, lt, S, text=text, color=color, t0=t0): + k = 1 + 0.12 * (1 - fx.ease_out((lt - t0) / 0.25)) + a = min(1.0, max(0.0, (lt - t0) / 0.12)) + caption(f, text, f.shape[0] - 260, int(round(8 * k)), lt, t0, 99, color, box=True) if a > 0 else None + return draw + + ovl = { + "intro": [(0.1, 2.0, lambda f, lt, S: centered_text(f, "YOUR REAL HEART RATE", H / 2 - 50, 9, bold=True, + alpha=fade_alpha(lt, 0.1, 2.0, 0.2), reveal=min(1.0, (lt - 0.1) / 0.7), seed=3))], + "hud": [(0.0, 2.4, big("...IN MINECRAFT"))], + "heartbeat": [(0.0, 2.4, big("LAMPS BEAT WITH YOU", 0xFF5555))], + "calmdoor": [(0.0, 2.6, big("DOORS OPEN WHEN YOU'RE CALM")), + (door_local + 0.1, 2.6, lambda f, lt, S: toast_at(f, "Advancement Made!", "Inner Peace", 1.0, lt, door_local + 0.1, 4.0))], + "bridge": [(0.0, 3.4, big("BRIDGES OPEN WHEN YOU PANIC", 0xFF5555)), + (bridge_local + 0.2, 3.4, lambda f, lt, S: toast_at(f, "Challenge Complete!", "Lava? No problem.", 1.0, lt, bridge_local + 0.2, 5.0, 0xFF55FF))], + } + + def gen_end(lt, W, H, S): + return logo_card(lt, W, H, S, [ + ("Free Fabric mod for Minecraft Java 26.3", 4, 0xAAAAAA, False), + ("minecraft.hyperate.io", 6, 0xFFFF55, True), + ], logo_px=16, y_logo=120, title_scale=11, gap=30) + + video = os.path.join(OUT, "teaser-video.mp4") + run_edit(cl, ovl, {"intro": render.gen_intro, "end": gen_end}, W, H, S, video, crf=18) + tr = score(cl, total, hits=[(c["calmdoor"]["start"] + door_local, 0.5), (c["bridge"]["start"] + bridge_local, 0.9)], intro_beats=2) + wav = os.path.join(OUT, "teaser-audio.wav") + mixdown(tr, [], total, wav) + mux(video, wav, os.path.join(OUT, "HypeBlock-Teaser-X.mp4")) + + +# ---------------------------------------------------------------- push GIF + +def gif(): + """2:1 loop, 640x320: the lamp heart switching on and off with the beat, the HypeBlock face pulsing.""" + W, H, fps, beat = 640, 320, 15, 0.75 # 80 BPM, two beats per loop + shot = os.path.join(mc.ROOT, "build/run/trailer/shots/heartbeat.mp4") + + def still(n): + raw = subprocess.run(["ffmpeg", "-loglevel", "error", "-i", shot, "-vf", + f"select=eq(n\\,{n}),scale={W * 2}:-2,crop={W * 2}:{H * 2}", "-frames:v", "1", + "-f", "rawvideo", "-pix_fmt", "rgb24", "-"], capture_output=True, check=True).stdout + f = np.frombuffer(raw, np.uint8).reshape(H * 2, W * 2, 3) + f = fx.Grade(W * 2, H * 2, vignette=0.5)(f, sat=1.25, exposure=1.7) + return np.asarray(Image.fromarray(f).resize((W, H), Image.LANCZOS).filter(ImageFilter.GaussianBlur(1.2))).astype(np.float32) + + # a lit and an unlit frame from (almost) the same camera position + lit, dark = still(412), still(408) + face = mc.hb_texture("hypeblock_active") + title = mc.text_image("HYPEBLOCK", 5, bold=True) + sub = mc.text_image("Your heart = redstone", 2, 0xFF5555) + frames = [] + n = int(round(2 * beat * fps)) + for i in range(n): + t = i / fps + ph = (t % beat) / beat + pulse = max(0.0, 1 - ph / 0.3) + f = dark * (1 - pulse) + lit * pulse + f = f * np.clip(1 - np.linspace(1, 0, W) * 0.55, 0, 1)[None, :, None] + f = f.astype(np.uint8).copy() + size = int(150 * (1 + 0.08 * pulse)) + fimg = face.resize((size, size), Image.NEAREST) + fx.over(f, fimg, 440 - size // 2 + 75, H // 2 - size // 2) + fx.over(f, title, 40, 105) + fx.over(f, sub, 44, 175) + frames.append(Image.fromarray(f)) + path = os.path.join(OUT, "HypeBlock-push.gif") + pal = frames[0].convert("P", palette=Image.ADAPTIVE, colors=128) + frames = [fr.quantize(palette=pal, dither=Image.Dither.NONE) for fr in frames] + frames[0].save(path, save_all=True, append_images=frames[1:], duration=int(1000 / fps), loop=0, optimize=True, disposal=1) + print("wrote", path, os.path.getsize(path) // 1024, "KB,", len(frames), "frames") + + +if __name__ == "__main__": + ap = argparse.ArgumentParser() + ap.add_argument("what", choices=["short", "teaser", "gif"]) + ap.add_argument("--lang", default="en", choices=["en", "de"]) + args = ap.parse_args() + os.makedirs(OUT, exist_ok=True) + {"short": lambda: short(args.lang), "teaser": teaser, "gif": gif}[args.what]() diff --git a/tools/trailer/render.py b/tools/trailer/render.py index dd2ec83..fa1d7a3 100644 --- a/tools/trailer/render.py +++ b/tools/trailer/render.py @@ -227,9 +227,9 @@ def gen_end(lt, W, H, S): # ---------------------------------------------------------------- reading shots class Reader: - def __init__(self, name, src, W, H): + def __init__(self, name, src, W, H, shots=None): self.W, self.H = W, H - path = os.path.join(SHOTS, name + ".mp4") + path = os.path.join(shots or SHOTS, name + ".mp4") self.proc = subprocess.Popen( ["ffmpeg", "-loglevel", "error", "-ss", f"{src:.3f}", "-i", path, "-vf", f"scale={W}:{H}:flags=lanczos", "-f", "rawvideo", "-pix_fmt", "rgb24", "-"], @@ -265,62 +265,71 @@ def main(): args.out = os.path.join(OUT, f"video-{LANG}.mp4") S = args.scale W, H = int(1920 * S) // 2 * 2, int(1080 * S) // 2 * 2 - os.makedirs(OUT, exist_ok=True) - - cl = clips() - t = 0.0 - for i, c in enumerate(cl): - c["start"] = t - c["end"] = t + c["dur"] - tr = c["out"][1] if c["out"] else 0 - t = c["end"] - tr - total = cl[-1]["end"] - - timeline = {"total": total, "fps": FPS, "clips": [{k: c[k] for k in ("name", "start", "end", "dur")} | {"out": c["out"]} for c in cl], + cl = layout(clips()) + timeline = {"total": cl[-1]["end"], "fps": FPS, + "clips": [{k: c[k] for k in ("name", "start", "end", "dur")} | {"out": c["out"]} for c in cl], "events": {"logo": cl[1]["start"] + LOGO_START, "door_open": cl[6]["start"] + DOOR_OPEN, "bridge_lamp": cl[7]["start"] + BRIDGE_LAMP, "bridge_open": cl[7]["start"] + BRIDGE_OPEN, "states": [cl[3]["start"] + s for s in STATE_TIMES]}} + os.makedirs(OUT, exist_ok=True) with open(os.path.join(OUT, "timeline.json"), "w") as fh: json.dump(timeline, fh, indent=1) - print(f"total {total:.2f} s") + run_edit(cl, overlays(), GENERATORS, W, H, S, args.out, args.t_from, args.t_to) - grade = fx.Grade(W, H) - trans = { - "crack": fx.CrackShatter(W, H, cell=max(8, int(120 * S))), - "block": fx.BlockWipe(W, H, cell=max(8, int(120 * S))), - "mosaic": fx.Mosaic(max_block=max(4, int(96 * S))), + +def layout(cl): + """Start/end of every clip; each one overlaps the next by its out transition.""" + t = 0.0 + for c in cl: + c["start"] = t + c["end"] = t + c["dur"] + t = c["end"] - (c["out"][1] if c["out"] else 0) + return cl + + +def transitions(W, H, S): + k = min(W, H) / 1080 + return { + "crack": fx.CrackShatter(W, H, cell=max(8, int(120 * k))), + "block": fx.BlockWipe(W, H, cell=max(8, int(120 * k))), + "mosaic": fx.Mosaic(max_block=max(4, int(96 * k))), "redstone": fx.RedstoneWipe(W, H), "punch": fx.HeartPunch(), - "chunks": fx.ChunkLoad(W, H, cell=max(8, int(135 * S))), + "chunks": fx.ChunkLoad(W, H, cell=max(8, int(135 * k))), "dirt": fx.DirtLoading(W, H, S, T("Loading terrain")), "fade": fx.Fade(), } - ovl = overlays() - readers = {} - t_from, t_to = max(0, args.t_from), min(total, args.t_to) + +def run_edit(cl, ovl, generators, W, H, S, out, t_from=0.0, t_to=1e9, shots=None, crf=17): + """Renders a laid-out clip list with transitions and overlays to an mp4 (no sound).""" + total = cl[-1]["end"] + print(f"total {total:.2f} s") + grade = fx.Grade(W, H) + trans = transitions(W, H, S) + readers = {} + t_from, t_to = max(0, t_from), min(total, t_to) enc = subprocess.Popen( ["ffmpeg", "-y", "-loglevel", "error", "-f", "rawvideo", "-pix_fmt", "rgb24", "-s", f"{W}x{H}", - "-r", str(FPS), "-i", "-", "-c:v", "libx264", "-preset", "medium", "-crf", "17", - "-pix_fmt", "yuv420p", "-movflags", "+faststart", args.out], stdin=subprocess.PIPE) + "-r", str(FPS), "-i", "-", "-c:v", "libx264", "-preset", "medium", "-crf", str(crf), + "-pix_fmt", "yuv420p", "-movflags", "+faststart", out], stdin=subprocess.PIPE) def clip_frame(i, c, gt): lt = gt - c["start"] if "gen" in c: - f = GENERATORS[c["gen"]](lt, W, H, S) + f = generators[c["gen"]](lt, W, H, S) else: if i not in readers: - readers[i] = Reader(c["name"], c["src"], W, H) + readers[i] = Reader(c.get("shot", c["name"]), c["src"], W, H, shots) f = grade(readers[i].frame(int(round(lt * FPS))), vignette=c.get("vignette", 1.0) * 0.8, exposure=c.get("exposure", 1.0)) for t0, t1, draw in ovl.get(c["name"], []): if t0 <= lt < t1: draw(f, lt, S) return f - n0, n1 = int(t_from * FPS), int(t_to * FPS) - for n in range(n0, n1): + for n in range(int(t_from * FPS), int(t_to * FPS)): gt = n / FPS active = [i for i, c in enumerate(cl) if c["start"] <= gt < c["end"]] if len(active) == 1: @@ -330,8 +339,7 @@ def clip_frame(i, c, gt): A = clip_frame(a, cl[a], gt) B = clip_frame(b, cl[b], gt) name, d = cl[a]["out"] - p = (gt - cl[b]["start"]) / d - frame = trans[name](A, B, p) + frame = trans[name](A, B, (gt - cl[b]["start"]) / d) for i in list(readers): if gt >= cl[i]["end"]: readers.pop(i).close() @@ -342,7 +350,7 @@ def clip_frame(i, c, gt): enc.wait() for r in readers.values(): r.close() - print("wrote", args.out) + print("wrote", out) if __name__ == "__main__": diff --git a/tools/trailer/script.py b/tools/trailer/script.py index ff5958a..d5bf07a 100644 --- a/tools/trailer/script.py +++ b/tools/trailer/script.py @@ -51,3 +51,25 @@ ("v23", "end", 1.3, "HypeBlock. Powered by HypeRate.", "HypeBlock. Powered by HypeRate."), ] + + +# YouTube Short (vertical, ~40 s). Clip-local cue times refer to the clips in promo.py; a line +# with clip None is placed right after the previous one. +SHORT_LINES = [ + ("s01", "intro", 0.3, "What if Minecraft could feel your heartbeat?", + "Was wäre, wenn Minecraft deinen Herzschlag spürt?"), + ("s02", "hud", 0.3, "This mod reads your real heart rate, live from your watch.", + "Diese Mod liest deinen echten Puls, live von deiner Uhr."), + ("s03", "heartbeat", 0.3, "Lamps that beat with you.", + "Lampen, die mit dir schlagen."), + ("s04", "strength", 0.3, "A signal that grows the more hyped you get.", + "Ein Signal, das mit deinem Hype wächst."), + ("s05", "calmdoor", 0.3, "A door that only opens if you stay calm.", + "Eine Tür, die nur aufgeht, wenn du ruhig bleibst."), + ("s06", "bridge", 0.3, "And a bridge over lava. Over one-ten for five seconds... and it opens.", + "Und eine Brücke über Lava. Fünf Sekunden über hundertzehn... und sie geht auf."), + ("s07", "finale", 0.3, "Your heart is the new redstone.", + "Dein Herz ist das neue Redstone."), + ("s08", "end", 0.4, "HypeBlock. Free mod, link below.", + "HypeBlock. Kostenlose Mod, Link unten."), +] diff --git a/tools/trailer/thumbnail.py b/tools/trailer/thumbnail.py index e6ceef2..a8b3565 100644 --- a/tools/trailer/thumbnail.py +++ b/tools/trailer/thumbnail.py @@ -69,7 +69,48 @@ def make(lang): print("wrote", path, os.path.getsize(path) // 1024, "KB") +def make_vertical(lang): + """1080x1920 for YouTube Shorts: titles on top, the HypeBlock in the middle, lamp heart below.""" + VW, VH = 1080, 1920 + l1, l2, sub = TEXT[lang] + shot = os.path.join(mc.ROOT, "build/run/trailer/shots-vertical/heartbeat.mp4") + raw = subprocess.run(["ffmpeg", "-loglevel", "error", "-i", shot, "-vf", f"select=eq(n\\,158),scale={VW}:{VH}", + "-frames:v", "1", "-f", "rawvideo", "-pix_fmt", "rgb24", "-"], capture_output=True, check=True).stdout + f = np.frombuffer(raw, np.uint8).reshape(VH, VW, 3) + f = fx.Grade(VW, VH, vignette=0.5)(f, vignette=1.0, sat=1.25, exposure=1.7) + a = np.asarray(Image.fromarray(f).filter(ImageFilter.GaussianBlur(2.0))).astype(np.float32) + ramp = np.clip(1 - np.linspace(0, 1, VH) * 1.7, 0, 1)[:, None, None] # dark at the top for the text + f = (a * (1 - 0.75 * ramp)).astype(np.uint8).copy() + yy, xx = np.ogrid[0:VH, 0:VW] + d = ((xx - VW / 2) ** 2 + (yy - 930) ** 2) / 380 ** 2 + f[:] = np.clip(f + np.exp(-d * 2)[:, :, None] * np.array([255, 40, 60], np.float32) * 0.55, 0, 255).astype(np.uint8) + t1 = mc.text_image(l1, 13, 0xFFFFFF, bold=True) + t2 = mc.text_image(l2, 13, 0xFF5555, bold=True) + fx.over(f, t1, (VW - t1.width) // 2, 230) + fx.over(f, t2, (VW - t2.width) // 2, 400) + face = mc.hb_texture("hypeblock_active").resize((448, 448), Image.NEAREST) + shadow = Image.composite(Image.new("RGBA", face.size, (0, 0, 0, 170)), Image.new("RGBA", face.size, (0, 0, 0, 0)), face.getchannel("A")) + fx.over(f, shadow, (VW - 448) // 2 + 14, 720) + fx.over(f, face, (VW - 448) // 2, 700) + st = mc.text_image(sub, 5, 0xFFFF55) + sx, sy = (VW - st.width) // 2, 1200 + f[sy - 14:sy + st.height + 10, sx - 20:sx + st.width + 20] = ( + f[sy - 14:sy + st.height + 10, sx - 20:sx + st.width + 20].astype(np.float32) * 0.3).astype(np.uint8) + fx.over(f, st, sx, sy) + tile = mc.text_image("128 BPM", 7, 0xFFFFFF) + heart = mc.hb_texture("hypeblock_active").crop((3, 3, 13, 13)).resize((84, 84), Image.NEAREST) + tw = 84 + 24 + tile.width + x, y = (VW - tw) // 2, 1330 + f[y - 18:y + 84 + 14, x - 20:x + tw + 20] = (f[y - 18:y + 84 + 14, x - 20:x + tw + 20].astype(np.float32) * 0.35).astype(np.uint8) + fx.over(f, heart, x, y - 6) + fx.over(f, tile, x + 108, y + 6) + path = os.path.join(OUT, f"thumbnail-short-{lang}.jpg") + Image.fromarray(f).save(path, quality=90) + print("wrote", path, os.path.getsize(path) // 1024, "KB") + + if __name__ == "__main__": os.makedirs(OUT, exist_ok=True) for lang in TEXT: make(lang) + make_vertical(lang) diff --git a/tools/trailer/voiceover.py b/tools/trailer/voiceover.py index f308bc3..ca582bc 100644 --- a/tools/trailer/voiceover.py +++ b/tools/trailer/voiceover.py @@ -14,7 +14,7 @@ sys.path.insert(0, os.path.dirname(__file__)) import mc # noqa: E402 -from script import LINES # noqa: E402 +from script import LINES, SHORT_LINES # noqa: E402 API = "https://api.elevenlabs.io" @@ -63,16 +63,18 @@ def main(): ap.add_argument("--lang", default="en", choices=["en", "de"]) ap.add_argument("--only", default="") ap.add_argument("--list", action="store_true") + ap.add_argument("--script", default="trailer", choices=["trailer", "short"]) args = ap.parse_args() voice, vname = find_voice() model = find_model() print(f"voice {vname} ({voice}), model {model}") if args.list: return - out = os.path.join(mc.ROOT, "build/trailer/vo", args.lang) + lines = SHORT_LINES if args.script == "short" else LINES + out = os.path.join(mc.ROOT, "build/trailer/vo", args.lang if args.script == "trailer" else f"short-{args.lang}") os.makedirs(out, exist_ok=True) only = set(filter(None, args.only.split(","))) - texts = [(i, en if args.lang == "en" else de) for i, _, _, en, de in LINES] + texts = [(i, en if args.lang == "en" else de) for i, _, _, en, de in lines] for n, (lid, text) in enumerate(texts): if only and lid not in only: continue