'Is it possible to add stroke to text in ffmpeg?
I would like to add black stroke to text in ffmpeg. Is it possible?
-c:v libx264 -vf "hue=h=0, drawtext=fontfile=../bin/RobotoCondensed-Bold.ttf:text='Hello.':fontcolor=white: fontsize=158: x=0+(w-text_w)/2: y=50+(h-text_h-line_h)/2" -c:a copy -shortest -pix_fmt yuv420p ../bin/ENG_01.mov
Solution 1:[1]
You can change border-color and width of border by using drawtext and adding these parameters
bordercolor=black:
borderw=5:
Your code will look
-c:v libx264 \
-vf "hue=h=0,\
drawtext=fontfile=../bin/RobotoCondensed-Bold.ttf:\
text='Hello.':\
bordercolor=white:\
borderw=5:\
fontcolor=white:\
fontsize=158:\
x=0+(w-text_w)/2: y=50+(h-text_h-line_h)/2"\
-c:a copy -shortest -pix_fmt yuv420p \
../bin/ENG_01.mov
Solution 2:[2]
It's easier to use the subtitles filter instead of drawtext to add a full stroke.
subtitles filter
ffmpeg will apply the Outline and OutlineColour options set in ASS files. Or you can manually set these in the ffmpeg command which is useful for other subtitle formats that don't support a stroke:
ffmpeg -i input -filter_complex "subtitles=your_subtitles_file.srt:force_style='Outline=5,OutlineColour=&H000000&'" output
From Advanced Substation Alpha Tags:
The color codes are given in hexadecimal in Blue Green Red order. Note that this is the opposite order of HTML color codes. Color codes must always start with
&Hand end with&. DefaultOutlineColouris black (&H000000&).
drawtext filter
Use the borderw and bordercolor options:
ffmpeg -i input -filter_complex "drawtext=text='drawtext stroke':fontsize=36:fontcolor=white:borderw=4:bordercolor=black:x=(w-text_w)/2:y=(h-text_h)/2" output
bordercolorcan accept hexadecimal values and you can also change the stroke opacity, such as withbordercolor=#[email protected].See the drawtext filter documentation for more info.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jack Slattery |
| Solution 2 |


