Change Vertical Subtitle Alignment in FFmpeg
Burning subtitles directly into a video using FFmpeg allows you to
hardcode text so it appears permanently on any media player. You can
easily adjust the vertical alignment—moving subtitles to the top,
middle, or bottom of the frame, or fine-tuning their exact vertical
offset—by using the force_style option within the
subtitles video filter.
The Subtitle Alignment System
FFmpeg relies on the SubStation Alpha (SSA/ASS) style specification to position text. In this system, alignment is defined by numbers corresponding to a standard numeric keypad:
- Top: 7 (Top-Left), 8 (Top-Center), 9 (Top-Right)
- Middle: 4 (Middle-Left), 5 (Middle-Center), 6 (Middle-Right)
- Bottom: 1 (Bottom-Left), 2 (Bottom-Center), 3 (Bottom-Right)
By default, standard SRT subtitles are rendered at the bottom center
(Alignment=2).
Move Subtitles to the Top of the Video
To move the subtitles to the top-center of the screen, set
Alignment=8 using the force_style
parameter:
ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt:force_style='Alignment=8'" -c:a copy output.mp4Move Subtitles to the Middle of the Screen
To center the subtitles vertically and horizontally:
ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt:force_style='Alignment=5'" -c:a copy output.mp4Fine-Tuning Vertical Position with MarginV
If you want subtitles near the bottom or top but need to adjust the
exact distance from the edge, use the MarginV setting.
MarginV defines the vertical margin in pixels.
To keep subtitles at the bottom center (Alignment=2) but
raise them 50 pixels higher than normal to avoid overlapping on-screen
graphics:
ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt:force_style='Alignment=2,MarginV=50'" -c:a copy output.mp4If Alignment is set to the top (e.g.,
Alignment=8), MarginV dictates how far down
the text appears from the top edge.
Combining Styles
You can combine alignment adjustments with other styling properties such as font size and color:
ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt:force_style='Alignment=8,MarginV=30,FontSize=24,PrimaryColour=&H00FFFFFF&'" -c:a copy output.mp4In this command, the subtitles are anchored to the top center with a 30-pixel margin, a font size of 24, and white text.