How to Use FFmpeg force_style to Override SRT Subtitles
This article explains how to use the force_style
parameter within FFmpeg’s subtitles filter to customize and
override the appearance of SRT subtitle files. You will learn the exact
command-line syntax and key style properties required to change subtitle
fonts, colors, sizes, borders, and positions when burning subtitles
directly into your video.
Understanding the force_style Parameter
When burning SubRip (.srt) subtitles into a video using FFmpeg, the
subtitles are converted internally to the Advanced SubStation Alpha
(ASS) format. Because SRT files do not natively support rich styling,
you must use the force_style option in FFmpeg’s
subtitles filter to inject ASS styling rules.
The basic syntax for the command is:
ffmpeg -i input.mp4 -vf "subtitles=subs.srt:force_style='Key=Value,Key=Value'" output.mp4Common Style Properties
The force_style parameter accepts various ASS style
properties. Here are the most commonly used options:
- Fontname: The name of the font installed on your
system (e.g.,
Arial,Helvetica,Verdana). - Fontsize: The size of the text in points.
- PrimaryColour: The fill color of the text in
hexadecimal ABGR format
(
&H<Alpha><Blue><Green><Red>). - OutlineColour: The color of the text border in ABGR format.
- BackColour: The color of the shadow or background box.
- BorderStyle: Use
1for an outline and shadow, or3for an opaque background box behind the text. - Outline: The thickness of the text border (in pixels).
- Shadow: The depth of the text shadow.
- Alignment: Position of the text based on a 10-key
numpad (e.g.,
2is bottom-center,6is middle-right,8is top-center). - MarginV: Vertical margin from the bottom or top border in pixels.
Understanding the ABGR Color Format
Unlike standard HTML hex colors (RGB), ASS styles use ABGR (Alpha,
Blue, Green, Red) format preceded by &H and followed by
&.
- White:
&H00FFFFFF&(No transparency) - Yellow:
&H0000FFFF& - Red:
&H000000FF& - Semi-transparent Black:
&H80000000&(Alpha is80in hex, which is roughly 50% opacity)
Practical Examples
Example 1: Yellow Text with Black Outline
To burn subtitles using Arial font, size 16, yellow text, and a distinct black outline, use the following command:
ffmpeg -i input.mp4 -vf "subtitles=subs.srt:force_style='Fontname=Arial,Fontsize=16,PrimaryColour=&H0000FFFF&,OutlineColour=&H00000000&,Outline=2'" output.mp4Example 2: Text inside a Semi-Transparent Black Box
To make text highly readable by placing it inside a translucent black
bounding box (commonly used in captions), set BorderStyle=3
and define a custom BackColour:
ffmpeg -i input.mp4 -vf "subtitles=subs.srt:force_style='Fontname=Helvetica,Fontsize=18,PrimaryColour=&H00FFFFFF&,BackColour=&H80000000&,BorderStyle=3'" output.mp4Example 3: Adjusting Position and Margins
If you want to raise the bottom-centered subtitles higher up on the
screen to avoid overlapping other elements, increase the
MarginV value:
ffmpeg -i input.mp4 -vf "subtitles=subs.srt:force_style='Fontname=Arial,Fontsize=14,Alignment=2,MarginV=50'" output.mp4Troubleshooting Platform-Specific Escaping
Depending on your operating system’s command-line interface, you may need to escape the quotation marks differently:
- Linux/macOS (Bash/Zsh): Use outer double quotes and
inner single quotes:
"subtitles=subs.srt:force_style='Fontname=Arial,Fontsize=16'" - Windows (Command Prompt): Escape the internal
quotes and colons with backslashes:
-vf "subtitles=subs.srt:force_style='Fontname=Arial\,Fontsize=16'"