Avatar frames that follow the outline of the avatar (ring and parts hung on it), packs of frames that arrive from a catalog on the site by themselves, the frame shown to other members through the members service, save an avatar by user name, the diary of the mod, the seek bar on every video, the beta version line and its what is new, plus tests, the catalog builder, the sprites and the scripts that draw them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
140 lines
5.8 KiB
Python
140 lines
5.8 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
LihonT 2 «Serena alpha»: one video from the scenes of the two alpha videos (make_serena_promo.py and make_serena_promo2.py),
|
|
1080x1920, 30 fps, one intro and one outro, the sticker style of make_luna_promo2.py.
|
|
|
|
usage (from the repository root):
|
|
py -X utf8 -B scripts/make_serena_alpha_video.py # work/serena-promo/serena_alpha.mp4
|
|
py -X utf8 -B scripts/make_serena_alpha_video.py --still 20.0 # one frame
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import math
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from multiprocessing import Pool
|
|
from pathlib import Path
|
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
import make_luna_promo2 as V # noqa: E402
|
|
import make_serena_promo as A # noqa: E402
|
|
import make_serena_promo2 as B # noqa: E402
|
|
|
|
W, H, FPS = V.W, V.H, V.FPS
|
|
ROOT = V.ROOT
|
|
UT = ROOT / "work" / "serena-promo" / "serena_alpha.mp4"
|
|
AUDIO = ROOT / "work" / "serena-promo" / "serena_alpha_audio.wav"
|
|
clamp, ease_out_cubic, ease_out_back, pop = V.clamp, V.ease_out_cubic, V.ease_out_back, V.pop
|
|
YELLOW, WHITE, PINK, CREAM = V.YELLOW, V.WHITE, V.PINK, V.CREAM
|
|
|
|
|
|
def scene_intro(layer, lt):
|
|
k = ease_out_back(lt / 0.9)
|
|
V.place(layer, V.ASSETS["logo"], W / 2, 760, 0.5 * k * (1 + 0.04 * math.sin(lt * 5)), math.sin(lt * 2.4) * 8 + (1 - k) * 360)
|
|
V.burst(layer, W / 2, 760, lt, 0.6, seed=34)
|
|
V.title(layer, max(0.0, lt - 0.9), "LihonT 2", "Serena alpha", y=1230)
|
|
V.label(layer, W / 2, 1480, "темы · значки · плагины · приколы", pop(lt, 1.8), size=42, fill=YELLOW)
|
|
|
|
|
|
def scene_outro(layer, lt):
|
|
k = ease_out_back(lt / 0.8)
|
|
V.place(layer, V.ASSETS["logo"], W / 2, 620, 0.46 * k * (1 + 0.04 * math.sin(lt * 5)), math.sin(lt * 2.4) * 8 + (1 - k) * 300)
|
|
V.burst(layer, W / 2, 620, lt, 0.5, seed=39, count=60, power=1000)
|
|
V.title(layer, max(0.0, lt - 0.5), "Serena alpha", "Открытый код · лицензия VCBFU v2", y=1000)
|
|
bounce = lambda t0: abs(math.sin((lt - t0) * 3)) * 14 if lt > t0 else 0 # noqa: E731
|
|
V.label(layer, W / 2, 1290 - bounce(1.2), "git.lihont.space", pop(lt, 1.2), size=60, fill=YELLOW)
|
|
V.label(layer, W / 2, 1440 - bounce(1.5), "Telegram · @lihont", pop(lt, 1.5), size=60, fill=WHITE)
|
|
V.label(layer, W / 2, 1580, "Это альфа: может быть шероховато", pop(lt, 2.2), size=34, fill=PINK)
|
|
|
|
|
|
# name, length in seconds, background colour, the function that draws the scene (its own time starts at 0)
|
|
PARTS = [
|
|
("intro", 3.2, CREAM, scene_intro),
|
|
("themes", 6.0, (255, 226, 200), A.scene_themes),
|
|
("win95", 4.8, (0, 128, 128), A.scene_win95),
|
|
("plugin", 6.0, (255, 236, 150), A.scene_plugin),
|
|
("icons", 6.2, (190, 240, 220), B.scene_icons),
|
|
("cards", 6.2, (215, 200, 255), B.scene_cards),
|
|
("fun", 5.2, (215, 200, 255), A.scene_fun),
|
|
("debug", 5.4, (190, 240, 220), A.scene_debug),
|
|
("safe", 4.4, (255, 205, 225), B.scene_safe),
|
|
("outro", 4.2, (255, 196, 176), scene_outro),
|
|
]
|
|
SCENES = []
|
|
_t = 0.0
|
|
for _name, _length, _color, _draw in PARTS:
|
|
SCENES.append((_name, _t, _t + _length, _color, _draw))
|
|
_t += _length
|
|
DURATION = SCENES[-1][2]
|
|
FRAMES = int(round(DURATION * FPS))
|
|
WIPE = V.WIPE
|
|
|
|
|
|
def frame_at(t: float) -> Image.Image:
|
|
V.init_assets()
|
|
index = 0
|
|
for n, (name, start, end, color, draw) in enumerate(SCENES):
|
|
if t >= start:
|
|
index = n
|
|
name, start, end, color, draw = SCENES[index]
|
|
img = Image.new("RGBA", (W, H), color + (255,))
|
|
if index > 0 and t - start < WIPE:
|
|
prev = SCENES[index - 1][3]
|
|
img = Image.new("RGBA", (W, H), prev + (255,))
|
|
r = 1700 * ease_out_cubic((t - start) / WIPE)
|
|
mask = Image.new("L", (W, H), 0)
|
|
ImageDraw.Draw(mask).ellipse([W / 2 - r, H / 2 - r, W / 2 + r, H / 2 + r], fill=255)
|
|
img.paste(Image.new("RGBA", (W, H), color + (255,)), (0, 0), mask)
|
|
if name != "win95": # the teal desktop of Windows 95 has no dot grid
|
|
ox, oy = int(t * 30) % 80, int(t * 18) % 80
|
|
img.alpha_composite(V.ASSETS["dots"], (-ox, -oy))
|
|
layer = Image.new("RGBA", (W, H), (0, 0, 0, 0))
|
|
draw(layer, t - start)
|
|
out = clamp((end - t) / 0.25) if index < len(SCENES) - 1 else 1.0
|
|
if out < 1.0:
|
|
layer.putalpha(layer.getchannel("A").point(lambda v, a=out: int(v * a)))
|
|
img.alpha_composite(layer)
|
|
return img
|
|
|
|
|
|
def render_frame(index: int) -> bytes:
|
|
return frame_at(index / FPS).convert("RGB").tobytes()
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--still", type=float)
|
|
parser.add_argument("--out", default=str(OUT))
|
|
parser.add_argument("--jobs", type=int, default=6)
|
|
args = parser.parse_args()
|
|
OUT.parent.mkdir(parents=True, exist_ok=True)
|
|
if args.still is not None:
|
|
path = OUT.parent / ("still_alpha_%.2f.png" % args.still)
|
|
frame_at(args.still).convert("RGB").save(path)
|
|
print(path)
|
|
return
|
|
import make_lihont_music
|
|
make_lihont_music.generate(AUDIO, DURATION, tuple(s[1] for s in SCENES[1:]))
|
|
command = [shutil.which("ffmpeg") or "ffmpeg", "-y", "-loglevel", "error", "-f", "rawvideo", "-pix_fmt", "rgb24",
|
|
"-s", "%dx%d" % (W, H), "-r", str(FPS), "-i", "-", "-i", str(AUDIO), "-c:v", "libx264", "-preset", "medium",
|
|
"-crf", "18", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "160k", "-shortest", args.out]
|
|
proc = subprocess.Popen(command, stdin=subprocess.PIPE)
|
|
with Pool(args.jobs, initializer=V.init_assets) as pool:
|
|
for n, data in enumerate(pool.imap(render_frame, range(FRAMES), chunksize=4)):
|
|
proc.stdin.write(data)
|
|
if n % 60 == 0:
|
|
print("frame %d/%d" % (n, FRAMES), flush=True)
|
|
proc.stdin.close()
|
|
proc.wait()
|
|
print("done:", args.out)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|