From fa6349b15e6d496db438632275af0df3a77795b5 Mon Sep 17 00:00:00 2001 From: hbrain Date: Tue, 26 May 2026 04:48:00 +0000 Subject: [PATCH] Strip unsupported symbols from captions --- movmaker.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/movmaker.py b/movmaker.py index fbdf4ed..347f082 100755 --- a/movmaker.py +++ b/movmaker.py @@ -547,6 +547,25 @@ def parse_data_file(path: Path | None) -> MovieData: return data +def strip_unsupported_caption_chars(text: str) -> str: + """Remove characters that bundled caption fonts cannot render reliably. + + FFmpeg drawtext does not provide dependable emoji fallback for our bundled + caption fonts, so emoji/symbol glyphs become unknown-character boxes in the + final video. Keep normal letters, numbers, punctuation, spacing, and marks; + drop symbols such as emoji. + """ + cleaned = [] + for ch in text: + cat = unicodedata.category(ch) + if cat.startswith("C"): + continue + if cat.startswith("S"): + continue + cleaned.append(ch) + return re.sub(r"\s+", " ", "".join(cleaned)).strip() + + def drawtext_escape(text: str) -> str: # Escape for ffmpeg drawtext text=... without surrounding quotes. return ( @@ -842,7 +861,11 @@ def build_video( f"if(lt(t\\,{start + caption_fade:.3f})\\,(t-{start:.3f})/{caption_fade:.3f}\\," f"if(lt(t\\,{end - caption_fade:.3f})\\,1\\,({end:.3f}-t)/{caption_fade:.3f}))" ) if caption_fade > 0 else "1" - caption_lines = [line.strip() for line in caption.split("|") if line.strip()] + caption_lines = [] + for line in caption.split("|"): + clean_line = strip_unsupported_caption_chars(line.strip()) + if clean_line: + caption_lines.append(clean_line) line_gap = int(caption_size * 1.2) block_height = line_gap * (len(caption_lines) - 1) for line_idx, caption_line in enumerate(caption_lines):