feat(remotion-composer): CJK-aware captions and caption styling props - #507
Open
sakuraozation wants to merge 1 commit into
Open
feat(remotion-composer): CJK-aware captions and caption styling props#507sakuraozation wants to merge 1 commit into
sakuraozation wants to merge 1 commit into
Conversation
CaptionOverlay assumes space-delimited text: it hardcodes a " " between words and lets lines wrap anywhere inside a word. For CJK captions this produces spurious inter-word spaces (Japanese does not use them) and mid-word line breaks, including punctuation stranded at line starts. Changes: - CaptionOverlay: new wordSeparator prop (default " " keeps current behavior; CJK callers pass ""). Each word renders as an unbreakable inline block so lines wrap only at word boundaries - visually unchanged for space-delimited text, fixes mid-word breaks for CJK. - WordCaption: optional pageBreakAfter flag; buildPages flushes the page early when set, so pages can align with sentence/scene boundaries instead of splitting a clause across pages. - TalkingHead: exposes captionColor / captionBackgroundColor (previously hardcoded inline), captionFontFamily, and captionWordSeparator, all defaulting to the current values. Tested by rendering TalkingHead stills with Japanese captions before and after (screenshots in PR), and with default props to confirm the space-delimited rendering is unchanged. Used in production for Japanese vertical ad videos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CaptionOverlayassumes space-delimited text, which breaks captions for CJK languages in three ways:" "is rendered between words — Japanese/Chinese don't use inter-word spaces, so captions show spurious gaps.wordsPerPagewords regardless of sentence boundaries, so a clause from the next sentence can leak onto the current page.This PR makes the caption system CJK-capable while keeping the default rendering for space-delimited languages pixel-identical, and exposes the caption colors that
TalkingHeadpreviously hardcoded.Before / after (same props, Japanese captions — the caption text itself explains the fix: "Japanese captions don't put spaces between words!"):
Before: spurious spaces, a break in the middle of 単語のあいだに, and a stranded ん! at a line start. After: no spaces, wraps only at word (clause) boundaries.
Related issue
None filed — happy to open one first if you prefer issue-first workflow.
Changes
CaptionOverlay: newwordSeparatorprop (default" "keeps current behavior; CJK callers pass"").CaptionOverlay: each word renders as an unbreakable inline block, so lines wrap only at word boundaries. For space-delimited text this matches the previous behavior (browsers already broke at the spaces); for CJK it prevents mid-word breaks.WordCaption: optionalpageBreakAfterflag;buildPagesflushes the page early when set, letting callers align pages with sentence/scene boundaries.TalkingHead: exposescaptionColor/captionBackgroundColor(previously hardcoded inline),captionFontFamily, andcaptionWordSeparator. All default to the current values, so existing props files render identically.One known limitation, by design: a single word/chunk wider than the caption box will overflow rather than break. Callers control chunk granularity (for Japanese, clause-level chunks of 2–10 characters are natural), so this hasn't been a problem in practice.
Testing
resolveAssetfix (fix(remotion-composer): resolve videoSrc through resolveAsset in TalkingHead #506) applied so the demo clip loads; the caption diff is exactly this branch." ", and word-boundary wrapping matches the browser's existing space-based breaks).tsc --noEmitclean.wordSeparator: "",pageBreakAfteron scene boundaries, and a Japanese rounded-gothiccaptionFontFamily.Checklist
Disclosure: this patch was developed with AI assistance, then human-reviewed and verified in production use. Happy to adjust anything to match project conventions.