Draw Text with Semi-Transparent Box in FFmpeg

Adding text overlay to a video often requires a background box to ensure the text remains legible against varying background colors. This article provides a straightforward guide on how to use FFmpeg’s drawtext filter to create a highly readable text overlay with a semi-transparent black background box.

To draw a semi-transparent background box behind your text, you must use the drawtext video filter with three specific parameters: box, boxcolor, and boxborderw.

The FFmpeg Command

Here is the standard command structure to achieve this effect:

ffmpeg -i input.mp4 -vf "drawtext=text='Your Text Here':fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=10:x=(w-text_w)/2:y=(h-text_h)/2" -codec:a copy output.mp4

Parameter Breakdown

Customizing the Transparency and Padding

If you want a darker, more prominent box with more padding, you can increase the alpha value and the border width:

boxcolor=black@0.75:boxborderw=20

This configuration increases the opacity of the black box to 75% and expands the padding to 20 pixels, ensuring the text is easily readable even on highly detailed or bright video backgrounds.