Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .claude/launch.json

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
4 changes: 4 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -59,7 +61,7 @@ public void runTest(ClientGameTestContext context) {
String only = System.getenv("HYPEBLOCK_TRAILER_SHOTS");
Set<String> 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) {
Expand All @@ -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);
});

Expand Down
394 changes: 394 additions & 0 deletions tools/trailer/promo.py

Large diffs are not rendered by default.

74 changes: 41 additions & 33 deletions tools/trailer/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "-"],
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand All @@ -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__":
Expand Down
22 changes: 22 additions & 0 deletions tools/trailer/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
]
41 changes: 41 additions & 0 deletions tools/trailer/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 5 additions & 3 deletions tools/trailer/voiceover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
Loading