Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 953
Svetlana Gajic Avatar asked Nov 26 '25 23:11

Svetlana Gajic


2 Answers

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
like image 144
Romualdo Arrechea Hernández Avatar answered Nov 28 '25 16:11

Romualdo Arrechea Hernández


It's easier to use the subtitles filter instead of drawtext to add a full stroke.

subtitles filter

enter image description here

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 &H and end with &. Default OutlineColour is black (&H000000&).

drawtext filter

enter image description here

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
  • bordercolor can accept hexadecimal values and you can also change the stroke opacity, such as with bordercolor=#[email protected].

  • See the drawtext filter documentation for more info.

like image 42
llogan Avatar answered Nov 28 '25 17:11

llogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!