FFmpeg drawtext: Change Font Style, Size, and Color
This article provides a straightforward guide on how to customize
text overlays in FFmpeg using the drawtext video filter.
You will learn the exact parameters required to modify the font family,
adjust the text size, and apply custom colors to create
professional-looking subtitles, watermarks, or text overlays on your
videos.
The drawtext filter in FFmpeg uses specific parameters
to control the appearance of text. To customize the style, size, and
color, you will use the fontfile (or font),
fontsize, and fontcolor parameters within your
filter chain.
1. Changing the Font Style
To change the font style, you must point FFmpeg to a font file on
your system using the fontfile parameter. This parameter
accepts absolute paths to TrueType (.ttf) or OpenType
(.otf) files.
If your FFmpeg installation is compiled with fontconfig
support, you can alternatively use the font parameter
followed by the font’s system name (e.g.,
font='Arial').
- Using a specific font file path:
fontfile='/path/to/Arial.ttf' - Using system font name (requires fontconfig):
font='Courier New'
2. Changing the Font Size
To adjust the size of the text, use the fontsize
parameter. This value is defined as an integer representing the font
size in pixels.
- Example:
fontsize=48
3. Changing the Font Color
To modify the text color, use the fontcolor parameter.
FFmpeg supports color names (such as white,
red, blue, yellow), 6-digit
hexadecimal values (prefixed with 0x or #), or
hexadecimal values with alpha transparency channels.
- Using color names:
fontcolor=yellow - Using hexadecimal values:
fontcolor=0xFF5733 - Using color with opacity (80% white):
fontcolor=white@0.8
Complete Command Example
To put these parameters together, apply the -vf (video
filter) flag followed by the drawtext arguments separated
by colons.
Here is a complete command that overlays the text “Sample Video Text” in 48px, bold yellow Arial font, positioned at coordinates (x=100, y=100):
ffmpeg -i input.mp4 -vf "drawtext=text='Sample Video Text':fontfile='/Library/Fonts/Arial Bold.ttf':fontsize=48:fontcolor=yellow:x=100:y=100" -codec:a copy output.mp4Adding Borders and Background Boxes (Optional)
To make your customized text more readable against complex video backgrounds, you can also add borders or a solid background box:
Add a text border: Use
borderw(border width) andbordercolor.borderw=2:bordercolor=blackAdd a background box: Use
box=1andboxcolor.box=1:boxcolor=black@0.5:boxborderw=10