FFmpeg drawtext印地语字体排版异常及use_kerning用法咨询
Let's break down your problem and walk through the fixes step by step:
First, a clear answer upfront: the use_kerning parameter won't solve your text ordering or shaping issue. That setting only controls kerning—adjusting spacing between specific character pairs for smoother readability—and has no impact on complex script rendering or text direction for languages like Hindi.
Why Your Current Command Isn't Working
Devanagari (the script used for Hindi) relies on complex text shaping to display correctly: vowels attached to consonants, conjunct character combinations, and proper glyph composition. Even with text_shaping=1 and HarfBuzz/Fribidi enabled, there are a few key missing pieces in your setup.
Step-by-Step Solutions
Confirm FFmpeg Has Required Libraries
First, check if your FFmpeg build actually includes HarfBuzz and Fribidi support. Run this command:ffmpeg -versionLook for
--enable-libharfbuzzand--enable-libfribidiin the output. If they're missing, you'll need to recompile FFmpeg with these flags enabled to handle complex scripts.Switch to a Devanagari-Compatible Font
The font you're using (/usr/share/xx.ttf) likely doesn't support Devanagari script. Use a font designed for Hindi, like:- Noto Sans Devanagari (open-source, widely available)
- Mangal (common system font for Hindi)
- Kruti Dev (popular for Hindi typography)
Fix Your Text's Unicode Sequence
The text you provided (1. पिता माता िस्रफ) has an invalid Unicode sequence:िस्रफis a broken version of the correct wordसिर्फ. Ensure your input text uses properly composed Devanagari characters—broken sequences will never render correctly, even with the right parameters.Revise the drawtext Command
Here's a corrected command with all critical parameters set properly:ffmpeg -framerate 30 -t 10 -i /opt/test.png -vf "drawtext=text_shaping=1:fontcolor=white:fontsize=60:fontfile=/usr/share/fonts/NotoSansDevanagari-Regular.ttf:text='1. पिता माता सिर्फ':y='max(550,700-t*200)':x=40,format=yuv420p" /usr/share/nginx/html/hello_v.mp4Key details:
text_shaping=1: This is mandatory to enable HarfBuzz's complex script handling for Devanagari.- No need for
direction=rtl: Devanagari is a left-to-right (LTR) script—direction=rtlonly applies to languages like Arabic or Hebrew.
Quick Note on use_kerning
If you want to adjust character spacing for better readability, you can add use_kerning=1 (it's enabled by default) or use_kerning=0 to disable it. For example:
drawtext=text_shaping=1:use_kerning=1:fontcolor=white:...
But remember, this won't fix your core rendering issue—it's just a spacing tweak.
内容的提问来源于stack exchange,提问作者Vinoth Poovalingam

