Creating video containing animated text using FFMPEG alone
Solution 1:
You can use the drawtext filter.
Dynamic text
The text can be changed during encoding if you use textfile
and reload
options:
textfile
A text file containing text to be drawn. The text must be a sequence of UTF-8 encoded characters.reload
If set to 1, the textfile will be reloaded before each frame. Be sure to update it atomically, or it may be read partially, or even fail.
Animate
The text can move around using expressions within the x
and y
drawtext options. See the drawtext documentation for a list of constants and functions.
Timeline editing
Some filters, such as drawtext, support the enable
option meaning you can turn the filter off and on. You can see what filters support timeline with:
ffmpeg -filters
Example
If you have an input video that you want to overlay with text:
ffmpeg -i input -vf "drawtext=enable='gte(t,3)':fontfile=Vera.ttf:textfile=text.txt:reload=1:y=h-line_h-10:x=(W/tw)*n" output
- This will enable the drawtext filter after 3 seconds
- Every time
text.txt
is updated the text will change - The words will move on the screen from the left to the right (I suck at these expressions but you'll get the idea)
If you have no input video and would just like to generate the text on black background:
ffmpeg -f lavfi -i "color=color=black, drawtext=enable='gte(t,3)':fontfile=Vera.ttf:fontcolor=white:textfile=text.txt:reload=1:y=h-line_h-10:x=(W/tw)*n" -t 5 output
Here, -t 5
specifies the overall length of the output. (If not specified, the encoding would run forever.) The font color is set to white so the text becomes visible.