mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
## Summary
Randy Vild (tenant `randy-vild`) emailed: *"I have completed 3 songs but
all three songs produce the large text at the end even though I have in
my settings smaller text like in my beginning."*
Root cause: the theme editor's size/position sliders only edit
`intro.*`. The end screen has its own `end.*` layout (title 350 /
closing message 400 / yellow capitals artist in Randy's theme). The
editor neither exposed it nor previewed it ("The end screen isn't
previewed").
## Changes
- **End screen tab**: own title/artist colours, size + position sliders
(closing message, song title, artist), show/hide song title / artist
name, capitals toggles, and **Copy title card layout**. That copies the
title card's regions/colours/capitals and moves the closing message just
above the title, or below the artist if there's no room, so they never
overlap.
- **End screen preview**: `theme_preview_service.render_end_screen` uses
the same `VideoGenerator.create_end_video` as `screens_worker`. The
preview column shows the screen for the active tab plus the lyrics
frame; Advanced shows all three.
- **Leave out the title card / end screen**: optional `intro.enabled` /
`end.enabled` (absent = included; not added to the DEFAULT_*
required-field lists). The setting is honoured end to end:
- The screens worker skips the omitted screen and records
`state_data.screens_included`.
- The video worker's prerequisite check and the `/retry` ladder
(`_has_title_screen`, which also requires `screens_progress: complete`)
treat an omitted screen as done.
- The orchestrator sets the omitted screen's path to `None` and gives
the original-vocals guide an intro offset of 0.
- Encoding passes explicit `include_title_screen` /
`include_end_screen=false` to the GCE worker. Without them, its loose
`*title*.png` / `*end*.png` globs would rebuild the screen from
`style/*_background.png`.
- `LocalEncodingService.encode_lossless_mp4` builds the concat from
whichever segments exist (1–3).
- The portrait renderer drops omitted cards.
- 11 new strings × 33 locales (`endScreenHint` removed). Docs: API.md,
README.md.
## Verification
- `make test` all green: frontend 1665 tests; backend unit, integration
and emulator suites.
- New `backend/tests/test_theme_screen_omission.py`, 28 tests:
- screens worker for all 4 include combinations;
- prerequisites and the retry helper;
- orchestrator config and encoder options;
- GCE `run_encoding` with decoy theme PNGs present;
- concat for n = 1/2/3.
- Real-ffmpeg renders:
- end-screen preview (its own background; text size changes only the end
screen);
- portrait durations with screens omitted.
- Frontend: editor tests for the end tab, copy layout, region toggles
and enable switches, plus unit tests for the `copyTitleCardLayoutToEnd`
util.
- Rendered Randy's real theme locally:
- as saved, the end screen reproduces the large text;
- after Copy title card layout, it matches his title card.
- Local CodeRabbit review: 0 findings.
## Deploy notes
- The worker paths changed (`gce_encoding/`,
`local_encoding_service.py`, `karaoke_gen/`), so CI blue-green redeploys
the encoding worker.
- Existing themes are unaffected: they have no `enabled` key.
@coderabbitai ignore
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
131 lines
4.6 KiB
Python
131 lines
4.6 KiB
Python
"""End-to-end portrait render on a tiny synthetic fixture.
|
|
|
|
Renders a real (short) portrait MP4 with ffmpeg and asserts the output dimensions,
|
|
total duration (title + body + end), and that lyrics are actually burned into the
|
|
body. Skipped when ffmpeg/ffprobe are unavailable.
|
|
"""
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from karaoke_gen.lyrics_transcriber.types import LyricsSegment, Word
|
|
from karaoke_gen.portrait import PortraitBrandConfig, PortraitLayout, render_portrait_video
|
|
|
|
pytestmark = pytest.mark.skipif(
|
|
not (shutil.which("ffmpeg") and shutil.which("ffprobe")),
|
|
reason="ffmpeg/ffprobe not available",
|
|
)
|
|
|
|
|
|
def _word(wid, text, start, end):
|
|
return Word(id=wid, text=text, start_time=start, end_time=end)
|
|
|
|
|
|
def _fixture_result():
|
|
seg1 = LyricsSegment(
|
|
id="s1", text="Hello portrait world", start_time=0.2, end_time=1.8,
|
|
words=[_word("w1", "Hello", 0.2, 0.7), _word("w2", "portrait", 0.8, 1.3),
|
|
_word("w3", "world", 1.4, 1.8)],
|
|
)
|
|
seg2 = LyricsSegment(
|
|
id="s2", text="Singing along tonight", start_time=2.0, end_time=3.6,
|
|
words=[_word("w4", "Singing", 2.0, 2.5), _word("w5", "along", 2.6, 3.0),
|
|
_word("w6", "tonight", 3.1, 3.6)],
|
|
)
|
|
return SimpleNamespace(corrected_segments=[seg1, seg2])
|
|
|
|
|
|
def _probe(path, entries):
|
|
out = subprocess.run(
|
|
["ffprobe", "-v", "error", "-select_streams", "v:0",
|
|
"-show_entries", entries, "-of", "default=noprint_wrappers=1:nokey=1", path],
|
|
capture_output=True, text=True, check=True,
|
|
).stdout.split()
|
|
return out
|
|
|
|
|
|
def test_render_portrait_end_to_end(tmp_path):
|
|
audio = tmp_path / "instr.flac"
|
|
subprocess.run(
|
|
["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-f", "lavfi",
|
|
"-i", "anullsrc=r=44100:cl=stereo", "-t", "4", str(audio)],
|
|
check=True,
|
|
)
|
|
|
|
out = tmp_path / "portrait.mp4"
|
|
# Short intro/outro to keep the encode quick.
|
|
styles = {"karaoke": {}, "intro": {"video_duration": 1}, "end": {"video_duration": 1}}
|
|
render_portrait_video(
|
|
correction_result=_fixture_result(),
|
|
instrumental_path=str(audio),
|
|
styles=styles,
|
|
artist="Test Artist",
|
|
title="Test Title",
|
|
output_path=str(out),
|
|
brand=PortraitBrandConfig(brand_text="NOMAD KARAOKE", footer_text="nomadkaraoke.com"),
|
|
layout=PortraitLayout(),
|
|
)
|
|
|
|
assert out.exists()
|
|
w, h = _probe(str(out), "stream=width,height")
|
|
assert (int(w), int(h)) == (1080, 1920)
|
|
|
|
dur = float(subprocess.run(
|
|
["ffprobe", "-v", "error", "-show_entries", "format=duration",
|
|
"-of", "default=noprint_wrappers=1:nokey=1", str(out)],
|
|
capture_output=True, text=True, check=True,
|
|
).stdout.strip())
|
|
# 1s intro + 4s body + 1s outro.
|
|
assert abs(dur - 6.0) < 0.5
|
|
|
|
# Assert lyrics are burned in: a frame ~1s into the body must have bright text
|
|
# pixels the empty title card does not.
|
|
frame = tmp_path / "f.png"
|
|
subprocess.run(
|
|
["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-ss", "2.0",
|
|
"-i", str(out), "-frames:v", "1", str(frame)],
|
|
check=True,
|
|
)
|
|
from PIL import Image
|
|
img = Image.open(frame).convert("L")
|
|
# Central lyric band should contain near-white text pixels.
|
|
band = img.crop((0, 900, 1080, 1500))
|
|
assert band.getextrema()[1] > 180, "expected bright lyric text in the body frame"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"intro_enabled,end_enabled,expected",
|
|
[(False, True, 5.0), (True, False, 5.0), (False, False, 4.0)],
|
|
)
|
|
def test_render_portrait_omits_screens_the_theme_leaves_out(tmp_path, intro_enabled, end_enabled, expected):
|
|
audio = tmp_path / "instr.flac"
|
|
subprocess.run(
|
|
["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-f", "lavfi",
|
|
"-i", "anullsrc=r=44100:cl=stereo", "-t", "4", str(audio)],
|
|
check=True,
|
|
)
|
|
out = tmp_path / "portrait.mp4"
|
|
styles = {
|
|
"karaoke": {},
|
|
"intro": {"video_duration": 1, "enabled": intro_enabled},
|
|
"end": {"video_duration": 1, "enabled": end_enabled},
|
|
}
|
|
render_portrait_video(
|
|
correction_result=_fixture_result(),
|
|
instrumental_path=str(audio),
|
|
styles=styles,
|
|
artist="Test Artist",
|
|
title="Test Title",
|
|
output_path=str(out),
|
|
layout=PortraitLayout(),
|
|
)
|
|
dur = float(subprocess.run(
|
|
["ffprobe", "-v", "error", "-show_entries", "format=duration",
|
|
"-of", "default=noprint_wrappers=1:nokey=1", str(out)],
|
|
capture_output=True, text=True, check=True,
|
|
).stdout.strip())
|
|
assert abs(dur - expected) < 0.5
|