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:
fontsize: Controls the size of the text.fontfileorfont: Specifies the font family or the direct path to the font file.fontcolor: Defines the color of the text.
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.mp41. 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).
Method A: Using a Font File (Recommended)
This is the most reliable method. Use the fontfile
parameter and provide the absolute path to a .ttf
(TrueType) or .otf (OpenType) file.
- Linux:
fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf - macOS:
fontfile=/Library/Fonts/Arial.ttf - Windows:
fontfile='C\:/Windows/Fonts/arial.ttf'(Note the backslash escaping for Windows paths)
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=Arial2. Configuring Font Size
The fontsize parameter accepts an integer that
represents the text height in pixels.
fontsize=48You 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.
Color Names: FFmpeg supports standard color names like
white,black,red,blue,yellow, andgreen.fontcolor=yellowHexadecimal Codes: You can use 6-digit hex codes (RGB) or 8-digit hex codes (RGBA for transparency). You must prefix the hex code with
0x.fontcolor=0xFF0000 @ 1.0 (Red with full opacity) fontcolor=0x00FF00@0.5 (Green with 50% opacity)Hex Strings: Alternatively, you can use standard CSS-like hex strings wrapped in quotes.
fontcolor='#FF5733'
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.mp4In 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.