How to Create Rolling Credits with FFmpeg Drawtext
This guide explains how to generate a vertical rolling credits
sequence using the FFmpeg drawtext filter. You will learn
how to configure the animation formulas, structure your credits in an
external text file, format the text for proper alignment, and control
the scroll speed to achieve smooth, readable playback.
1. Prepare the Credits Text File
For a rolling credits sequence, putting text directly in the command
line is impractical. Create a plain text file named
credits.txt in your working directory. Ensure there are
extra empty lines at the beginning and end to allow the text to roll
cleanly into and out of the frame.
Example credits.txt:
DIRECTED BY
Jane Doe
PRODUCED BY
John Smith
LEAD ACTORS
Alice Johnson
Robert Lee
CINEMATOGRAPHY
Mark Davis
SPECIAL THANKS
The Open Source Community
2. Basic Command Syntax
To generate a standalone credits video over a plain black background,
use the color filter source combined with
drawtext:
ffmpeg -f lavfi -i color=c=black:s=1920x1080:r=60:d=20 -vf \
"drawtext=fontfile=/path/to/font.ttf:textfile=credits.txt:\
fontsize=36:fontcolor=white:x=(w-text_w)/2:y=h-t*120" \
-c:v libx264 -pix_fmt yuv420p credits.mp4To apply rolling credits over an existing video
(input.mp4):
ffmpeg -i input.mp4 -vf \
"drawtext=fontfile=/path/to/font.ttf:textfile=credits.txt:\
fontsize=36:fontcolor=white:x=(w-text_w)/2:y=h-t*120" \
-c:v libx264 -c:a copy output.mp43. Understanding the Coordinate Expressions
The rolling effect relies on dynamic mathematical expressions for the
x and y parameters:
x=(w-text_w)/2: Centers the text horizontally.wis the input width, andtext_wis the rendered width of the longest line of text.y=h-t*120: Controls the vertical motion.his the video height (starting the text just off the bottom edge at time zero).trepresents the elapsed time in seconds.120is the speed in pixels per second. Increasing this number speeds up the scroll; decreasing it slows it down.
4. Dynamic Timing Across a Specific Duration
If you need the credits to scroll through their entire length across
an exact duration, use the rendered height variable
(text_h):
ffmpeg -f lavfi -i color=c=black:s=1920x1080:r=60:d=30 -vf \
"drawtext=fontfile=/path/to/font.ttf:textfile=credits.txt:\
fontsize=36:fontcolor=white:x=(w-text_w)/2:y=h-(h+text_h)*(t/30)" \
-c:v libx264 -pix_fmt yuv420p credits.mp4In this formula:
h + text_hrepresents the total travel distance required for the text to enter the bottom and exit off the top.t/30scales the movement progress across a 30-second duration. Replace30with your desired video length.
5. Preventing Text Jitter
Text can appear to stutter or jitter if the movement calculation lands on fractional pixel values. You can round the vertical position to the nearest integer to ensure stable movement:
y='round(h-(h+text_h)*(t/30))'Additionally, rendering at a higher frame rate (such as 60 fps with
:r=60) significantly reduces perceived judder during
vertical scrolling compared to standard 24 or 30 fps playback.