Configure Font Size, Family, and Color in FFmpeg

This guide explains how to customize text overlays using the FFmpeg drawtext filter. You will learn how to adjust the font size, select specific font families or files, and apply custom colors to ensure your text overlays look professional and are easy to read.

The Basic Syntax

To customize text in FFmpeg, you pass specific parameters to the -vf (video filter) flag using the drawtext filter. The three key parameters for styling text are:

Here is a basic template of the command:

ffmpeg -i input.mp4 -vf "drawtext=text='Your Text':fontsize=24:fontfile=/path/to/font.ttf:fontcolor=white" -codec:a copy output.mp4

1. Configuring Font Family

You can define the font family in two ways: by pointing directly to a font file on your system, or by using the system’s font name (which requires FFmpeg to be compiled with --enable-libfontconfig).

This is the most reliable method. Use the fontfile parameter and provide the absolute path to a .ttf (TrueType) or .otf (OpenType) file.

Method B: Using System Font Names

If your FFmpeg build supports fontconfig, you can simply use the font parameter followed by the font name:

font=Arial

2. Configuring Font Size

The fontsize parameter accepts an integer that represents the text height in pixels.

fontsize=48

You can also use basic mathematical expressions. For example, to make the font size dynamically scale to 1/20th of the video height, use:

fontsize='h/20'

3. Configuring Font Color

The fontcolor parameter allows you to style your text using color names, hex codes, or opacity values.


Complete Example

Below is a complete command that overlays the text “Breaking News” in Arial font (size 36, yellow color) near the bottom-center of a video:

ffmpeg -i input.mp4 -vf "drawtext=text='Breaking News':fontfile=/Library/Fonts/Arial.ttf:fontsize=36:fontcolor=yellow:x=(w-text_w)/2:y=h-100" -codec:a copy output.mp4

In this example: * x=(w-text_w)/2 centers the text horizontally. * y=h-100 positions the text 100 pixels from the bottom of the video frame. * -codec:a copy copies the audio stream without re-encoding to save processing time.