Add Arabic subtitle support - #1210
Conversation
|
Thank you for the thorough investigation and for putting together such a comprehensive Arabic subtitle implementation. The Tajawal fonts, Raqm detection, Docker updates, documentation, and tests are all greatly appreciated. I also verified the font coverage and ran the full test suite successfully on the PR branch ( Before we merge this, could you please address the following items:
Thank you again for the strong contribution. We look forward to reviewing the update! |
39040f4 to
5ac1619
Compare
|
Thanks for the careful review — all four items are addressed and pushed. 1. Rebase + Italian locale Rebased onto 2. Cross-platform local install
The requirement is now documented per platform in all three READMEs: Docker needs nothing, Linux needs One caveat worth stating plainly: I have no macOS or Windows machine to test against, so I implemented this from your report and verified only the shell logic (syntax, path selection order, idempotency, and the no-Homebrew no-op). I would appreciate your confirmation that the Darwin branch actually flips 3. Process-global warning Replaced the 4. Subtitle geometry Removed from this PR entirely. Both the metric height floor and the no-background visible-pixel centering are gone, along with their two tests. Your measurements match mine, which is what makes taking the "separate it" option easy: Tajawal only moved ~98 px to ~99 px, so Arabic support genuinely does not depend on the change. The underlying issue is still real — MoviePy falls back to the glyph ink box when Pillow's removed Verification: One separate issue you may want to know about While running the Docker image locally I found that the That is independent of Arabic support, but it does mean the |
|
Thanks, the updates address the review feedback. |
Bundle an Arabic font and enable complex text layout so right-to-left subtitles render with joined letters and correct word order. - Add Tajawal Regular/Bold (SIL OFL) to resource/fonts. Tajawal covers Arabic, Latin and both digit sets, so mixed-script subtitles render from a single font. The font picker already discovers .ttf files, so no UI change is needed. - Install libraqm0 in both Docker images. Pillow wheels no longer bundle Raqm but still load it at runtime; without it Pillow falls back to basic layout, which leaves Arabic letters unjoined and in reversed order even when the font has the glyphs. - Add the Homebrew library directory to DYLD_LIBRARY_PATH in webui.sh on macOS, since Pillow dlopens libraqm/libfribidi from outside the default search path. - Warn in the WebUI and once per generate_video() call when subtitles contain right-to-left text but no shaping engine is available, since the failure is otherwise silent. - Document the requirement per platform, including that the Windows Pillow wheel needs an external FriBiDi DLL the one-click package does not ship.
5ac1619 to
cf7023f
Compare
|
Rebased onto Dockerfile — I dropped my old edit entirely and kept your new install block as-is, adding
Worth noting that One extra change while rebasing: On the earlier geometry discussion: I squashed the two commits into one while rebasing, since the second was only review fixes to the first and replaying both would have meant resolving the same conflict twice. Verification on the new base: The macOS caveat from my previous comment still stands — the |
Closes #1205.
Adding an Arabic font alone is not enough — Arabic subtitles fail in three independent places. All three are fixed here.
Root causes
1. No bundled font has Arabic glyphs. All nine files in
resource/fontsfail the project's ownsubtitle_font_supports_textcheck for Arabic, so subtitles render as tofu boxes.2. There is no text shaping / bidi engine. This is the real blocker. Pillow wheels no longer bundle Raqm —
PIL.features.check("raqm")isFalseon bothlinux/amd64andlinux/arm64with the Pillow thatmoviepy==2.2.1pulls in. Pillow then falls back to BASIC layout, so Arabic renders as isolated, unconnected letters in left-to-right order — unreadable even with a correct Arabic font.Pillow still loads libraqm at runtime, so installing the system package is enough to flip it:
مرحبا بالعالم+ libraqm0libraqm0is available on both image bases (python:3.11-slim-bullseyeandnvidia/cuda:...-ubuntu22.04).3. The subtitle box clips fonts with large vertical metrics. MoviePy computes text height via Pillow's private
_multiline_spacing, which newer Pillow removed; it then falls back to the glyph ink bbox while still positioning the baseline by ascent. Fonts whoseascent + descentexceeds their ink height get their descenders cut off. This is not Arabic-specific — the bundled CJK fonts simply have compact metrics, so it never surfaced — but it bites immediately for typical Arabic fonts.Changes
resource/fonts— addTajawal-Regular.ttf/Tajawal-Bold.ttf(SIL OFL, ~60KB each) plus the license text. Tajawal covers Arabic, Latin and both ASCII and Arabic-Indic digits, so mixed-script subtitles come from one font. Noto Sans Arabic was rejected because it contains no Latin letters — verified with this project's own glyph checker — so any subtitle mixing Arabic with an English word or brand name would show tofu. Cairo publishes only a variable font upstream.get_all_fonts()already discovers.ttf, so the picker needs no change.Dockerfile,Dockerfile.gpu— installlibraqm0.app/services/video.py— floor the subtitle height at the font'sascent + descent + 2 * stroke_width; center the no-background subtitle by its visible pixels (the background branches already did this); detect RTL text and warn once in the task log when no shaping engine is present.webui/Main.py+ all 9 locales — warn in the subtitle settings panel when the script contains RTL text but Raqm is unavailable, so the user finds out before rendering rather than after.Testing
ruff checkclean.generate_videoon a real render: Arabic renders joined and right-to-left; mixed Arabic/Latin bidi is correct (مرحبا MoneyPrinterTurbo 2026placesمرحباon the right); plain, rectangular-background and rounded-background paths all verified.Note for reviewers
The height/centering fix changes subtitle geometry slightly for existing users: with
MicrosoftYaHeiBoldat size 60 the box grows from 95px to 118px and bottom-anchored text moves up about 26px. It is the more correct result — centering is now exact and tall-metric fonts no longer clip — but Tajawal's metrics are compact enough that Arabic works without it. If you would rather keep existing output byte-identical, that part can be dropped on its own without affecting Arabic support.Known limitation
split_long_tokeninwrap_textstill splits character by character, which breaks Arabic letter joining for a single word wider than the wrap width. Rare in practice since Arabic is space-delimited; left unchanged to keep this PR focused.