Skip to content

Drawtext

Video Single output Transform

Draw text on top of video frames using libfreetype library.

FFmpeg filter: drawtext — the official reference.

Add it to a graph. The explicit form works for every filter — bind it to its input and read the result from outputs():

$node = $video->addFilter(new Drawtext(…));
$result = $node->outputs()[0];

Shorthand. Single-output filters can skip the node — apply() returns the result stream directly:

$result = $video->apply(new Drawtext(…));

TODO — when this filter shines: what it’s the right tool for, what to reach for instead when it isn’t, and how it composes with neighbouring filters.

TODO — prose: how the filter actually works and what its key parameters mean (the explanation FFmpeg’s terse option help omits).

TODO — runnable PHP, with the equivalent ffmpeg CLI alongside.

TODO

TODO

ParameterTypeDefaultRange / valuesDescription
fontfilestring——set font file
textstring——set text
textfilestring——set text file
fontcolorstringblack—set foreground color
fontcolor_exprstring——set foreground color expression
boxcolorstringwhite—set box color
bordercolorstringblack—set border color
shadowcolorstringblack—set shadow color
boxboolfalse—set box
boxborderwstring0—set box borders width
line_spacingint0—set line spacing in pixels
fontsizeint|float|string—expressionset font size
text_alignint|string0—set text alignment
xint|float|string0expressionset x expression
yint|float|string0expressionset y expression
boxwint0≥ 0set box width
boxhint0≥ 0set box height
shadowxint0—set shadow x offset
shadowyint0—set shadow y offset
borderwint0—set border width
tabsizeint4≥ 0set tab size
basetimeint——set base time
fontstringSans—Font name
expansionDrawtextExpansionnormalnone, normal, strftimeset the expansion mode
y_alignDrawtextYAligntexttext, baseline, fontset the y alignment
timecodestring——set initial timecode
tc24hmaxboolfalse—set 24 hours max (timecode only)
timecode_ratestring——set rate (timecode only)
reloadint0≥ 0reload text file at specified frame interval
alphastring1—apply alpha while rendering
fix_boundsboolfalse—check and fix text coords to avoid clipping
start_numberint0≥ 0start frame number for n/frame_num variable
text_sourcestring——the source of text
text_shapingbooltrue—attempt to shape text before drawing
ft_load_flagsint|string0—set font loading flags for libfreetype

FFmpeg also names these options (use the parameter shown above): r → timecode_rate, rate → timecode_rate.


Maps to FFmpeg’s drawtext filter. Verified against ffmpeg n7.1.1.

An Artisan Build project.

Built on FFmpeg — an independent binding, not affiliated with or endorsed by the FFmpeg project. Support FFmpeg.