Burn Subtitles into Video with FFmpeg and Change Font Size
This article provides a straightforward guide on how to permanently
burn subtitles into a video file using FFmpeg’s subtitles
filter. You will learn the exact commands needed to hardcode subtitles
from an external file (such as an SRT or ASS file) and how to use the
force_style option to customize the font size, font family,
and other visual properties.
Burning Subtitles with Default Styles
To burn subtitles into a video stream, you must use the video filter
(-vf) flag with the subtitles filter. The
basic command takes your input video and subtitle file, overlays the
text onto the video frames, and re-encodes the video.
Run the following command in your terminal:
ffmpeg -i input.mp4 -vf "subtitles=subs.srt" output.mp4In this command: * -i input.mp4 specifies the input
video. * -vf "subtitles=subs.srt" applies the subtitles
filter using the file subs.srt. * output.mp4
is the resulting video with hardcoded subtitles.
Adjusting the Subtitle Font Size
By default, FFmpeg uses the system’s default font and size
configuration. To customize the font size, you need to pass the
force_style parameter to the subtitles filter.
This parameter accepts Advanced SubStation Alpha (ASS) style
overrides.
To increase or decrease the font size, use the FontSize
property:
ffmpeg -i input.mp4 -vf "subtitles=subs.srt:force_style='FontSize=24'" output.mp4Change 24 to your desired size (defined in points).
Adjusting Font Name and Size Together
You can customize multiple properties at once, such as the font
family (FontName) and the font size, by separating the
style parameters with commas inside the force_style
string:
ffmpeg -i input.mp4 -vf "subtitles=subs.srt:force_style='FontName=Arial,FontSize=20'" output.mp4- FontName: The name of the font installed on your system (e.g., Arial, Verdana, Trebuchet MS).
- FontSize: The size of the text.
Adding Advanced Styling (Colors and Outlines)
To make your subtitles more readable, you can also modify the text
color, outline color, and outline thickness using
force_style:
ffmpeg -i input.mp4 -vf "subtitles=subs.srt:force_style='FontName=Helvetica,FontSize=22,PrimaryColour=&H00FFFF&,OutlineColour=&H000000&,Outline=2'" output.mp4- PrimaryColour: The text color specified in
hexadecimal format (AABBGGRR).
&H00FFFF&represents yellow. - OutlineColour: The color of the text border.
&H000000&represents black. - Outline: The thickness of the border (e.g.,
2pixels).
Requirements for Styling to Work
- Font Availability: The font specified in
FontNamemust be installed on your operating system. - Fontconfig: FFmpeg must be compiled with
--enable-libassand--enable-fontconfigto find and render system fonts properly. If a specified font is not found, FFmpeg will fall back to a default system font.