Nodes/ComfyUI-Subtitle-Effects/Subtitle Text Replace (文本替换)
ComfyUI Node

Subtitle Text Replace (文本替换)

Fix every typo in your subtitles without touching the source file

By liaowu-boos·Created 3 months ago·Updated 3 months ago· 2
Subtitle Text Replace (文本替换)
  • subtitle_data
  • subtitle_data
  • preview
find
replace_with
use_regexfalse
remove_punctuationfalse

There's a specific kind of pain this node exists to fix: your Whisper transcription nailed the timing but butchered the text, or you transcribed in English and want to burn Chinese, or you just noticed a name is spelled wrong in thirty subtitles. Re-editing the SRT and re-parsing is annoying. SubtitleTextReplace is the search-and-replace node for the ComfyUI-Subtitle-Effects pipeline, and it's the closest thing the pack has to a free pass for sloppy transcripts.

It sits between your subtitle source and any effect node. Wire SUBTITLE_DATA in, get edited SUBTITLE_DATA out - nothing is touched in place, the node deep-copies the entries before it rewrites them, so your source stays pristine.

How it works

Think of it as a per-entry text filter. Every subtitle entry gets passed through your replace rule, then repacked into a fresh SUBTITLE_DATA with the same fps and source. That's the whole mechanism - no rendering, no frames touched, runs in milliseconds.

The two knobs that make it more than a dumb str.replace:

  • use_regex - when on, your find string is treated as a regular expression and handed to re.sub. This is the one that saves you: \bComfyUI\b instead of hoping you caught every case, or ^\s+ to strip leading whitespace. If your find is plain text, leave it off - regex special characters like . will match too much if you don't expect them.
  • remove_punctuation - strips every Unicode punctuation character (anything in the Unicode P category, so it catches full-width Chinese punctuation too). Great for the "clean up for a big bold title" pass, where you don't want ,。! cluttering the frame.

One behavior worth knowing: after replacement, entries that end up with empty text get dropped and the rest are renumbered, so your subtitle indexes stay sequential instead of leaving holes. The preview output shows the edited entries in bracket format so you can check your work in a text node before committing pixels to it.

The inputs that matter

Required: subtitle_data (in), find, and replace_with. That's it. find empty means no replacement happens - so a node with nothing in find and remove_punctuation off is just a passthrough. The two booleans are optional and both default off.

Outputs: subtitle_data (the edited entries, ready for any effect node) and preview (a string you can display).

Install

Part of the ComfyUI-Subtitle-Effects pack:

cd ComfyUI/custom_nodes
git clone https://github.com/liaowu-boos/ComfyUI-Subtitle-Effects.git
cd ComfyUI-Subtitle-Effects
pip install "Pillow>=9.0.0" "jieba>=0.42"

Or install through ComfyUI Manager by searching liaowu-boos/ComfyUI-Subtitle-Effects, then restart ComfyUI. All nodes land under Subtitle Effects. No models to download, CPU-only, effectively free to run.

Common issues

  • remove_punctuation strips more than you wanted. It's aggressive on purpose - it removes all punctuation, including apostrophes and periods inside English. Don't use it on subtitles where don't needs to stay don't.
  • Regex not matching. Remember it's re.sub semantics: find is the pattern, replace_with is the replacement. If you're replacing literal dots or brackets, escape them or keep use_regex off.
  • Nothing changed. Check that the SUBTITLE_DATA actually has entries - wire a SubtitleSource's preview into a display node to confirm you're feeding it real data, because an empty source silently passes through.

It's a small utility, but it's the one you'll reach for every time a transcription comes back wrong - which, if you've used Whisper on real audio, is every time.

CategorySubtitle Effects/Process

Inputs (5)

NameTypeDefaultDescription
subtitle_dataSUBTITLE_DATA
findSTRING
replace_withSTRING
use_regexoptBOOLEANfalse
remove_punctuationoptBOOLEANfalse

Outputs (2)

NameTypeDescription
subtitle_dataSUBTITLE_DATA
previewSTRING