How to Adjust ffmpeg drawtext Line Spacing

This article explains how to control and adjust the line spacing of multi-line text rendered using the FFmpeg drawtext video filter. You will learn about the specific parameter used for line spacing, how to apply both positive and negative spacing values, and see practical command-line examples to customize your video overlays.

To adjust the spacing between lines of text in the drawtext filter, you must use the line_spacing parameter. This parameter accepts an integer value (in pixels) that dictates the distance between consecutive lines of text.

The line_spacing Parameter

By default, FFmpeg calculates line spacing based on the font’s metadata. You can override this behavior by appending line_spacing=value to your drawtext filter chain.

Practical Command Example

Here is a basic FFmpeg command demonstrating how to apply line_spacing to a multi-line string. In this example, \n is used to create a line break:

ffmpeg -i input.mp4 -vf "drawtext=fontfile=OpenSans.ttf:text='Line One\nLine Two':fontsize=36:fontcolor=white:line_spacing=20:x=(w-text_w)/2:y=(h-text_h)/2" -codec:a copy output.mp4

Using Negative Line Spacing

Some fonts naturally have large default vertical padding. If you want to compress the lines to make the text more compact, you can use a negative pixel value:

ffmpeg -i input.mp4 -vf "drawtext=fontfile=OpenSans.ttf:text='Top Line\nBottom Line':fontsize=36:fontcolor=white:line_spacing=-8:x=(w-text_w)/2:y=(h-text_h)/2" -codec:a copy output.mp4

Applying Line Spacing with External Text Files

If you are importing a large amount of multi-line text from an external .txt file using the textfile parameter, the line_spacing option works exactly the same way:

ffmpeg -i input.mp4 -vf "drawtext=fontfile=OpenSans.ttf:textfile=subtitles.txt:fontsize=28:fontcolor=yellow:line_spacing=12:x=100:y=100" -codec:a copy output.mp4