mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-12-02 01:48:08 +09:00
## Summary Japanese (and other CJK) karaoke videos rendered with **overlapping lyric lines** that ran off both screen edges — reported for job `4dcca2d6` (レッツゴー!陰陽師). **Root cause:** `SegmentResizer` split lines using raw **character count** (`len(text) <= max_line_length`), a proxy for visual width calibrated for Latin. East-Asian Wide/Fullwidth glyphs render ~2.5× a Latin character and CJK has no inter-word spaces, so a Japanese line well under the *character* budget was ~2× too wide for the 4K frame. With no `WrapStyle` set, libass smart-wraps the too-wide line onto a second physical row that lands on the next slot's fixed Y position → overlap. ## Changes - **Display-width metric** (`display_width`, `unicodedata.east_asian_width` W/F → `WIDE_RATIO=2.7` units, else 1). For pure ASCII/Latin `display_width == len`, so **English/European output is byte-for-byte unchanged** (the Latin natural-break splitter is untouched). - Only the **oversize gate** uses display width; wide-script segments are then split by **word-token packing** (`_pack_words_into_lines`) — boundary-safe (never cuts inside a multi-char CJK token like `立ち向かう`) and counts the inter-token space the renderer emits. - **Preserve wordless oversized segments** instead of dropping them (guards a latent pre-existing bug). - `WIDE_RATIO=2.7` calibrated against the real render (libass ~0.70× effective size; Montserrat/Avenir vs Noto/Hiragino): ~14 CJK glyphs/line, ~83% of 3840px. ## Testing - New `test_segment_resizer_cjk.py` (13 tests): JP/ZH/KO splitting, mixed CJK+Latin, `display_width` units, **exact** English byte-for-byte output, multi-char CJK token non-fragmentation, wordless-segment preservation. - Full backend unit suite: **1701 passed**, 8 skipped. - **End-to-end verified:** re-rendered job `4dcca2d6` through the production `generate_outputs` path with the fix — over-budget lines **21/36 → 0**, and rendered 4K frames confirm no overlap (same timestamps as the original bug report). ## Review Reviewed locally with CodeRabbit (3 cycles → no findings). Findings fixed: CJK-token fragmentation, wordless-segment lyric drop, exact-ASSII test assertion. @coderabbitai ignore --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>