Center Text Box at Bottom of Video Using FFmpeg
This article explains how to position a text box at the bottom center
of a video using the FFmpeg drawtext filter. You will learn
the mathematical formulas required for perfect horizontal and vertical
alignment, how to style the background text box, and how to execute the
complete command-line instruction for your video editing workflows.
To position text and its background box at the bottom center of a
video, you must use specific mathematical variables within the
drawtext filter’s x (horizontal) and
y (vertical) coordinates.
The Math for Bottom-Center Alignment
FFmpeg uses the following variables to calculate positions
dynamically: * w: Width of the input video *
h: Height of the input video * tw: Width of
the rendered text * th: Height of the rendered text
To center the text horizontally, set the x coordinate
to:
x=(w-tw)/2
To position the text at the bottom of the video, set the
y coordinate to the total height minus the text height,
minus a padding value (e.g., 50 pixels) to keep it from touching the
very edge of the screen:
y=h-th-50
Enabling the Text Box
To place a background box behind the text, you need to enable the box
parameter and define its styling: * box=1: Enables the
background box. * boxcolor=black@0.6: Sets the box color to
black with a 60% opacity. * boxborderw=10: Adds 10 pixels
of padding around the text inside the box.
Complete FFmpeg Command
Combine these parameters into a single filtergraph command. Here is the template to use:
ffmpeg -i input.mp4 -vf "drawtext=text='Your Text Here':fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=10:x=(w-tw)/2:y=h-th-50" -c:a copy output.mp4Parameter Breakdown
-i input.mp4: Specifies your source video file.-vf "drawtext=...": Applies the video filtergraph and calls thedrawtextfilter.text='Your Text Here': The text you want to display on the video.fontcolor=white: Sets the text color to white for contrast.fontsize=24: Sets the size of the font.box=1:boxcolor=black@0.5:boxborderw=10: Creates a semi-transparent black background box with a padding of 10 pixels.x=(w-tw)/2: Centers the box and text horizontally.y=h-th-50: Positions the box and text 50 pixels from the bottom of the video frame.-c:a copy: Copies the audio stream without re-encoding to save processing time.output.mp4: The path to the newly generated video file.