Strip unsupported symbols from captions
This commit is contained in:
parent
2c8a997044
commit
fa6349b15e
1 changed files with 24 additions and 1 deletions
25
movmaker.py
25
movmaker.py
|
|
@ -547,6 +547,25 @@ def parse_data_file(path: Path | None) -> MovieData:
|
||||||
return data
|
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:
|
def drawtext_escape(text: str) -> str:
|
||||||
# Escape for ffmpeg drawtext text=... without surrounding quotes.
|
# Escape for ffmpeg drawtext text=... without surrounding quotes.
|
||||||
return (
|
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\\,{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}))"
|
f"if(lt(t\\,{end - caption_fade:.3f})\\,1\\,({end:.3f}-t)/{caption_fade:.3f}))"
|
||||||
) if caption_fade > 0 else "1"
|
) 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)
|
line_gap = int(caption_size * 1.2)
|
||||||
block_height = line_gap * (len(caption_lines) - 1)
|
block_height = line_gap * (len(caption_lines) - 1)
|
||||||
for line_idx, caption_line in enumerate(caption_lines):
|
for line_idx, caption_line in enumerate(caption_lines):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue