Use when the user has a video + an SRT and wants the subtitles either burned into the pixels (libass, always-visible) or soft-muxed as a togglable track. Als...
用于将字幕烧入视频(libass,始终可见)或软封装为可切换轨道。
jianshuo
未分类clawhubv0.1.01 版本100000Key: 无需
★ 0
Stars
📥 248
下载
💾 0
安装
1
版本
#latest
概述
wjs-burning-subtitles
Video + SRT → video with subtitles. Also the final-encode stage for the localization pipeline: takes a video, an optional dub track from /wjs-dubbing-video, and an optional SRT to burn, and produces the upload-ready MP4 in one ffmpeg pass. No cascade of decodes/re-encodes.
When to use
User has an SRT and wants it always-visible on the video (burn-in for 微信视频号 / 抖音 / WeChat — players that won't honor embedded subtitle tracks).
User wants a togglable subtitle track (soft-mux) for QuickTime / VLC / IINA / mobile players that support mov_text.
Final composite after /wjs-dubbing-video: burn target-language subs + mix dub over original-as-bed in one encode.
When NOT to use
No SRT yet → run /wjs-transcribing-audio then /wjs-translating-subtitles first.
HTML/CSS captions (kinetic, per-word highlights, custom fonts) on a clip composed in HyperFrames → use /wjs-overlaying-video instead. Don't mix libass burn-in with HyperFrames captions on the same output.
The "subtitles" are actually motion graphics (animated callouts, lower-thirds with logos, kinetic typography) → that's /wjs-overlaying-video, not this skill.
The 3 modes of render.py
scripts/render.py auto-detects mode from flags:
Subtitles only — --video + --srt → re-encodes video with burned subs, original audio passes through.
Dub only — --video + --dub → keeps original video stream; replaces or mixes the audio track.
Full localized cut — --video + --srt + --dub → burns subs AND mixes dub. By default keeps original audio at low volume as a "bed" under the dub (set --bed-volume 0 or --no-original-audio to drop it).
Burn-in requires an ffmpeg built with libass. The script auto-downloads a static libass-enabled build from evermeet.cx into /tmp/ff_bin/ on first use if needed.
Soft-mux (togglable subtitle track)
Player apps can show/hide. Works with any ffmpeg build — does not need libass:
render.py --video IN.mp4 --srt SUB.srt --soft-mux runs this path.
Hardcoded burn-in (always visible, libass)
Required for WeChat/抖音/朋友圈 etc. where the player will not honor embedded subtitle tracks.
Verify libass is available BEFORE promising burn-in
ffmpeg -filters 2>&1 | grep -E "subtitles|^.. ass "
If neither subtitles nor ass shows up, the build lacks libass. Homebrew's default ffmpeg formula is often stripped (no --enable-libass, no --enable-libfreetype, no drawtext). Don't waste time fighting the comma-escaping inside force_style — it will fail with No such filter: 'subtitles' no matter how the shell quotes it.
Fastest fix on macOS — drop in a static build, no system changes
Then use $FF instead of ffmpeg for the render. The brew binary is fine for everything else (probe, audio extraction, soft-mux). render.py does this auto-fallback if its default ffmpeg lacks libass.
Burn-in render with style overrides
🛑 Checkpoint — confirm before full-render. Burn-in re-encodes the entire video (minutes of CPU on a 5-min clip). Before kicking it off:
Render only the first 30s with -t 30 for a fast preview.
Extract a frame from the longest-line cue (see Fontsize calibration below) and Read it.
Show the user the preview frame + the cue text, ask: "字号/字体/边距 OK 吗?OK 才跑全片。" Wait for explicit confirmation.
Skip the checkpoint only if the user has already approved a full render of this exact video at this exact font config in the same conversation.
Inside force_style, escape every comma as \, (the filter graph parser eats the bare comma as a chain separator). All other special chars are fine.
Fontsize calibration — critical
libass scales its internal PlayRes up to the actual video resolution. The number you pass is not pixels in the output. As a starting calibration on a 544×960 vertical phone video, Fontsize=22 rendered each Chinese character at ~55px wide and overflowed the frame, while Fontsize=12 rendered at ~30–35px wide and fit cleanly with 15-char lines.
Rule of thumb: start at Fontsize=12, render, then always extract a frame and look:
$FF -ss 30 -i output.mp4 -frames:v 1 /tmp/frame.png -y
# then Read /tmp/frame.png to verify the longest-line cue fits
Pick a timestamp that lands on the cue with the most characters per line — short lines won't expose overflow. Add MarginL=20 MarginR=20 as a safety inset; never trust default left/right margins.
Style cheatsheet
Keys that matter (libass force_style):
Fontname=PingFang SC — macOS default CJK; alternates: Songti SC, Heiti SC, STHeiti, Hiragino Sans GB.
Fontsize=12 — start small, scale up only after frame check.
PrimaryColour=&H00FFFFFF — white text (BBGGRR + alpha).
OutlineColour=&H00000000 — black outline.
BorderStyle=1 — outline only (clean over varied backgrounds). Use BorderStyle=3 for an opaque box behind text when the background is busy.
Outline=2 — 2px outline thickness.
Shadow=1 — subtle drop shadow.
MarginL=20 MarginR=20 — keep text inside the frame.
MarginV=40 — vertical distance from the bottom edge.
SRT line-length discipline for burn-in
Even with correct Fontsize, lines that are too long will wrap or overflow. Keep each on-screen line ≤ ~15 Chinese characters (~42 Latin chars). Use explicit \n line breaks inside the SRT block — do not rely on auto-wrapping. Two short lines beat one long one every time. (This is upstream discipline — /wjs-translating-subtitles should already cap cues at these limits.)
Audio mixing — keep the original as a low-volume bed
A pure dub-only track sounds dubbed (because it is). Mixing the original audio at low volume under the dub gives the "professional translation" feel — you still hear the speaker's breath, emphasis, and laughter, just under the new voice.
Full cut: _final.mp4 (re-encoded video with burned subs + mixed audio)
Anti-patterns
❌ Promising burn-in without verifying libass. Check ffmpeg -filters | grep subtitles first; auto-fall back to evermeet static build if missing.
❌ Committing a burn render without a frame check. Always extract a frame at the longest-line cue and Read it before kicking off the full render.
❌ Bare commas inside force_style. The filter graph parser eats them. Escape every internal comma as \,.
❌ Mixing libass burn-in with HyperFrames captions. Pick ONE caption system per output video. If you're using HTML/CSS captions in /wjs-overlaying-video, don't burn here too.
❌ Using period milliseconds in the SRT. Whisper local writes .mmm; libass tolerates it but other downstream tools choke. Normalize to ,mmm.
❌ Defaulting to BorderStyle=3 (opaque box). Use BorderStyle=1 (outline only) unless the background is genuinely busy — the box looks heavy and dated.
Upstream
/wjs-transcribing-audio + /wjs-translating-subtitles — produce the SRT input.
/wjs-dubbing-video — produces the *__dub.mp4 input for full-localized-cut mode. The dub-only file is technically a finished video; this skill is what mixes the original underneath and burns the subs to make it shippable.
Common pitfalls
Fontsize that worked on one video looks tiny / huge on another. libass scales by PlayRes ratio, not pixels. Recalibrate per video resolution; don't trust a hardcoded value.
Margin defaults clip text on vertical phone videos. Always set MarginL=20 MarginR=20 and MarginV=40 (or higher) explicitly.
mov_text track shows up in QuickTime but not in some Android players. If the target audience is mobile-Chinese, soft-mux is unreliable; burn instead.
Background-bus busy / contrast issues. Increase Outline=2 → Outline=3, or switch to BorderStyle=3 for a translucent box (BackColour=&H80000000 for 50% black).