How to Set Character Spacing in FFmpeg drawtext

This article explains how to adjust the character spacing (kerning) of rendered text in FFmpeg. While the native drawtext filter does not feature a direct letter-spacing parameter, you can achieve precise character spacing using alternative methods. Below, we cover why this limitation exists and how to implement custom spacing using the advanced subtitles filter with ASS styles, as well as basic workarounds for the standard drawtext filter.


The Limitation of the drawtext Filter

FFmpeg’s drawtext filter uses the FreeType library to render fonts. While FreeType supports font-defined kerning, the drawtext filter itself does not provide a direct option (such as letter_spacing or tracking) to manually increase or decrease the gap between individual characters.

To achieve custom letter spacing, the recommended approach is to use the subtitles filter with Advanced SubStation Alpha (ASS) syntax. If you must use drawtext, manual character separation is the primary workaround.


The most precise way to render text with custom character spacing in FFmpeg is to use the subtitles filter combined with an .ass subtitle file. The ASS format natively supports the \fsp (font spacing) tag, which allows you to define custom letter spacing in pixels.

Step 1: Create an ASS Subtitle File

Create a text file named subtitles.ass and paste the following template. The \fsp10 tag sets the letter spacing to 10 pixels:

[Script Info]
PlayResX: 1920
PlayResY: 1080

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, BackColour, OutlineColour, Bold, Italic, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,60,&H00FFFFFF,&H00000000,&H00000000,0,0,5,10,10,10,1

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:10.00,Default,,0,0,0,,{\fsp10}CUSTOM SPACING TEXT

Note: Change \fsp10 to any integer to increase or decrease the spacing (e.g., \fsp5 or \fsp20).

Step 2: Run the FFmpeg Command

Apply the ASS file to your video using the subtitles filter:

ffmpeg -i input.mp4 -vf "subtitles=subtitles.ass" output.mp4

Method 2: Manual Spacing Workaround with drawtext

If you cannot use external subtitle files and must use the drawtext filter, you can simulate basic character spacing by manually inserting spaces between your characters and adjusting the font size to compensate.

Example Command:

ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:text='C U S T O M  S P A C I N G':fontcolor=white:fontsize=48:x=(w-text_w)/2:y=(h-text_h)/2" output.mp4

Tips for this workaround: